diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-11-19 23:21:15 +0000 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-11-19 23:21:15 +0000 |
commit | c804109db7bb08cce1246acbca2030c3b979f242 (patch) | |
tree | 79d2d3b26e60647e3a7a58cd1f7e1b06baaad05a | |
parent | 343757e71ff21cf92192147c136a8cc615f273b8 (diff) | |
download | RSAComb-c804109db7bb08cce1246acbca2030c3b979f242.tar.gz RSAComb-c804109db7bb08cce1246acbca2030c3b979f242.zip |
Integrate new ConjunctiveQuery in filtering program computation
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala | 37 | ||||
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | 9 | ||||
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | 3 |
3 files changed, 15 insertions, 34 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala index adc6f56..6df30fd 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala | |||
@@ -30,44 +30,24 @@ import scala.collection.JavaConverters._ | |||
30 | import uk.ac.ox.cs.rsacomb.implicits.RSAAtom | 30 | import uk.ac.ox.cs.rsacomb.implicits.RSAAtom |
31 | import uk.ac.ox.cs.rsacomb.suffix.{RSASuffix, Forward, Backward} | 31 | import uk.ac.ox.cs.rsacomb.suffix.{RSASuffix, Forward, Backward} |
32 | import uk.ac.ox.cs.rsacomb.util.RSA | 32 | import uk.ac.ox.cs.rsacomb.util.RSA |
33 | import uk.ac.ox.cs.rsacomb.sparql.ConjunctiveQuery | ||
33 | 34 | ||
34 | object FilteringProgram { | 35 | object FilteringProgram { |
35 | 36 | ||
36 | def apply(query: SelectQuery, constants: List[Term]): FilteringProgram = | 37 | def apply(query: ConjunctiveQuery, constants: List[Term]): FilteringProgram = |
37 | new FilteringProgram(query, constants) | 38 | new FilteringProgram(query, constants) |
38 | 39 | ||
39 | } // object FilteringProgram | 40 | } // object FilteringProgram |
40 | 41 | ||
41 | class FilteringProgram(query: SelectQuery, constants: List[Term]) | 42 | class FilteringProgram(query: ConjunctiveQuery, constants: List[Term]) |
42 | extends RSAAtom { | 43 | extends RSAAtom { |
43 | 44 | ||
44 | /* Makes mplicit conversion OWLAPI IRI <-> RDFox IRI available */ | 45 | /* Makes mplicit conversion OWLAPI IRI <-> RDFox IRI available */ |
45 | // import implicits.RDFox._ | 46 | // import implicits.RDFox._ |
46 | 47 | ||
47 | implicit val variables: (List[Term], List[Term]) = { | 48 | val answer: List[Term] = query.answer.toList |
48 | val all: Set[Variable] = query.getQueryBody.getWherePattern match { | 49 | val bounded: List[Term] = query.bounded.toList |
49 | case b: ConjunctionPattern => { | 50 | implicit val variables = (answer, bounded) |
50 | b.getConjuncts.asScala.toSet.flatMap { conj: QueryPattern => | ||
51 | conj match { | ||
52 | case c: TriplePattern => | ||
53 | Set(c.getSubject, c.getPredicate, c.getObject).collect { | ||
54 | case v: Variable => v | ||
55 | } | ||
56 | case _ => Set() | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | case _ => Set() | ||
61 | } | ||
62 | if (query.getAllPossibleVariables) { | ||
63 | (all.toList, List()) | ||
64 | } else { | ||
65 | val answer = query.getSelection.asScala.map(_.getVariable).toSet | ||
66 | (answer.toList, (all &~ answer).toList) | ||
67 | } | ||
68 | } | ||
69 | |||
70 | val (answer, bounded) = variables | ||
71 | 51 | ||
72 | val named: List[Rule] = | 52 | val named: List[Rule] = |
73 | constants.map(a => Rule.create(RSA.Named(a))) | 53 | constants.map(a => Rule.create(RSA.Named(a))) |
@@ -108,7 +88,7 @@ class FilteringProgram(query: SelectQuery, constants: List[Term]) | |||
108 | val varV = Variable.create("V") | 88 | val varV = Variable.create("V") |
109 | val varW = Variable.create("W") | 89 | val varW = Variable.create("W") |
110 | // Query formula as a rule body | 90 | // Query formula as a rule body |
111 | val body = queryToBody(query.getQueryBody.getWherePattern) | 91 | val body = queryToBody(query.where) |
112 | // Auxiliar predicates/helpers | 92 | // Auxiliar predicates/helpers |
113 | def not(atom: TupleTableAtom): BodyFormula = Negation.create(atom) | 93 | def not(atom: TupleTableAtom): BodyFormula = Negation.create(atom) |
114 | // val predQM = | 94 | // val predQM = |
@@ -320,7 +300,8 @@ class FilteringProgram(query: SelectQuery, constants: List[Term]) | |||
320 | 300 | ||
321 | /* Rules 8x */ | 301 | /* Rules 8x */ |
322 | val r8a = | 302 | val r8a = |
323 | for (v <- answer) yield Rule.create(RSA.SP, RSA.QM, not(RSA.Named(v))) | 303 | for (v <- answer) |
304 | yield Rule.create(RSA.SP, RSA.QM, not(RSA.Named(v))) | ||
324 | val r8b = | 305 | val r8b = |
325 | Rule.create(RSA.SP, RSA.FK) | 306 | Rule.create(RSA.SP, RSA.FK) |
326 | val r8c = | 307 | val r8c = |
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 28196be..db52793 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | |||
@@ -11,6 +11,7 @@ import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Term} | |||
11 | 11 | ||
12 | /* Local imports */ | 12 | /* Local imports */ |
13 | import util.{RDFoxHelpers, RSA} | 13 | import util.{RDFoxHelpers, RSA} |
14 | import sparql.ConjunctiveQuery | ||
14 | 15 | ||
15 | object RSAComb extends App { | 16 | object RSAComb extends App { |
16 | 17 | ||
@@ -56,8 +57,7 @@ object RSAComb extends App { | |||
56 | if (ontology.isRSA) { | 57 | if (ontology.isRSA) { |
57 | 58 | ||
58 | /* Load query */ | 59 | /* Load query */ |
59 | val query = RDFoxHelpers.parseSelectQuery( | 60 | val query = """ |
60 | """ | ||
61 | PREFIX : <http://example.com/rsa_example.owl#> | 61 | PREFIX : <http://example.com/rsa_example.owl#> |
62 | 62 | ||
63 | SELECT ?X | 63 | SELECT ?X |
@@ -67,11 +67,10 @@ object RSAComb extends App { | |||
67 | ?Y :S ?Z . | 67 | ?Y :S ?Z . |
68 | ?Z a :D . | 68 | ?Z a :D . |
69 | } | 69 | } |
70 | """ | 70 | """ |
71 | ) | ||
72 | 71 | ||
73 | /* Compute answers to query */ | 72 | /* Compute answers to query */ |
74 | query match { | 73 | ConjunctiveQuery(query) match { |
75 | case Some(query) => { | 74 | case Some(query) => { |
76 | 75 | ||
77 | import implicits.JavaCollections._ | 76 | import implicits.JavaCollections._ |
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 c4d4184..9640ccc 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -49,6 +49,7 @@ import org.semanticweb.owlapi.model.OWLObjectInverseOf | |||
49 | import uk.ac.ox.cs.rsacomb.converter.{RDFoxAxiomConverter, SkolemStrategy} | 49 | import uk.ac.ox.cs.rsacomb.converter.{RDFoxAxiomConverter, SkolemStrategy} |
50 | import uk.ac.ox.cs.rsacomb.implicits.RSAAxiom | 50 | import uk.ac.ox.cs.rsacomb.implicits.RSAAxiom |
51 | import uk.ac.ox.cs.rsacomb.suffix.{Empty, Forward, Backward, Inverse} | 51 | import uk.ac.ox.cs.rsacomb.suffix.{Empty, Forward, Backward, Inverse} |
52 | import uk.ac.ox.cs.rsacomb.sparql.ConjunctiveQuery | ||
52 | import uk.ac.ox.cs.rsacomb.util.{RDFoxHelpers, RSA} | 53 | import uk.ac.ox.cs.rsacomb.util.{RDFoxHelpers, RSA} |
53 | 54 | ||
54 | object RSAOntology { | 55 | object RSAOntology { |
@@ -261,7 +262,7 @@ class RSAOntology(val ontology: OWLOntology) extends RSAAxiom { | |||
261 | Graph(edges: _*) | 262 | Graph(edges: _*) |
262 | } | 263 | } |
263 | 264 | ||
264 | def filteringProgram(query: SelectQuery): FilteringProgram = | 265 | def filteringProgram(query: ConjunctiveQuery): FilteringProgram = |
265 | new FilteringProgram(query, individuals) | 266 | new FilteringProgram(query, individuals) |
266 | 267 | ||
267 | lazy val canonicalModel = new CanonicalModel(this) | 268 | lazy val canonicalModel = new CanonicalModel(this) |