diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-07 18:08:33 +0000 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-07 18:08:33 +0000 |
commit | b241f9b23b225dec5ffc3f8ddd6c81771091f599 (patch) | |
tree | a88c4f0e1ef1a592cabe15a37cfeb2ac45fefcec | |
parent | daf6c30152f3bb1ac6f10f1eeb783687f1a6a214 (diff) | |
download | RSAComb-b241f9b23b225dec5ffc3f8ddd6c81771091f599.tar.gz RSAComb-b241f9b23b225dec5ffc3f8ddd6c81771091f599.zip |
Add diagnostics for (un)filtered answer ratio
3 files changed, 38 insertions, 5 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 60511af..6891c8c 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | |||
@@ -57,13 +57,29 @@ object RSAComb extends App { | |||
57 | Logger print "Ontology is RSA!" | 57 | Logger print "Ontology is RSA!" |
58 | 58 | ||
59 | /** Read SPARQL query from file */ | 59 | /** Read SPARQL query from file */ |
60 | val query = RDFoxUtil.loadQueryFromFile(queryPath.getAbsoluteFile) | 60 | val strQuery = RDFoxUtil.loadQueryFromFile(queryPath.getAbsoluteFile) |
61 | 61 | val query = ConjunctiveQuery parse strQuery | |
62 | /* Compute answers to query */ | 62 | |
63 | ConjunctiveQuery.parse(query).map(ontology ask _) match { | 63 | query match { |
64 | case Some(answers) => Logger print answers | 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 | if (u.length > 0) (1 - answers.length / u.length) * 100 else 0 | ||
73 | case None => 0 | ||
74 | } | ||
75 | Logger.print( | ||
76 | s"Percentage of spurious answers: $percentage%", | ||
77 | Logger.DEBUG | ||
78 | ) | ||
79 | } | ||
65 | case None => | 80 | case None => |
66 | throw new RuntimeException("Submitted query is not conjunctive") | 81 | throw new RuntimeException("Submitted query is not conjunctive") |
67 | } | 82 | } |
83 | |||
68 | } | 84 | } |
69 | } | 85 | } |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala index 708e4c7..6a34555 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -403,6 +403,20 @@ class RSAOntology(val ontology: OWLOntology) { | |||
403 | answers | 403 | answers |
404 | } | 404 | } |
405 | 405 | ||
406 | /** Returns set of unfiltered answers. | ||
407 | * | ||
408 | * This is equivalent to quering just the canonical model. | ||
409 | * | ||
410 | * @note this method does not load any data to RDFox. The return | ||
411 | * value is considered well defined only after | ||
412 | * [[uk.ac.ox.cs.rsacomb.RSAOntology.ask RSAOntology.ask]] | ||
413 | * for the corresponding query has been called. | ||
414 | */ | ||
415 | def askUnfiltered(cq: ConjunctiveQuery): Option[Seq[Seq[Resource]]] = { | ||
416 | val query = RDFoxUtil.buildDescriptionQuery("QM", cq.variables.length) | ||
417 | queryDataStore(cq, query, RSA.Prefixes) | ||
418 | } | ||
419 | |||
406 | def self(axiom: OWLSubClassOfAxiom): Set[Term] = { | 420 | def self(axiom: OWLSubClassOfAxiom): Set[Term] = { |
407 | // Assuming just one role in the signature of a T5 axiom | 421 | // Assuming just one role in the signature of a T5 axiom |
408 | val role = axiom.objectPropertyExpressionsInSignature(0) | 422 | val role = axiom.objectPropertyExpressionsInSignature(0) |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala index 327ae8e..50cbb86 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala | |||
@@ -17,6 +17,9 @@ class ConjunctiveQueryAnswers( | |||
17 | val answers: Seq[Seq[Resource]] | 17 | val answers: Seq[Seq[Resource]] |
18 | ) { | 18 | ) { |
19 | 19 | ||
20 | /** Returns number of answers. */ | ||
21 | val length: Int = if (bcq) 0 else answers.length | ||
22 | |||
20 | override def toString(): String = | 23 | override def toString(): String = |
21 | if (bcq) { | 24 | if (bcq) { |
22 | if (answers.isEmpty) "FALSE" else "TRUE" | 25 | if (answers.isEmpty) "FALSE" else "TRUE" |