diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-02 18:47:49 +0000 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-12-02 18:47:49 +0000 |
commit | 91de03f187f298004d90708c5815e86134b10eae (patch) | |
tree | 6b027414dba598859c5f27740e7a30799308b38e | |
parent | bb2fe6440ea4f7e7aeca037c4a4351a28aac3a9f (diff) | |
download | RSAComb-91de03f187f298004d90708c5815e86134b10eae.tar.gz RSAComb-91de03f187f298004d90708c5815e86134b10eae.zip |
Make filtering program generate/load facts as facts
3 files changed, 26 insertions, 16 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 52be937..4e533c6 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala | |||
@@ -76,6 +76,15 @@ class FilteringProgram(query: ConjunctiveQuery, constants: List[Term]) { | |||
76 | val nis: Rule = | 76 | val nis: Rule = |
77 | Rule.create(RSA.NI(varX), RSA.Congruent(varX, varY), RSA.Named(varY)) | 77 | Rule.create(RSA.NI(varX), RSA.Congruent(varX, varY), RSA.Named(varY)) |
78 | 78 | ||
79 | /** Initializes instances of `rsa:Named`. | ||
80 | * | ||
81 | * They represent the set of constants appearing in the original | ||
82 | * ontology. | ||
83 | * | ||
84 | * @note corresponds to rules 2 in Table 3. | ||
85 | */ | ||
86 | val facts = constants map RSA.Named | ||
87 | |||
79 | /** Collection of filtering program rules. */ | 88 | /** Collection of filtering program rules. */ |
80 | val rules: List[Rule] = | 89 | val rules: List[Rule] = |
81 | nis :: { | 90 | nis :: { |
@@ -89,15 +98,6 @@ class FilteringProgram(query: ConjunctiveQuery, constants: List[Term]) { | |||
89 | */ | 98 | */ |
90 | val r1 = Rule.create(RSA.QM, query.atoms: _*) | 99 | val r1 = Rule.create(RSA.QM, query.atoms: _*) |
91 | 100 | ||
92 | /** Initializes instances of `rsa:Named`. | ||
93 | * | ||
94 | * They represent the set of constants appearing in the original | ||
95 | * ontology. | ||
96 | * | ||
97 | * @note corresponds to rules 2 in Table 3. | ||
98 | */ | ||
99 | val r2 = constants.map(c => Rule.create(RSA.Named(c))) | ||
100 | |||
101 | /** Initializes instances of `rsa:ID`. | 101 | /** Initializes instances of `rsa:ID`. |
102 | * | 102 | * |
103 | * They are initialized as a minimal congruence relation over the | 103 | * They are initialized as a minimal congruence relation over the |
@@ -307,7 +307,7 @@ class FilteringProgram(query: ConjunctiveQuery, constants: List[Term]) { | |||
307 | */ | 307 | */ |
308 | val r9 = Rule.create(RSA.Ans, RSA.QM, not(RSA.SP)) | 308 | val r9 = Rule.create(RSA.Ans, RSA.QM, not(RSA.SP)) |
309 | 309 | ||
310 | (r1 :: r2 ::: | 310 | (r1 :: |
311 | r3a ::: r3b :: r3c :: | 311 | r3a ::: r3b :: r3c :: |
312 | r4a ::: r4b ::: r4c ::: | 312 | r4a ::: r4b ::: r4c ::: |
313 | r5a ::: r5b ::: r5c ::: | 313 | r5a ::: r5b ::: r5c ::: |
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 f90e3c1..a965ef9 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -327,9 +327,11 @@ class RSAOntology(val ontology: OWLOntology) { | |||
327 | def ask(query: ConjunctiveQuery): ConjunctiveQueryAnswers = { | 327 | def ask(query: ConjunctiveQuery): ConjunctiveQueryAnswers = { |
328 | import implicits.JavaCollections._ | 328 | import implicits.JavaCollections._ |
329 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) | 329 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) |
330 | val filter = this.filteringProgram(query) | ||
330 | RDFoxUtil.addRules(data, this.canonicalModel.rules) | 331 | RDFoxUtil.addRules(data, this.canonicalModel.rules) |
331 | RDFoxUtil.addFacts(data, this.canonicalModel.facts) | 332 | RDFoxUtil.addFacts(data, this.canonicalModel.facts) |
332 | data.addRules(this.filteringProgram(query).rules) | 333 | RDFoxUtil.addRules(data, filter.rules) |
334 | RDFoxUtil.addFacts(data, filter.facts) | ||
333 | val answers = RDFoxUtil | 335 | val answers = RDFoxUtil |
334 | .submitQuery( | 336 | .submitQuery( |
335 | data, | 337 | data, |
diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala index 71c9a99..86e0253 100644 --- a/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala | |||
@@ -65,24 +65,32 @@ class FilteringProgramSpec extends AnyFlatSpec with Matchers { | |||
65 | 65 | ||
66 | import FilteringProgramSpec._ | 66 | import FilteringProgramSpec._ |
67 | 67 | ||
68 | "CQ 0" should "generate 30 rules" in { | 68 | "CQ 0" should "generate 27 rules and 3 facts" in { |
69 | val cq = ConjunctiveQuery(cq0).get | 69 | val cq = ConjunctiveQuery(cq0).get |
70 | FilteringProgram(cq, constants).rules should have length 30 | 70 | val filter = FilteringProgram(cq, constants) |
71 | filter.facts should have length 3 | ||
72 | filter.rules should have length 27 | ||
71 | } | 73 | } |
72 | 74 | ||
73 | "CQ 1" should "generate 15 rules" in { | 75 | "CQ 1" should "generate 15 rules" in { |
74 | val cq = ConjunctiveQuery(cq1).get | 76 | val cq = ConjunctiveQuery(cq1).get |
75 | FilteringProgram(cq, List()).rules should have length 15 | 77 | val filter = FilteringProgram(cq, List()) |
78 | filter.facts shouldBe empty | ||
79 | filter.rules should have length 15 | ||
76 | } | 80 | } |
77 | 81 | ||
78 | "CQ 2" should "generate 51 rules" in { | 82 | "CQ 2" should "generate 51 rules" in { |
79 | val cq = ConjunctiveQuery(cq2).get | 83 | val cq = ConjunctiveQuery(cq2).get |
80 | FilteringProgram(cq, List()).rules should have length 51 | 84 | val filter = FilteringProgram(cq, List()) |
85 | filter.facts shouldBe empty | ||
86 | filter.rules should have length 51 | ||
81 | } | 87 | } |
82 | 88 | ||
83 | "BCQ 0" should "generate 46 rules" in { | 89 | "BCQ 0" should "generate 46 rules" in { |
84 | val cq = ConjunctiveQuery(bcq0).get | 90 | val cq = ConjunctiveQuery(bcq0).get |
85 | FilteringProgram(cq, constants).rules should have length 46 | 91 | val filter = FilteringProgram(cq, constants) |
92 | filter.facts should have length 3 | ||
93 | filter.rules should have length 43 | ||
86 | } | 94 | } |
87 | 95 | ||
88 | } | 96 | } |