From c29174ade7131639e9ea01c3ce408ee0a873c962 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Tue, 5 Jan 2021 10:19:13 +0000 Subject: Slightly rework main execution --- src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | 85 ++++++++++++--------------- 1 file changed, 39 insertions(+), 46 deletions(-) (limited to 'src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala') diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala index f54884f..0554dbc 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala @@ -1,37 +1,41 @@ package uk.ac.ox.cs.rsacomb -/* Java imports */ import java.io.File import java.util.HashMap import scala.collection.JavaConverters._ - import tech.oxfordsemantic.jrdfox.client.UpdateType -import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Term} +import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery -/* Local imports */ import util.{Logger, RDFoxUtil, RSA} import sparql.ConjunctiveQuery +/** Entry point of the program. + * + * The executable expects a SPARQL query and a non-empty sequence of + * ontology files as arguments. The query file is expected to contain + * exactly one query, while the ontology files will be programmatically + * merged in a single ontology. + * + * @todo better arguments handling is needed. Look into some library + * for this. + * @todo at the moment the input ontology is assumed to be Horn-ALCHOIQ. + * This might not be the case. + */ object RSAComb extends App { val help: String = """ rsacomb - combined approach for CQ answering for RSA ontologies. USAGE - rsacomb ... + rsacomb [...] where - - query: a (single) SPARQL query file. - - ontology: one or more ontologies. + - query: path to a file containing a single SPARQL query + - ontology: one or more ontology files """ - /* Simple arguments handling - * - * TODO: use something better later on - */ - if (args.length < 2) { println(help) sys.exit; @@ -46,52 +50,41 @@ object RSAComb extends App { sys.exit; } - /* TODO: It might be required to check if the ontology in input is - * Horn-ALCHOIQ. At the moment we are assuming this is always the - * case. - */ - val ontology = RSAOntology(ontoPaths: _*) if (ontology.isRSA) { Logger print "Ontology is RSA!" - /** Read SPARQL query from file */ - val strQuery = RDFoxUtil.loadQueryFromFile(queryPath.getAbsoluteFile) - val query = ConjunctiveQuery parse strQuery + val query = RDFoxUtil.loadQueryFromFile(queryPath.getAbsoluteFile) - query match { + ConjunctiveQuery.parse(query) match { case Some(query) => { val answers = ontology ask query Logger.print(s"$answers", Logger.QUIET) Logger print s"Number of answer: ${answers.length} (${answers.lengthWithMultiplicity})" - val unfiltered = ontology askUnfiltered query - unfiltered map { u => - Logger.print( - s"Number of unfiltered answers: ${u.length} (${u.map(_._1).sum}).", - Logger.DEBUG - ) - //u foreach println - val spurious = { - val sp = - RDFoxUtil.buildDescriptionQuery("SP", query.variables.length) - ontology.queryDataStore(query, sp, RSA.Prefixes) - } - spurious map { s => - Logger.print( - s"Number of spurious answers: ${s.length} (${s.map(_._1).sum})", - Logger.DEBUG - ) - //s foreach println - val perc = - if (u.length > 0) (s.length / u.length.toFloat) * 100 else 0 - Logger.print( - s"Percentage of spurious answers: $perc%", - Logger.DEBUG - ) + /* Additional DEBUG information */ + if (Logger.level >= Logger.DEBUG) { + /* Unfiltered rules */ + val unfiltered = ontology askUnfiltered query + unfiltered map { u => + Logger print s"Number of unfiltered answers: ${u.length} (${u.map(_._1).sum})." + + /* Spurious answers */ + val spurious = { + val variables = query.variables.length + val sp = RDFoxUtil.buildDescriptionQuery("SP", variables) + ontology.queryDataStore(query, sp, RSA.Prefixes) + } + spurious map { s => + Logger print s"Number of spurious answers: ${s.length} (${s.map(_._1).sum})" + + /* Spurious/unfiltered percentage */ + val perc = + if (u.length > 0) (s.length / u.length.toFloat) * 100 else 0 + Logger print s"Percentage of spurious answers: $perc%" + } } - } } case None => -- cgit v1.2.3