diff options
Diffstat (limited to 'src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala')
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | 39 |
1 files changed, 31 insertions, 8 deletions
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 c7ace0f..eaacedc 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | |||
| @@ -10,7 +10,7 @@ import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery | |||
| 10 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Term} | 10 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Term} |
| 11 | 11 | ||
| 12 | /* Local imports */ | 12 | /* Local imports */ |
| 13 | import util.{RDFoxUtil, RSA} | 13 | import util.{Logger, RDFoxUtil, RSA} |
| 14 | import sparql.ConjunctiveQuery | 14 | import sparql.ConjunctiveQuery |
| 15 | 15 | ||
| 16 | object RSAComb extends App { | 16 | object RSAComb extends App { |
| @@ -53,15 +53,38 @@ object RSAComb extends App { | |||
| 53 | 53 | ||
| 54 | val ontology = RSAOntology(ontoPaths: _*) | 54 | val ontology = RSAOntology(ontoPaths: _*) |
| 55 | if (ontology.isRSA) { | 55 | if (ontology.isRSA) { |
| 56 | //println("ONTOLOGY IS RSA") | 56 | |
| 57 | Logger print "Ontology is RSA!" | ||
| 57 | 58 | ||
| 58 | /** Read SPARQL query from file */ | 59 | /** Read SPARQL query from file */ |
| 59 | val source = io.Source.fromFile(queryPath.getAbsoluteFile) | 60 | val strQuery = RDFoxUtil.loadQueryFromFile(queryPath.getAbsoluteFile) |
| 60 | val query = source.getLines mkString "\n" | 61 | val query = ConjunctiveQuery parse strQuery |
| 61 | source.close() | 62 | |
| 63 | query match { | ||
| 64 | case Some(query) => { | ||
| 65 | val answers = ontology ask query | ||
| 66 | Logger.print(s"$answers", Logger.QUIET) | ||
| 67 | Logger print s"Number of answer: ${answers.length}" | ||
| 68 | |||
| 69 | val unfiltered = ontology askUnfiltered query | ||
| 70 | val percentage = unfiltered match { | ||
| 71 | case Some(u) => { | ||
| 72 | Logger.print( | ||
| 73 | s"Number of spurious answers: ${u.length}.", | ||
| 74 | Logger.DEBUG | ||
| 75 | ) | ||
| 76 | if (u.length > 0) (1 - answers.length / u.length) * 100 else 0 | ||
| 77 | } | ||
| 78 | case None => 0 | ||
| 79 | } | ||
| 80 | Logger.print( | ||
| 81 | s"Percentage of spurious answers: $percentage%", | ||
| 82 | Logger.DEBUG | ||
| 83 | ) | ||
| 84 | } | ||
| 85 | case None => | ||
| 86 | throw new RuntimeException("Submitted query is not conjunctive") | ||
| 87 | } | ||
| 62 | 88 | ||
| 63 | /* Compute answers to query */ | ||
| 64 | val answers = ConjunctiveQuery.parse(query).map(ontology ask _) | ||
| 65 | answers map (_.toString) foreach println | ||
| 66 | } | 89 | } |
| 67 | } | 90 | } |
