diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-29 18:35:51 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-29 18:35:51 +0100 |
| commit | 4b7253559c290b6fdd1c4122830f153fda85dd62 (patch) | |
| tree | 37c1487e4682be719dec532ca3d7e1af353fb9a1 | |
| parent | 6a559a415b3bdb3048021839e5bcf5bbf5aa4bbd (diff) | |
| download | ACQuA-4b7253559c290b6fdd1c4122830f153fda85dd62.tar.gz ACQuA-4b7253559c290b6fdd1c4122830f153fda85dd62.zip | |
Disposable.
34 files changed, 5263 insertions, 3899 deletions
diff --git a/data/Pagoda-2.0.0-uobm1-test_queries.log b/data/Pagoda-2.0.0-uobm1-test_queries.log new file mode 100644 index 0000000..42b338a --- /dev/null +++ b/data/Pagoda-2.0.0-uobm1-test_queries.log | |||
| @@ -0,0 +1,1158 @@ | |||
| 1 | The axiom: DataPropertyRange(<http://semantics.crl.ibm.com/univ-bench-dl.owl#firstName> xsd:string) is being ignored. | ||
| 2 | The axiom: DataPropertyRange(<http://semantics.crl.ibm.com/univ-bench-dl.owl#lastName> xsd:string) is being ignored. | ||
| 3 | The number of data property range axioms that are ignored: 2(186) | ||
| 4 | XMLReader initialized using JAXP: org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser@5456afaa | ||
| 5 | SimpleETL rewriting DONE | ||
| 6 | additional ontology data is saved in /home/alessandro/Desktop/Pagoda_basic-version/PAGOdA/tmp2015-05-28T14:42:07.907/ABox.ttl. | ||
| 7 | HermiT classification done: 0.108 | ||
| 8 | classification done and enriched lower bound rules. | ||
| 9 | The number of rules: 238 | ||
| 10 | OntologyID: OntologyID(OntologyIRI(<http://semantics.crl.ibm.com/univ-bench-dl.owl>)) | ||
| 11 | ELHO fragment extracted ... | ||
| 12 | Preprocessing ... checking satisfiability ... | ||
| 13 | rl-lower-bound store after importing data: 257920 (257920 new) | ||
| 14 | rl-lower-bound store finished importing data in 0.576 seconds. | ||
| 15 | Prefix declared: prefix0:=http://semantics.crl.ibm.com/univ-bench-dl.owl# | ||
| 16 | rl-lower-bound store after materialising lower program: 515592 (257672 new) | ||
| 17 | rl-lower-bound store finished the materialisation of lower program in 0.557 seconds. | ||
| 18 | The number of answers in the lower bound: 0 | ||
| 19 | The number of sameAs assertions in RL lower store: 102 | ||
| 20 | elho-lower-bound store after importing data: 257920 (257920 new) | ||
| 21 | elho-lower-bound store finished importing data in 0.559 seconds. | ||
| 22 | elho-lower-bound store after materialising saturate named individuals: 341262 (83342 new) | ||
| 23 | elho-lower-bound store finished the materialisation of saturate named individuals in 0.173 seconds. | ||
| 24 | elho-lower-bound store after materialising lower program: 557087 (215825 new) | ||
| 25 | elho-lower-bound store finished the materialisation of lower program in 0.525 seconds. | ||
| 26 | elho-lower-store finished its own materialisation in 0.579 seconds. | ||
| 27 | Failed to find configuration: location-mapping.ttl;location-mapping.rdf;location-mapping.n3;etc/location-mapping.rdf;etc/location-mapping.n3;etc/location-mapping.ttl | ||
| 28 | @Time to group individuals by equality: 0.062 | ||
| 29 | The number of answers in the lower bound: 0 | ||
| 30 | lazy-upper-bound store after importing data: 257920 (257920 new) | ||
| 31 | lazy-upper-bound store finished importing data in 0.555 seconds. | ||
| 32 | lazy-upper-bound store after materialising saturate named individuals: 341262 (83342 new) | ||
| 33 | lazy-upper-bound store finished the materialisation of saturate named individuals in 0.18 seconds. | ||
| 34 | lazy-upper-bound store is materialising multi-stage upper program ... | ||
| 35 | Iteration 1: | ||
| 36 | The lazy-upper-bound store is valid. | ||
| 37 | lazy-upper-bound store after materialising datalog-rules: 550540 (209278 new) | ||
| 38 | Time to materialise datalog-rules: 0.612 | ||
| 39 | Time to detect violations: 0.367 | ||
| 40 | Time to make the constraint being satisfied: 0.01 594 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingLover>(X) | ||
| 41 | tuple number: 594 before: 550540 after: 550540 (0 new) . | ||
| 42 | Time to make the constraint being satisfied: 0.006 553 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallLover>(X) | ||
| 43 | tuple number: 553 before: 550540 after: 550540 (0 new) . | ||
| 44 | Time to make the constraint being satisfied: 0.056 9627 tuples for <http://semantics.crl.ibm.com/univ-bench-dl.owl#NonScienceStudent>(X) v <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasMajor_Science_exist>(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#Student>(X) | ||
| 45 | tuple number: 0 before: 550540 after: 550540 (0 new) . | ||
| 46 | Time to make the constraint being satisfied: 0.007 48 tuples for <http://semantics.crl.ibm.com/univ-bench-dl.owl#Man>(X) v <http://semantics.crl.ibm.com/univ-bench-dl.owl#Woman>(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#Person>(X) | ||
| 47 | tuple number: 0 before: 550540 after: 550540 (0 new) . | ||
| 48 | Time to make the constraint being satisfied: 0.004 331 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingFan>(X) | ||
| 49 | tuple number: 331 before: 550540 after: 550540 (0 new) . | ||
| 50 | Time to make the constraint being satisfied: 0.005 596 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballLover>(X) | ||
| 51 | tuple number: 596 before: 550540 after: 550540 (0 new) . | ||
| 52 | Time to make the constraint being satisfied: 0.005 345 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#TennisClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#TennisFan>(X) | ||
| 53 | tuple number: 345 before: 550540 after: 550540 (0 new) . | ||
| 54 | Time to make the constraint being satisfied: 0.052 43968 tuples for <http://semantics.crl.ibm.com/univ-bench-dl.owl#PeopleWithManyHobbies>(X) v [Y1 == Y2]@atMost(2 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) v [Y1 == Y3]@atMost(2 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) v [Y2 == Y3]@atMost(2 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#like>(X,Y1), <http://semantics.crl.ibm.com/univ-bench-dl.owl#like>(X,Y2), <http://semantics.crl.ibm.com/univ-bench-dl.owl#like>(X,Y3) | ||
| 55 | tuple number: 0 before: 550540 after: 550540 (0 new) . | ||
| 56 | Time to make the constraint being satisfied: 0.008 1065 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#worksFor> <http://semantics.crl.ibm.com/univ-bench-dl.owl#ResearchGroup>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#ResearchAssistant>(X) | ||
| 57 | tuple number: 1065 before: 550540 after: 550540 (0 new) . | ||
| 58 | Time to make the constraint being satisfied: 0.004 478 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#worksFor> <http://semantics.crl.ibm.com/univ-bench-dl.owl#Organization>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#Employee>(X) | ||
| 59 | tuple number: 478 before: 550540 after: 550540 (0 new) . | ||
| 60 | Time to make the constraint being satisfied: 0.004 4 tuples for <http://semantics.crl.ibm.com/univ-bench-dl.owl#WomanCollege>(X) v <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasStudent_Man_exist>(X) v <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasStudent_UndergraduateStudent_neg_exist>(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#College>(X) | ||
| 61 | tuple number: 0 before: 550540 after: 550540 (0 new) . | ||
| 62 | Time to make the constraint being satisfied: 0.004 380 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> <http://semantics.crl.ibm.com/univ-bench-dl.owl#Sports>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#SportsLover>(X) | ||
| 63 | tuple number: 380 before: 550540 after: 550540 (0 new) . | ||
| 64 | Time to make the constraint being satisfied: 0.005 283 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#Sports>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#SportsFan>(X) | ||
| 65 | tuple number: 283 before: 550540 after: 550540 (0 new) . | ||
| 66 | Time to make the constraint being satisfied: 0.004 361 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallFan>(X) | ||
| 67 | tuple number: 361 before: 550540 after: 550540 (0 new) . | ||
| 68 | Time to make the constraint being satisfied: 0.004 352 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballFan>(X) | ||
| 69 | tuple number: 352 before: 550540 after: 550540 (0 new) . | ||
| 70 | lazy-upper-bound store after adding facts for violations: 550540 (0 new) | ||
| 71 | Time to add triples for violations: 0.283 | ||
| 72 | Iteration 2: | ||
| 73 | The lazy-upper-bound store is valid. | ||
| 74 | lazy-upper-bound store after materialising datalog-rules: 582920 (32380 new) | ||
| 75 | Time to materialise datalog-rules: 0.057 | ||
| 76 | Time to detect violations: 0.233 | ||
| 77 | Time to make the constraint being satisfied: 0.007 3966 tuples for <http://semantics.crl.ibm.com/univ-bench-dl.owl#PeopleWithManyHobbies>(X) v [Y1 == Y2]@atMost(2 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) v [Y1 == Y3]@atMost(2 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) v [Y2 == Y3]@atMost(2 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#like>(X,Y1), <http://semantics.crl.ibm.com/univ-bench-dl.owl#like>(X,Y2), <http://semantics.crl.ibm.com/univ-bench-dl.owl#like>(X,Y3) | ||
| 78 | tuple number: 0 before: 582920 after: 582920 (0 new) . | ||
| 79 | Time to make the constraint being satisfied: 0.015 1835 tuples for atLeast(3 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#PeopleWithManyHobbies>(X) | ||
| 80 | tuple number: 1835 before: 582920 after: 582920 (0 new) . | ||
| 81 | lazy-upper-bound store after adding facts for violations: 582920 (0 new) | ||
| 82 | Time to add triples for violations: 0.04 | ||
| 83 | Iteration 3: | ||
| 84 | The lazy-upper-bound store is valid. | ||
| 85 | lazy-upper-bound store after materialising datalog-rules: 594418 (11498 new) | ||
| 86 | Time to materialise datalog-rules: 0.026 | ||
| 87 | Time to detect violations: 0.338 | ||
| 88 | Time to make the constraint being satisfied: 0.005 481 tuples for atLeast(3 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#PeopleWithManyHobbies>(X) | ||
| 89 | tuple number: 481 before: 594418 after: 594418 (0 new) . | ||
| 90 | lazy-upper-bound store after adding facts for violations: 594418 (0 new) | ||
| 91 | Time to add triples for violations: 0.017 | ||
| 92 | Iteration 4: | ||
| 93 | The lazy-upper-bound store is valid. | ||
| 94 | lazy-upper-bound store after materialising datalog-rules: 597304 (2886 new) | ||
| 95 | Time to materialise datalog-rules: 0.016 | ||
| 96 | lazy-upper-bound store after materialising multi-stage upper program: 597304 (256042 new) | ||
| 97 | lazy-upper-bound store is DONE for multi-stage materialising in 2.512 seconds. | ||
| 98 | The lazy-upper-bound store is valid. | ||
| 99 | There are no contradictions derived in the lazy upper bound materialisation. | ||
| 100 | The ontology and dataset is satisfiable. | ||
| 101 | time for satisfiability checking: 6.915 | ||
| 102 | tracking store after importing data: 257920 (257920 new) | ||
| 103 | tracking store finished importing data in 0.589 seconds. | ||
| 104 | tracking store after materialising saturate named individuals: 341262 (83342 new) | ||
| 105 | tracking store finished the materialisation of saturate named individuals in 0.174 seconds. | ||
| 106 | tracking store after materialising lower program: 557087 (215825 new) | ||
| 107 | tracking store finished the materialisation of lower program in 0.532 seconds. | ||
| 108 | tracking store is materialising multi-stage upper program ... | ||
| 109 | Iteration 1: | ||
| 110 | current store after materialising upper related rules: 646037 (88950 new) | ||
| 111 | current store finished the materialisation of upper related rules in 0.513 seconds. | ||
| 112 | gap query evaluted ... | ||
| 113 | current store before importing gap tuples: 646037 | ||
| 114 | There are 126566 tuples in the gap between lower and upper bound materialisation. | ||
| 115 | current store after importing gap tuples: 764044 (118007). | ||
| 116 | current store finished importing gap tuples: 764044 in 0.372. | ||
| 117 | tracking store after materialising datalog-rules: 764044 (206957 new) | ||
| 118 | Time to materialise datalog-rules: 0.898 | ||
| 119 | Time to detect violations: 0.124 | ||
| 120 | Time to make the constraint being satisfied: 0.01 478 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingLover>(X) | ||
| 121 | tuple number: 478 before: 764044 after: 764044 (0 new) . | ||
| 122 | Time to make the constraint being satisfied: 0.007 500 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballLover>(X) | ||
| 123 | tuple number: 500 before: 764044 after: 764044 (0 new) . | ||
| 124 | Time to make the constraint being satisfied: 0.004 5 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasStudent> <http://semantics.crl.ibm.com/univ-bench-dl.owl#UndergraduateStudent_neg>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#College>(X) | ||
| 125 | tuple number: 5 before: 764044 after: 764044 (0 new) . | ||
| 126 | Time to make the constraint being satisfied: 0.005 295 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#TennisClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#TennisFan>(X) | ||
| 127 | tuple number: 295 before: 764044 after: 764044 (0 new) . | ||
| 128 | Time to make the constraint being satisfied: 0.008 489 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallLover>(X) | ||
| 129 | tuple number: 489 before: 764044 after: 764044 (0 new) . | ||
| 130 | Time to make the constraint being satisfied: 0.01 1065 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#worksFor> <http://semantics.crl.ibm.com/univ-bench-dl.owl#ResearchGroup>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#ResearchAssistant>(X) | ||
| 131 | tuple number: 1065 before: 764044 after: 764044 (0 new) . | ||
| 132 | Time to make the constraint being satisfied: 0.012 1543 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#worksFor> <http://semantics.crl.ibm.com/univ-bench-dl.owl#Organization>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#Employee>(X) | ||
| 133 | tuple number: 1543 before: 764044 after: 764044 (0 new) . | ||
| 134 | Time to make the constraint being satisfied: 0.048 9627 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMajor> <http://semantics.crl.ibm.com/univ-bench-dl.owl#Science>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#Student>(X) | ||
| 135 | tuple number: 9627 before: 764044 after: 764044 (0 new) . | ||
| 136 | Time to make the constraint being satisfied: 0.012 1772 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> <http://semantics.crl.ibm.com/univ-bench-dl.owl#Sports>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#SportsLover>(X) | ||
| 137 | tuple number: 1772 before: 764044 after: 764044 (0 new) . | ||
| 138 | Time to make the constraint being satisfied: 0.01 1311 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#Sports>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#SportsFan>(X) | ||
| 139 | tuple number: 1311 before: 764044 after: 764044 (0 new) . | ||
| 140 | Time to make the constraint being satisfied: 0.005 270 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingFan>(X) | ||
| 141 | tuple number: 270 before: 764044 after: 764044 (0 new) . | ||
| 142 | Time to make the constraint being satisfied: 0.004 4 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasStudent> <http://semantics.crl.ibm.com/univ-bench-dl.owl#Man>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#College>(X) | ||
| 143 | tuple number: 4 before: 764044 after: 764044 (0 new) . | ||
| 144 | Time to make the constraint being satisfied: 0.005 297 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallFan>(X) | ||
| 145 | tuple number: 297 before: 764044 after: 764044 (0 new) . | ||
| 146 | Time to make the constraint being satisfied: 0.012 1772 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#PeopleWithHobby>(X) | ||
| 147 | tuple number: 1772 before: 764044 after: 764044 (0 new) . | ||
| 148 | Time to make the constraint being satisfied: 0.006 290 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballClass>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballFan>(X) | ||
| 149 | tuple number: 290 before: 764044 after: 764044 (0 new) . | ||
| 150 | Time to make the constraint being satisfied: 0.084 7041 tuples for atLeast(3 <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> owl:Thing)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#PeopleWithManyHobbies>(X) | ||
| 151 | tuple number: 7041 before: 764044 after: 764044 (0 new) . | ||
| 152 | tracking store after adding facts for violations: 764044 (0 new) | ||
| 153 | Time to add triples for violations: 0.38 | ||
| 154 | Iteration 2: | ||
| 155 | current store after materialising upper related rules: 831557 (67513 new) | ||
| 156 | current store finished the materialisation of upper related rules in 0.137 seconds. | ||
| 157 | gap query evaluted ... | ||
| 158 | current store before importing gap tuples: 831557 | ||
| 159 | There are 41367 tuples in the gap between lower and upper bound materialisation. | ||
| 160 | current store after importing gap tuples: 867593 (36036). | ||
| 161 | current store finished importing gap tuples: 867593 in 0.097. | ||
| 162 | tracking store after materialising datalog-rules: 867593 (103549 new) | ||
| 163 | Time to materialise datalog-rules: 0.245 | ||
| 164 | Time to detect violations: 0.134 | ||
| 165 | Time to make the constraint being satisfied: 0.005 2 tuples for atLeast(1 <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMajor> <http://semantics.crl.ibm.com/univ-bench-dl.owl#Science>)(X) :- <http://semantics.crl.ibm.com/univ-bench-dl.owl#Student>(X) | ||
| 166 | tuple number: 2 before: 867593 after: 867593 (0 new) . | ||
| 167 | tracking store after adding facts for violations: 867593 (0 new) | ||
| 168 | Time to add triples for violations: 0.024 | ||
| 169 | Iteration 3: | ||
| 170 | current store after materialising upper related rules: 867601 (8 new) | ||
| 171 | current store finished the materialisation of upper related rules in 0.012 seconds. | ||
| 172 | gap query evaluted ... | ||
| 173 | current store before importing gap tuples: 867601 | ||
| 174 | There are 4 tuples in the gap between lower and upper bound materialisation. | ||
| 175 | current store after importing gap tuples: 867605 (4). | ||
| 176 | current store finished importing gap tuples: 867605 in 0.01. | ||
| 177 | tracking store after materialising datalog-rules: 867605 (12 new) | ||
| 178 | Time to materialise datalog-rules: 0.033 | ||
| 179 | tracking store after materialising multi-stage upper program: 867605 (310518 new) | ||
| 180 | tracking store is DONE for multi-stage materialising in 1.91 seconds. | ||
| 181 | The number of answers in the upper bound: 12782 | ||
| 182 | The number of answers in the upper bound: 0 | ||
| 183 | The number of answers in the upper bound: 14182 | ||
| 184 | The number of answers in the upper bound: 1 | ||
| 185 | The number of answers in the upper bound: 5 | ||
| 186 | The number of answers in the upper bound: 23 | ||
| 187 | There are 5 different bottom fragments. | ||
| 188 | 12782 triples are added into the store. | ||
| 189 | Prefix declared: prefix1:=http://semantics.crl.ibm.com/univ-bench-dl-TBox.owl# | ||
| 190 | 14182 triples are added into the store. | ||
| 191 | 1 triples are added into the store. | ||
| 192 | 5 triples are added into the store. | ||
| 193 | 23 triples are added into the store. | ||
| 194 | tracking store after materialising tracking program: 1441314 (573709 new) | ||
| 195 | tracking store finished the materialisation of tracking program in 2.941 seconds. | ||
| 196 | @Time to group individuals by equality: 0.018 | ||
| 197 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Science> 10 | ||
| 198 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Person> 0 | ||
| 199 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#ScienceStudent> 0 | ||
| 200 | class: <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasStudent_Man_exist> 0 | ||
| 201 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Organization> 5 | ||
| 202 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#College> 4 | ||
| 203 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#UndergraduateStudent> 0 | ||
| 204 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Student> 9627 | ||
| 205 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#WomanCollege> 1 | ||
| 206 | class: <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasMajor_Science_exist> 3153 | ||
| 207 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Woman> 0 | ||
| 208 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Man> 0 | ||
| 209 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isMemberOf> 0 | ||
| 210 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMember> 0 | ||
| 211 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMajor> 3153 | ||
| 212 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isStudentOf> 0 | ||
| 213 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasStudent> 0 | ||
| 214 | property: <http://www.w3.org/2002/07/owl#sameAs> 0 | ||
| 215 | ABox extraction Done | ||
| 216 | TBox extraction Done | ||
| 217 | Before adding bottom fragment: | ||
| 218 | ABoxAxiomsCount = 15953, TBoxAxiomsCount = 24 | ||
| 219 | finish extracting axioms for bottom 0_1 | ||
| 220 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Person> 48 | ||
| 221 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Student> 9627 | ||
| 222 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Organization> 5 | ||
| 223 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#WomanCollege> 1 | ||
| 224 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Science> 0 | ||
| 225 | class: <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasMajor_Science_exist> 0 | ||
| 226 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#UndergraduateStudent> 0 | ||
| 227 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#College> 4 | ||
| 228 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Woman> 7211 | ||
| 229 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Man> 6873 | ||
| 230 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#ScienceStudent> 0 | ||
| 231 | class: <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasStudent_Man_exist> 19 | ||
| 232 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasStudent> 0 | ||
| 233 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMember> 0 | ||
| 234 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isMemberOf> 0 | ||
| 235 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMajor> 0 | ||
| 236 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isStudentOf> 0 | ||
| 237 | property: <http://www.w3.org/2002/07/owl#sameAs> 48 | ||
| 238 | ABox extraction Done | ||
| 239 | TBox extraction Done | ||
| 240 | Before adding bottom fragment: | ||
| 241 | ABoxAxiomsCount = 23836, TBoxAxiomsCount = 24 | ||
| 242 | finish extracting axioms for bottom 0_2 | ||
| 243 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#WomanCollege> 1 | ||
| 244 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Organization> 5 | ||
| 245 | class: <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasMajor_Science_exist> 0 | ||
| 246 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#College> 4 | ||
| 247 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Student> 9627 | ||
| 248 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#UndergraduateStudent> 0 | ||
| 249 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Person> 0 | ||
| 250 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#ScienceStudent> 0 | ||
| 251 | class: <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasStudent_Man_exist> 0 | ||
| 252 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Woman> 0 | ||
| 253 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Man> 0 | ||
| 254 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Science> 0 | ||
| 255 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMember> 0 | ||
| 256 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isMemberOf> 0 | ||
| 257 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMajor> 0 | ||
| 258 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isStudentOf> 0 | ||
| 259 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasStudent> 0 | ||
| 260 | property: <http://www.w3.org/2002/07/owl#sameAs> 0 | ||
| 261 | ABox extraction Done | ||
| 262 | TBox extraction Done | ||
| 263 | Before adding bottom fragment: | ||
| 264 | ABoxAxiomsCount = 9637, TBoxAxiomsCount = 23 | ||
| 265 | finish extracting axioms for bottom 0_3 | ||
| 266 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#College> 4 | ||
| 267 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Student> 9627 | ||
| 268 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Person> 0 | ||
| 269 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Woman> 0 | ||
| 270 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#UndergraduateStudent> 0 | ||
| 271 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#WomanCollege> 1 | ||
| 272 | class: <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasMajor_Science_exist> 0 | ||
| 273 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Man> 0 | ||
| 274 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#ScienceStudent> 0 | ||
| 275 | class: <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#concept_hasStudent_Man_exist> 0 | ||
| 276 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Organization> 5 | ||
| 277 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Science> 0 | ||
| 278 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasStudent> 264 | ||
| 279 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMember> 0 | ||
| 280 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isMemberOf> 0 | ||
| 281 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#hasMajor> 0 | ||
| 282 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isStudentOf> 0 | ||
| 283 | property: <http://www.w3.org/2002/07/owl#sameAs> 0 | ||
| 284 | ABox extraction Done | ||
| 285 | TBox extraction Done | ||
| 286 | Before adding bottom fragment: | ||
| 287 | ABoxAxiomsCount = 9901, TBoxAxiomsCount = 24 | ||
| 288 | finish extracting axioms for bottom 0_4 | ||
| 289 | property: <http://www.w3.org/2002/07/owl#sameAs> 37 | ||
| 290 | ABox extraction Done | ||
| 291 | TBox extraction Done | ||
| 292 | Before adding bottom fragment: | ||
| 293 | ABoxAxiomsCount = 37, TBoxAxiomsCount = 2 | ||
| 294 | finish extracting axioms for bottom 0_5 | ||
| 295 | The ontology is consistent! | ||
| 296 | Preprocessing Done in 18.306 seconds. | ||
| 297 | ---------- start evaluating Query 1 ---------- | ||
| 298 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:UndergraduateStudent . ?x benchmark:takesCourse <http://www.Department0.University0.edu/Course0> } | ||
| 299 | 0.0 | ||
| 300 | The number of answers in the lower bound: 21 | ||
| 301 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:UndergraduateStudent . ?x benchmark:takesCourse <http://www.Department0.University0.edu/Course0> } | ||
| 302 | 0.005 | ||
| 303 | The number of answers returned by the upper bound: 21 | ||
| 304 | The number of answers in the upper bound: 21 | ||
| 305 | Difficulty of this query: UpperBound | ||
| 306 | Total time to answer this query: 0.006 | ||
| 307 | The number of answer tuples: 21 | ||
| 308 | time for LowerBound: 0.001 | ||
| 309 | time for UpperBound: 0.005 | ||
| 310 | time for ELLowerBound: 0.0 | ||
| 311 | time for Fragment: 0.0 | ||
| 312 | time for FragmentRefinement: 0.0 | ||
| 313 | time for Summarisation: 0.0 | ||
| 314 | time for Dependency: 0.0 | ||
| 315 | time for FullReasoning: 0.0 | ||
| 316 | ---------- start evaluating Query 2 ---------- | ||
| 317 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Employee } | ||
| 318 | 0.001 | ||
| 319 | The number of answers in the lower bound: 2465 | ||
| 320 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Employee } | ||
| 321 | 0.002 | ||
| 322 | The number of answers returned by the upper bound: 2465 | ||
| 323 | The number of answers in the upper bound: 2465 | ||
| 324 | Difficulty of this query: UpperBound | ||
| 325 | Total time to answer this query: 0.009 | ||
| 326 | The number of answer tuples: 2465 | ||
| 327 | time for LowerBound: 0.007 | ||
| 328 | time for UpperBound: 0.002 | ||
| 329 | time for ELLowerBound: 0.0 | ||
| 330 | time for Fragment: 0.0 | ||
| 331 | time for FragmentRefinement: 0.0 | ||
| 332 | time for Summarisation: 0.0 | ||
| 333 | time for Dependency: 0.0 | ||
| 334 | time for FullReasoning: 0.0 | ||
| 335 | ---------- start evaluating Query 3 ---------- | ||
| 336 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Student . ?x benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 337 | 0.005 | ||
| 338 | The number of answers in the lower bound: 581 | ||
| 339 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Student . ?x benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 340 | 0.009 | ||
| 341 | The number of answers returned by the upper bound: 581 | ||
| 342 | The number of answers in the upper bound: 581 | ||
| 343 | Difficulty of this query: UpperBound | ||
| 344 | Total time to answer this query: 0.016 | ||
| 345 | The number of answer tuples: 581 | ||
| 346 | time for LowerBound: 0.007 | ||
| 347 | time for UpperBound: 0.009 | ||
| 348 | time for ELLowerBound: 0.0 | ||
| 349 | time for Fragment: 0.0 | ||
| 350 | time for FragmentRefinement: 0.0 | ||
| 351 | time for Summarisation: 0.0 | ||
| 352 | time for Dependency: 0.0 | ||
| 353 | time for FullReasoning: 0.0 | ||
| 354 | ---------- start evaluating Query 4 ---------- | ||
| 355 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Publication . ?x benchmark:publicationAuthor ?y . ?y rdf:type benchmark:Faculty . ?y benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 356 | 0.001 | ||
| 357 | The number of answers in the lower bound: 292 | ||
| 358 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Publication . ?x benchmark:publicationAuthor ?y . ?y rdf:type benchmark:Faculty . ?y benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 359 | 0.006 | ||
| 360 | The number of answers returned by the upper bound: 292 | ||
| 361 | The number of answers in the upper bound: 292 | ||
| 362 | Difficulty of this query: UpperBound | ||
| 363 | Total time to answer this query: 0.01 | ||
| 364 | The number of answer tuples: 292 | ||
| 365 | time for LowerBound: 0.003 | ||
| 366 | time for UpperBound: 0.007 | ||
| 367 | time for ELLowerBound: 0.0 | ||
| 368 | time for Fragment: 0.0 | ||
| 369 | time for FragmentRefinement: 0.0 | ||
| 370 | time for Summarisation: 0.0 | ||
| 371 | time for Dependency: 0.0 | ||
| 372 | time for FullReasoning: 0.0 | ||
| 373 | ---------- start evaluating Query 5 ---------- | ||
| 374 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:ResearchGroup . ?x benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 375 | 0.001 | ||
| 376 | The number of answers in the lower bound: 235 | ||
| 377 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:ResearchGroup . ?x benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 378 | 0.003 | ||
| 379 | The number of answers returned by the upper bound: 235 | ||
| 380 | The number of answers in the upper bound: 235 | ||
| 381 | Difficulty of this query: UpperBound | ||
| 382 | Total time to answer this query: 0.005 | ||
| 383 | The number of answer tuples: 235 | ||
| 384 | time for LowerBound: 0.002 | ||
| 385 | time for UpperBound: 0.003 | ||
| 386 | time for ELLowerBound: 0.0 | ||
| 387 | time for Fragment: 0.0 | ||
| 388 | time for FragmentRefinement: 0.0 | ||
| 389 | time for Summarisation: 0.0 | ||
| 390 | time for Dependency: 0.0 | ||
| 391 | time for FullReasoning: 0.0 | ||
| 392 | ---------- start evaluating Query 6 ---------- | ||
| 393 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Person . <http://www.University0.edu> benchmark:hasAlumnus ?x } | ||
| 394 | 0.006 | ||
| 395 | The number of answers in the lower bound: 991 | ||
| 396 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Person . <http://www.University0.edu> benchmark:hasAlumnus ?x } | ||
| 397 | 0.007 | ||
| 398 | The number of answers returned by the upper bound: 991 | ||
| 399 | The number of answers in the upper bound: 991 | ||
| 400 | Difficulty of this query: UpperBound | ||
| 401 | Total time to answer this query: 0.016 | ||
| 402 | The number of answer tuples: 991 | ||
| 403 | time for LowerBound: 0.008 | ||
| 404 | time for UpperBound: 0.008 | ||
| 405 | time for ELLowerBound: 0.0 | ||
| 406 | time for Fragment: 0.0 | ||
| 407 | time for FragmentRefinement: 0.0 | ||
| 408 | time for Summarisation: 0.0 | ||
| 409 | time for Dependency: 0.0 | ||
| 410 | time for FullReasoning: 0.0 | ||
| 411 | ---------- start evaluating Query 7 ---------- | ||
| 412 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Person . ?x benchmark:hasSameHomeTownWith <http://www.Department0.University0.edu/FullProfessor0> } | ||
| 413 | 0.0 | ||
| 414 | The number of answers in the lower bound: 0 | ||
| 415 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Person . ?x benchmark:hasSameHomeTownWith <http://www.Department0.University0.edu/FullProfessor0> } | ||
| 416 | 0.001 | ||
| 417 | The number of answers in the upper bound: 0 | ||
| 418 | Difficulty of this query: UpperBound | ||
| 419 | Total time to answer this query: 0.002 | ||
| 420 | The number of answer tuples: 0 | ||
| 421 | time for LowerBound: 0.001 | ||
| 422 | time for UpperBound: 0.001 | ||
| 423 | time for ELLowerBound: 0.0 | ||
| 424 | time for Fragment: 0.0 | ||
| 425 | time for FragmentRefinement: 0.0 | ||
| 426 | time for Summarisation: 0.0 | ||
| 427 | time for Dependency: 0.0 | ||
| 428 | time for FullReasoning: 0.0 | ||
| 429 | ---------- start evaluating Query 8 ---------- | ||
| 430 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:SportsLover . <http://www.Department0.University0.edu> benchmark:hasMember ?x } | ||
| 431 | 0.0 | ||
| 432 | The number of answers in the lower bound: 376 | ||
| 433 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:SportsLover . <http://www.Department0.University0.edu> benchmark:hasMember ?x } | ||
| 434 | 0.002 | ||
| 435 | The number of answers returned by the upper bound: 376 | ||
| 436 | The number of answers in the upper bound: 376 | ||
| 437 | Difficulty of this query: UpperBound | ||
| 438 | Total time to answer this query: 0.003 | ||
| 439 | The number of answer tuples: 376 | ||
| 440 | time for LowerBound: 0.001 | ||
| 441 | time for UpperBound: 0.002 | ||
| 442 | time for ELLowerBound: 0.0 | ||
| 443 | time for Fragment: 0.0 | ||
| 444 | time for FragmentRefinement: 0.0 | ||
| 445 | time for Summarisation: 0.0 | ||
| 446 | time for Dependency: 0.0 | ||
| 447 | time for FullReasoning: 0.0 | ||
| 448 | ---------- start evaluating Query 9 ---------- | ||
| 449 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:GraduateCourse . ?x benchmark:isTaughtBy ?y . ?y rdf:type benchmark:SportsLover . ?y benchmark:isMemberOf ?z . ?z benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 450 | 0.002 | ||
| 451 | The number of answers in the lower bound: 747 | ||
| 452 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:GraduateCourse . ?x benchmark:isTaughtBy ?y . ?y rdf:type benchmark:SportsLover . ?y benchmark:isMemberOf ?z . ?z benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 453 | 0.004 | ||
| 454 | The number of answers returned by the upper bound: 747 | ||
| 455 | The number of answers in the upper bound: 747 | ||
| 456 | Difficulty of this query: UpperBound | ||
| 457 | Total time to answer this query: 0.01 | ||
| 458 | The number of answer tuples: 747 | ||
| 459 | time for LowerBound: 0.005 | ||
| 460 | time for UpperBound: 0.005 | ||
| 461 | time for ELLowerBound: 0.0 | ||
| 462 | time for Fragment: 0.0 | ||
| 463 | time for FragmentRefinement: 0.0 | ||
| 464 | time for Summarisation: 0.0 | ||
| 465 | time for Dependency: 0.0 | ||
| 466 | time for FullReasoning: 0.0 | ||
| 467 | ---------- start evaluating Query 10 ---------- | ||
| 468 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x benchmark:isFriendOf <http://www.Department0.University0.edu/FullProfessor0> } | ||
| 469 | 0.001 | ||
| 470 | The number of answers in the lower bound: 8 | ||
| 471 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x benchmark:isFriendOf <http://www.Department0.University0.edu/FullProfessor0> } | ||
| 472 | 0.002 | ||
| 473 | The number of answers returned by the upper bound: 8 | ||
| 474 | The number of answers in the upper bound: 8 | ||
| 475 | Difficulty of this query: UpperBound | ||
| 476 | Total time to answer this query: 0.003 | ||
| 477 | The number of answer tuples: 8 | ||
| 478 | time for LowerBound: 0.001 | ||
| 479 | time for UpperBound: 0.002 | ||
| 480 | time for ELLowerBound: 0.0 | ||
| 481 | time for Fragment: 0.0 | ||
| 482 | time for FragmentRefinement: 0.0 | ||
| 483 | time for Summarisation: 0.0 | ||
| 484 | time for Dependency: 0.0 | ||
| 485 | time for FullReasoning: 0.0 | ||
| 486 | ---------- start evaluating Query 11 ---------- | ||
| 487 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Person . ?x benchmark:like ?y . ?z rdf:type benchmark:Chair . ?z benchmark:isHeadOf <http://www.Department0.University0.edu> . ?z benchmark:like ?y } | ||
| 488 | 0.003 | ||
| 489 | The number of answers in the lower bound: 2416 | ||
| 490 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Person . ?x benchmark:like ?y . ?z rdf:type benchmark:Chair . ?z benchmark:isHeadOf <http://www.Department0.University0.edu> . ?z benchmark:like ?y } | ||
| 491 | 0.005 | ||
| 492 | The number of answers returned by the upper bound: 3886 | ||
| 493 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Person . ?x benchmark:like ?y . ?z rdf:type benchmark:Chair . ?z benchmark:isHeadOf <http://www.Department0.University0.edu> . ?z benchmark:like ?y . ?y a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> . ?z a <http://www.cs.ox.ac.uk/PAGOdA/auxiliary#Original> } | ||
| 494 | 0.032 | ||
| 495 | The number of answers returned by the upper bound: 2416 | ||
| 496 | The number of answers in the upper bound: 2416 | ||
| 497 | Difficulty of this query: UpperBound | ||
| 498 | Total time to answer this query: 0.04 | ||
| 499 | The number of answer tuples: 2416 | ||
| 500 | time for LowerBound: 0.008 | ||
| 501 | time for UpperBound: 0.032 | ||
| 502 | time for ELLowerBound: 0.0 | ||
| 503 | time for Fragment: 0.0 | ||
| 504 | time for FragmentRefinement: 0.0 | ||
| 505 | time for Summarisation: 0.0 | ||
| 506 | time for Dependency: 0.0 | ||
| 507 | time for FullReasoning: 0.0 | ||
| 508 | ---------- start evaluating Query 12 ---------- | ||
| 509 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Student . ?x benchmark:takesCourse ?y . ?y benchmark:isTaughtBy <http://www.Department0.University0.edu/FullProfessor0> } | ||
| 510 | 0.009 | ||
| 511 | The number of answers in the lower bound: 50 | ||
| 512 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Student . ?x benchmark:takesCourse ?y . ?y benchmark:isTaughtBy <http://www.Department0.University0.edu/FullProfessor0> } | ||
| 513 | 0.011 | ||
| 514 | The number of answers returned by the upper bound: 50 | ||
| 515 | The number of answers in the upper bound: 50 | ||
| 516 | Difficulty of this query: UpperBound | ||
| 517 | Total time to answer this query: 0.021 | ||
| 518 | The number of answer tuples: 50 | ||
| 519 | time for LowerBound: 0.01 | ||
| 520 | time for UpperBound: 0.011 | ||
| 521 | time for ELLowerBound: 0.0 | ||
| 522 | time for Fragment: 0.0 | ||
| 523 | time for FragmentRefinement: 0.0 | ||
| 524 | time for Summarisation: 0.0 | ||
| 525 | time for Dependency: 0.0 | ||
| 526 | time for FullReasoning: 0.0 | ||
| 527 | ---------- start evaluating Query 13 ---------- | ||
| 528 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:PeopleWithHobby . ?x benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 529 | 0.004 | ||
| 530 | The number of answers in the lower bound: 416 | ||
| 531 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:PeopleWithHobby . ?x benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 532 | 0.005 | ||
| 533 | The number of answers returned by the upper bound: 416 | ||
| 534 | The number of answers in the upper bound: 416 | ||
| 535 | Difficulty of this query: UpperBound | ||
| 536 | Total time to answer this query: 0.01 | ||
| 537 | The number of answer tuples: 416 | ||
| 538 | time for LowerBound: 0.005 | ||
| 539 | time for UpperBound: 0.005 | ||
| 540 | time for ELLowerBound: 0.0 | ||
| 541 | time for Fragment: 0.0 | ||
| 542 | time for FragmentRefinement: 0.0 | ||
| 543 | time for Summarisation: 0.0 | ||
| 544 | time for Dependency: 0.0 | ||
| 545 | time for FullReasoning: 0.0 | ||
| 546 | ---------- start evaluating Query 14 ---------- | ||
| 547 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Woman . ?x rdf:type benchmark:Student . ?x benchmark:isMemberOf ?y . ?y benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 548 | 0.012 | ||
| 549 | The number of answers in the lower bound: 6535 | ||
| 550 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Woman . ?x rdf:type benchmark:Student . ?x benchmark:isMemberOf ?y . ?y benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 551 | 0.013 | ||
| 552 | The number of answers returned by the upper bound: 6535 | ||
| 553 | The number of answers in the upper bound: 6535 | ||
| 554 | Difficulty of this query: UpperBound | ||
| 555 | Total time to answer this query: 0.039 | ||
| 556 | The number of answer tuples: 6535 | ||
| 557 | time for LowerBound: 0.024 | ||
| 558 | time for UpperBound: 0.015 | ||
| 559 | time for ELLowerBound: 0.0 | ||
| 560 | time for Fragment: 0.0 | ||
| 561 | time for FragmentRefinement: 0.0 | ||
| 562 | time for Summarisation: 0.0 | ||
| 563 | time for Dependency: 0.0 | ||
| 564 | time for FullReasoning: 0.0 | ||
| 565 | ---------- start evaluating Query 15 ---------- | ||
| 566 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:PeopleWithManyHobbies . ?x benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 567 | 0.0 | ||
| 568 | The number of answers in the lower bound: 0 | ||
| 569 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:PeopleWithManyHobbies . ?x benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 570 | 0.003 | ||
| 571 | The number of answers in the upper bound: 112 | ||
| 572 | 0.003 | ||
| 573 | The number of answers in the lower bound: 0 | ||
| 574 | 112 triples are added into the store. | ||
| 575 | tracking store after materialising tracking program: 1517657 (76343 new) | ||
| 576 | tracking store finished the materialisation of tracking program in 0.749 seconds. | ||
| 577 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isTaughtBy> 19 | ||
| 578 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isHeadOf> 1 | ||
| 579 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isMemberOf> 111 | ||
| 580 | property: <http://www.w3.org/2002/07/owl#sameAs> 1 | ||
| 581 | ABox extraction Done | ||
| 582 | TBox extraction Done | ||
| 583 | Before adding bottom fragment: | ||
| 584 | ABoxAxiomsCount = 132, TBoxAxiomsCount = 2 | ||
| 585 | None of bottom fragments is added for this query. | ||
| 586 | ABox axioms: 132 TBox axioms: 2 | ||
| 587 | grouping individuals by its concepts | ||
| 588 | The summary of ABox is consistent with the TBox. | ||
| 589 | @TIME to check one tuple: 0.02 | ||
| 590 | @TIME to filter out non-answers by summarisation: 0.044 | ||
| 591 | Hermit was called 1 times. | ||
| 592 | Hermit was called 0 times. | ||
| 593 | Total time for full reasoner: 0.056 | ||
| 594 | Difficulty of this query: Summarisation | ||
| 595 | Total time to answer this query: 0.936 | ||
| 596 | The number of answer tuples: 0 | ||
| 597 | time for LowerBound: 0.0 | ||
| 598 | time for UpperBound: 0.004 | ||
| 599 | time for ELLowerBound: 0.003 | ||
| 600 | time for Fragment: 0.873 | ||
| 601 | time for FragmentRefinement: 0.0 | ||
| 602 | time for Summarisation: 0.063 | ||
| 603 | time for Dependency: 0.0 | ||
| 604 | time for FullReasoning: 0.0 | ||
| 605 | ---------- start evaluating Query 16 ---------- | ||
| 606 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Publication . ?x benchmark:publicationAuthor _:y . _:y rdf:type benchmark:Faculty . _:y benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 607 | 0.002 | ||
| 608 | The number of answers in the lower bound: 292 | ||
| 609 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Publication . ?x benchmark:publicationAuthor _:y . _:y rdf:type benchmark:Faculty . _:y benchmark:isMemberOf <http://www.Department0.University0.edu> } | ||
| 610 | 0.003 | ||
| 611 | The number of answers returned by the upper bound: 292 | ||
| 612 | The number of answers in the upper bound: 292 | ||
| 613 | Difficulty of this query: UpperBound | ||
| 614 | Total time to answer this query: 0.006 | ||
| 615 | The number of answer tuples: 292 | ||
| 616 | time for LowerBound: 0.003 | ||
| 617 | time for UpperBound: 0.003 | ||
| 618 | time for ELLowerBound: 0.0 | ||
| 619 | time for Fragment: 0.0 | ||
| 620 | time for FragmentRefinement: 0.0 | ||
| 621 | time for Summarisation: 0.0 | ||
| 622 | time for Dependency: 0.0 | ||
| 623 | time for FullReasoning: 0.0 | ||
| 624 | ---------- start evaluating Query 17 ---------- | ||
| 625 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:GraduateCourse . ?x benchmark:isTaughtBy _:y . _:y rdf:type benchmark:SportsLover . _:y benchmark:isMemberOf _:z . _:z benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 626 | 0.003 | ||
| 627 | The number of answers in the lower bound: 747 | ||
| 628 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:GraduateCourse . ?x benchmark:isTaughtBy _:y . _:y rdf:type benchmark:SportsLover . _:y benchmark:isMemberOf _:z . _:z benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 629 | 0.004 | ||
| 630 | The number of answers returned by the upper bound: 747 | ||
| 631 | The number of answers in the upper bound: 747 | ||
| 632 | Difficulty of this query: UpperBound | ||
| 633 | Total time to answer this query: 0.009 | ||
| 634 | The number of answer tuples: 747 | ||
| 635 | time for LowerBound: 0.005 | ||
| 636 | time for UpperBound: 0.004 | ||
| 637 | time for ELLowerBound: 0.0 | ||
| 638 | time for Fragment: 0.0 | ||
| 639 | time for FragmentRefinement: 0.0 | ||
| 640 | time for Summarisation: 0.0 | ||
| 641 | time for Dependency: 0.0 | ||
| 642 | time for FullReasoning: 0.0 | ||
| 643 | ---------- start evaluating Query 18 ---------- | ||
| 644 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Person . ?x benchmark:like _:y . _:z rdf:type benchmark:Chair . _:z benchmark:isHeadOf <http://www.Department0.University0.edu> . _:z benchmark:like _:y } | ||
| 645 | 0.003 | ||
| 646 | The number of answers in the lower bound: 2416 | ||
| 647 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Person . ?x benchmark:like _:y . _:z rdf:type benchmark:Chair . _:z benchmark:isHeadOf <http://www.Department0.University0.edu> . _:z benchmark:like _:y } | ||
| 648 | 0.006 | ||
| 649 | The number of answers returned by the upper bound: 3886 | ||
| 650 | The number of answers in the upper bound: 3886 | ||
| 651 | 1.16 | ||
| 652 | The number of answers in the lower bound: 2416 | ||
| 653 | 1470 triples are added into the store. | ||
| 654 | tracking store after materialising tracking program: 1717999 (200342 new) | ||
| 655 | tracking store finished the materialisation of tracking program in 3.166 seconds. | ||
| 656 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingFan> 675 | ||
| 657 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#PeopleWithHobby> 8813 | ||
| 658 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Sports> 7 | ||
| 659 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallClass> 1 | ||
| 660 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#SportsLover> 7881 | ||
| 661 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Chair> 1 | ||
| 662 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#TennisClass> 1 | ||
| 663 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballFan> 687 | ||
| 664 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingClass> 1 | ||
| 665 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballLover> 2281 | ||
| 666 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#SportsFan> 3489 | ||
| 667 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallFan> 686 | ||
| 668 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballClass> 1 | ||
| 669 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallLover> 2268 | ||
| 670 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#TennisFan> 699 | ||
| 671 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#SwimmingLover> 2178 | ||
| 672 | class: <http://semantics.crl.ibm.com/univ-bench-dl.owl#Person> 8787 | ||
| 673 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#like> 13770 | ||
| 674 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isCrazyAbout> 3381 | ||
| 675 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isHeadOf> 18 | ||
| 676 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#isTaughtBy> 1602 | ||
| 677 | property: <http://semantics.crl.ibm.com/univ-bench-dl.owl#love> 13770 | ||
| 678 | property: <http://www.w3.org/2002/07/owl#sameAs> 37 | ||
| 679 | ABox extraction Done | ||
| 680 | TBox extraction Done | ||
| 681 | Before adding bottom fragment: | ||
| 682 | ABoxAxiomsCount = 71034, TBoxAxiomsCount = 30 | ||
| 683 | Part of bottom fragments is added for this query. | ||
| 684 | ABox axioms: 71034 TBox axioms: 30 | ||
| 685 | grouping individuals by its concepts | ||
| 686 | Prefix declared: prefix2:=http://www.Department4.University0.edu/ | ||
| 687 | The summary of ABox is consistent with the TBox. | ||
| 688 | @TIME to check one tuple: 0.545 | ||
| 689 | @TIME to check one tuple: 0.129 | ||
| 690 | @TIME to check one tuple: 0.105 | ||
| 691 | @TIME to check one tuple: 0.09 | ||
| 692 | @TIME to check one tuple: 0.091 | ||
| 693 | @TIME to check one tuple: 0.091 | ||
| 694 | @TIME to check one tuple: 0.112 | ||
| 695 | @TIME to check one tuple: 0.087 | ||
| 696 | @TIME to check one tuple: 0.075 | ||
| 697 | @TIME to check one tuple: 0.071 | ||
| 698 | @TIME to check one tuple: 0.07 | ||
| 699 | @TIME to check one tuple: 0.07 | ||
| 700 | @TIME to check one tuple: 0.07 | ||
| 701 | @TIME to check one tuple: 0.073 | ||
| 702 | @TIME to check one tuple: 0.071 | ||
| 703 | @TIME to check one tuple: 0.864 | ||
| 704 | @TIME to check one tuple: 0.063 | ||
| 705 | @TIME to check one tuple: 0.063 | ||
| 706 | @TIME to check one tuple: 0.062 | ||
| 707 | @TIME to check one tuple: 0.063 | ||
| 708 | @TIME to check one tuple: 0.063 | ||
| 709 | @TIME to check one tuple: 0.064 | ||
| 710 | @TIME to check one tuple: 0.063 | ||
| 711 | @TIME to check one tuple: 0.063 | ||
| 712 | @TIME to check one tuple: 0.061 | ||
| 713 | @TIME to check one tuple: 0.094 | ||
| 714 | @TIME to check one tuple: 0.096 | ||
| 715 | @TIME to check one tuple: 0.065 | ||
| 716 | @TIME to check one tuple: 0.064 | ||
| 717 | @TIME to check one tuple: 0.064 | ||
| 718 | @TIME to check one tuple: 0.097 | ||
| 719 | @TIME to check one tuple: 0.1 | ||
| 720 | @TIME to check one tuple: 0.148 | ||
| 721 | @TIME to check one tuple: 0.1 | ||
| 722 | @TIME to check one tuple: 0.105 | ||
| 723 | @TIME to check one tuple: 0.074 | ||
| 724 | @TIME to check one tuple: 0.063 | ||
| 725 | @TIME to check one tuple: 0.094 | ||
| 726 | @TIME to check one tuple: 0.062 | ||
| 727 | @TIME to check one tuple: 0.064 | ||
| 728 | @TIME to check one tuple: 0.063 | ||
| 729 | @TIME to check one tuple: 0.063 | ||
| 730 | @TIME to check one tuple: 0.063 | ||
| 731 | @TIME to check one tuple: 0.062 | ||
| 732 | @TIME to check one tuple: 0.062 | ||
| 733 | @TIME to check one tuple: 0.061 | ||
| 734 | @TIME to check one tuple: 0.061 | ||
| 735 | @TIME to check one tuple: 0.061 | ||
| 736 | @TIME to check one tuple: 0.061 | ||
| 737 | @TIME to check one tuple: 0.063 | ||
| 738 | @TIME to check one tuple: 0.062 | ||
| 739 | @TIME to check one tuple: 0.063 | ||
| 740 | @TIME to filter out non-answers by summarisation: 6.698 | ||
| 741 | The number of answers to be checked with HermiT: 1460/1470 | ||
| 742 | (http://www.Department16.University0.edu/GraduateStudent74@http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballFan^http://semantics.crl.ibm.com/univ-bench-dl.owl#BaseballLover^http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallFan^http://semantics.crl.ibm.com/univ-bench-dl.owl#BasketBallLover^http://semantics.crl.ibm.com/univ-bench-dl.owl#PeopleWithHobby^http://semantics.crl.ibm.com/univ-bench-dl.owl#Person^http://semantics.crl.ibm.com/univ-bench-dl.owl#SportsFan^http://semantics.crl.ibm.com/univ-bench-dl.owl#SportsLover^http://semantics.crl.ibm.com/univ-bench-dl.owl#TennisFan) | ||
| 743 | (http://www.Department5.University0.edu/UndergraduateStudent359@http://semantics.crl.ibm.com/univ-bench-dl.owl#PeopleWithHobby^http://semantics.crl.ibm.com/univ-bench-dl.owl#Person^http://semantics.crl.ibm.com/univ-bench-dl.owl#SportsLover) | ||
| 744 | The number of times to call homomorphism checker: 762299(645781,115809). | ||
| 745 | Time to compute endomorphism relation: 2.32 | ||
| 746 | link: 2272 | ||
| 747 | @TIME to group individuals in the gap: 2.32 | ||
| 748 | The number of different groups: 853 | ||
| 749 | The number of individuals to be checked by Homomorphism checker: 1460 | ||
| 750 | Entrances: 98 Exists: 353 | ||
| 751 | start checking front ... <http://www.Department7.University0.edu/UndergraduateStudent70> | ||
| 752 | @TIME to check one tuple: 24.128 | ||
| 753 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent430> | ||
| 754 | start checking back ... <http://www.Department18.University0.edu/GraduateStudent32> | ||
| 755 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent106> | ||
| 756 | start checking back ... <http://www.Department0.University0.edu/UndergraduateStudent443> | ||
| 757 | start checking back ... <http://www.Department4.University0.edu/GraduateStudent111> | ||
| 758 | start checking back ... <http://www.Department10.University0.edu/UndergraduateStudent148> | ||
| 759 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent223> | ||
| 760 | start checking back ... <http://www.Department5.University0.edu/AssistantProfessor8> | ||
| 761 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent145> | ||
| 762 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent27> | ||
| 763 | start checking back ... <http://www.Department10.University0.edu/GraduateStudent14> | ||
| 764 | start checking back ... <http://www.Department8.University0.edu/GraduateStudent132> | ||
| 765 | start checking back ... <http://www.Department14.University0.edu/GraduateStudent35> | ||
| 766 | start checking back ... <http://www.Department5.University0.edu/GraduateStudent172> | ||
| 767 | start checking back ... <http://www.Department10.University0.edu/GraduateStudent118> | ||
| 768 | start checking back ... <http://www.Department12.University0.edu/AssistantProfessor0> | ||
| 769 | start checking back ... <http://www.Department3.University0.edu/FullProfessor2> | ||
| 770 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent413> | ||
| 771 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent412> | ||
| 772 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent497> | ||
| 773 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent184> | ||
| 774 | start checking back ... <http://www.Department11.University0.edu/GraduateStudent121> | ||
| 775 | start checking back ... <http://www.Department17.University0.edu/GraduateStudent6> | ||
| 776 | start checking back ... <http://www.Department16.University0.edu/SystemsStaff10> | ||
| 777 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent239> | ||
| 778 | start checking back ... <http://www.Department13.University0.edu/GraduateStudent59> | ||
| 779 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent218> | ||
| 780 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent354> | ||
| 781 | start checking back ... <http://www.Department10.University0.edu/GraduateStudent94> | ||
| 782 | start checking back ... <http://www.Department11.University0.edu/GraduateStudent123> | ||
| 783 | start checking back ... <http://www.Department10.University0.edu/Chair10> | ||
| 784 | start checking back ... <http://www.Department9.University0.edu/UndergraduateStudent16> | ||
| 785 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent209> | ||
| 786 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent458> | ||
| 787 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent358> | ||
| 788 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent203> | ||
| 789 | start checking back ... <http://www.Department9.University0.edu/UndergraduateStudent126> | ||
| 790 | start checking back ... <http://www.Department13.University0.edu/Lecturer6> | ||
| 791 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent224> | ||
| 792 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent369> | ||
| 793 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent463> | ||
| 794 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent234> | ||
| 795 | start checking back ... <http://www.Department16.University0.edu/GraduateStudent101> | ||
| 796 | start checking back ... <http://www.Department7.University0.edu/other_staff7> | ||
| 797 | start checking back ... <http://www.Department7.University0.edu/GraduateStudent149> | ||
| 798 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent311> | ||
| 799 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent259> | ||
| 800 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent285> | ||
| 801 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent281> | ||
| 802 | start checking back ... <http://www.Department10.University0.edu/Lecturer6> | ||
| 803 | start checking back ... <http://www.Department4.University0.edu/UndergraduateStudent213> | ||
| 804 | start checking back ... <http://www.Department10.University0.edu/GraduateStudent90> | ||
| 805 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent335> | ||
| 806 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent356> | ||
| 807 | start checking back ... <http://www.Department17.University0.edu/AssociateProfessor5> | ||
| 808 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent329> | ||
| 809 | start checking back ... <http://www.Department0.University0.edu/other_staff16> | ||
| 810 | start checking back ... <http://www.Department16.University0.edu/GraduateStudent88> | ||
| 811 | start checking back ... <http://www.Department15.University0.edu/UndergraduateStudent270> | ||
| 812 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent203> | ||
| 813 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent112> | ||
| 814 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent172> | ||
| 815 | start checking back ... <http://www.Department13.University0.edu/FullProfessor7> | ||
| 816 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent169> | ||
| 817 | start checking back ... <http://www.Department6.University0.edu/UndergraduateStudent207> | ||
| 818 | start checking back ... <http://www.Department14.University0.edu/FullProfessor1> | ||
| 819 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent180> | ||
| 820 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent321> | ||
| 821 | start checking back ... <http://www.Department16.University0.edu/GraduateStudent56> | ||
| 822 | start checking back ... <http://www.Department3.University0.edu/SystemsStaff9> | ||
| 823 | start checking back ... <http://www.Department6.University0.edu/UndergraduateStudent377> | ||
| 824 | start checking back ... <http://www.Department0.University0.edu/UndergraduateStudent71> | ||
| 825 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent327> | ||
| 826 | start checking back ... <http://www.Department1.University0.edu/AssistantProfessor5> | ||
| 827 | start checking back ... <http://www.Department0.University0.edu/GraduateStudent1> | ||
| 828 | start checking back ... <http://www.Department0.University0.edu/UndergraduateStudent359> | ||
| 829 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent181> | ||
| 830 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent148> | ||
| 831 | start checking back ... <http://www.Department10.University0.edu/UndergraduateStudent107> | ||
| 832 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent248> | ||
| 833 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent519> | ||
| 834 | start checking back ... <http://www.Department0.University0.edu/AssistantProfessor5> | ||
| 835 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent256> | ||
| 836 | start checking back ... <http://www.Department9.University0.edu/GraduateStudent44> | ||
| 837 | start checking back ... <http://www.Department11.University0.edu/UndergraduateStudent322> | ||
| 838 | start checking back ... <http://www.Department7.University0.edu/GraduateStudent28> | ||
| 839 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent530> | ||
| 840 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent572> | ||
| 841 | start checking back ... <http://www.Department1.University0.edu/AssociateProfessor6> | ||
| 842 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent196> | ||
| 843 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent379> | ||
| 844 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent45> | ||
| 845 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent63> | ||
| 846 | start checking back ... <http://www.Department15.University0.edu/UndergraduateStudent344> | ||
| 847 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent157> | ||
| 848 | start checking back ... <http://www.Department16.University0.edu/Lecturer2> | ||
| 849 | start checking back ... <http://www.Department14.University0.edu/GraduateStudent30> | ||
| 850 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent369> | ||
| 851 | start checking back ... <http://www.Department11.University0.edu/GraduateStudent35> | ||
| 852 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent318> | ||
| 853 | start checking back ... <http://www.Department18.University0.edu/GraduateStudent124> | ||
| 854 | start checking back ... <http://www.Department16.University0.edu/UndergraduateStudent290> | ||
| 855 | start checking back ... <http://www.Department4.University0.edu/GraduateStudent53> | ||
| 856 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent411> | ||
| 857 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent371> | ||
| 858 | start checking back ... <http://www.Department17.University0.edu/GraduateStudent57> | ||
| 859 | start checking back ... <http://www.Department4.University0.edu/UndergraduateStudent344> | ||
| 860 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent142> | ||
| 861 | start checking back ... <http://www.Department13.University0.edu/GraduateStudent170> | ||
| 862 | start checking back ... <http://www.Department1.University0.edu/GraduateStudent146> | ||
| 863 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent58> | ||
| 864 | start checking back ... <http://www.Department16.University0.edu/UndergraduateStudent41> | ||
| 865 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent131> | ||
| 866 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent231> | ||
| 867 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent313> | ||
| 868 | start checking back ... <http://www.Department0.University0.edu/UndergraduateStudent208> | ||
| 869 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent103> | ||
| 870 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent85> | ||
| 871 | start checking back ... <http://www.Department0.University0.edu/SystemsStaff4> | ||
| 872 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent593> | ||
| 873 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent41> | ||
| 874 | start checking back ... <http://www.College0.University0.edu/woman_student104> | ||
| 875 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent248> | ||
| 876 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent6> | ||
| 877 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent212> | ||
| 878 | start checking back ... <http://www.Department14.University0.edu/AssociateProfessor9> | ||
| 879 | start checking back ... <http://www.Department1.University0.edu/SameIndividual0> | ||
| 880 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent407> | ||
| 881 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent540> | ||
| 882 | start checking back ... <http://www.Department15.University0.edu/GraduateStudent75> | ||
| 883 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent291> | ||
| 884 | start checking back ... <http://www.Department8.University0.edu/GraduateStudent66> | ||
| 885 | start checking back ... <http://www.Department17.University0.edu/GraduateStudent85> | ||
| 886 | start checking back ... <http://www.Department11.University0.edu/GraduateStudent31> | ||
| 887 | start checking back ... <http://www.Department0.University0.edu/UndergraduateStudent299> | ||
| 888 | start checking back ... <http://www.Department6.University0.edu/GraduateStudent6> | ||
| 889 | start checking back ... <http://www.Department0.University0.edu/AssociateProfessor4> | ||
| 890 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent242> | ||
| 891 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent296> | ||
| 892 | start checking back ... <http://www.Department0.University0.edu/GraduateStudent114> | ||
| 893 | start checking back ... <http://www.Department13.University0.edu/UndergraduateStudent209> | ||
| 894 | start checking back ... <http://www.Department8.University0.edu/AssociateProfessor3> | ||
| 895 | start checking back ... <http://www.Department15.University0.edu/UndergraduateStudent153> | ||
| 896 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent2> | ||
| 897 | start checking back ... <http://www.Department0.University0.edu/UndergraduateStudent352> | ||
| 898 | start checking back ... <http://www.College0.University0.edu/woman_student154> | ||
| 899 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent148> | ||
| 900 | start checking back ... <http://www.Department5.University0.edu/GraduateStudent16> | ||
| 901 | start checking back ... <http://www.Department1.University0.edu/GraduateStudent27> | ||
| 902 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent298> | ||
| 903 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent237> | ||
| 904 | start checking back ... <http://www.Department16.University0.edu/GraduateStudent140> | ||
| 905 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent92> | ||
| 906 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent186> | ||
| 907 | start checking back ... <http://www.Department8.University0.edu/GraduateStudent91> | ||
| 908 | start checking back ... <http://www.Department0.University0.edu/GraduateStudent26> | ||
| 909 | start checking back ... <http://www.Department15.University0.edu/UndergraduateStudent237> | ||
| 910 | start checking back ... <http://www.Department14.University0.edu/GraduateStudent140> | ||
| 911 | start checking back ... <http://www.Department11.University0.edu/UndergraduateStudent183> | ||
| 912 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent46> | ||
| 913 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent264> | ||
| 914 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent41> | ||
| 915 | start checking back ... <http://www.Department0.University0.edu/GraduateStudent16> | ||
| 916 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent200> | ||
| 917 | start checking back ... <http://www.Department6.University0.edu/Chair6> | ||
| 918 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent22> | ||
| 919 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent108> | ||
| 920 | start checking back ... <http://www.Department16.University0.edu/UndergraduateStudent81> | ||
| 921 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent399> | ||
| 922 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent128> | ||
| 923 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent91> | ||
| 924 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent357> | ||
| 925 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent327> | ||
| 926 | start checking back ... <http://www.Department8.University0.edu/AssistantProfessor8> | ||
| 927 | start checking back ... <http://www.Department4.University0.edu/UndergraduateStudent335> | ||
| 928 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent99> | ||
| 929 | start checking back ... <http://www.Department5.University0.edu/GraduateStudent78> | ||
| 930 | start checking back ... <http://www.Department13.University0.edu/other_staff6> | ||
| 931 | start checking back ... <http://www.Department13.University0.edu/UndergraduateStudent321> | ||
| 932 | start checking back ... <http://www.Department6.University0.edu/other_staff13> | ||
| 933 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent240> | ||
| 934 | start checking back ... <http://www.Department3.University0.edu/GraduateStudent32> | ||
| 935 | start checking back ... <http://www.Department15.University0.edu/AssociateProfessor4> | ||
| 936 | start checking back ... <http://www.Department2.University0.edu/other_staff13> | ||
| 937 | start checking back ... <http://www.Department4.University0.edu/SystemsStaff10> | ||
| 938 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent249> | ||
| 939 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent505> | ||
| 940 | start checking back ... <http://www.Department10.University0.edu/UndergraduateStudent52> | ||
| 941 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent513> | ||
| 942 | start checking back ... <http://www.Department11.University0.edu/UndergraduateStudent184> | ||
| 943 | start checking back ... <http://www.Department6.University0.edu/GraduateStudent148> | ||
| 944 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent471> | ||
| 945 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent205> | ||
| 946 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent186> | ||
| 947 | start checking back ... <http://www.Department13.University0.edu/UndergraduateStudent470> | ||
| 948 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent404> | ||
| 949 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent308> | ||
| 950 | start checking back ... <http://www.Department9.University0.edu/UndergraduateStudent142> | ||
| 951 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent283> | ||
| 952 | start checking back ... <http://www.Department13.University0.edu/UndergraduateStudent530> | ||
| 953 | start checking back ... <http://www.Department8.University0.edu/AssociateProfessor0> | ||
| 954 | start checking back ... <http://www.Department5.University0.edu/Lecturer2> | ||
| 955 | start checking back ... <http://www.Department16.University0.edu/AssociateProfessor4> | ||
| 956 | start checking back ... <http://www.Department11.University0.edu/AssistantProfessor0> | ||
| 957 | start checking back ... <http://www.Department16.University0.edu/AssistantProfessor5> | ||
| 958 | start checking back ... <http://www.Department7.University0.edu/FullProfessor7> | ||
| 959 | start checking back ... <http://www.Department11.University0.edu/FullProfessor5> | ||
| 960 | start checking back ... <http://www.Department8.University0.edu/FullProfessor4> | ||
| 961 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent368> | ||
| 962 | start checking back ... <http://www.Department11.University0.edu/UndergraduateStudent213> | ||
| 963 | start checking back ... <http://www.Department16.University0.edu/GraduateStudent74> | ||
| 964 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent6> | ||
| 965 | start checking back ... <http://www.Department9.University0.edu/UndergraduateStudent229> | ||
| 966 | start checking back ... <http://www.Department16.University0.edu/other_staff4> | ||
| 967 | start checking back ... <http://www.Department6.University0.edu/UndergraduateStudent319> | ||
| 968 | start checking back ... <http://www.Department8.University0.edu/GraduateStudent156> | ||
| 969 | start checking back ... <http://www.Department11.University0.edu/GraduateStudent32> | ||
| 970 | start checking back ... <http://www.Department11.University0.edu/UndergraduateStudent370> | ||
| 971 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent145> | ||
| 972 | start checking back ... <http://www.Department18.University0.edu/GraduateStudent103> | ||
| 973 | start checking back ... <http://www.Department10.University0.edu/UndergraduateStudent412> | ||
| 974 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent286> | ||
| 975 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent316> | ||
| 976 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent171> | ||
| 977 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent492> | ||
| 978 | start checking back ... <http://www.Department9.University0.edu/UndergraduateStudent133> | ||
| 979 | start checking back ... <http://www.Department17.University0.edu/GraduateStudent55> | ||
| 980 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent209> | ||
| 981 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent59> | ||
| 982 | start checking back ... <http://www.Department6.University0.edu/UndergraduateStudent12> | ||
| 983 | start checking back ... <http://www.Department15.University0.edu/UndergraduateStudent128> | ||
| 984 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent556> | ||
| 985 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent427> | ||
| 986 | start checking back ... <http://www.Department0.University0.edu/UndergraduateStudent301> | ||
| 987 | start checking back ... <http://www.Department13.University0.edu/UndergraduateStudent511> | ||
| 988 | start checking back ... <http://www.Department15.University0.edu/SystemsStaff11> | ||
| 989 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent6> | ||
| 990 | start checking back ... <http://www.Department2.University0.edu/other_staff3> | ||
| 991 | start checking back ... <http://www.Department5.University0.edu/GraduateStudent74> | ||
| 992 | start checking back ... <http://www.Department1.University0.edu/GraduateStudent150> | ||
| 993 | start checking back ... <http://www.Department18.University0.edu/GraduateStudent159> | ||
| 994 | start checking back ... <http://www.Department5.University0.edu/GraduateStudent9> | ||
| 995 | start checking back ... <http://www.Department11.University0.edu/UndergraduateStudent105> | ||
| 996 | start checking back ... <http://www.Department6.University0.edu/GraduateStudent120> | ||
| 997 | start checking back ... <http://www.Department9.University0.edu/GraduateStudent0> | ||
| 998 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent385> | ||
| 999 | start checking back ... <http://www.Department13.University0.edu/UndergraduateStudent341> | ||
| 1000 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent24> | ||
| 1001 | start checking back ... <http://www.Department1.University0.edu/GraduateStudent69> | ||
| 1002 | start checking back ... <http://www.Department10.University0.edu/GraduateStudent134> | ||
| 1003 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent430> | ||
| 1004 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent8> | ||
| 1005 | start checking back ... <http://www.Department5.University0.edu/GraduateStudent81> | ||
| 1006 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent39> | ||
| 1007 | start checking back ... <http://www.Department15.University0.edu/UndergraduateStudent88> | ||
| 1008 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent111> | ||
| 1009 | start checking back ... <http://www.Department15.University0.edu/AssociateProfessor7> | ||
| 1010 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent241> | ||
| 1011 | start checking back ... <http://www.Department10.University0.edu/AssistantProfessor1> | ||
| 1012 | start checking back ... <http://www.Department13.University0.edu/UndergraduateStudent19> | ||
| 1013 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent341> | ||
| 1014 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent424> | ||
| 1015 | start checking back ... <http://www.Department6.University0.edu/UndergraduateStudent136> | ||
| 1016 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent169> | ||
| 1017 | start checking back ... <http://www.Department15.University0.edu/GraduateStudent128> | ||
| 1018 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent325> | ||
| 1019 | start checking back ... <http://www.Department10.University0.edu/UndergraduateStudent73> | ||
| 1020 | start checking back ... <http://www.Department12.University0.edu/GraduateStudent95> | ||
| 1021 | start checking back ... <http://www.Department5.University0.edu/AssistantProfessor2> | ||
| 1022 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent415> | ||
| 1023 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent114> | ||
| 1024 | start checking back ... <http://www.Department3.University0.edu/FullProfessor5> | ||
| 1025 | start checking back ... <http://www.Department9.University0.edu/UndergraduateStudent423> | ||
| 1026 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent269> | ||
| 1027 | start checking back ... <http://www.Department12.University0.edu/GraduateStudent67> | ||
| 1028 | start checking back ... <http://www.Department4.University0.edu/ClericalStaff1> | ||
| 1029 | start checking back ... <http://www.Department6.University0.edu/UndergraduateStudent297> | ||
| 1030 | start checking back ... <http://www.Department13.University0.edu/UndergraduateStudent379> | ||
| 1031 | start checking back ... <http://www.Department18.University0.edu/GraduateStudent139> | ||
| 1032 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent110> | ||
| 1033 | start checking back ... <http://www.Department11.University0.edu/GraduateStudent135> | ||
| 1034 | start checking back ... <http://www.Department2.University0.edu/GraduateStudent108> | ||
| 1035 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent257> | ||
| 1036 | start checking back ... <http://www.Department13.University0.edu/UndergraduateStudent332> | ||
| 1037 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent192> | ||
| 1038 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent333> | ||
| 1039 | start checking back ... <http://www.Department10.University0.edu/other_staff8> | ||
| 1040 | start checking back ... <http://www.Department1.University0.edu/GraduateStudent154> | ||
| 1041 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent400> | ||
| 1042 | start checking back ... <http://www.Department4.University0.edu/UndergraduateStudent73> | ||
| 1043 | start checking back ... <http://www.College0.University0.edu/woman_student203> | ||
| 1044 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent116> | ||
| 1045 | start checking back ... <http://www.Department3.University0.edu/SystemsStaff14> | ||
| 1046 | start checking back ... <http://www.Department9.University0.edu/UndergraduateStudent65> | ||
| 1047 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent482> | ||
| 1048 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent324> | ||
| 1049 | start checking back ... <http://www.Department13.University0.edu/GraduateStudent24> | ||
| 1050 | start checking back ... <http://www.Department11.University0.edu/UndergraduateStudent67> | ||
| 1051 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent404> | ||
| 1052 | start checking back ... <http://www.Department9.University0.edu/UndergraduateStudent138> | ||
| 1053 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent42> | ||
| 1054 | start checking back ... <http://www.Department15.University0.edu/UndergraduateStudent127> | ||
| 1055 | start checking back ... <http://www.Department10.University0.edu/UndergraduateStudent164> | ||
| 1056 | start checking back ... <http://www.Department3.University0.edu/SameIndividual0> | ||
| 1057 | start checking back ... <http://www.Department17.University0.edu/SystemsStaff15> | ||
| 1058 | start checking back ... <http://www.Department6.University0.edu/UndergraduateStudent337> | ||
| 1059 | start checking back ... <http://www.Department3.University0.edu/GraduateStudent134> | ||
| 1060 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent453> | ||
| 1061 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent571> | ||
| 1062 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent120> | ||
| 1063 | start checking back ... <http://www.Department1.University0.edu/AssociateProfessor12> | ||
| 1064 | start checking back ... <http://www.Department0.University0.edu/GraduateStudent4> | ||
| 1065 | start checking back ... <http://www.Department7.University0.edu/FullProfessor2> | ||
| 1066 | start checking back ... <http://www.Department14.University0.edu/AssociateProfessor1> | ||
| 1067 | start checking back ... <http://www.Department17.University0.edu/AssistantProfessor8> | ||
| 1068 | start checking back ... <http://www.Department18.University0.edu/GraduateStudent153> | ||
| 1069 | start checking back ... <http://www.Department11.University0.edu/other_staff8> | ||
| 1070 | start checking back ... <http://www.Department1.University0.edu/UndergraduateStudent35> | ||
| 1071 | start checking back ... <http://www.Department9.University0.edu/AssociateProfessor5> | ||
| 1072 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent219> | ||
| 1073 | start checking back ... <http://www.Department14.University0.edu/UndergraduateStudent166> | ||
| 1074 | start checking back ... <http://www.Department8.University0.edu/SystemsStaff8> | ||
| 1075 | start checking back ... <http://www.Department6.University0.edu/FullProfessor5> | ||
| 1076 | start checking back ... <http://www.Department10.University0.edu/GraduateStudent161> | ||
| 1077 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent94> | ||
| 1078 | start checking back ... <http://www.Department3.University0.edu/ClericalStaff0> | ||
| 1079 | start checking back ... <http://www.Department2.University0.edu/other_staff16> | ||
| 1080 | start checking back ... <http://www.Department16.University0.edu/UndergraduateStudent381> | ||
| 1081 | start checking back ... <http://www.Department2.University0.edu/GraduateStudent15> | ||
| 1082 | start checking back ... <http://www.Department1.University0.edu/GraduateStudent36> | ||
| 1083 | start checking back ... <http://www.Department12.University0.edu/UndergraduateStudent273> | ||
| 1084 | start checking back ... <http://www.Department10.University0.edu/UndergraduateStudent147> | ||
| 1085 | start checking back ... <http://www.Department10.University0.edu/other_staff0> | ||
| 1086 | start checking back ... <http://www.Department3.University0.edu/UndergraduateStudent94> | ||
| 1087 | start checking back ... <http://www.Department5.University0.edu/GraduateStudent164> | ||
| 1088 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent293> | ||
| 1089 | start checking back ... <http://www.Department15.University0.edu/UndergraduateStudent269> | ||
| 1090 | start checking back ... <http://www.Department18.University0.edu/UndergraduateStudent514> | ||
| 1091 | start checking back ... <http://www.Department7.University0.edu/UndergraduateStudent51> | ||
| 1092 | start checking back ... <http://www.Department2.University0.edu/UndergraduateStudent127> | ||
| 1093 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent306> | ||
| 1094 | start checking back ... <http://www.Department10.University0.edu/GraduateStudent112> | ||
| 1095 | start checking back ... <http://www.Department5.University0.edu/UndergraduateStudent322> | ||
| 1096 | start checking back ... <http://www.Department6.University0.edu/UndergraduateStudent282> | ||
| 1097 | start checking back ... <http://www.Department17.University0.edu/UndergraduateStudent498> | ||
| 1098 | start checking back ... <http://www.Department10.University0.edu/UndergraduateStudent417> | ||
| 1099 | start checking back ... <http://www.Department9.University0.edu/UndergraduateStudent86> | ||
| 1100 | start checking back ... <http://www.Department13.University0.edu/GraduateStudent43> | ||
| 1101 | start checking back ... <http://www.Department8.University0.edu/UndergraduateStudent358> | ||
| 1102 | start checking back ... <http://www.Department16.University0.edu/UndergraduateStudent277> | ||
| 1103 | start checking back ... <http://www.Department16.University0.edu/GraduateStudent85> | ||
| 1104 | start checking back ... <http://www.Department11.University0.edu/UndergraduateStudent10> | ||
| 1105 | start checking back ... <http://www.Department17.University0.edu/GraduateStudent42> | ||
| 1106 | The number of correct answers: 0 | ||
| 1107 | Hermit was called 52 times. | ||
| 1108 | Hermit was called 1 times. | ||
| 1109 | Total time for full reasoner: 47.885 | ||
| 1110 | Difficulty of this query: FullReasoning | ||
| 1111 | Total time to answer this query: 53.158 | ||
| 1112 | The number of answer tuples: 2416 | ||
| 1113 | time for LowerBound: 0.005 | ||
| 1114 | time for UpperBound: 0.021 | ||
| 1115 | time for ELLowerBound: 1.16 | ||
| 1116 | time for Fragment: 4.037 | ||
| 1117 | time for FragmentRefinement: 0.0 | ||
| 1118 | time for Summarisation: 7.498 | ||
| 1119 | time for Dependency: 0.0 | ||
| 1120 | time for FullReasoning: 38.332 | ||
| 1121 | ---------- start evaluating Query 19 ---------- | ||
| 1122 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Student . ?x benchmark:takesCourse _:y . _:y benchmark:isTaughtBy <http://www.Department0.University0.edu/FullProfessor0> } | ||
| 1123 | 0.009 | ||
| 1124 | The number of answers in the lower bound: 50 | ||
| 1125 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Student . ?x benchmark:takesCourse _:y . _:y benchmark:isTaughtBy <http://www.Department0.University0.edu/FullProfessor0> } | ||
| 1126 | 0.011 | ||
| 1127 | The number of answers returned by the upper bound: 50 | ||
| 1128 | The number of answers in the upper bound: 50 | ||
| 1129 | Difficulty of this query: UpperBound | ||
| 1130 | Total time to answer this query: 0.021 | ||
| 1131 | The number of answer tuples: 50 | ||
| 1132 | time for LowerBound: 0.01 | ||
| 1133 | time for UpperBound: 0.011 | ||
| 1134 | time for ELLowerBound: 0.0 | ||
| 1135 | time for Fragment: 0.0 | ||
| 1136 | time for FragmentRefinement: 0.0 | ||
| 1137 | time for Summarisation: 0.0 | ||
| 1138 | time for Dependency: 0.0 | ||
| 1139 | time for FullReasoning: 0.0 | ||
| 1140 | ---------- start evaluating Query 20 ---------- | ||
| 1141 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Woman . ?x rdf:type benchmark:Student . ?x benchmark:isMemberOf _:y . _:y benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 1142 | 0.011 | ||
| 1143 | The number of answers in the lower bound: 6535 | ||
| 1144 | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX benchmark: <http://semantics.crl.ibm.com/univ-bench-dl.owl#> SELECT distinct ?x WHERE { ?x rdf:type benchmark:Woman . ?x rdf:type benchmark:Student . ?x benchmark:isMemberOf _:y . _:y benchmark:subOrganizationOf <http://www.University0.edu> } | ||
| 1145 | 0.013 | ||
| 1146 | The number of answers returned by the upper bound: 6535 | ||
| 1147 | The number of answers in the upper bound: 6535 | ||
| 1148 | Difficulty of this query: UpperBound | ||
| 1149 | Total time to answer this query: 0.03 | ||
| 1150 | The number of answer tuples: 6535 | ||
| 1151 | time for LowerBound: 0.015 | ||
| 1152 | time for UpperBound: 0.015 | ||
| 1153 | time for ELLowerBound: 0.0 | ||
| 1154 | time for Fragment: 0.0 | ||
| 1155 | time for FragmentRefinement: 0.0 | ||
| 1156 | time for Summarisation: 0.0 | ||
| 1157 | time for Dependency: 0.0 | ||
| 1158 | time for FullReasoning: 0.0 \ No newline at end of file | ||
diff --git a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java index b92bceb..638a151 100644 --- a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java +++ b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | |||
| @@ -23,577 +23,585 @@ import java.util.regex.Pattern; | |||
| 23 | 23 | ||
| 24 | public class RLPlusOntology implements KnowledgeBase { | 24 | public class RLPlusOntology implements KnowledgeBase { |
| 25 | 25 | ||
| 26 | private static final String DEFAULT_ONTOLOGY_FILE_EXTENSION = "owl"; | 26 | private static final String DEFAULT_ONTOLOGY_FILE_EXTENSION = "owl"; |
| 27 | private static final Pattern ONTOLOGY_ID_REGEX = Pattern.compile("ontologyid\\((?<id>[a-z0-9\\-]+)\\)"); | 27 | private static final Pattern ONTOLOGY_ID_REGEX = Pattern.compile("ontologyid\\((?<id>[a-z0-9\\-]+)\\)"); |
| 28 | OWLOntologyManager manager; | 28 | OWLOntologyManager manager; |
| 29 | OWLDataFactory factory; | 29 | OWLDataFactory factory; |
| 30 | String ontologyIRI; | 30 | String ontologyIRI; |
| 31 | String corrFileName = null; | 31 | String corrFileName = null; |
| 32 | String outputPath, aBoxPath; | 32 | String outputPath, aBoxPath; |
| 33 | OWLOntology inputOntology = null; | 33 | OWLOntology inputOntology = null; |
| 34 | OWLOntology tBox = null; | 34 | OWLOntology tBox = null; |
| 35 | OWLOntology aBox = null; | 35 | OWLOntology aBox = null; |
| 36 | OWLOntology restOntology = null; | 36 | OWLOntology restOntology = null; |
| 37 | OWLOntology outputOntology = null; //RL ontology | 37 | OWLOntology outputOntology = null; //RL ontology |
| 38 | DLOntology dlOntology = null; | 38 | DLOntology dlOntology = null; |
| 39 | int rlCounter = 0; | 39 | int rlCounter = 0; |
| 40 | LinkedList<Clause> clauses; | 40 | LinkedList<Clause> clauses; |
| 41 | Map<OWLAxiom, OWLAxiom> correspondence; | 41 | Map<OWLAxiom, OWLAxiom> correspondence; |
| 42 | BottomStrategy botStrategy; | 42 | BottomStrategy botStrategy; |
| 43 | Random random = new Random(19900114); | 43 | Random random = new Random(19900114); |
| 44 | private Map<OWLClassExpression, Integer> subCounter = null; | 44 | private Map<OWLClassExpression, Integer> subCounter = null; |
| 45 | private Map<OWLClass, OWLClass> atomic2negation = new HashMap<OWLClass, OWLClass>(); | 45 | private Map<OWLClass, OWLClass> atomic2negation = new HashMap<OWLClass, OWLClass>(); |
| 46 | 46 | ||
| 47 | // FIXME multiple anonymous ontologies | 47 | // TODO don't know if it is correct |
| 48 | @Override | 48 | @Override |
| 49 | public void load(OWLOntology ontology, uk.ac.ox.cs.pagoda.constraints.BottomStrategy bottomStrategy) { | 49 | public void load(OWLOntology ontology, uk.ac.ox.cs.pagoda.constraints.BottomStrategy bottomStrategy) { |
| 50 | if (bottomStrategy instanceof UnaryBottom) | 50 | if(bottomStrategy instanceof UnaryBottom) |
| 51 | botStrategy = BottomStrategy.UNARY; | 51 | botStrategy = BottomStrategy.UNARY; |
| 52 | else if (bottomStrategy instanceof NullaryBottom) | 52 | else if(bottomStrategy instanceof NullaryBottom) |
| 53 | botStrategy = BottomStrategy.NULLARY; | 53 | botStrategy = BottomStrategy.NULLARY; |
| 54 | else | 54 | else |
| 55 | botStrategy = BottomStrategy.TOREMOVE; | 55 | botStrategy = BottomStrategy.TOREMOVE; |
| 56 | 56 | ||
| 57 | if(corrFileName == null) | 57 | if(corrFileName == null) |
| 58 | corrFileName = "rlplus.crr"; | 58 | corrFileName = "rlplus.crr"; |
| 59 | manager = ontology.getOWLOntologyManager(); | 59 | manager = ontology.getOWLOntologyManager(); |
| 60 | // manager = OWLManager.createOWLOntologyManager(); | 60 | // manager = OWLManager.createOWLOntologyManager(); |
| 61 | factory = manager.getOWLDataFactory(); | 61 | factory = manager.getOWLDataFactory(); |
| 62 | inputOntology = ontology; | 62 | inputOntology = ontology; |
| 63 | 63 | ||
| 64 | try { | 64 | try { |
| 65 | IRI ontologyIri; | 65 | IRI ontologyIri; |
| 66 | if(ontology.isAnonymous()) { | 66 | if(ontology.isAnonymous()) { |
| 67 | Matcher matcher = ONTOLOGY_ID_REGEX.matcher(ontology.getOntologyID().toString().toLowerCase()); | 67 | Matcher matcher = ONTOLOGY_ID_REGEX.matcher(ontology.getOntologyID().toString().toLowerCase()); |
| 68 | if(!matcher.matches()) throw new Error("Anonymous ontology without internal id"); | 68 | if(!matcher.matches()) throw new Error("Anonymous ontology without internal id"); |
| 69 | ontologyIri = | 69 | ontologyIri = |
| 70 | IRI.create("http://www.example.org/", matcher.group("id") + "." + DEFAULT_ONTOLOGY_FILE_EXTENSION); | 70 | IRI.create("http://www.example.org/", matcher.group("id") + "." + DEFAULT_ONTOLOGY_FILE_EXTENSION); |
| 71 | } | 71 | } |
| 72 | else | 72 | else |
| 73 | ontologyIri = inputOntology.getOntologyID().getOntologyIRI(); | 73 | ontologyIri = inputOntology.getOntologyID().getOntologyIRI(); |
| 74 | 74 | ||
| 75 | String ontologyIriPrefix = ontologyIri.getNamespace(); | 75 | String ontologyIriPrefix = ontologyIri.getNamespace(); |
| 76 | ontologyIRI = ontologyIri.toString(); | 76 | ontologyIRI = ontologyIri.toString(); |
| 77 | String ontologyIriFragment = ontologyIri.getFragment(); | 77 | String ontologyIriFragment = ontologyIri.getFragment(); |
| 78 | String originalFileName = FilenameUtils.removeExtension(ontologyIriFragment); | 78 | String originalFileName = FilenameUtils.removeExtension(ontologyIriFragment); |
| 79 | String originalExtension = FilenameUtils.getExtension(ontologyIriFragment); | 79 | String originalExtension = FilenameUtils.getExtension(ontologyIriFragment); |
| 80 | if(originalExtension.isEmpty()) originalExtension = DEFAULT_ONTOLOGY_FILE_EXTENSION; | 80 | if(originalExtension.isEmpty()) originalExtension = DEFAULT_ONTOLOGY_FILE_EXTENSION; |
| 81 | 81 | ||
| 82 | 82 | ||
| 83 | IRI rlOntologyIRI = IRI.create(ontologyIriPrefix, originalFileName + "-RL." + originalExtension); | 83 | IRI rlOntologyIRI = IRI.create(ontologyIriPrefix, originalFileName + "-RL." + originalExtension); |
| 84 | outputPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), | 84 | outputPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), |
| 85 | originalFileName + "-RL." + originalExtension).toString(); | 85 | originalFileName + "-RL." + originalExtension).toString(); |
| 86 | IRI rlDocumentIRI = IRI.create("file://" + outputPath); | 86 | IRI rlDocumentIRI = IRI.create("file://" + outputPath); |
| 87 | outputOntology = manager.createOntology(rlOntologyIRI); | 87 | outputOntology = manager.createOntology(rlOntologyIRI); |
| 88 | manager.setOntologyDocumentIRI(outputOntology, rlDocumentIRI); | 88 | manager.setOntologyDocumentIRI(outputOntology, rlDocumentIRI); |
| 89 | 89 | ||
| 90 | String tBoxOntologyFragment = originalFileName + "-TBox." + originalExtension; | 90 | String tBoxOntologyFragment = originalFileName + "-TBox." + originalExtension; |
| 91 | IRI tBoxOntologyIRI = IRI.create(ontologyIriPrefix, tBoxOntologyFragment); | 91 | IRI tBoxOntologyIRI = IRI.create(ontologyIriPrefix, tBoxOntologyFragment); |
| 92 | IRI tBoxDocumentIRI = | 92 | IRI tBoxDocumentIRI = |
| 93 | IRI.create("file://" + Paths.get(Utility.getGlobalTempDirAbsolutePath(), tBoxOntologyFragment)); | 93 | IRI.create("file://" + Paths.get(Utility.getGlobalTempDirAbsolutePath(), tBoxOntologyFragment)); |
| 94 | 94 | ||
| 95 | String aBoxOntologyFragment = originalFileName + "-ABox." + originalExtension; | 95 | String aBoxOntologyFragment = originalFileName + "-ABox." + originalExtension; |
| 96 | IRI aBoxOntologyIRI = IRI.create(ontologyIriPrefix, aBoxOntologyFragment); | 96 | IRI aBoxOntologyIRI = IRI.create(ontologyIriPrefix, aBoxOntologyFragment); |
| 97 | aBoxPath = Paths.get(Utility.getGlobalTempDirAbsolutePath()) + aBoxOntologyFragment; | 97 | aBoxPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), aBoxOntologyFragment).toString(); |
| 98 | IRI aBoxDocumentIRI = | 98 | IRI aBoxDocumentIRI = |
| 99 | IRI.create("file://" + Paths.get(Utility.getGlobalTempDirAbsolutePath(), aBoxOntologyFragment)); | 99 | IRI.create("file://" + Paths.get(Utility.getGlobalTempDirAbsolutePath(), aBoxOntologyFragment)); |
| 100 | 100 | ||
| 101 | tBox = manager.createOntology(tBoxOntologyIRI); | 101 | tBox = manager.createOntology(tBoxOntologyIRI); |
| 102 | aBox = manager.createOntology(aBoxOntologyIRI); | 102 | aBox = manager.createOntology(aBoxOntologyIRI); |
| 103 | manager.setOntologyDocumentIRI(tBox, tBoxDocumentIRI); | 103 | manager.setOntologyDocumentIRI(tBox, tBoxDocumentIRI); |
| 104 | manager.setOntologyDocumentIRI(aBox, aBoxDocumentIRI); | 104 | manager.setOntologyDocumentIRI(aBox, aBoxDocumentIRI); |
| 105 | 105 | ||
| 106 | FileOutputStream aBoxOut = new FileOutputStream(aBoxPath); | 106 | FileOutputStream aBoxOut = new FileOutputStream(aBoxPath); |
| 107 | manager.saveOntology(aBox, aBoxOut); | 107 | manager.saveOntology(aBox, aBoxOut); |
| 108 | aBoxOut.close(); | 108 | aBoxOut.close(); |
| 109 | 109 | ||
| 110 | restOntology = manager.createOntology(); | 110 | restOntology = manager.createOntology(); |
| 111 | } catch(OWLOntologyCreationException | OWLOntologyStorageException | IOException e) { | 111 | } catch(OWLOntologyCreationException | OWLOntologyStorageException | IOException e) { |
| 112 | e.printStackTrace(); | 112 | e.printStackTrace(); |
| 113 | System.exit(1); | 113 | System.exit(1); |
| 114 | } | 114 | } |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | public OWLOntology getTBox() { | 117 | public OWLOntology getTBox() { |
| 118 | return tBox; | 118 | return tBox; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | public String getABoxPath() { | 121 | public String getABoxPath() { |
| 122 | return aBoxPath; | 122 | return aBoxPath; |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | private void add2SubCounter(OWLClassExpression exp) { | 125 | public void simplify() { |
| 126 | Integer count = subCounter.get(exp); | 126 | if(simplifyABox()) { |
| 127 | if (count == null) count = 0; | 127 | save(aBox); |
| 128 | ++count; | ||
| 129 | subCounter.put(exp, count); | ||
| 130 | } | ||
| 131 | |||
| 132 | public void simplify() { | ||
| 133 | if(simplifyABox()) { | ||
| 134 | save(aBox); | ||
| 135 | // save(tBox); | 128 | // save(tBox); |
| 136 | } else | 129 | } |
| 137 | tBox = inputOntology; | 130 | else |
| 138 | } | 131 | tBox = inputOntology; |
| 132 | } | ||
| 139 | 133 | ||
| 140 | @Override | 134 | @Override |
| 141 | public void transform() { | 135 | public void transform() { |
| 142 | simplify(); | 136 | simplify(); |
| 143 | filter(); | 137 | filter(); |
| 144 | clausify(); | 138 | clausify(); |
| 145 | 139 | ||
| 146 | subCounter = new HashMap<OWLClassExpression, Integer>(); | 140 | subCounter = new HashMap<OWLClassExpression, Integer>(); |
| 147 | clauses = new LinkedList<Clause>(); | 141 | clauses = new LinkedList<Clause>(); |
| 148 | Clausifier clausifier = Clausifier.getInstance(restOntology); | 142 | Clausifier clausifier = Clausifier.getInstance(restOntology); |
| 149 | 143 | ||
| 150 | for (DLClause c: dlOntology.getDLClauses()) { | 144 | for(DLClause c : dlOntology.getDLClauses()) { |
| 151 | Clause clause = new Clause(clausifier, c); | 145 | Clause clause = new Clause(clausifier, c); |
| 152 | clauses.add(clause); | 146 | clauses.add(clause); |
| 153 | 147 | ||
| 154 | /* | 148 | /* |
| 155 | * count the expressions in the left | 149 | * count the expressions in the left |
| 156 | */ | 150 | */ |
| 157 | for (OWLClassExpression exp: clause.getSubClasses()) { | 151 | for(OWLClassExpression exp : clause.getSubClasses()) { |
| 158 | if(exp instanceof OWLClass) | 152 | if(exp instanceof OWLClass) |
| 159 | add2SubCounter(exp); | 153 | add2SubCounter(exp); |
| 160 | else if (exp instanceof OWLObjectSomeValuesFrom) { | 154 | else if(exp instanceof OWLObjectSomeValuesFrom) { |
| 161 | OWLObjectSomeValuesFrom someValue = (OWLObjectSomeValuesFrom)exp; | 155 | OWLObjectSomeValuesFrom someValue = (OWLObjectSomeValuesFrom) exp; |
| 162 | add2SubCounter(factory.getOWLObjectSomeValuesFrom(someValue.getProperty(), factory.getOWLThing())); | 156 | add2SubCounter(factory.getOWLObjectSomeValuesFrom(someValue.getProperty(), factory.getOWLThing())); |
| 163 | add2SubCounter(someValue.getFiller()); | 157 | add2SubCounter(someValue.getFiller()); |
| 164 | } | 158 | } |
| 165 | else if (exp instanceof OWLObjectMinCardinality) { | 159 | else if(exp instanceof OWLObjectMinCardinality) { |
| 166 | OWLObjectMinCardinality minCard = (OWLObjectMinCardinality)exp; | 160 | OWLObjectMinCardinality minCard = (OWLObjectMinCardinality) exp; |
| 167 | add2SubCounter(factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), factory.getOWLThing())); | 161 | add2SubCounter(factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), factory.getOWLThing())); |
| 168 | add2SubCounter(minCard.getFiller()); | 162 | add2SubCounter(minCard.getFiller()); |
| 169 | } else | 163 | } |
| 170 | Utility.logError("strange class expression: " + exp); | 164 | else |
| 171 | 165 | Utility.logError("strange class expression: " + exp); | |
| 172 | } | 166 | |
| 173 | } | 167 | } |
| 174 | 168 | } | |
| 175 | correspondence = new HashMap<OWLAxiom, OWLAxiom>(); | 169 | |
| 176 | Set<OWLAxiom> addedAxioms = new HashSet<OWLAxiom>(); | 170 | correspondence = new HashMap<OWLAxiom, OWLAxiom>(); |
| 177 | OWLClassExpression subExp; | 171 | Set<OWLAxiom> addedAxioms = new HashSet<OWLAxiom>(); |
| 178 | for (Clause clause: clauses) { | 172 | OWLClassExpression subExp; |
| 179 | subExp = uk.ac.ox.cs.pagoda.owl.OWLHelper.getSimplifiedConjunction(factory, clause.getSubClasses()); | 173 | for(Clause clause : clauses) { |
| 180 | addedAxioms.clear(); | 174 | subExp = uk.ac.ox.cs.pagoda.owl.OWLHelper.getSimplifiedConjunction(factory, clause.getSubClasses()); |
| 181 | for (OWLClassExpression exp: getDisjunctionApprox0(clause.getSuperClasses())) { | 175 | addedAxioms.clear(); |
| 182 | addedAxioms.add(factory.getOWLSubClassOfAxiom(subExp, transform(exp, addedAxioms))); | 176 | for(OWLClassExpression exp : getDisjunctionApprox0(clause.getSuperClasses())) { |
| 183 | for(OWLAxiom a : addedAxioms) | 177 | addedAxioms.add(factory.getOWLSubClassOfAxiom(subExp, transform(exp, addedAxioms))); |
| 184 | addAxiom2output(a, factory.getOWLSubClassOfAxiom(subExp, | 178 | for(OWLAxiom a : addedAxioms) |
| 185 | OWLHelper.getSimplifiedDisjunction(factory, clause.getSuperClasses()))); | 179 | addAxiom2output(a, factory.getOWLSubClassOfAxiom(subExp, |
| 186 | } | 180 | OWLHelper.getSimplifiedDisjunction(factory, clause.getSuperClasses()))); |
| 187 | } | 181 | } |
| 188 | 182 | } | |
| 189 | subCounter.clear(); | 183 | |
| 190 | } | 184 | subCounter.clear(); |
| 191 | 185 | } | |
| 192 | @Override | 186 | |
| 193 | public void save() { | 187 | @Override |
| 194 | if (corrFileName != null) | 188 | public void save() { |
| 195 | save(correspondence, corrFileName); | 189 | if(corrFileName != null) |
| 196 | save(outputOntology); | 190 | save(correspondence, corrFileName); |
| 197 | } | 191 | save(outputOntology); |
| 198 | 192 | } | |
| 199 | private void save(Map<OWLAxiom, OWLAxiom> map, String corrFileName) { | 193 | |
| 200 | if (corrFileName == null) return ; | 194 | public OWLOntologyManager getOWLOntologyManager() { |
| 201 | ObjectOutput output; | 195 | return inputOntology.getOWLOntologyManager(); |
| 202 | try { | 196 | } |
| 203 | output = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(corrFileName))); | 197 | |
| 204 | output.writeObject(map); | 198 | public String getOntologyIRI() { |
| 205 | output.close(); | 199 | return ontologyIRI; |
| 206 | } catch (IOException e) { | 200 | } |
| 207 | e.printStackTrace(); | 201 | |
| 208 | } | 202 | public OWLOntology getOutputOntology() { |
| 209 | } | 203 | return outputOntology; |
| 210 | 204 | } | |
| 211 | protected void save(OWLOntology onto) { | 205 | |
| 212 | try { | 206 | @Override |
| 213 | onto.getOWLOntologyManager().saveOntology(onto); | 207 | public String getOutputPath() { |
| 214 | } catch (OWLOntologyStorageException e) { | 208 | return outputPath; |
| 215 | e.printStackTrace(); | 209 | } |
| 216 | } | 210 | |
| 217 | } | 211 | @Override |
| 218 | 212 | public String getDirectory() { | |
| 219 | /* | 213 | return outputPath.substring(0, outputPath.lastIndexOf(Utility.FILE_SEPARATOR)); |
| 220 | * treat disjunction as conjunction | 214 | } |
| 221 | */ | 215 | |
| 222 | private Set<OWLClassExpression> getDisjunctionApprox0(Set<OWLClassExpression> superClasses) { | 216 | public void setCorrespondenceFileLoc(String path) { |
| 223 | return superClasses; | 217 | corrFileName = path; |
| 224 | } | 218 | } |
| 225 | 219 | ||
| 226 | /* | 220 | private void add2SubCounter(OWLClassExpression exp) { |
| 227 | * choose one simple class disjunct | 221 | Integer count = subCounter.get(exp); |
| 228 | */ | 222 | if(count == null) count = 0; |
| 229 | @SuppressWarnings("unused") | 223 | ++count; |
| 230 | private Set<OWLClassExpression> getDisjunctionApprox1(Set<OWLClassExpression> superClasses) { | 224 | subCounter.put(exp, count); |
| 231 | if(superClasses.isEmpty() || superClasses.size() == 1) | 225 | } |
| 232 | return superClasses; | 226 | |
| 233 | 227 | private void save(Map<OWLAxiom, OWLAxiom> map, String corrFileName) { | |
| 234 | OWLClassExpression rep = null; | 228 | if(corrFileName == null) return; |
| 235 | int min = Integer.MAX_VALUE, o; | 229 | ObjectOutput output; |
| 236 | for(OWLClassExpression exp : superClasses) | 230 | try { |
| 237 | if(exp instanceof OWLClass && (o = getOccurrence(exp)) < min) { | 231 | output = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(corrFileName))); |
| 238 | min = o; | 232 | output.writeObject(map); |
| 239 | rep = exp; | 233 | output.close(); |
| 240 | } | 234 | } catch(IOException e) { |
| 241 | 235 | e.printStackTrace(); | |
| 242 | if(rep == null) rep = superClasses.iterator().next(); | 236 | } |
| 243 | 237 | } | |
| 244 | return Collections.singleton(rep); | 238 | |
| 245 | } | 239 | protected void save(OWLOntology onto) { |
| 246 | 240 | try { | |
| 247 | /* | 241 | onto.getOWLOntologyManager().saveOntology(onto); |
| 248 | * randomly choose a class expression to represent this disjunction | 242 | } catch(OWLOntologyStorageException e) { |
| 249 | */ | 243 | e.printStackTrace(); |
| 250 | @SuppressWarnings("unused") | 244 | } |
| 251 | private Set<OWLClassExpression> getDisjunctionApprox2(Set<OWLClassExpression> superClasses) { | 245 | } |
| 252 | if(superClasses.isEmpty() || superClasses.size() == 1) | 246 | |
| 253 | return superClasses; | 247 | /* |
| 254 | 248 | * treat disjunction as conjunction | |
| 255 | int index = random.nextInt() % superClasses.size(); | 249 | */ |
| 256 | if (index < 0) index += superClasses.size(); | 250 | private Set<OWLClassExpression> getDisjunctionApprox0(Set<OWLClassExpression> superClasses) { |
| 257 | 251 | return superClasses; | |
| 258 | int i = 0; | 252 | } |
| 259 | for(OWLClassExpression exp : superClasses) | 253 | |
| 260 | if (i++ == index) | 254 | /* |
| 261 | return Collections.singleton(exp); | 255 | * choose one simple class disjunct |
| 262 | return null; | 256 | */ |
| 263 | } | 257 | @SuppressWarnings("unused") |
| 264 | 258 | private Set<OWLClassExpression> getDisjunctionApprox1(Set<OWLClassExpression> superClasses) { | |
| 265 | /* | 259 | if(superClasses.isEmpty() || superClasses.size() == 1) |
| 266 | * choose the one that appears least in the l.h.s. | 260 | return superClasses; |
| 267 | */ | 261 | |
| 268 | @SuppressWarnings("unused") | 262 | OWLClassExpression rep = null; |
| 269 | private Set<OWLClassExpression> getDisjunctionApprox3(Set<OWLClassExpression> superClasses) { | 263 | int min = Integer.MAX_VALUE, o; |
| 270 | if(superClasses.isEmpty() || superClasses.size() == 1) | 264 | for(OWLClassExpression exp : superClasses) |
| 271 | return superClasses; | 265 | if(exp instanceof OWLClass && (o = getOccurrence(exp)) < min) { |
| 272 | 266 | min = o; | |
| 273 | OWLClassExpression rep = null, exp1; | 267 | rep = exp; |
| 274 | int occurrence = Integer.MAX_VALUE, o; | 268 | } |
| 275 | for (OWLClassExpression exp: superClasses) { | 269 | |
| 276 | o = 0; | 270 | if(rep == null) rep = superClasses.iterator().next(); |
| 277 | exp1 = exp; | 271 | |
| 278 | if (exp instanceof OWLObjectMinCardinality) { | 272 | return Collections.singleton(rep); |
| 279 | OWLObjectMinCardinality minCard = (OWLObjectMinCardinality)exp; | 273 | } |
| 280 | if (minCard.getCardinality() == 1) | 274 | |
| 281 | exp1 = factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), minCard.getFiller()); | 275 | /* |
| 282 | } | 276 | * randomly choose a class expression to represent this disjunction |
| 283 | 277 | */ | |
| 284 | if (!subCounter.containsKey(exp1) || (o = subCounter.get(exp1)) < occurrence) { | 278 | @SuppressWarnings("unused") |
| 285 | rep = exp; | 279 | private Set<OWLClassExpression> getDisjunctionApprox2(Set<OWLClassExpression> superClasses) { |
| 286 | occurrence = o; | 280 | if(superClasses.isEmpty() || superClasses.size() == 1) |
| 287 | } | 281 | return superClasses; |
| 288 | } | 282 | |
| 289 | 283 | int index = random.nextInt() % superClasses.size(); | |
| 290 | return Collections.singleton(rep); | 284 | if(index < 0) index += superClasses.size(); |
| 291 | } | 285 | |
| 292 | 286 | int i = 0; | |
| 293 | private int getOccurrence(OWLClassExpression exp) { | 287 | for(OWLClassExpression exp : superClasses) |
| 294 | if (!subCounter.containsKey(exp)) | 288 | if(i++ == index) |
| 295 | return 0; | 289 | return Collections.singleton(exp); |
| 296 | return subCounter.get(exp); | 290 | return null; |
| 297 | } | 291 | } |
| 298 | 292 | ||
| 299 | @SuppressWarnings("unused") | 293 | /* |
| 300 | private Set<OWLClassExpression> getDisjunctionApprox4(Set<OWLClassExpression> superClasses) { | 294 | * choose the one that appears least in the l.h.s. |
| 301 | if(superClasses.isEmpty() || superClasses.size() == 1) | 295 | */ |
| 302 | return superClasses; | 296 | @SuppressWarnings("unused") |
| 303 | 297 | private Set<OWLClassExpression> getDisjunctionApprox3(Set<OWLClassExpression> superClasses) { | |
| 304 | OWLClassExpression rep = null; | 298 | if(superClasses.isEmpty() || superClasses.size() == 1) |
| 305 | int occurrence = Integer.MAX_VALUE, o; | 299 | return superClasses; |
| 306 | for (OWLClassExpression exp: superClasses) { | 300 | |
| 307 | o = 0; | 301 | OWLClassExpression rep = null, exp1; |
| 308 | if (exp instanceof OWLObjectMinCardinality) { | 302 | int occurrence = Integer.MAX_VALUE, o; |
| 309 | OWLObjectMinCardinality minCard = (OWLObjectMinCardinality)exp; | 303 | for(OWLClassExpression exp : superClasses) { |
| 310 | if (minCard.getCardinality() == 1) { | 304 | o = 0; |
| 311 | o = getOccurrence((factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), factory.getOWLThing()))); | 305 | exp1 = exp; |
| 312 | o += getOccurrence(minCard.getFiller()); | 306 | if(exp instanceof OWLObjectMinCardinality) { |
| 307 | OWLObjectMinCardinality minCard = (OWLObjectMinCardinality) exp; | ||
| 308 | if(minCard.getCardinality() == 1) | ||
| 309 | exp1 = factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), minCard.getFiller()); | ||
| 310 | } | ||
| 311 | |||
| 312 | if(!subCounter.containsKey(exp1) || (o = subCounter.get(exp1)) < occurrence) { | ||
| 313 | rep = exp; | ||
| 314 | occurrence = o; | ||
| 315 | } | ||
| 316 | } | ||
| 317 | |||
| 318 | return Collections.singleton(rep); | ||
| 319 | } | ||
| 320 | |||
| 321 | private int getOccurrence(OWLClassExpression exp) { | ||
| 322 | if(!subCounter.containsKey(exp)) | ||
| 323 | return 0; | ||
| 324 | return subCounter.get(exp); | ||
| 325 | } | ||
| 326 | |||
| 327 | @SuppressWarnings("unused") | ||
| 328 | private Set<OWLClassExpression> getDisjunctionApprox4(Set<OWLClassExpression> superClasses) { | ||
| 329 | if(superClasses.isEmpty() || superClasses.size() == 1) | ||
| 330 | return superClasses; | ||
| 331 | |||
| 332 | OWLClassExpression rep = null; | ||
| 333 | int occurrence = Integer.MAX_VALUE, o; | ||
| 334 | for(OWLClassExpression exp : superClasses) { | ||
| 335 | o = 0; | ||
| 336 | if(exp instanceof OWLObjectMinCardinality) { | ||
| 337 | OWLObjectMinCardinality minCard = (OWLObjectMinCardinality) exp; | ||
| 338 | if(minCard.getCardinality() == 1) { | ||
| 339 | o = | ||
| 340 | getOccurrence((factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), factory.getOWLThing()))); | ||
| 341 | o += getOccurrence(minCard.getFiller()); | ||
| 313 | // if (o < o1) o = o1; | 342 | // if (o < o1) o = o1; |
| 314 | } | 343 | } |
| 315 | } else | 344 | } |
| 316 | o = getOccurrence(exp); | 345 | else |
| 317 | 346 | o = getOccurrence(exp); | |
| 318 | if (o < occurrence || o == occurrence && !(rep instanceof OWLClass)) { | 347 | |
| 319 | rep = exp; | 348 | if(o < occurrence || o == occurrence && !(rep instanceof OWLClass)) { |
| 320 | occurrence = o; | 349 | rep = exp; |
| 321 | } | 350 | occurrence = o; |
| 322 | } | 351 | } |
| 323 | 352 | } | |
| 324 | return Collections.singleton(rep); | 353 | |
| 325 | } | 354 | return Collections.singleton(rep); |
| 326 | 355 | } | |
| 327 | private boolean simplifyABox() { | 356 | |
| 328 | boolean flag = false; | 357 | private boolean simplifyABox() { |
| 329 | Map<OWLClassExpression, OWLClass> complex2atomic= new HashMap<OWLClassExpression, OWLClass>(); | 358 | boolean flag = false; |
| 330 | 359 | Map<OWLClassExpression, OWLClass> complex2atomic = new HashMap<OWLClassExpression, OWLClass>(); | |
| 331 | OWLDatatype anyURI = factory.getOWLDatatype(IRI.create(Namespace.XSD_NS + "anyURI")); | 360 | |
| 332 | OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); | 361 | OWLDatatype anyURI = factory.getOWLDatatype(IRI.create(Namespace.XSD_NS + "anyURI")); |
| 333 | OWLObjectProperty differentFrom = factory.getOWLObjectProperty(IRI.create(Namespace.INEQUALITY)); | 362 | OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); |
| 334 | 363 | OWLObjectProperty differentFrom = factory.getOWLObjectProperty(IRI.create(Namespace.INEQUALITY)); | |
| 335 | for (OWLOntology imported: inputOntology.getImportsClosure()) | 364 | |
| 336 | for (OWLAxiom axiom: imported.getAxioms()) { | 365 | for(OWLOntology imported : inputOntology.getImportsClosure()) |
| 337 | if (axiom instanceof OWLClassAssertionAxiom) { | 366 | for(OWLAxiom axiom : imported.getAxioms()) { |
| 338 | flag = true; | 367 | if(axiom instanceof OWLClassAssertionAxiom) { |
| 339 | OWLClassAssertionAxiom assertion = (OWLClassAssertionAxiom)axiom; | 368 | flag = true; |
| 340 | OWLClassExpression clsExp = assertion.getClassExpression(); | 369 | OWLClassAssertionAxiom assertion = (OWLClassAssertionAxiom) axiom; |
| 341 | OWLClass cls; | 370 | OWLClassExpression clsExp = assertion.getClassExpression(); |
| 342 | if (clsExp instanceof OWLClass) { | 371 | OWLClass cls; |
| 343 | if (((OWLClass) clsExp).toStringID().startsWith("owl:")) | 372 | if(clsExp instanceof OWLClass) { |
| 344 | manager.addAxiom(tBox, axiom); | 373 | if(((OWLClass) clsExp).toStringID().startsWith("owl:")) |
| 345 | else manager.addAxiom(aBox, axiom); | 374 | manager.addAxiom(tBox, axiom); |
| 346 | } | 375 | else manager.addAxiom(aBox, axiom); |
| 347 | else { | 376 | } |
| 348 | if ((cls = complex2atomic.get(clsExp)) == null) { | 377 | else { |
| 349 | complex2atomic.put(clsExp, cls = getNewConcept(tBox, rlCounter++)); | 378 | if((cls = complex2atomic.get(clsExp)) == null) { |
| 350 | manager.addAxiom(tBox, factory.getOWLSubClassOfAxiom(cls, clsExp)); | 379 | complex2atomic.put(clsExp, cls = getNewConcept(tBox, rlCounter++)); |
| 351 | } | 380 | manager.addAxiom(tBox, factory.getOWLSubClassOfAxiom(cls, clsExp)); |
| 352 | manager.addAxiom(aBox, factory.getOWLClassAssertionAxiom(cls, assertion.getIndividual())); | 381 | } |
| 353 | } | 382 | manager.addAxiom(aBox, factory.getOWLClassAssertionAxiom(cls, assertion.getIndividual())); |
| 354 | } | 383 | } |
| 355 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom || axiom instanceof OWLDataPropertyAssertionAxiom || axiom instanceof OWLAnnotationAssertionAxiom) { | 384 | } |
| 356 | if(axiom.getDataPropertiesInSignature().contains(anyURI)) continue; | 385 | else if(axiom instanceof OWLObjectPropertyAssertionAxiom || axiom instanceof OWLDataPropertyAssertionAxiom || axiom instanceof OWLAnnotationAssertionAxiom) { |
| 357 | flag = true; | 386 | if(axiom.getDataPropertiesInSignature().contains(anyURI)) continue; |
| 358 | manager.addAxiom(aBox, axiom); | 387 | flag = true; |
| 359 | } | 388 | manager.addAxiom(aBox, axiom); |
| 360 | else if (axiom instanceof OWLSameIndividualAxiom) { | 389 | } |
| 361 | OWLIndividual firstIndividual = null, previousIndividual = null, lastIndividual = null; | 390 | else if(axiom instanceof OWLSameIndividualAxiom) { |
| 362 | for (OWLIndividual next: ((OWLSameIndividualAxiom) axiom).getIndividuals()) { | 391 | OWLIndividual firstIndividual = null, previousIndividual = null, lastIndividual = null; |
| 363 | if(firstIndividual == null) firstIndividual = previousIndividual = next; | 392 | for(OWLIndividual next : ((OWLSameIndividualAxiom) axiom).getIndividuals()) { |
| 364 | else | 393 | if(firstIndividual == null) firstIndividual = previousIndividual = next; |
| 365 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, previousIndividual, next)); | 394 | else |
| 366 | previousIndividual = lastIndividual = next; | 395 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, previousIndividual, next)); |
| 367 | } | 396 | previousIndividual = lastIndividual = next; |
| 368 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, lastIndividual, firstIndividual)); | 397 | } |
| 369 | } | 398 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, lastIndividual, firstIndividual)); |
| 370 | else if (axiom instanceof OWLDifferentIndividualsAxiom) { | 399 | } |
| 371 | int index1 = 0, index2; | 400 | else if(axiom instanceof OWLDifferentIndividualsAxiom) { |
| 372 | for (OWLIndividual individual1: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { | 401 | int index1 = 0, index2; |
| 373 | ++index1; | 402 | for(OWLIndividual individual1 : ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { |
| 374 | index2 = 0; | 403 | ++index1; |
| 375 | for (OWLIndividual individual2: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { | 404 | index2 = 0; |
| 376 | if (index2++ < index1) { | 405 | for(OWLIndividual individual2 : ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { |
| 377 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(differentFrom, individual1, individual2)); | 406 | if(index2++ < index1) { |
| 378 | } else break; | 407 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(differentFrom, individual1, individual2)); |
| 379 | } | 408 | } |
| 380 | } | 409 | else break; |
| 381 | } else | 410 | } |
| 382 | manager.addAxiom(tBox, axiom); | 411 | } |
| 383 | } | 412 | } |
| 384 | 413 | else | |
| 385 | return flag; | 414 | manager.addAxiom(tBox, axiom); |
| 386 | } | 415 | } |
| 387 | 416 | ||
| 388 | private void filter() { | 417 | return flag; |
| 389 | OWL2RLProfile profile = new OWL2RLProfile(); | 418 | } |
| 390 | OWLProfileReport report = profile.checkOntology(tBox); | 419 | |
| 391 | Set<OWLAxiom> rlAxioms = tBox.getAxioms(); | 420 | private void filter() { |
| 392 | OWLAxiom axiom; | 421 | OWL2RLProfile profile = new OWL2RLProfile(); |
| 393 | 422 | OWLProfileReport report = profile.checkOntology(tBox); | |
| 394 | for (OWLProfileViolation violation: report.getViolations()) { | 423 | Set<OWLAxiom> rlAxioms = tBox.getAxioms(); |
| 395 | manager.addAxiom(restOntology, axiom = violation.getAxiom()); | 424 | OWLAxiom axiom; |
| 396 | rlAxioms.remove(axiom); | 425 | |
| 397 | } | 426 | for(OWLProfileViolation violation : report.getViolations()) { |
| 398 | 427 | manager.addAxiom(restOntology, axiom = violation.getAxiom()); | |
| 399 | for (Iterator<OWLAxiom> iter = rlAxioms.iterator(); iter.hasNext(); ) | 428 | rlAxioms.remove(axiom); |
| 400 | addAxiom2output(iter.next(), null); | 429 | } |
| 401 | } | 430 | |
| 402 | 431 | for(Iterator<OWLAxiom> iter = rlAxioms.iterator(); iter.hasNext(); ) | |
| 403 | private void clausify() { | 432 | addAxiom2output(iter.next(), null); |
| 404 | Configuration conf = new Configuration(); | 433 | } |
| 405 | OWLClausification clausifier = new OWLClausification(conf); | 434 | |
| 406 | dlOntology = (DLOntology)clausifier.preprocessAndClausify(restOntology, null)[1]; | 435 | private void clausify() { |
| 407 | clausifier = null; | 436 | Configuration conf = new Configuration(); |
| 408 | } | 437 | OWLClausification clausifier = new OWLClausification(conf); |
| 409 | 438 | dlOntology = (DLOntology) clausifier.preprocessAndClausify(restOntology, null)[1]; | |
| 410 | protected void addAxiom2output(OWLAxiom axiom, OWLAxiom correspondingAxiom) { | 439 | clausifier = null; |
| 411 | manager.addAxiom(outputOntology, axiom); | 440 | } |
| 412 | if (correspondingAxiom != null) | 441 | |
| 413 | correspondence.put(axiom, correspondingAxiom); | 442 | protected void addAxiom2output(OWLAxiom axiom, OWLAxiom correspondingAxiom) { |
| 414 | } | 443 | manager.addAxiom(outputOntology, axiom); |
| 415 | 444 | if(correspondingAxiom != null) | |
| 416 | private OWLClassExpression transform(OWLClassExpression exp, Set<OWLAxiom> addedAxioms) { | 445 | correspondence.put(axiom, correspondingAxiom); |
| 417 | if (exp instanceof OWLClass) | 446 | } |
| 418 | return exp; | 447 | |
| 419 | 448 | private OWLClassExpression transform(OWLClassExpression exp, Set<OWLAxiom> addedAxioms) { | |
| 420 | if (exp instanceof OWLObjectHasValue) | 449 | if(exp instanceof OWLClass) |
| 421 | return exp; | 450 | return exp; |
| 422 | 451 | ||
| 423 | if (exp instanceof OWLObjectSomeValuesFrom) { | 452 | if(exp instanceof OWLObjectHasValue) |
| 424 | OWLObjectSomeValuesFrom someValueExp = (OWLObjectSomeValuesFrom)exp; | 453 | return exp; |
| 425 | 454 | ||
| 426 | OWLClassExpression tExp = someValueExp.getFiller(); | 455 | if(exp instanceof OWLObjectSomeValuesFrom) { |
| 427 | if (tExp.equals(factory.getOWLThing())) | 456 | OWLObjectSomeValuesFrom someValueExp = (OWLObjectSomeValuesFrom) exp; |
| 428 | exp = factory.getOWLObjectMinCardinality(1, someValueExp.getProperty()); | 457 | |
| 429 | else | 458 | OWLClassExpression tExp = someValueExp.getFiller(); |
| 430 | exp = factory.getOWLObjectMinCardinality(1, someValueExp.getProperty(), someValueExp.getFiller()); | 459 | if(tExp.equals(factory.getOWLThing())) |
| 431 | } | 460 | exp = factory.getOWLObjectMinCardinality(1, someValueExp.getProperty()); |
| 432 | 461 | else | |
| 433 | if (exp instanceof OWLObjectMinCardinality) { | 462 | exp = factory.getOWLObjectMinCardinality(1, someValueExp.getProperty(), someValueExp.getFiller()); |
| 434 | OWLObjectMinCardinality minExp = (OWLObjectMinCardinality)exp; | 463 | } |
| 435 | OWLObjectPropertyExpression r; | 464 | |
| 436 | 465 | if(exp instanceof OWLObjectMinCardinality) { | |
| 437 | if (minExp.getFiller().equals(factory.getOWLThing())) { | 466 | OWLObjectMinCardinality minExp = (OWLObjectMinCardinality) exp; |
| 438 | r = minExp.getProperty(); | 467 | OWLObjectPropertyExpression r; |
| 439 | } | 468 | |
| 440 | //TODO to be restored ... | 469 | if(minExp.getFiller().equals(factory.getOWLThing())) { |
| 441 | //else if ((r = exists2role.get(someValueExp)) == null) { | 470 | r = minExp.getProperty(); |
| 442 | // deal with r' \subseteq r & range(r') \subseteq C | 471 | } |
| 443 | else { | 472 | //TODO to be restored ... |
| 444 | r = getNewRole(outputOntology, rlCounter); | 473 | //else if ((r = exists2role.get(someValueExp)) == null) { |
| 445 | addedAxioms.add(factory.getOWLSubObjectPropertyOfAxiom(r, minExp.getProperty())); | 474 | // deal with r' \subseteq r & range(r') \subseteq C |
| 446 | OWLClassExpression tExp = minExp.getFiller(); | 475 | else { |
| 447 | if (!(tExp instanceof OWLObjectComplementOf)) { | 476 | r = getNewRole(outputOntology, rlCounter); |
| 448 | if (tExp.equals(factory.getOWLThing())); | 477 | addedAxioms.add(factory.getOWLSubObjectPropertyOfAxiom(r, minExp.getProperty())); |
| 449 | else | 478 | OWLClassExpression tExp = minExp.getFiller(); |
| 450 | addedAxioms.add(factory.getOWLObjectPropertyRangeAxiom(r, tExp)); | 479 | if(!(tExp instanceof OWLObjectComplementOf)) { |
| 451 | } | 480 | if(tExp.equals(factory.getOWLThing())) ; |
| 452 | else if (botStrategy != BottomStrategy.TOREMOVE) { | 481 | else |
| 453 | OWLClass cls = (OWLClass) tExp.getComplementNNF(); | 482 | addedAxioms.add(factory.getOWLObjectPropertyRangeAxiom(r, tExp)); |
| 454 | OWLClass neg; | 483 | } |
| 455 | if ((neg = atomic2negation.get(cls)) == null) { | 484 | else if(botStrategy != BottomStrategy.TOREMOVE) { |
| 456 | neg = getNewConcept(outputOntology, rlCounter); | 485 | OWLClass cls = (OWLClass) tExp.getComplementNNF(); |
| 457 | addedAxioms.add(factory.getOWLDisjointClassesAxiom(neg, cls)); | 486 | OWLClass neg; |
| 458 | atomic2negation.put(cls, neg); | 487 | if((neg = atomic2negation.get(cls)) == null) { |
| 459 | } | 488 | neg = getNewConcept(outputOntology, rlCounter); |
| 460 | addedAxioms.add(factory.getOWLObjectPropertyRangeAxiom(r, neg)); | 489 | addedAxioms.add(factory.getOWLDisjointClassesAxiom(neg, cls)); |
| 461 | } | 490 | atomic2negation.put(cls, neg); |
| 491 | } | ||
| 492 | addedAxioms.add(factory.getOWLObjectPropertyRangeAxiom(r, neg)); | ||
| 493 | } | ||
| 462 | // exists2role.put(someValueExp, (OWLObjectProperty) r); | 494 | // exists2role.put(someValueExp, (OWLObjectProperty) r); |
| 463 | } | 495 | } |
| 464 | 496 | ||
| 465 | // deal with r'(x,c) | 497 | // deal with r'(x,c) |
| 466 | Set<OWLClassExpression> ret = new HashSet<OWLClassExpression>(); | 498 | Set<OWLClassExpression> ret = new HashSet<OWLClassExpression>(); |
| 467 | int num = minExp.getCardinality(); | 499 | int num = minExp.getCardinality(); |
| 468 | 500 | ||
| 469 | Set<OWLNamedIndividual> cs = new HashSet<OWLNamedIndividual>(); | 501 | Set<OWLNamedIndividual> cs = new HashSet<OWLNamedIndividual>(); |
| 470 | OWLNamedIndividual c; | 502 | OWLNamedIndividual c; |
| 471 | for (int i = 0; i < num; ++i) { | 503 | for(int i = 0; i < num; ++i) { |
| 472 | c = getNewIndividual(outputOntology, rlCounter++); | 504 | c = getNewIndividual(outputOntology, rlCounter++); |
| 473 | ret.add(factory.getOWLObjectHasValue(r, c)); | 505 | ret.add(factory.getOWLObjectHasValue(r, c)); |
| 474 | cs.add(c); | 506 | cs.add(c); |
| 475 | } | 507 | } |
| 476 | 508 | ||
| 477 | if (botStrategy != BottomStrategy.TOREMOVE && cs.size() > 1) { | 509 | if(botStrategy != BottomStrategy.TOREMOVE && cs.size() > 1) { |
| 478 | addedAxioms.add(factory.getOWLDifferentIndividualsAxiom(cs)); | 510 | addedAxioms.add(factory.getOWLDifferentIndividualsAxiom(cs)); |
| 479 | } | 511 | } |
| 480 | 512 | ||
| 481 | return OWLHelper.getSimplifiedConjunction(factory, ret); | 513 | return OWLHelper.getSimplifiedConjunction(factory, ret); |
| 482 | } | 514 | } |
| 483 | 515 | ||
| 484 | if (exp instanceof OWLObjectMaxCardinality) { | 516 | if(exp instanceof OWLObjectMaxCardinality) { |
| 485 | OWLObjectMaxCardinality maxExp = (OWLObjectMaxCardinality)exp; | 517 | OWLObjectMaxCardinality maxExp = (OWLObjectMaxCardinality) exp; |
| 486 | OWLClassExpression tExp = maxExp.getFiller(); | 518 | OWLClassExpression tExp = maxExp.getFiller(); |
| 487 | int card = maxExp.getCardinality() >= 1 ? 1 : 0; | 519 | int card = maxExp.getCardinality() >= 1 ? 1 : 0; |
| 488 | if (!(tExp instanceof OWLObjectComplementOf)) | 520 | if(!(tExp instanceof OWLObjectComplementOf)) |
| 489 | return factory.getOWLObjectMaxCardinality(card, maxExp.getProperty(), tExp); | 521 | return factory.getOWLObjectMaxCardinality(card, maxExp.getProperty(), tExp); |
| 490 | else { | 522 | else { |
| 491 | Utility.logDebug("oh, to be tested ... "); | 523 | Utility.logDebug("oh, to be tested ... "); |
| 492 | OWLClassExpression tExp1 = factory.getOWLObjectAllValuesFrom(maxExp.getProperty(), tExp.getComplementNNF()); | 524 | OWLClassExpression tExp1 = |
| 493 | if (card == 0) | 525 | factory.getOWLObjectAllValuesFrom(maxExp.getProperty(), tExp.getComplementNNF()); |
| 494 | return tExp1; | 526 | if(card == 0) |
| 495 | else { | 527 | return tExp1; |
| 496 | OWLClassExpression tExp2 = factory.getOWLObjectMaxCardinality(1, maxExp.getProperty()); | 528 | else { |
| 497 | return factory.getOWLObjectIntersectionOf(tExp1, tExp2); | 529 | OWLClassExpression tExp2 = factory.getOWLObjectMaxCardinality(1, maxExp.getProperty()); |
| 498 | } | 530 | return factory.getOWLObjectIntersectionOf(tExp1, tExp2); |
| 499 | } | 531 | } |
| 500 | } | 532 | } |
| 501 | 533 | } | |
| 502 | if (exp instanceof OWLObjectAllValuesFrom) | 534 | |
| 503 | return exp; | 535 | if(exp instanceof OWLObjectAllValuesFrom) |
| 504 | 536 | return exp; | |
| 505 | if (exp instanceof OWLObjectOneOf) | 537 | |
| 506 | if (((OWLObjectOneOf) exp).getIndividuals().size() == 1) | 538 | if(exp instanceof OWLObjectOneOf) |
| 507 | return exp; | 539 | if(((OWLObjectOneOf) exp).getIndividuals().size() == 1) |
| 508 | else | 540 | return exp; |
| 509 | return null; | 541 | else |
| 510 | 542 | return null; | |
| 511 | if (exp instanceof OWLDataHasValue) | 543 | |
| 512 | return exp; | 544 | if(exp instanceof OWLDataHasValue) |
| 513 | 545 | return exp; | |
| 514 | //TODO overapproximation - dealing with OWLDataMinCardinality | 546 | |
| 515 | 547 | //TODO overapproximation - dealing with OWLDataMinCardinality | |
| 516 | if (exp instanceof OWLDataSomeValuesFrom) { | 548 | |
| 517 | return exp; | 549 | if(exp instanceof OWLDataSomeValuesFrom) { |
| 518 | } | 550 | return exp; |
| 519 | 551 | } | |
| 520 | if (exp instanceof OWLDataMinCardinality) { | 552 | |
| 521 | return exp; | 553 | if(exp instanceof OWLDataMinCardinality) { |
| 522 | } | 554 | return exp; |
| 523 | 555 | } | |
| 524 | if (exp instanceof OWLDataMaxCardinality) { | 556 | |
| 525 | return exp; | 557 | if(exp instanceof OWLDataMaxCardinality) { |
| 526 | } | 558 | return exp; |
| 527 | 559 | } | |
| 528 | 560 | ||
| 529 | Set<OWLClassExpression> exps = exp.asConjunctSet(); | 561 | |
| 530 | if (exps.size() == 1 && exps.iterator().next() == exp) { | 562 | Set<OWLClassExpression> exps = exp.asConjunctSet(); |
| 531 | Utility.logError(exp, "error in transform of Ontology~~~~"); | 563 | if(exps.size() == 1 && exps.iterator().next() == exp) { |
| 532 | } | 564 | Utility.logError(exp, "error in transform of Ontology~~~~"); |
| 533 | Set<OWLClassExpression> nexps = new HashSet<OWLClassExpression>(); | 565 | } |
| 534 | OWLClassExpression ne; | 566 | Set<OWLClassExpression> nexps = new HashSet<OWLClassExpression>(); |
| 535 | boolean changes = false; | 567 | OWLClassExpression ne; |
| 536 | for (OWLClassExpression e: exps) { | 568 | boolean changes = false; |
| 537 | ne = transform(e, addedAxioms); | 569 | for(OWLClassExpression e : exps) { |
| 538 | if (ne != e) changes = true; | 570 | ne = transform(e, addedAxioms); |
| 539 | nexps.add(ne); | 571 | if(ne != e) changes = true; |
| 540 | } | 572 | nexps.add(ne); |
| 541 | if (changes) | 573 | } |
| 542 | return OWLHelper.getSimplifiedConjunction(factory, nexps); | 574 | if(changes) |
| 543 | else | 575 | return OWLHelper.getSimplifiedConjunction(factory, nexps); |
| 544 | return exp; | 576 | else |
| 545 | } | 577 | return exp; |
| 546 | 578 | } | |
| 547 | protected OWLNamedIndividual getNewIndividual(OWLOntology onto, int number) { | 579 | |
| 548 | OWLOntologyManager manager = onto.getOWLOntologyManager(); | 580 | protected OWLNamedIndividual getNewIndividual(OWLOntology onto, int number) { |
| 549 | OWLDataFactory factory = manager.getOWLDataFactory(); | 581 | OWLOntologyManager manager = onto.getOWLOntologyManager(); |
| 550 | OWLNamedIndividual newIndividual = factory.getOWLNamedIndividual(IRI.create(Namespace.PAGODA_ANONY + "NI" + number)); | 582 | OWLDataFactory factory = manager.getOWLDataFactory(); |
| 551 | manager.addAxiom(onto, factory.getOWLDeclarationAxiom(newIndividual)); | 583 | OWLNamedIndividual newIndividual = |
| 552 | return newIndividual; | 584 | factory.getOWLNamedIndividual(IRI.create(Namespace.PAGODA_ANONY + "NI" + number)); |
| 553 | } | 585 | manager.addAxiom(onto, factory.getOWLDeclarationAxiom(newIndividual)); |
| 554 | 586 | return newIndividual; | |
| 555 | protected OWLObjectProperty getNewRole(OWLOntology onto, int number) { | 587 | } |
| 556 | OWLOntologyManager manager = onto.getOWLOntologyManager(); | 588 | |
| 557 | OWLDataFactory factory = manager.getOWLDataFactory(); | 589 | protected OWLObjectProperty getNewRole(OWLOntology onto, int number) { |
| 558 | OWLObjectProperty newProperty = factory.getOWLObjectProperty(IRI.create(Namespace.PAGODA_AUX + "NR" + number)); | 590 | OWLOntologyManager manager = onto.getOWLOntologyManager(); |
| 559 | manager.addAxiom(onto, factory.getOWLDeclarationAxiom(newProperty)); | 591 | OWLDataFactory factory = manager.getOWLDataFactory(); |
| 560 | return newProperty; | 592 | OWLObjectProperty newProperty = factory.getOWLObjectProperty(IRI.create(Namespace.PAGODA_AUX + "NR" + number)); |
| 561 | } | 593 | manager.addAxiom(onto, factory.getOWLDeclarationAxiom(newProperty)); |
| 562 | 594 | return newProperty; | |
| 563 | private OWLClass getNewConcept(OWLOntology onto, int number) { | 595 | } |
| 564 | OWLOntologyManager manager = onto.getOWLOntologyManager(); | 596 | |
| 565 | OWLDataFactory factory = manager.getOWLDataFactory(); | 597 | private OWLClass getNewConcept(OWLOntology onto, int number) { |
| 566 | OWLClass newClass = factory.getOWLClass(IRI.create(Namespace.PAGODA_AUX + "NC" + number)); | 598 | OWLOntologyManager manager = onto.getOWLOntologyManager(); |
| 567 | manager.addAxiom(onto, factory.getOWLDeclarationAxiom(newClass)); | 599 | OWLDataFactory factory = manager.getOWLDataFactory(); |
| 568 | return newClass; | 600 | OWLClass newClass = factory.getOWLClass(IRI.create(Namespace.PAGODA_AUX + "NC" + number)); |
| 569 | } | 601 | manager.addAxiom(onto, factory.getOWLDeclarationAxiom(newClass)); |
| 570 | 602 | return newClass; | |
| 571 | public OWLOntologyManager getOWLOntologyManager() { | 603 | } |
| 572 | return inputOntology.getOWLOntologyManager(); | 604 | |
| 573 | } | 605 | private enum BottomStrategy {TOREMOVE, NULLARY, UNARY} |
| 574 | |||
| 575 | public String getOntologyIRI() { | ||
| 576 | return ontologyIRI; | ||
| 577 | } | ||
| 578 | |||
| 579 | public OWLOntology getOutputOntology() { | ||
| 580 | return outputOntology; | ||
| 581 | } | ||
| 582 | |||
| 583 | @Override | ||
| 584 | public String getOutputPath() { | ||
| 585 | return outputPath; | ||
| 586 | } | ||
| 587 | |||
| 588 | @Override | ||
| 589 | public String getDirectory() { | ||
| 590 | return outputPath.substring(0, outputPath.lastIndexOf(Utility.FILE_SEPARATOR)); | ||
| 591 | } | ||
| 592 | |||
| 593 | public void setCorrespondenceFileLoc(String path) { | ||
| 594 | corrFileName = path; | ||
| 595 | } | ||
| 596 | |||
| 597 | private enum BottomStrategy { TOREMOVE, NULLARY, UNARY } | ||
| 598 | } | 606 | } |
| 599 | 607 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java index 50996d0..b708bee 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java | |||
| @@ -11,161 +11,173 @@ import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | |||
| 11 | import uk.ac.ox.cs.pagoda.rules.Program; | 11 | import uk.ac.ox.cs.pagoda.rules.Program; |
| 12 | import uk.ac.ox.cs.pagoda.util.Timer; | 12 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 13 | import uk.ac.ox.cs.pagoda.util.Utility; | 13 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 14 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 14 | 15 | ||
| 15 | import java.util.Collection; | 16 | import java.util.Collection; |
| 16 | 17 | ||
| 17 | public class MultiStageQueryEngine extends StageQueryEngine { | 18 | public class MultiStageQueryEngine extends StageQueryEngine { |
| 18 | 19 | ||
| 19 | public MultiStageQueryEngine(String name, boolean checkValidity) { | 20 | public MultiStageQueryEngine(String name, boolean checkValidity) { |
| 20 | super(name, checkValidity); | 21 | super(name, checkValidity); |
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | /** | 24 | /** |
| 24 | * c-chase | 25 | * c-chase |
| 25 | */ | 26 | */ |
| 26 | @Override | 27 | @Override |
| 27 | public void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap) { | 28 | public void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap) { |
| 28 | materialise("lower program", dProgram.getLower().toString()); | 29 | if(isDisposed()) throw new DisposedException(); |
| 29 | Program generalProgram = dProgram.getGeneral(); | 30 | |
| 30 | FoldedApplication program = new FoldedApplication(generalProgram, dProgram.getUpperBottomStrategy()); | 31 | materialise("lower program", dProgram.getLower().toString()); |
| 31 | Treatment treatment = new Pick4NegativeConceptNaive(this, program); | 32 | Program generalProgram = dProgram.getGeneral(); |
| 32 | materialise(program, treatment, gap); | 33 | FoldedApplication program = new FoldedApplication(generalProgram, dProgram.getUpperBottomStrategy()); |
| 33 | } | 34 | Treatment treatment = new Pick4NegativeConceptNaive(this, program); |
| 34 | 35 | materialise(program, treatment, gap); | |
| 35 | /** | 36 | } |
| 36 | * c-chase^f | 37 | |
| 37 | */ | 38 | /** |
| 38 | @Override | 39 | * c-chase^f |
| 39 | public int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap) { | 40 | */ |
| 40 | if (gap != null) | 41 | @Override |
| 41 | materialise("lower program", dProgram.getLower().toString()); | 42 | public int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap) { |
| 42 | 43 | if(isDisposed()) throw new DisposedException(); | |
| 43 | Program generalProgram = dProgram.getGeneral(); | 44 | |
| 44 | RestrictedApplication program = new RestrictedApplication(generalProgram, dProgram.getUpperBottomStrategy()); | 45 | if(gap != null) |
| 45 | Treatment treatment = new Pick4NegativeConceptNaive(this, program); | 46 | materialise("lower program", dProgram.getLower().toString()); |
| 46 | int ret = materialise(program, treatment, gap); | 47 | |
| 47 | treatment.dispose(); // does nothing | 48 | Program generalProgram = dProgram.getGeneral(); |
| 48 | return ret; | 49 | RestrictedApplication program = new RestrictedApplication(generalProgram, dProgram.getUpperBottomStrategy()); |
| 49 | } | 50 | Treatment treatment = new Pick4NegativeConceptNaive(this, program); |
| 50 | 51 | int ret = materialise(program, treatment, gap); | |
| 51 | public int materialise4SpecificQuery(Program generalProgram, QueryRecord record, BottomStrategy upperBottom) { | 52 | treatment.dispose(); // does nothing |
| 52 | RestrictedApplication program = new RestrictedApplication(generalProgram, upperBottom); | 53 | return ret; |
| 53 | Treatment treatment = new Pick4NegativeConceptQuerySpecific(this, program, record); | 54 | } |
| 54 | int ret = materialise(program, treatment, null); | 55 | |
| 55 | treatment.dispose(); | 56 | public int materialise4SpecificQuery(Program generalProgram, QueryRecord record, BottomStrategy upperBottom) { |
| 56 | return ret; | 57 | if(isDisposed()) throw new DisposedException(); |
| 57 | } | 58 | |
| 58 | 59 | RestrictedApplication program = new RestrictedApplication(generalProgram, upperBottom); | |
| 59 | /** | 60 | Treatment treatment = new Pick4NegativeConceptQuerySpecific(this, program, record); |
| 60 | * delta-chase | 61 | int ret = materialise(program, treatment, null); |
| 61 | */ | 62 | treatment.dispose(); |
| 62 | @Override | 63 | return ret; |
| 63 | public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap) { | 64 | } |
| 64 | materialise("lower program", dProgram.getLower().toString()); | 65 | |
| 65 | Program generalProgram = dProgram.getGeneral(); | 66 | /** |
| 66 | LimitedSkolemisationApplication program = new LimitedSkolemisationApplication(generalProgram, dProgram.getUpperBottomStrategy()); | 67 | * delta-chase |
| 67 | Treatment treatment = new Pick4NegativeConceptNaive(this, program); | 68 | */ |
| 68 | return materialise(program, treatment, gap); | 69 | @Override |
| 69 | } | 70 | public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap) { |
| 70 | 71 | if(isDisposed()) throw new DisposedException(); | |
| 71 | private int materialise(MultiStageUpperProgram program, Treatment treatment, GapByStore4ID gap) { | 72 | |
| 72 | if (gap != null) | 73 | materialise("lower program", dProgram.getLower().toString()); |
| 73 | treatment.addAdditionalGapTuples(); | 74 | Program generalProgram = dProgram.getGeneral(); |
| 74 | String programName = "multi-stage upper program"; | 75 | LimitedSkolemisationApplication program = |
| 75 | Utility.logInfo(name + " store is materialising " + programName + " ..."); | 76 | new LimitedSkolemisationApplication(generalProgram, dProgram.getUpperBottomStrategy()); |
| 76 | Timer t = new Timer(); | 77 | Treatment treatment = new Pick4NegativeConceptNaive(this, program); |
| 77 | 78 | return materialise(program, treatment, gap); | |
| 78 | String datalogProgram = program.getDatalogRuleText(); | 79 | } |
| 79 | long tripleCountBeforeMat = 0; | 80 | |
| 80 | 81 | private int materialise(MultiStageUpperProgram program, Treatment treatment, GapByStore4ID gap) { | |
| 81 | // TODO to be removed ... | 82 | if(gap != null) |
| 83 | treatment.addAdditionalGapTuples(); | ||
| 84 | String programName = "multi-stage upper program"; | ||
| 85 | Utility.logInfo(name + " store is materialising " + programName + " ..."); | ||
| 86 | Timer t = new Timer(); | ||
| 87 | |||
| 88 | String datalogProgram = program.getDatalogRuleText(); | ||
| 89 | long tripleCountBeforeMat = 0; | ||
| 90 | |||
| 91 | // TODO to be removed ... | ||
| 82 | // if (gap == null) | 92 | // if (gap == null) |
| 83 | // program.save("output/multi.dlog"); | 93 | // program.save("output/multi.dlog"); |
| 84 | 94 | ||
| 85 | Collection<Violation> violations; | 95 | Collection<Violation> violations; |
| 86 | int iteration = 0; | 96 | int iteration = 0; |
| 87 | Timer subTimer = new Timer(); | 97 | Timer subTimer = new Timer(); |
| 88 | boolean incrementally; | 98 | boolean incrementally; |
| 89 | try { | 99 | try { |
| 90 | while (true) { | 100 | while(true) { |
| 91 | long oldTripleCount = store.getTriplesCount(); | 101 | long oldTripleCount = store.getTriplesCount(); |
| 92 | 102 | ||
| 93 | subTimer.reset(); | 103 | subTimer.reset(); |
| 94 | Utility.logInfo("Iteration " + ++iteration + ": "); | 104 | Utility.logInfo("Iteration " + ++iteration + ": "); |
| 95 | 105 | ||
| 96 | incrementally = (iteration != 1); | 106 | incrementally = (iteration != 1); |
| 97 | 107 | ||
| 98 | if (!incrementally) | 108 | if(!incrementally) |
| 99 | tripleCountBeforeMat = oldTripleCount; | 109 | tripleCountBeforeMat = oldTripleCount; |
| 100 | 110 | ||
| 101 | if (gap != null) { | 111 | if(gap != null) { |
| 102 | try { | 112 | try { |
| 103 | gap.compile(incrementally ? null : datalogProgram); | 113 | gap.compile(incrementally ? null : datalogProgram); |
| 104 | gap.addBackTo(); | 114 | gap.addBackTo(); |
| 105 | } finally { | 115 | } finally { |
| 106 | gap.clear(); | 116 | gap.clear(); |
| 107 | } | 117 | } |
| 108 | } | 118 | } |
| 109 | else { | 119 | else { |
| 110 | if (!incrementally) { | 120 | if(!incrementally) { |
| 111 | // store.addRules(new String[] {datalogProgram}); | 121 | // store.addRules(new String[] {datalogProgram}); |
| 112 | store.importRules(datalogProgram); | 122 | store.importRules(datalogProgram); |
| 113 | } | 123 | } |
| 114 | store.applyReasoning(incrementally); | 124 | store.applyReasoning(incrementally); |
| 115 | } | 125 | } |
| 116 | 126 | ||
| 117 | // Utility.logInfo("The number of sameAs assertions in the current store: " + getSameAsNumber()); | 127 | // Utility.logInfo("The number of sameAs assertions in the current store: " + getSameAsNumber()); |
| 118 | 128 | ||
| 119 | if (!isValid()) { | 129 | if(!isValid()) { |
| 120 | if (iteration == 1) { | 130 | if(iteration == 1) { |
| 121 | Utility.logInfo("The ontology is inconsistent."); | 131 | Utility.logInfo("The ontology is inconsistent."); |
| 122 | return -1; | 132 | return -1; |
| 123 | } | 133 | } |
| 124 | Utility.logInfo(name + " store FAILED for multi-stage materialisation in " + t.duration() + " seconds."); | 134 | Utility.logInfo(name + " store FAILED for multi-stage materialisation in " + t.duration() + " seconds."); |
| 125 | return 0; | 135 | return 0; |
| 126 | } | 136 | } |
| 127 | else validMaterialisation = null; | 137 | else validMaterialisation = null; |
| 128 | 138 | ||
| 129 | long tripleCount = store.getTriplesCount(); | 139 | long tripleCount = store.getTriplesCount(); |
| 130 | Utility.logDebug(name + " store after materialising datalog-rules: " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); | 140 | Utility.logDebug(name + " store after materialising datalog-rules: " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); |
| 131 | Utility.logDebug("Time to materialise datalog-rules: " + subTimer.duration()); | 141 | Utility.logDebug("Time to materialise datalog-rules: " + subTimer.duration()); |
| 132 | 142 | ||
| 133 | subTimer.reset(); | 143 | subTimer.reset(); |
| 134 | if ((violations = program.isIntegrated(this, incrementally)) == null || violations.size() == 0) { | 144 | if((violations = program.isIntegrated(this, incrementally)) == null || violations.size() == 0) { |
| 135 | store.clearRulesAndMakeFactsExplicit(); | 145 | store.clearRulesAndMakeFactsExplicit(); |
| 136 | Utility.logInfo(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - tripleCountBeforeMat) + " new)"); | 146 | Utility.logInfo(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - tripleCountBeforeMat) + " new)"); |
| 137 | Utility.logInfo(name + " store is DONE for multi-stage materialising in " + t.duration() + " seconds."); | 147 | Utility.logInfo(name + " store is DONE for multi-stage materialising in " + t.duration() + " seconds."); |
| 138 | return isValid() ? 1 : 0; | 148 | return isValid() ? 1 : 0; |
| 139 | } | 149 | } |
| 140 | Utility.logDebug("Time to detect violations: " + subTimer.duration()); | 150 | Utility.logDebug("Time to detect violations: " + subTimer.duration()); |
| 141 | 151 | ||
| 142 | store.makeFactsExplicit(); | 152 | store.makeFactsExplicit(); |
| 143 | subTimer.reset(); | 153 | subTimer.reset(); |
| 144 | oldTripleCount = store.getTriplesCount(); | 154 | oldTripleCount = store.getTriplesCount(); |
| 145 | for (Violation v : violations) { | 155 | for(Violation v : violations) { |
| 146 | 156 | ||
| 147 | Utility.logDebug("Dealing with violation: " + v.constraint); | 157 | Utility.logDebug("Dealing with violation: " + v.constraint); |
| 148 | Utility.logDebug("Number of violation tuples: " + v.size()); | 158 | Utility.logDebug("Number of violation tuples: " + v.size()); |
| 149 | 159 | ||
| 150 | Timer localTimer = new Timer(); | 160 | Timer localTimer = new Timer(); |
| 151 | int number = v.size(); | 161 | int number = v.size(); |
| 152 | long vOldCounter = store.getTriplesCount(); | 162 | long vOldCounter = store.getTriplesCount(); |
| 153 | if (!treatment.makeSatisfied(v)) { | 163 | if(!treatment.makeSatisfied(v)) { |
| 154 | validMaterialisation = false; | 164 | validMaterialisation = false; |
| 155 | Utility.logInfo(name + " store FAILED for multi-stage materialisation in " + t.duration() + " seconds."); | 165 | Utility.logInfo(name + " store FAILED for multi-stage materialisation in " + t.duration() + " seconds."); |
| 156 | return 0; | 166 | return 0; |
| 157 | } | 167 | } |
| 158 | Utility.logDebug("Time to make the constraint being satisfied: " + localTimer.duration()); | 168 | Utility.logDebug("Time to make the constraint being satisfied: " + localTimer.duration()); |
| 159 | Utility.logDebug("Triples in the store: before=" + vOldCounter + ", after=" + store.getTriplesCount() + ", new=" + (store.getTriplesCount() - vOldCounter)); | 169 | Utility.logDebug("Triples in the store: before=" + vOldCounter + ", after=" + store.getTriplesCount() + ", new=" + (store |
| 160 | } | 170 | .getTriplesCount() - vOldCounter)); |
| 161 | Utility.logDebug(name + " store after adding facts for violations: " + (tripleCount = store.getTriplesCount()) + " (" + (tripleCount - oldTripleCount) + " new)"); | 171 | } |
| 162 | Utility.logDebug("Time to add triples for violations: " + subTimer.duration()); | 172 | Utility.logDebug(name + " store after adding facts for violations: " + (tripleCount = |
| 163 | } | 173 | store.getTriplesCount()) + " (" + (tripleCount - oldTripleCount) + " new)"); |
| 164 | } catch (JRDFStoreException e) { | 174 | Utility.logDebug("Time to add triples for violations: " + subTimer.duration()); |
| 165 | e.printStackTrace(); | 175 | } |
| 166 | } | 176 | } catch(JRDFStoreException e) { |
| 167 | return 0; | 177 | e.printStackTrace(); |
| 168 | } | 178 | } |
| 169 | 179 | return 0; | |
| 180 | } | ||
| 181 | |||
| 170 | } | 182 | } |
| 171 | 183 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java index e652f66..c8776fe 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java | |||
| @@ -23,10 +23,6 @@ public abstract class StageQueryEngine extends BasicQueryEngine { | |||
| 23 | 23 | ||
| 24 | public abstract int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap); | 24 | public abstract int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap); |
| 25 | 25 | ||
| 26 | public void dispose() { | ||
| 27 | super.dispose(); | ||
| 28 | } | ||
| 29 | |||
| 30 | public boolean isValid() { | 26 | public boolean isValid() { |
| 31 | if (!checkValidity) return true; | 27 | if (!checkValidity) return true; |
| 32 | if (validMaterialisation != null) return validMaterialisation; | 28 | if (validMaterialisation != null) return validMaterialisation; |
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConcept.java b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConcept.java index 00e7e2b..687fa4a 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConcept.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConcept.java | |||
| @@ -14,194 +14,193 @@ import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; | |||
| 14 | import uk.ac.ox.cs.pagoda.util.Namespace; | 14 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 15 | import uk.ac.ox.cs.pagoda.util.SparqlHelper; | 15 | import uk.ac.ox.cs.pagoda.util.SparqlHelper; |
| 16 | import uk.ac.ox.cs.pagoda.util.Utility; | 16 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 17 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 17 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; | 18 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; |
| 18 | import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; | 19 | import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; |
| 19 | 20 | ||
| 20 | import java.util.*; | 21 | import java.util.*; |
| 21 | 22 | ||
| 22 | public abstract class Pick4NegativeConcept implements Treatment { | 23 | public abstract class Pick4NegativeConcept extends Treatment { |
| 23 | 24 | ||
| 24 | public Set<Atom> addedGroundAtoms = new HashSet<Atom>(); | 25 | public Set<Atom> addedGroundAtoms = new HashSet<Atom>(); |
| 25 | MultiStageQueryEngine engine; | 26 | MultiStageQueryEngine engine; |
| 26 | MultiStageUpperProgram program; | 27 | MultiStageUpperProgram program; |
| 27 | RDFoxTripleManager tripleManager; | 28 | RDFoxTripleManager tripleManager; |
| 28 | PredicateDependency dependencyGraph; | 29 | PredicateDependency dependencyGraph; |
| 29 | boolean addGap = false; | 30 | boolean addGap = false; |
| 30 | 31 | ||
| 31 | public Pick4NegativeConcept(MultiStageQueryEngine store, MultiStageUpperProgram multiProgram) { | 32 | public Pick4NegativeConcept(MultiStageQueryEngine store, MultiStageUpperProgram multiProgram) { |
| 32 | this.engine = store; | 33 | this.engine = store; |
| 33 | this.program = multiProgram; | 34 | this.program = multiProgram; |
| 34 | this.tripleManager = new RDFoxTripleManager(store.getDataStore(), true); | 35 | this.tripleManager = new RDFoxTripleManager(store.getDataStore(), true); |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | void addTripleByID(Atom atom, Atom gapAtom, Map<Variable, Integer> assignment) { | 38 | @Override |
| 38 | int[] newTuple = tripleManager.getInstance(atom, assignment); | 39 | public void addAdditionalGapTuples() { |
| 39 | tripleManager.addTripleByID(newTuple); | 40 | if(isDisposed()) throw new DisposedException(); |
| 40 | if (addGap) | 41 | addGap = true; |
| 41 | tripleManager.addTripleByID(tripleManager.getInstance(gapAtom, assignment)); | 42 | } |
| 42 | } | 43 | |
| 43 | 44 | void addTripleByID(Atom atom, Atom gapAtom, Map<Variable, Integer> assignment) { | |
| 44 | protected boolean makeSatisfied(Violation violation, Comparator<Atom> comp) { | 45 | if(isDisposed()) throw new DisposedException(); |
| 45 | LinkedList<AnswerTupleID> tuples = violation.getTuples(); | 46 | int[] newTuple = tripleManager.getInstance(atom, assignment); |
| 46 | DLClause constraint = violation.getConstraint(); | 47 | tripleManager.addTripleByID(newTuple); |
| 47 | Map<Variable, Integer> assignment = new HashMap<Variable, Integer>(); | 48 | if(addGap) |
| 48 | 49 | tripleManager.addTripleByID(tripleManager.getInstance(gapAtom, assignment)); | |
| 49 | if (constraint.getHeadLength() > 1) { | 50 | } |
| 50 | Atom[] orderedAtoms = Arrays.copyOf(constraint.getHeadAtoms(), constraint.getHeadLength()); | 51 | |
| 51 | Arrays.sort(orderedAtoms, comp); | 52 | protected boolean makeSatisfied(Violation violation, Comparator<Atom> comp) { |
| 52 | 53 | LinkedList<AnswerTupleID> tuples = violation.getTuples(); | |
| 53 | Set<AnswerTupleID> negTuples = new HashSet<AnswerTupleID>(); | 54 | DLClause constraint = violation.getConstraint(); |
| 54 | String negativeQuery; | 55 | Map<Variable, Integer> assignment = new HashMap<Variable, Integer>(); |
| 55 | String[] subVars; | 56 | |
| 56 | for (Atom headAtom: orderedAtoms) { | 57 | if(constraint.getHeadLength() > 1) { |
| 57 | Atom negativeAtom = MultiStageUpperProgram.getNegativeAtom(headAtom); | 58 | Atom[] orderedAtoms = Arrays.copyOf(constraint.getHeadAtoms(), constraint.getHeadLength()); |
| 58 | if (negativeAtom == null) continue; | 59 | Arrays.sort(orderedAtoms, comp); |
| 59 | negativeQuery = SparqlHelper.getSPARQLQuery(new Atom[] { negativeAtom }, | 60 | |
| 60 | subVars = MultiStageUpperProgram.getVarSubset(violation.getVariables(), headAtom)); | 61 | Set<AnswerTupleID> negTuples = new HashSet<AnswerTupleID>(); |
| 61 | negTuples.clear(); | 62 | String negativeQuery; |
| 62 | Atom gapHeadAtom = addGap ? getGapAtom(headAtom) : null; | 63 | String[] subVars; |
| 63 | TupleIterator negAnswers = null; | 64 | for(Atom headAtom : orderedAtoms) { |
| 64 | try { | 65 | Atom negativeAtom = MultiStageUpperProgram.getNegativeAtom(headAtom); |
| 65 | negAnswers = engine.internal_evaluateNotExpanded(negativeQuery); | 66 | if(negativeAtom == null) continue; |
| 66 | for (long multi = negAnswers.open(); multi != 0; multi = negAnswers.getNext()) | 67 | negativeQuery = SparqlHelper.getSPARQLQuery(new Atom[]{negativeAtom}, |
| 67 | negTuples.add(new AnswerTupleID(negAnswers)); | 68 | subVars = |
| 68 | } catch (JRDFStoreException e) { | 69 | MultiStageUpperProgram.getVarSubset(violation.getVariables(), headAtom)); |
| 69 | e.printStackTrace(); | 70 | negTuples.clear(); |
| 70 | } finally { | 71 | Atom gapHeadAtom = addGap ? getGapAtom(headAtom) : null; |
| 71 | if (negAnswers != null) negAnswers.dispose(); | 72 | TupleIterator negAnswers = null; |
| 72 | } | 73 | try { |
| 73 | 74 | negAnswers = engine.internal_evaluateNotExpanded(negativeQuery); | |
| 74 | if (!tuples.isEmpty()) | 75 | for(long multi = negAnswers.open(); multi != 0; multi = negAnswers.getNext()) |
| 76 | negTuples.add(new AnswerTupleID(negAnswers)); | ||
| 77 | } catch(JRDFStoreException e) { | ||
| 78 | e.printStackTrace(); | ||
| 79 | } finally { | ||
| 80 | if(negAnswers != null) negAnswers.dispose(); | ||
| 81 | } | ||
| 82 | |||
| 83 | if(!tuples.isEmpty()) | ||
| 75 | // program.addUpdatedPredicates(dependencyGraph.getDependence(headAtom.getDLPredicate())); | 84 | // program.addUpdatedPredicates(dependencyGraph.getDependence(headAtom.getDLPredicate())); |
| 76 | program.addUpdatedPredicate(headAtom.getDLPredicate()); | 85 | program.addUpdatedPredicate(headAtom.getDLPredicate()); |
| 77 | 86 | ||
| 78 | Comparator<AnswerTupleID> tComp = new TupleComparator(subVars); | 87 | Comparator<AnswerTupleID> tComp = new TupleComparator(subVars); |
| 79 | Collections.sort(tuples, tComp); | 88 | Collections.sort(tuples, tComp); |
| 80 | 89 | ||
| 81 | AnswerTupleID lastAdded = null; | 90 | AnswerTupleID lastAdded = null; |
| 82 | 91 | ||
| 83 | for (Iterator<AnswerTupleID> iter = tuples.iterator(); iter.hasNext(); ) { | 92 | for(Iterator<AnswerTupleID> iter = tuples.iterator(); iter.hasNext(); ) { |
| 84 | 93 | ||
| 85 | AnswerTupleID tuple = iter.next(); | 94 | AnswerTupleID tuple = iter.next(); |
| 86 | if (!negTuples.contains(MultiStageUpperProgram.project(tuple, violation.getVariables(), subVars))) { | 95 | if(!negTuples.contains(MultiStageUpperProgram.project(tuple, violation.getVariables(), subVars))) { |
| 87 | if (lastAdded == null || tComp.compare(lastAdded, tuple) != 0) { | 96 | if(lastAdded == null || tComp.compare(lastAdded, tuple) != 0) { |
| 88 | lastAdded = tuple; | 97 | lastAdded = tuple; |
| 89 | tuple.getAssignment(violation.getVariables(), assignment); | 98 | tuple.getAssignment(violation.getVariables(), assignment); |
| 90 | addTripleByID(headAtom, gapHeadAtom, assignment); | 99 | addTripleByID(headAtom, gapHeadAtom, assignment); |
| 91 | } | 100 | } |
| 92 | iter.remove(); | 101 | iter.remove(); |
| 93 | } | 102 | } |
| 94 | } | 103 | } |
| 95 | // tuples.reset(); | 104 | // tuples.reset(); |
| 96 | 105 | ||
| 97 | if (tuples.isEmpty()) | 106 | if(tuples.isEmpty()) |
| 98 | return true; | 107 | return true; |
| 99 | } | 108 | } |
| 100 | if (!tuples.isEmpty()) return false; | 109 | if(!tuples.isEmpty()) return false; |
| 101 | } | 110 | } |
| 102 | else { | 111 | else { |
| 103 | Set<Atom> headAtoms = new HashSet<Atom>(); | 112 | Set<Atom> headAtoms = new HashSet<Atom>(); |
| 104 | 113 | ||
| 105 | ArrayList<Tuple<Individual>> violationTuples = new ArrayList<>(violation.getTuples().size()); | 114 | ArrayList<Tuple<Individual>> violationTuples = new ArrayList<>(violation.getTuples().size()); |
| 106 | for (int i = 0; i < violation.getTuples().size(); i++) { | 115 | for(int i = 0; i < violation.getTuples().size(); i++) { |
| 107 | AnswerTupleID answerTupleID = violation.getTuples().get(i); | 116 | AnswerTupleID answerTupleID = violation.getTuples().get(i); |
| 108 | TupleBuilder<Individual> tupleBuilder = new TupleBuilder<>(); | 117 | TupleBuilder<Individual> tupleBuilder = new TupleBuilder<>(); |
| 109 | for (int j = 0; j < answerTupleID.getArity(); j++) { | 118 | for(int j = 0; j < answerTupleID.getArity(); j++) { |
| 110 | String rawTerm = tripleManager.getRawTerm(answerTupleID.getTerm(j)); | 119 | String rawTerm = tripleManager.getRawTerm(answerTupleID.getTerm(j)); |
| 111 | Individual individual = Individual.create(rawTerm.substring(1, rawTerm.length()-1)); | 120 | Individual individual = Individual.create(rawTerm.substring(1, rawTerm.length() - 1)); |
| 112 | tupleBuilder.append(individual); | 121 | tupleBuilder.append(individual); |
| 113 | } | 122 | } |
| 114 | violationTuples.add(tupleBuilder.build()); | 123 | violationTuples.add(tupleBuilder.build()); |
| 115 | } | 124 | } |
| 116 | 125 | ||
| 117 | for (DLClause clause : program.convertExist(constraint, violation.getClause(), violationTuples)) { | 126 | for(DLClause clause : program.convertExist(constraint, violation.getClause(), violationTuples)) { |
| 118 | 127 | ||
| 119 | if (!DLClauseHelper.hasSubsetBodyAtoms(clause, constraint)) { | 128 | if(!DLClauseHelper.hasSubsetBodyAtoms(clause, constraint)) { |
| 120 | Utility.logError("There might be an error here... Cannot happen!!!"); | 129 | Utility.logError("There might be an error here... Cannot happen!!!"); |
| 121 | throw new Error("This condition should not happen!!!"); | 130 | throw new Error("This condition should not happen!!!"); |
| 122 | } | 131 | } |
| 123 | 132 | ||
| 124 | Atom tHeadAtom = clause.getHeadAtom(0); | 133 | Atom tHeadAtom = clause.getHeadAtom(0); |
| 125 | Atom tGapHeadAtom = addGap ? getGapAtom(tHeadAtom) : null; | 134 | Atom tGapHeadAtom = addGap ? getGapAtom(tHeadAtom) : null; |
| 126 | if (DLClauseHelper.isGround(tHeadAtom)) { | 135 | if(DLClauseHelper.isGround(tHeadAtom)) { |
| 127 | if (!addedGroundAtoms.contains(tHeadAtom)) { | 136 | if(!addedGroundAtoms.contains(tHeadAtom)) { |
| 128 | program.addUpdatedPredicate(tHeadAtom.getDLPredicate()); | 137 | program.addUpdatedPredicate(tHeadAtom.getDLPredicate()); |
| 129 | addTripleByID(tHeadAtom, tGapHeadAtom, null); | 138 | addTripleByID(tHeadAtom, tGapHeadAtom, null); |
| 130 | addedGroundAtoms.add(tHeadAtom); | 139 | addedGroundAtoms.add(tHeadAtom); |
| 131 | } | 140 | } |
| 132 | } else headAtoms.add(tHeadAtom); | 141 | } |
| 133 | } | 142 | else headAtoms.add(tHeadAtom); |
| 134 | if (!tuples.isEmpty()) | 143 | } |
| 135 | for (Atom atom: headAtoms) | 144 | if(!tuples.isEmpty()) |
| 136 | program.addUpdatedPredicate(atom.getDLPredicate()); | 145 | for(Atom atom : headAtoms) |
| 137 | 146 | program.addUpdatedPredicate(atom.getDLPredicate()); | |
| 138 | for (AnswerTupleID tuple: tuples) { | 147 | |
| 139 | tuple.getAssignment(violation.getVariables(), assignment); | 148 | for(AnswerTupleID tuple : tuples) { |
| 140 | for (Atom atom: headAtoms) { | 149 | tuple.getAssignment(violation.getVariables(), assignment); |
| 141 | addTripleByID(atom, getGapAtom(atom), assignment); | 150 | for(Atom atom : headAtoms) { |
| 142 | } | 151 | addTripleByID(atom, getGapAtom(atom), assignment); |
| 143 | } | 152 | } |
| 144 | } | 153 | } |
| 145 | 154 | } | |
| 146 | assignment.clear(); | 155 | |
| 147 | return true; | 156 | assignment.clear(); |
| 148 | } | 157 | return true; |
| 149 | 158 | } | |
| 150 | private Atom getGapAtom(Atom atom) { | 159 | |
| 151 | if (!addGap) return null; | 160 | private Atom getGapAtom(Atom atom) { |
| 152 | String gapPredicate = GapTupleIterator.getGapPredicate(getPredicateIRI(atom.getDLPredicate())); | 161 | if(!addGap) return null; |
| 153 | Atom gapAtom = atom.getArity() == 1 ? Atom.create(AtomicConcept.create(gapPredicate), atom.getArgument(0)) : | 162 | String gapPredicate = GapTupleIterator.getGapPredicate(getPredicateIRI(atom.getDLPredicate())); |
| 154 | Atom.create(AtomicRole.create(gapPredicate), atom.getArgument(0), atom.getArgument(1)); | 163 | Atom gapAtom = atom.getArity() == 1 ? Atom.create(AtomicConcept.create(gapPredicate), atom.getArgument(0)) : |
| 155 | return gapAtom; | 164 | Atom.create(AtomicRole.create(gapPredicate), atom.getArgument(0), atom.getArgument(1)); |
| 156 | } | 165 | return gapAtom; |
| 157 | 166 | } | |
| 158 | private String getPredicateIRI(DLPredicate dlPredicate) { | 167 | |
| 159 | if (dlPredicate instanceof Equality || dlPredicate instanceof AnnotatedEquality) | 168 | private String getPredicateIRI(DLPredicate dlPredicate) { |
| 160 | return Namespace.EQUALITY; | 169 | if(dlPredicate instanceof Equality || dlPredicate instanceof AnnotatedEquality) |
| 161 | if (dlPredicate instanceof Inequality) | 170 | return Namespace.EQUALITY; |
| 162 | return Namespace.INEQUALITY; | 171 | if(dlPredicate instanceof Inequality) |
| 163 | if (dlPredicate instanceof AtomicConcept) | 172 | return Namespace.INEQUALITY; |
| 164 | return ((AtomicConcept) dlPredicate).getIRI(); | 173 | if(dlPredicate instanceof AtomicConcept) |
| 165 | if (dlPredicate instanceof AtomicRole) | 174 | return ((AtomicConcept) dlPredicate).getIRI(); |
| 166 | return ((AtomicRole) dlPredicate).getIRI(); | 175 | if(dlPredicate instanceof AtomicRole) |
| 167 | return null; | 176 | return ((AtomicRole) dlPredicate).getIRI(); |
| 168 | } | 177 | return null; |
| 169 | 178 | } | |
| 170 | @Override | 179 | |
| 171 | public void dispose() { | ||
| 172 | // tripleManager.outputAddedInstance(); | ||
| 173 | // addedGroundAtoms.clear(); | ||
| 174 | } | ||
| 175 | |||
| 176 | @Override | ||
| 177 | public void addAdditionalGapTuples() { | ||
| 178 | addGap = true; | ||
| 179 | } | ||
| 180 | |||
| 181 | } | 180 | } |
| 182 | 181 | ||
| 183 | class TupleComparator implements Comparator<AnswerTupleID> { | 182 | class TupleComparator implements Comparator<AnswerTupleID> { |
| 184 | 183 | ||
| 185 | int[] validIndexes; | 184 | int[] validIndexes; |
| 186 | 185 | ||
| 187 | public TupleComparator(String[] validTerms) { | 186 | public TupleComparator(String[] validTerms) { |
| 188 | int num = 0; | 187 | int num = 0; |
| 189 | for (int i = 0; i < validTerms.length; ++i) | 188 | for(int i = 0; i < validTerms.length; ++i) |
| 190 | if (validTerms[i] != null) | 189 | if(validTerms[i] != null) |
| 191 | ++num; | 190 | ++num; |
| 192 | validIndexes = new int[num]; | 191 | validIndexes = new int[num]; |
| 193 | for (int i = 0, j = 0; i < validTerms.length; ++i) | 192 | for(int i = 0, j = 0; i < validTerms.length; ++i) |
| 194 | if (validTerms[i] != null) | 193 | if(validTerms[i] != null) |
| 195 | validIndexes[j++] = i; | 194 | validIndexes[j++] = i; |
| 196 | } | 195 | } |
| 197 | 196 | ||
| 198 | @Override | 197 | @Override |
| 199 | public int compare(AnswerTupleID o1, AnswerTupleID o2) { | 198 | public int compare(AnswerTupleID o1, AnswerTupleID o2) { |
| 200 | int delta = 0; | 199 | int delta = 0; |
| 201 | for (int i = 0; i < validIndexes.length; ++i) | 200 | for(int i = 0; i < validIndexes.length; ++i) |
| 202 | if ((delta = o1.getTerm(validIndexes[i]) - o2.getTerm(validIndexes[i])) != 0) | 201 | if((delta = o1.getTerm(validIndexes[i]) - o2.getTerm(validIndexes[i])) != 0) |
| 203 | return delta; | 202 | return delta; |
| 204 | return 0; | 203 | return 0; |
| 205 | } | 204 | } |
| 206 | 205 | ||
| 207 | } \ No newline at end of file | 206 | } \ No newline at end of file |
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConceptNaive.java b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConceptNaive.java index b0c5d46..af190fc 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConceptNaive.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConceptNaive.java | |||
| @@ -1,25 +1,25 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.multistage.treatement; | 1 | package uk.ac.ox.cs.pagoda.multistage.treatement; |
| 2 | 2 | ||
| 3 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 3 | import uk.ac.ox.cs.pagoda.constraints.PredicateDependency; | 4 | import uk.ac.ox.cs.pagoda.constraints.PredicateDependency; |
| 4 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; | 5 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; |
| 5 | import uk.ac.ox.cs.pagoda.multistage.MultiStageUpperProgram; | 6 | import uk.ac.ox.cs.pagoda.multistage.MultiStageUpperProgram; |
| 6 | import uk.ac.ox.cs.pagoda.multistage.Violation; | 7 | import uk.ac.ox.cs.pagoda.multistage.Violation; |
| 7 | 8 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | |
| 8 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 9 | 9 | ||
| 10 | public class Pick4NegativeConceptNaive extends Pick4NegativeConcept { | 10 | public class Pick4NegativeConceptNaive extends Pick4NegativeConcept { |
| 11 | 11 | ||
| 12 | SimpleComparator comp = new SimpleComparator(); | ||
| 13 | |||
| 12 | public Pick4NegativeConceptNaive(MultiStageQueryEngine store, MultiStageUpperProgram multiProgram) { | 14 | public Pick4NegativeConceptNaive(MultiStageQueryEngine store, MultiStageUpperProgram multiProgram) { |
| 13 | super(store, multiProgram); | 15 | super(store, multiProgram); |
| 14 | dependencyGraph = new PredicateDependency(multiProgram.getClauses()); | 16 | dependencyGraph = new PredicateDependency(multiProgram.getClauses()); |
| 15 | } | 17 | } |
| 16 | 18 | ||
| 17 | SimpleComparator comp = new SimpleComparator(); | ||
| 18 | |||
| 19 | @Override | 19 | @Override |
| 20 | public boolean makeSatisfied(Violation violation) throws JRDFStoreException { | 20 | public boolean makeSatisfied(Violation violation) throws JRDFStoreException { |
| 21 | if(isDisposed()) throw new DisposedException(); | ||
| 21 | return makeSatisfied(violation, comp); | 22 | return makeSatisfied(violation, comp); |
| 22 | } | 23 | } |
| 23 | |||
| 24 | } | 24 | } |
| 25 | 25 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConceptQuerySpecific.java b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConceptQuerySpecific.java index 10aa22f..20b4376 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConceptQuerySpecific.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Pick4NegativeConceptQuerySpecific.java | |||
| @@ -11,77 +11,81 @@ import uk.ac.ox.cs.pagoda.multistage.Violation; | |||
| 11 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | 11 | import uk.ac.ox.cs.pagoda.query.QueryRecord; |
| 12 | import uk.ac.ox.cs.pagoda.rules.approximators.OverApproxExist; | 12 | import uk.ac.ox.cs.pagoda.rules.approximators.OverApproxExist; |
| 13 | import uk.ac.ox.cs.pagoda.util.Namespace; | 13 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 14 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 14 | 15 | ||
| 15 | import java.util.Comparator; | 16 | import java.util.Comparator; |
| 16 | import java.util.Set; | 17 | import java.util.Set; |
| 17 | 18 | ||
| 18 | public class Pick4NegativeConceptQuerySpecific extends Pick4NegativeConcept { | 19 | public class Pick4NegativeConceptQuerySpecific extends Pick4NegativeConcept { |
| 19 | 20 | ||
| 20 | QueryRecord record; | 21 | QueryRecord record; |
| 21 | Comparator<Atom> comp; | 22 | Comparator<Atom> comp; |
| 22 | Normalisation norm; | 23 | Normalisation norm; |
| 23 | 24 | ||
| 24 | public Pick4NegativeConceptQuerySpecific(MultiStageQueryEngine multiStageQueryEngine, RestrictedApplication program, QueryRecord record) { | 25 | public Pick4NegativeConceptQuerySpecific(MultiStageQueryEngine multiStageQueryEngine, RestrictedApplication program, QueryRecord record) { |
| 25 | super(multiStageQueryEngine, program); | 26 | super(multiStageQueryEngine, program); |
| 26 | this.record = record; | 27 | this.record = record; |
| 27 | norm = program.getNormalisation(); | 28 | norm = program.getNormalisation(); |
| 28 | dependencyGraph = new PredicateDependency(record.getRelevantClauses()); | 29 | dependencyGraph = new PredicateDependency(record.getRelevantClauses()); |
| 29 | comp = new DisjunctComparator(new SimpleComparator()); | 30 | comp = new DisjunctComparator(new SimpleComparator()); |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | @Override | 33 | @Override |
| 33 | public boolean makeSatisfied(Violation violation) throws JRDFStoreException { | 34 | public boolean makeSatisfied(Violation violation) throws JRDFStoreException { |
| 34 | return makeSatisfied(violation, comp); | 35 | if(isDisposed()) throw new DisposedException(); |
| 35 | } | 36 | return makeSatisfied(violation, comp); |
| 36 | 37 | } | |
| 37 | class DisjunctComparator implements Comparator<Atom> { | 38 | |
| 38 | 39 | class DisjunctComparator implements Comparator<Atom> { | |
| 39 | // Map<DLPredicate, Integer> dist = new HashMap<DLPredicate, Integer>(); | 40 | |
| 40 | Comparator<Atom> m_reference; | 41 | // Map<DLPredicate, Integer> dist = new HashMap<DLPredicate, Integer>(); |
| 41 | Set<DLPredicate> dsts; | 42 | Comparator<Atom> m_reference; |
| 42 | 43 | Set<DLPredicate> dsts; | |
| 43 | public DisjunctComparator(Comparator<Atom> referenceComp) { | 44 | |
| 44 | m_reference = referenceComp; | 45 | public DisjunctComparator(Comparator<Atom> referenceComp) { |
| 45 | dsts = dependencyGraph.collectPredicate(DLClauseHelper.getQuery(record.getQueryText(), null).getBodyAtoms()); | 46 | m_reference = referenceComp; |
| 46 | } | 47 | dsts = dependencyGraph.collectPredicate(DLClauseHelper.getQuery(record.getQueryText(), null) |
| 47 | 48 | .getBodyAtoms()); | |
| 48 | @Override | 49 | } |
| 49 | public int compare(Atom arg0, Atom arg1) { | 50 | |
| 50 | int dist0 = getDistance(arg0.getDLPredicate()); | 51 | @Override |
| 51 | int dist1 = getDistance(arg1.getDLPredicate()); | 52 | public int compare(Atom arg0, Atom arg1) { |
| 52 | int ret = dist1 - dist0; | 53 | int dist0 = getDistance(arg0.getDLPredicate()); |
| 53 | if (ret != 0) return ret; | 54 | int dist1 = getDistance(arg1.getDLPredicate()); |
| 54 | 55 | int ret = dist1 - dist0; | |
| 55 | return - m_reference.compare(arg0, arg1); | 56 | if(ret != 0) return ret; |
| 56 | } | 57 | |
| 57 | 58 | return -m_reference.compare(arg0, arg1); | |
| 58 | private int getDistance(DLPredicate p) { | 59 | } |
| 59 | if (p instanceof Equality || p instanceof AnnotatedEquality) | 60 | |
| 60 | return -1; | 61 | private int getDistance(DLPredicate p) { |
| 61 | if (p instanceof Inequality) | 62 | if(p instanceof Equality || p instanceof AnnotatedEquality) |
| 62 | p = AtomicRole.create(Namespace.INEQUALITY); | 63 | return -1; |
| 63 | 64 | if(p instanceof Inequality) | |
| 64 | AtLeastConcept alc; | 65 | p = AtomicRole.create(Namespace.INEQUALITY); |
| 65 | if (p instanceof AtomicConcept) | 66 | |
| 66 | if ((alc = norm.getRightAtLeastConcept((AtomicConcept) p)) != null) { | 67 | AtLeastConcept alc; |
| 67 | AtomicRole r = alc.getOnRole() instanceof AtomicRole ? | 68 | if(p instanceof AtomicConcept) |
| 68 | (AtomicRole) alc.getOnRole() : | 69 | if((alc = norm.getRightAtLeastConcept((AtomicConcept) p)) != null) { |
| 69 | ((InverseRole) alc.getOnRole()).getInverseOf(); | 70 | AtomicRole r = alc.getOnRole() instanceof AtomicRole ? |
| 70 | AtomicConcept c = alc.getToConcept() instanceof AtomicConcept ? | 71 | (AtomicRole) alc.getOnRole() : |
| 71 | (AtomicConcept) alc.getToConcept() : | 72 | ((InverseRole) alc.getOnRole()).getInverseOf(); |
| 72 | OverApproxExist.getNegationConcept(((AtomicNegationConcept) alc.getToConcept()).getNegatedAtomicConcept()); | 73 | AtomicConcept c = alc.getToConcept() instanceof AtomicConcept ? |
| 73 | 74 | (AtomicConcept) alc.getToConcept() : | |
| 74 | if (c.equals(AtomicConcept.THING)) | 75 | OverApproxExist.getNegationConcept(((AtomicNegationConcept) alc.getToConcept()).getNegatedAtomicConcept()); |
| 75 | return dependencyGraph.distance(dsts, r); | 76 | |
| 76 | else | 77 | if(c.equals(AtomicConcept.THING)) |
| 77 | return dependencyGraph.distance(dsts, r, c); | 78 | return dependencyGraph.distance(dsts, r); |
| 78 | } else if ((alc = norm.getLeftAtLeastConcept((AtomicConcept) p)) != null) { | 79 | else |
| 79 | return 2; | 80 | return dependencyGraph.distance(dsts, r, c); |
| 80 | } | 81 | } |
| 81 | 82 | else if((alc = norm.getLeftAtLeastConcept((AtomicConcept) p)) != null) { | |
| 82 | return dependencyGraph.distance(dsts, p); | 83 | return 2; |
| 83 | } | 84 | } |
| 84 | 85 | ||
| 85 | } | 86 | return dependencyGraph.distance(dsts, p); |
| 87 | } | ||
| 88 | |||
| 89 | } | ||
| 86 | 90 | ||
| 87 | } | 91 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/treatement/SkolemTreatment.java b/src/uk/ac/ox/cs/pagoda/multistage/treatement/SkolemTreatment.java deleted file mode 100644 index 7a92b79..0000000 --- a/src/uk/ac/ox/cs/pagoda/multistage/treatement/SkolemTreatment.java +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.multistage.treatement; | ||
| 2 | |||
| 3 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 4 | import uk.ac.ox.cs.pagoda.multistage.FoldedApplication; | ||
| 5 | import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; | ||
| 6 | import uk.ac.ox.cs.pagoda.multistage.Violation; | ||
| 7 | |||
| 8 | // TODO should I implement something like this? | ||
| 9 | public class SkolemTreatment implements Treatment { | ||
| 10 | |||
| 11 | public SkolemTreatment(MultiStageQueryEngine multiStageQueryEngine, FoldedApplication program) { | ||
| 12 | // TODO Auto-generated constructor stub | ||
| 13 | } | ||
| 14 | |||
| 15 | @Override | ||
| 16 | public boolean makeSatisfied(Violation violation) throws JRDFStoreException { | ||
| 17 | // TODO Auto-generated method stub | ||
| 18 | return false; | ||
| 19 | } | ||
| 20 | |||
| 21 | @Override | ||
| 22 | public void dispose() { | ||
| 23 | // TODO Auto-generated method stub | ||
| 24 | |||
| 25 | } | ||
| 26 | |||
| 27 | @Override | ||
| 28 | public void addAdditionalGapTuples() { | ||
| 29 | // TODO Auto-generated method stub | ||
| 30 | |||
| 31 | } | ||
| 32 | |||
| 33 | } | ||
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Treatment.java b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Treatment.java index 686379a..cb81af0 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/treatement/Treatment.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/treatement/Treatment.java | |||
| @@ -1,14 +1,12 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.multistage.treatement; | 1 | package uk.ac.ox.cs.pagoda.multistage.treatement; |
| 2 | 2 | ||
| 3 | import uk.ac.ox.cs.pagoda.multistage.Violation; | ||
| 4 | |||
| 5 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 3 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 4 | import uk.ac.ox.cs.pagoda.multistage.Violation; | ||
| 5 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; | ||
| 6 | 6 | ||
| 7 | public interface Treatment { | 7 | public abstract class Treatment extends Disposable { |
| 8 | 8 | ||
| 9 | public boolean makeSatisfied(Violation violation) throws JRDFStoreException; | 9 | public abstract boolean makeSatisfied(Violation violation) throws JRDFStoreException; |
| 10 | |||
| 11 | public void dispose(); | ||
| 12 | 10 | ||
| 13 | public void addAdditionalGapTuples(); | 11 | public abstract void addAdditionalGapTuples(); |
| 14 | } | 12 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java index cb2b0a3..78aced1 100644 --- a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java +++ b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java | |||
| @@ -172,7 +172,7 @@ public class AnswerTuple { | |||
| 172 | String lexicalForm = matcher.group("lexicalForm"); | 172 | String lexicalForm = matcher.group("lexicalForm"); |
| 173 | String dataTypeIRI = matcher.group("dataType"); | 173 | String dataTypeIRI = matcher.group("dataType"); |
| 174 | Datatype dataType; | 174 | Datatype dataType; |
| 175 | if (dataTypeIRI.isEmpty()) dataType = Datatype.RDF_PLAIN_LITERAL; | 175 | if(dataTypeIRI == null || dataTypeIRI.isEmpty()) dataType = Datatype.RDF_PLAIN_LITERAL; |
| 176 | else dataType = uk.ac.ox.cs.JRDFox.model.Datatype.value(dataTypeIRI); | 176 | else dataType = uk.ac.ox.cs.JRDFox.model.Datatype.value(dataTypeIRI); |
| 177 | terms[i] = uk.ac.ox.cs.JRDFox.model.Literal.create(lexicalForm, dataType); | 177 | terms[i] = uk.ac.ox.cs.JRDFox.model.Literal.create(lexicalForm, dataType); |
| 178 | } | 178 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/query/AnswerTuples.java b/src/uk/ac/ox/cs/pagoda/query/AnswerTuples.java index e1e5302..81efed0 100644 --- a/src/uk/ac/ox/cs/pagoda/query/AnswerTuples.java +++ b/src/uk/ac/ox/cs/pagoda/query/AnswerTuples.java | |||
| @@ -1,23 +1,22 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | 1 | package uk.ac.ox.cs.pagoda.query; |
| 2 | 2 | ||
| 3 | public interface AnswerTuples { | 3 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; |
| 4 | |||
| 5 | public void reset(); | ||
| 6 | |||
| 7 | public boolean isValid(); | ||
| 8 | |||
| 9 | public int getArity(); | ||
| 10 | |||
| 11 | public String[] getAnswerVariables(); | ||
| 12 | |||
| 13 | public void moveNext(); | ||
| 14 | |||
| 15 | public void dispose(); | ||
| 16 | |||
| 17 | public AnswerTuple getTuple(); | ||
| 18 | |||
| 19 | public boolean contains(AnswerTuple t); | ||
| 20 | |||
| 21 | public void remove(); | ||
| 22 | 4 | ||
| 5 | public abstract class AnswerTuples extends Disposable { | ||
| 6 | |||
| 7 | public abstract void reset(); | ||
| 8 | |||
| 9 | public abstract boolean isValid(); | ||
| 10 | |||
| 11 | public abstract int getArity(); | ||
| 12 | |||
| 13 | public abstract String[] getAnswerVariables(); | ||
| 14 | |||
| 15 | public abstract void moveNext(); | ||
| 16 | |||
| 17 | public abstract AnswerTuple getTuple(); | ||
| 18 | |||
| 19 | public abstract boolean contains(AnswerTuple t); | ||
| 20 | |||
| 21 | public abstract void remove(); | ||
| 23 | } | 22 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/query/AnswerTuplesImp.java b/src/uk/ac/ox/cs/pagoda/query/AnswerTuplesImp.java index 3e0f320..fd3fb1f 100644 --- a/src/uk/ac/ox/cs/pagoda/query/AnswerTuplesImp.java +++ b/src/uk/ac/ox/cs/pagoda/query/AnswerTuplesImp.java | |||
| @@ -3,7 +3,7 @@ package uk.ac.ox.cs.pagoda.query; | |||
| 3 | import java.util.Iterator; | 3 | import java.util.Iterator; |
| 4 | import java.util.Set; | 4 | import java.util.Set; |
| 5 | 5 | ||
| 6 | public class AnswerTuplesImp implements AnswerTuples { | 6 | public class AnswerTuplesImp extends AnswerTuples { |
| 7 | 7 | ||
| 8 | int m_index; | 8 | int m_index; |
| 9 | Iterator<AnswerTuple> m_iter; | 9 | Iterator<AnswerTuple> m_iter; |
| @@ -54,9 +54,6 @@ public class AnswerTuplesImp implements AnswerTuples { | |||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | @Override | 56 | @Override |
| 57 | public void dispose() {} | ||
| 58 | |||
| 59 | @Override | ||
| 60 | public void reset() { | 57 | public void reset() { |
| 61 | if (m_answers1 == null || m_answers1.isEmpty()) { | 58 | if (m_answers1 == null || m_answers1.isEmpty()) { |
| 62 | m_index = 2; | 59 | m_index = 2; |
diff --git a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java index 1f81a78..742b7da 100644 --- a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java +++ b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java | |||
| @@ -11,6 +11,8 @@ import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; | |||
| 11 | import uk.ac.ox.cs.pagoda.util.Namespace; | 11 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 12 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; | 12 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; |
| 13 | import uk.ac.ox.cs.pagoda.util.Utility; | 13 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 14 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; | ||
| 15 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 14 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; | 16 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; |
| 15 | import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; | 17 | import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; |
| 16 | 18 | ||
| @@ -18,162 +20,180 @@ import java.io.*; | |||
| 18 | import java.lang.reflect.Type; | 20 | import java.lang.reflect.Type; |
| 19 | import java.util.*; | 21 | import java.util.*; |
| 20 | 22 | ||
| 21 | public class QueryRecord { | 23 | public class QueryRecord extends Disposable { |
| 22 | 24 | ||
| 23 | public static final String botQueryText = "SELECT ?X WHERE { ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Nothing> }"; | 25 | public static final String botQueryText = |
| 24 | public static final String SEPARATOR = "----------------------------------------"; | 26 | "SELECT ?X WHERE { ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Nothing> }"; |
| 25 | private static final String RDF_TYPE = "a"; //"rdf:type"; //RDF.type.toString(); | 27 | public static final String SEPARATOR = "----------------------------------------"; |
| 26 | boolean processed = false; | 28 | private static final String RDF_TYPE = "a"; //"rdf:type"; //RDF.type.toString(); |
| 27 | String stringQueryID = null; | 29 | boolean processed = false; |
| 28 | OWLOntology relevantOntology = null; | 30 | String stringQueryID = null; |
| 29 | Set<DLClause> relevantClauses = new HashSet<DLClause>(); | 31 | OWLOntology relevantOntology = null; |
| 30 | double[] timer; | 32 | Set<DLClause> relevantClauses = new HashSet<DLClause>(); |
| 31 | int subID; | 33 | double[] timer; |
| 32 | DLClause queryClause = null; | 34 | int subID; |
| 33 | int queryID = -1; | 35 | DLClause queryClause = null; |
| 34 | Set<AnswerTuple> soundAnswerTuples = new HashSet<AnswerTuple>(); | 36 | int queryID = -1; |
| 35 | private Step difficulty; | 37 | Set<AnswerTuple> soundAnswerTuples = new HashSet<AnswerTuple>(); |
| 36 | private String queryText; | 38 | private Step difficulty; |
| 37 | private String[][] answerVariables = null; | 39 | private String queryText; |
| 38 | private Set<AnswerTuple> gapAnswerTuples = null; | 40 | private String[][] answerVariables = null; |
| 39 | private QueryManager m_manager; | 41 | private Set<AnswerTuple> gapAnswerTuples = null; |
| 40 | 42 | private QueryManager m_manager; | |
| 41 | private QueryRecord() { | 43 | |
| 42 | } | 44 | private QueryRecord() { |
| 45 | } | ||
| 43 | 46 | ||
| 44 | // private boolean containsAuxPredicate(String str) { | 47 | // private boolean containsAuxPredicate(String str) { |
| 45 | // return str.contains(Namespace.PAGODA_AUX) || str.contains("_AUX") || str.contains("owl#Nothing") || | 48 | // return str.contains(Namespace.PAGODA_AUX) || str.contains("_AUX") || str.contains("owl#Nothing") || |
| 46 | // str.contains("internal:def"); | 49 | // str.contains("internal:def"); |
| 47 | // } | 50 | // } |
| 48 | 51 | ||
| 49 | public QueryRecord(QueryManager manager, String text, int id, int subID) { | 52 | public QueryRecord(QueryManager manager, String text, int id, int subID) { |
| 50 | m_manager = manager; | 53 | m_manager = manager; |
| 51 | resetInfo(text, id, subID); | 54 | resetInfo(text, id, subID); |
| 52 | resetTimer(); | 55 | resetTimer(); |
| 53 | } | 56 | } |
| 54 | 57 | ||
| 55 | public static Collection<String> collectQueryTexts(Collection<QueryRecord> queryRecords) { | 58 | public static Collection<String> collectQueryTexts(Collection<QueryRecord> queryRecords) { |
| 56 | Collection<String> texts = new LinkedList<String>(); | 59 | Collection<String> texts = new LinkedList<String>(); |
| 57 | for(QueryRecord record : queryRecords) | 60 | for(QueryRecord record : queryRecords) |
| 58 | texts.add(record.queryText); | 61 | texts.add(record.queryText); |
| 59 | return texts; | 62 | return texts; |
| 60 | } | 63 | } |
| 61 | 64 | ||
| 62 | public void resetInfo(String text, int id, int subid) { | 65 | public void resetInfo(String text, int id, int subid) { |
| 63 | queryID = id; | 66 | if(isDisposed()) throw new DisposedException(); |
| 64 | subID = subid; | 67 | |
| 65 | stringQueryID = id + (subID == 0 ? "" : "_" + subID); | 68 | queryID = id; |
| 66 | m_manager.remove(queryText); | 69 | subID = subid; |
| 67 | m_manager.put(text, this); | 70 | stringQueryID = id + (subID == 0 ? "" : "_" + subID); |
| 68 | queryClause = null; | 71 | m_manager.remove(queryText); |
| 69 | answerVariables = ConjunctiveQueryHelper.getAnswerVariables(text); | 72 | m_manager.put(text, this); |
| 70 | queryText = text; // .replace("_:", "?"); | 73 | queryClause = null; |
| 71 | } | 74 | answerVariables = ConjunctiveQueryHelper.getAnswerVariables(text); |
| 72 | 75 | queryText = text; // .replace("_:", "?"); | |
| 73 | public void resetTimer() { | 76 | } |
| 74 | int length = Step.values().length; | 77 | |
| 75 | timer = new double[length]; | 78 | public void resetTimer() { |
| 76 | for(int i = 0; i < length; ++i) timer[i] = 0; | 79 | if(isDisposed()) throw new DisposedException(); |
| 77 | } | 80 | |
| 78 | 81 | int length = Step.values().length; | |
| 79 | public AnswerTuples getAnswers() { | 82 | timer = new double[length]; |
| 80 | if(isProcessed()) | 83 | for(int i = 0; i < length; ++i) timer[i] = 0; |
| 81 | return getLowerBoundAnswers(); | 84 | } |
| 82 | 85 | ||
| 83 | return getUpperBoundAnswers(); | 86 | public AnswerTuples getAnswers() { |
| 84 | } | 87 | if(isDisposed()) throw new DisposedException(); |
| 85 | 88 | ||
| 86 | public AnswerTuples getLowerBoundAnswers() { | 89 | if(isProcessed()) |
| 87 | return new AnswerTuplesImp(answerVariables[0], soundAnswerTuples); | 90 | return getLowerBoundAnswers(); |
| 88 | } | 91 | |
| 89 | 92 | return getUpperBoundAnswers(); | |
| 90 | public AnswerTuples getUpperBoundAnswers() { | 93 | } |
| 91 | return new AnswerTuplesImp(answerVariables[0], soundAnswerTuples, gapAnswerTuples); | 94 | |
| 92 | } | 95 | public AnswerTuples getLowerBoundAnswers() { |
| 93 | 96 | if(isDisposed()) throw new DisposedException(); | |
| 94 | public boolean updateLowerBoundAnswers(AnswerTuples answerTuples) { | 97 | |
| 95 | if(answerTuples == null) return false; | 98 | return new AnswerTuplesImp(answerVariables[0], soundAnswerTuples); |
| 96 | boolean update = false; | 99 | } |
| 97 | for(AnswerTuple tuple; answerTuples.isValid(); answerTuples.moveNext()) { | 100 | |
| 98 | tuple = answerTuples.getTuple(); | 101 | public AnswerTuples getUpperBoundAnswers() { |
| 99 | if(!soundAnswerTuples.contains(tuple) && (gapAnswerTuples == null || gapAnswerTuples.contains(tuple))) { | 102 | if(isDisposed()) throw new DisposedException(); |
| 100 | soundAnswerTuples.add(tuple); | 103 | |
| 101 | if(gapAnswerTuples != null) | 104 | return new AnswerTuplesImp(answerVariables[0], soundAnswerTuples, gapAnswerTuples); |
| 102 | gapAnswerTuples.remove(tuple); | 105 | } |
| 103 | update = true; | 106 | |
| 104 | } | 107 | public boolean updateLowerBoundAnswers(AnswerTuples answerTuples) { |
| 105 | } | 108 | if(isDisposed()) throw new DisposedException(); |
| 106 | 109 | ||
| 107 | if(soundAnswerTuples.isEmpty()) | 110 | if(answerTuples == null) return false; |
| 108 | Utility.logInfo("Lower bound answers empty"); | 111 | boolean update = false; |
| 109 | else if(update) | 112 | for(AnswerTuple tuple; answerTuples.isValid(); answerTuples.moveNext()) { |
| 110 | Utility.logInfo("Lower bound answers updated: " + soundAnswerTuples.size()); | 113 | tuple = answerTuples.getTuple(); |
| 111 | else | 114 | if(!soundAnswerTuples.contains(tuple) && (gapAnswerTuples == null || gapAnswerTuples.contains(tuple))) { |
| 112 | Utility.logInfo("Lower bound answers unchanged"); | 115 | soundAnswerTuples.add(tuple); |
| 113 | 116 | if(gapAnswerTuples != null) | |
| 114 | return update; | 117 | gapAnswerTuples.remove(tuple); |
| 115 | } | 118 | update = true; |
| 116 | 119 | } | |
| 117 | public boolean updateUpperBoundAnswers(AnswerTuples answerTuples) { | 120 | } |
| 118 | return updateUpperBoundAnswers(answerTuples, false); | 121 | |
| 119 | } | 122 | if(soundAnswerTuples.isEmpty()) |
| 120 | 123 | Utility.logInfo("Lower bound answers empty"); | |
| 121 | public boolean updateUpperBoundAnswers(AnswerTuples answerTuples, boolean toCheckAux) { | 124 | else if(update) |
| 122 | if(!(answerTuples instanceof RDFoxAnswerTuples)) { | 125 | Utility.logInfo("Lower bound answers updated: " + soundAnswerTuples.size()); |
| 123 | String msg = "The upper bound must be computed by RDFox!"; | 126 | else |
| 124 | Utility.logError(msg); | 127 | Utility.logInfo("Lower bound answers unchanged"); |
| 125 | throw new IllegalArgumentException(msg); | 128 | |
| 126 | } | 129 | return update; |
| 127 | 130 | } | |
| 128 | RDFoxAnswerTuples rdfoxAnswerTuples = (RDFoxAnswerTuples) answerTuples; | 131 | |
| 129 | 132 | public boolean updateUpperBoundAnswers(AnswerTuples answerTuples) { | |
| 130 | Set<AnswerTuple> candidateGapAnswerTuples = new HashSet<AnswerTuple>(); | 133 | if(isDisposed()) throw new DisposedException(); |
| 131 | AnswerTuple tuple; | 134 | |
| 132 | for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { | 135 | return updateUpperBoundAnswers(answerTuples, false); |
| 133 | tuple = rdfoxAnswerTuples.getTuple(); | 136 | } |
| 134 | if(isBottom() || !tuple.hasAnonymousIndividual()) | 137 | |
| 135 | if((!toCheckAux || !tuple.hasAuxPredicate()) && !soundAnswerTuples.contains(tuple)) | 138 | public boolean updateUpperBoundAnswers(AnswerTuples answerTuples, boolean toCheckAux) { |
| 136 | candidateGapAnswerTuples.add(tuple); | 139 | if(isDisposed()) throw new DisposedException(); |
| 137 | } | 140 | |
| 138 | 141 | if(!(answerTuples instanceof RDFoxAnswerTuples)) { | |
| 139 | /*** START: debugging ***/ | 142 | String msg = "The upper bound must be computed by RDFox!"; |
| 140 | if(PagodaProperties.isDebuggingMode()) { | 143 | Utility.logError(msg); |
| 141 | if(rdfoxAnswerTuples.getArity() != getAnswerVariables().length) | 144 | throw new IllegalArgumentException(msg); |
| 142 | throw new IllegalArgumentException( | 145 | } |
| 143 | "The arity of answers (" + rdfoxAnswerTuples.getArity() + ") " + | 146 | |
| 144 | "is different from the number of answer variables (" + | 147 | RDFoxAnswerTuples rdfoxAnswerTuples = (RDFoxAnswerTuples) answerTuples; |
| 145 | getAnswerVariables().length + ")"); | 148 | |
| 146 | 149 | Set<AnswerTuple> candidateGapAnswerTuples = new HashSet<AnswerTuple>(); | |
| 147 | Set<AnswerTuple> namedAnswerTuples = new HashSet<>(); | 150 | AnswerTuple tuple; |
| 148 | rdfoxAnswerTuples.reset(); | 151 | for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { |
| 149 | for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { | 152 | tuple = rdfoxAnswerTuples.getTuple(); |
| 150 | tuple = rdfoxAnswerTuples.getTuple(); | 153 | if(isBottom() || !tuple.hasAnonymousIndividual()) |
| 154 | if((!toCheckAux || !tuple.hasAuxPredicate()) && !soundAnswerTuples.contains(tuple)) | ||
| 155 | candidateGapAnswerTuples.add(tuple); | ||
| 156 | } | ||
| 157 | |||
| 158 | /*** START: debugging ***/ | ||
| 159 | if(PagodaProperties.isDebuggingMode()) { | ||
| 160 | if(rdfoxAnswerTuples.getArity() != getAnswerVariables().length) | ||
| 161 | throw new IllegalArgumentException( | ||
| 162 | "The arity of answers (" + rdfoxAnswerTuples.getArity() + ") " + | ||
| 163 | "is different from the number of answer variables (" + | ||
| 164 | getAnswerVariables().length + ")"); | ||
| 165 | |||
| 166 | Set<AnswerTuple> namedAnswerTuples = new HashSet<>(); | ||
| 167 | rdfoxAnswerTuples.reset(); | ||
| 168 | for(; rdfoxAnswerTuples.isValid(); rdfoxAnswerTuples.moveNext()) { | ||
| 169 | tuple = rdfoxAnswerTuples.getTuple(); | ||
| 151 | // if(isBottom() || !tuple.hasAnonymousIndividual()) { | 170 | // if(isBottom() || !tuple.hasAnonymousIndividual()) { |
| 152 | namedAnswerTuples.add(tuple); | 171 | namedAnswerTuples.add(tuple); |
| 153 | // } | 172 | // } |
| 154 | } | 173 | } |
| 155 | HashSet<AnswerTuple> difference = new HashSet<>(soundAnswerTuples); | 174 | HashSet<AnswerTuple> difference = new HashSet<>(soundAnswerTuples); |
| 156 | difference.removeAll(namedAnswerTuples); | 175 | difference.removeAll(namedAnswerTuples); |
| 157 | if(!difference.isEmpty()) | 176 | if(!difference.isEmpty()) |
| 158 | throw new IllegalArgumentException("The upper bound does not contain the lower bound! Missing answers: " + difference | 177 | throw new IllegalArgumentException("The upper bound does not contain the lower bound! Missing answers: " + difference |
| 159 | .size()); | 178 | .size()); |
| 160 | } | 179 | } |
| 161 | /*** END: debugging ***/ | 180 | /*** END: debugging ***/ |
| 162 | 181 | ||
| 163 | boolean update; | 182 | boolean update; |
| 164 | if(gapAnswerTuples == null) { | 183 | if(gapAnswerTuples == null) { |
| 165 | gapAnswerTuples = candidateGapAnswerTuples; | 184 | gapAnswerTuples = candidateGapAnswerTuples; |
| 166 | update = true; | 185 | update = true; |
| 167 | } else { | 186 | } |
| 168 | update = gapAnswerTuples.retainAll(candidateGapAnswerTuples); | 187 | else { |
| 169 | } | 188 | update = gapAnswerTuples.retainAll(candidateGapAnswerTuples); |
| 170 | 189 | } | |
| 171 | if(update) | 190 | |
| 172 | Utility.logInfo("Upper bound answers updated: " + getNumberOfAnswers()); | 191 | if(update) |
| 173 | else | 192 | Utility.logInfo("Upper bound answers updated: " + getNumberOfAnswers()); |
| 174 | Utility.logInfo("Upper bound answers unchanged"); | 193 | else |
| 175 | 194 | Utility.logInfo("Upper bound answers unchanged"); | |
| 176 | return update; | 195 | |
| 196 | return update; | ||
| 177 | 197 | ||
| 178 | // boolean update = false; | 198 | // boolean update = false; |
| 179 | // for(Iterator<AnswerTuple> iter = gapAnswerTuples.iterator(); iter.hasNext(); ) { | 199 | // for(Iterator<AnswerTuple> iter = gapAnswerTuples.iterator(); iter.hasNext(); ) { |
| @@ -183,96 +203,116 @@ public class QueryRecord { | |||
| 183 | // update = true; | 203 | // update = true; |
| 184 | // } | 204 | // } |
| 185 | // } | 205 | // } |
| 186 | } | 206 | } |
| 187 | 207 | ||
| 188 | public int getNumberOfAnswers() { | 208 | public int getNumberOfAnswers() { |
| 189 | return soundAnswerTuples.size() + gapAnswerTuples.size(); | 209 | if(isDisposed()) throw new DisposedException(); |
| 190 | } | 210 | |
| 191 | 211 | return soundAnswerTuples.size() + gapAnswerTuples.size(); | |
| 192 | public void markAsProcessed() { | 212 | } |
| 193 | processed = true; | 213 | |
| 194 | } | 214 | public void markAsProcessed() { |
| 195 | 215 | processed = true; | |
| 196 | public boolean isProcessed() { | 216 | } |
| 197 | if(gapAnswerTuples != null && gapAnswerTuples.isEmpty()) processed = true; | 217 | |
| 198 | return processed; | 218 | public boolean isProcessed() { |
| 199 | } | 219 | if(isDisposed()) throw new DisposedException(); |
| 200 | 220 | ||
| 201 | public String[] getDistinguishedVariables() { | 221 | if(gapAnswerTuples != null && gapAnswerTuples.isEmpty()) processed = true; |
| 202 | return answerVariables[1]; | 222 | return processed; |
| 203 | } | 223 | } |
| 204 | 224 | ||
| 205 | public String[] getAnswerVariables() { | 225 | public String[] getDistinguishedVariables() { |
| 206 | return answerVariables[0]; | 226 | if(isDisposed()) throw new DisposedException(); |
| 207 | } | 227 | |
| 208 | 228 | return answerVariables[1]; | |
| 209 | public String[][] getVariables() { | 229 | } |
| 210 | return answerVariables; | 230 | |
| 211 | } | 231 | public String[] getAnswerVariables() { |
| 212 | 232 | if(isDisposed()) throw new DisposedException(); | |
| 213 | public String getQueryText() { | 233 | |
| 214 | return queryText; | 234 | return answerVariables[0]; |
| 215 | } | 235 | } |
| 216 | 236 | ||
| 217 | public String getQueryID() { | 237 | public String[][] getVariables() { |
| 218 | return stringQueryID; | 238 | if(isDisposed()) throw new DisposedException(); |
| 219 | } | 239 | |
| 220 | 240 | return answerVariables; | |
| 221 | public AnswerTuples getGapAnswers() { | 241 | } |
| 222 | return new AnswerTuplesImp(answerVariables[0], gapAnswerTuples); | 242 | |
| 223 | } | 243 | public String getQueryText() { |
| 224 | 244 | if(isDisposed()) throw new DisposedException(); | |
| 225 | public String toString() { | 245 | |
| 226 | return queryText; | 246 | return queryText; |
| 227 | } | 247 | } |
| 228 | 248 | ||
| 229 | public void outputAnswers(BufferedWriter writer) throws IOException { | 249 | public String getQueryID() { |
| 230 | 250 | if(isDisposed()) throw new DisposedException(); | |
| 231 | int answerCounter = soundAnswerTuples.size(); | 251 | |
| 232 | if(!isProcessed()) answerCounter += gapAnswerTuples.size(); | 252 | return stringQueryID; |
| 233 | 253 | } | |
| 234 | Utility.logInfo("The number of answer tuples: " + answerCounter); | 254 | |
| 235 | 255 | public AnswerTuples getGapAnswers() { | |
| 236 | if (writer != null) { | 256 | if(isDisposed()) throw new DisposedException(); |
| 237 | writer.write("-------------- Query " + queryID + " ---------------------"); | 257 | |
| 238 | writer.newLine(); | 258 | return new AnswerTuplesImp(answerVariables[0], gapAnswerTuples); |
| 239 | writer.write(queryText); | 259 | } |
| 240 | writer.newLine(); | 260 | |
| 241 | StringBuilder space = new StringBuilder(); | 261 | public String toString() { |
| 242 | int arity = getArity(), varSpace = 0; | 262 | if(isDisposed()) throw new DisposedException(); |
| 243 | for (int i = 0; i < arity; ++i) | 263 | |
| 244 | varSpace += answerVariables[0][i].length(); | 264 | return queryText; |
| 245 | for (int i = 0; i < (SEPARATOR.length() - varSpace) / (arity + 1); ++i) | 265 | } |
| 246 | space.append(" "); | 266 | |
| 247 | for (int i = 0; i < getArity(); ++i) { | 267 | public void outputAnswers(BufferedWriter writer) throws IOException { |
| 248 | writer.write(space.toString()); | 268 | if(isDisposed()) throw new DisposedException(); |
| 249 | writer.write(answerVariables[0][i]); | 269 | |
| 250 | } | 270 | int answerCounter = soundAnswerTuples.size(); |
| 251 | writer.newLine(); | 271 | if(!isProcessed()) answerCounter += gapAnswerTuples.size(); |
| 252 | writer.write(SEPARATOR); | 272 | |
| 253 | writer.newLine(); | 273 | Utility.logInfo("The number of answer tuples: " + answerCounter); |
| 254 | for (AnswerTuple tuple: soundAnswerTuples) { | 274 | |
| 255 | writer.write(tuple.toString()); | 275 | if(writer != null) { |
| 256 | writer.newLine(); | 276 | writer.write("-------------- Query " + queryID + " ---------------------"); |
| 257 | } | 277 | writer.newLine(); |
| 258 | if(!isProcessed()) | 278 | writer.write(queryText); |
| 259 | for (AnswerTuple tuple: gapAnswerTuples) { | 279 | writer.newLine(); |
| 260 | writer.write("*"); | 280 | StringBuilder space = new StringBuilder(); |
| 261 | writer.write(tuple.toString()); | 281 | int arity = getArity(), varSpace = 0; |
| 262 | writer.newLine(); | 282 | for(int i = 0; i < arity; ++i) |
| 263 | } | 283 | varSpace += answerVariables[0][i].length(); |
| 284 | for(int i = 0; i < (SEPARATOR.length() - varSpace) / (arity + 1); ++i) | ||
| 285 | space.append(" "); | ||
| 286 | for(int i = 0; i < getArity(); ++i) { | ||
| 287 | writer.write(space.toString()); | ||
| 288 | writer.write(answerVariables[0][i]); | ||
| 289 | } | ||
| 290 | writer.newLine(); | ||
| 291 | writer.write(SEPARATOR); | ||
| 292 | writer.newLine(); | ||
| 293 | for(AnswerTuple tuple : soundAnswerTuples) { | ||
| 294 | writer.write(tuple.toString()); | ||
| 295 | writer.newLine(); | ||
| 296 | } | ||
| 297 | if(!isProcessed()) | ||
| 298 | for(AnswerTuple tuple : gapAnswerTuples) { | ||
| 299 | writer.write("*"); | ||
| 300 | writer.write(tuple.toString()); | ||
| 301 | writer.newLine(); | ||
| 302 | } | ||
| 264 | // writer.write(SEPARATOR); | 303 | // writer.write(SEPARATOR); |
| 265 | writer.newLine(); | 304 | writer.newLine(); |
| 266 | } | 305 | } |
| 267 | 306 | ||
| 268 | } | 307 | } |
| 269 | 308 | ||
| 270 | public void outputAnswerStatistics() { | 309 | public void outputAnswerStatistics() { |
| 310 | if(isDisposed()) throw new DisposedException(); | ||
| 271 | 311 | ||
| 272 | int answerCounter = soundAnswerTuples.size(); | 312 | int answerCounter = soundAnswerTuples.size(); |
| 273 | if(!isProcessed()) answerCounter += gapAnswerTuples.size(); | 313 | if(!isProcessed()) answerCounter += gapAnswerTuples.size(); |
| 274 | 314 | ||
| 275 | Utility.logInfo("The number of answer tuples: " + answerCounter); | 315 | Utility.logInfo("The number of answer tuples: " + answerCounter); |
| 276 | // if (jsonAnswers != null) { | 316 | // if (jsonAnswers != null) { |
| 277 | // JSONObject jsonAnswer = new JSONObject(); | 317 | // JSONObject jsonAnswer = new JSONObject(); |
| 278 | // | 318 | // |
| @@ -297,407 +337,476 @@ public class QueryRecord { | |||
| 297 | // | 337 | // |
| 298 | // jsonAnswers.put(Integer.toString(queryID), jsonAnswer); | 338 | // jsonAnswers.put(Integer.toString(queryID), jsonAnswer); |
| 299 | // } | 339 | // } |
| 300 | } | 340 | } |
| 301 | 341 | ||
| 302 | public void outputTimes() { | 342 | public void outputTimes() { |
| 303 | for (Step step: Step.values()) { | 343 | if(isDisposed()) throw new DisposedException(); |
| 304 | Utility.logDebug("time for " + step + ": " + timer[step.ordinal()]); | 344 | |
| 305 | } | 345 | for(Step step : Step.values()) { |
| 306 | } | 346 | Utility.logDebug("time for " + step + ": " + timer[step.ordinal()]); |
| 307 | 347 | } | |
| 308 | public String outputSoundAnswerTuple() { | 348 | } |
| 309 | StringBuilder builder = new StringBuilder(); | 349 | |
| 310 | for (AnswerTuple tuple: soundAnswerTuples) | 350 | public String outputSoundAnswerTuple() { |
| 311 | builder.append(tuple.toString()).append(Utility.LINE_SEPARATOR); | 351 | if(isDisposed()) throw new DisposedException(); |
| 312 | return builder.toString(); | 352 | |
| 313 | } | 353 | StringBuilder builder = new StringBuilder(); |
| 314 | 354 | for(AnswerTuple tuple : soundAnswerTuples) | |
| 315 | public String outputGapAnswerTuple() { | 355 | builder.append(tuple.toString()).append(Utility.LINE_SEPARATOR); |
| 316 | StringBuilder builder = new StringBuilder(); | 356 | return builder.toString(); |
| 317 | for(AnswerTuple tuple : gapAnswerTuples) | 357 | } |
| 318 | builder.append(tuple.toString()).append(Utility.LINE_SEPARATOR); | 358 | |
| 319 | return builder.toString(); | 359 | public String outputGapAnswerTuple() { |
| 320 | } | 360 | if(isDisposed()) throw new DisposedException(); |
| 321 | 361 | ||
| 322 | public Step getDifficulty() { | 362 | StringBuilder builder = new StringBuilder(); |
| 323 | return difficulty; | 363 | for(AnswerTuple tuple : gapAnswerTuples) |
| 324 | } | 364 | builder.append(tuple.toString()).append(Utility.LINE_SEPARATOR); |
| 325 | 365 | return builder.toString(); | |
| 326 | public void setDifficulty(Step step) { | 366 | } |
| 327 | this.difficulty = step; | 367 | |
| 328 | } | 368 | public Step getDifficulty() { |
| 329 | 369 | if(isDisposed()) throw new DisposedException(); | |
| 330 | public OWLOntology getRelevantOntology() { | 370 | |
| 331 | return relevantOntology; | 371 | return difficulty; |
| 332 | } | 372 | } |
| 333 | 373 | ||
| 334 | public void setRelevantOntology(OWLOntology knowledgebase) { | 374 | public void setDifficulty(Step step) { |
| 335 | relevantOntology = knowledgebase; | 375 | if(isDisposed()) throw new DisposedException(); |
| 336 | } | 376 | |
| 337 | 377 | this.difficulty = step; | |
| 338 | public void saveRelevantOntology(String filename) { | 378 | } |
| 339 | if(relevantOntology == null) return; | 379 | |
| 340 | OWLOntologyManager manager = relevantOntology.getOWLOntologyManager(); | 380 | public OWLOntology getRelevantOntology() { |
| 341 | try { | 381 | if(isDisposed()) throw new DisposedException(); |
| 342 | FileOutputStream outputStream = new FileOutputStream(filename); | 382 | |
| 343 | manager.saveOntology(relevantOntology, outputStream); | 383 | return relevantOntology; |
| 344 | outputStream.close(); | 384 | } |
| 345 | } catch (OWLOntologyStorageException e) { | 385 | |
| 346 | e.printStackTrace(); | 386 | public void setRelevantOntology(OWLOntology knowledgebase) { |
| 347 | } catch (FileNotFoundException e) { | 387 | if(isDisposed()) throw new DisposedException(); |
| 348 | e.printStackTrace(); | 388 | |
| 349 | } catch (IOException e) { | 389 | relevantOntology = knowledgebase; |
| 350 | e.printStackTrace(); | 390 | } |
| 351 | } | 391 | |
| 352 | } | 392 | public void saveRelevantOntology(String filename) { |
| 353 | 393 | if(isDisposed()) throw new DisposedException(); | |
| 354 | public void saveRelevantClause() { | 394 | |
| 355 | if(relevantClauses == null) return; | 395 | if(relevantOntology == null) return; |
| 356 | GeneralProgram p = new GeneralProgram(relevantClauses, relevantOntology); | 396 | OWLOntologyManager manager = relevantOntology.getOWLOntologyManager(); |
| 357 | p.save(); | 397 | try { |
| 358 | } | 398 | FileOutputStream outputStream = new FileOutputStream(filename); |
| 359 | 399 | manager.saveOntology(relevantOntology, outputStream); | |
| 360 | public void removeUpperBoundAnswers(Collection<AnswerTuple> answers) { | 400 | outputStream.close(); |
| 361 | for (AnswerTuple answer: answers) { | 401 | } catch(OWLOntologyStorageException e) { |
| 402 | e.printStackTrace(); | ||
| 403 | } catch(FileNotFoundException e) { | ||
| 404 | e.printStackTrace(); | ||
| 405 | } catch(IOException e) { | ||
| 406 | e.printStackTrace(); | ||
| 407 | } | ||
| 408 | } | ||
| 409 | |||
| 410 | public void saveRelevantClause() { | ||
| 411 | if(isDisposed()) throw new DisposedException(); | ||
| 412 | |||
| 413 | if(relevantClauses == null) return; | ||
| 414 | GeneralProgram p = new GeneralProgram(relevantClauses, relevantOntology); | ||
| 415 | p.save(); | ||
| 416 | } | ||
| 417 | |||
| 418 | public void removeUpperBoundAnswers(Collection<AnswerTuple> answers) { | ||
| 419 | if(isDisposed()) throw new DisposedException(); | ||
| 420 | |||
| 421 | for(AnswerTuple answer : answers) { | ||
| 362 | // if (soundAnswerTuples.contains(answer)) | 422 | // if (soundAnswerTuples.contains(answer)) |
| 363 | // Utility.logError("The answer (" + answer + ") cannot be removed, because it is in the lower bound."); | 423 | // Utility.logError("The answer (" + answer + ") cannot be removed, because it is in the lower bound."); |
| 364 | if (!gapAnswerTuples.contains(answer)) | 424 | if(!gapAnswerTuples.contains(answer)) |
| 365 | Utility.logError("The answer (" + answer + ") cannot be removed, because it is not in the upper bound."); | 425 | Utility.logError("The answer (" + answer + ") cannot be removed, because it is not in the upper bound."); |
| 366 | gapAnswerTuples.remove(answer); | 426 | gapAnswerTuples.remove(answer); |
| 367 | } | 427 | } |
| 368 | } | 428 | } |
| 369 | 429 | ||
| 370 | public void addLowerBoundAnswers(Collection<AnswerTuple> answers) { | 430 | public void addLowerBoundAnswers(Collection<AnswerTuple> answers) { |
| 371 | for (AnswerTuple answer: answers) { | 431 | if(isDisposed()) throw new DisposedException(); |
| 372 | if (!gapAnswerTuples.contains(answer)) | 432 | |
| 373 | Utility.logError("The answer (" + answer + ") cannot be added, because it is not in the upper bound."); | 433 | for(AnswerTuple answer : answers) { |
| 374 | gapAnswerTuples.remove(answer); | 434 | if(!gapAnswerTuples.contains(answer)) |
| 375 | 435 | Utility.logError("The answer (" + answer + ") cannot be added, because it is not in the upper bound."); | |
| 376 | answer = AnswerTuple.getInstance(answer, answerVariables[0].length); | 436 | gapAnswerTuples.remove(answer); |
| 437 | |||
| 438 | answer = AnswerTuple.getInstance(answer, answerVariables[0].length); | ||
| 377 | // if (soundAnswerTuples.contains(answer)) | 439 | // if (soundAnswerTuples.contains(answer)) |
| 378 | // Utility.logError("The answer (" + answer + ") cannot be added, because it is in the lower bound."); | 440 | // Utility.logError("The answer (" + answer + ") cannot be added, because it is in the lower bound."); |
| 379 | soundAnswerTuples.add(answer); | 441 | soundAnswerTuples.add(answer); |
| 380 | } | 442 | } |
| 381 | } | 443 | } |
| 382 | 444 | ||
| 383 | public int getNoOfSoundAnswers() { | 445 | public int getNoOfSoundAnswers() { |
| 384 | return soundAnswerTuples.size(); | 446 | if(isDisposed()) throw new DisposedException(); |
| 385 | } | 447 | |
| 386 | 448 | return soundAnswerTuples.size(); | |
| 387 | public void addProcessingTime(Step step, double time) { | 449 | } |
| 388 | timer[step.ordinal()] += time; | 450 | |
| 389 | } | 451 | public void addProcessingTime(Step step, double time) { |
| 390 | 452 | if(isDisposed()) throw new DisposedException(); | |
| 391 | public int getArity() { | 453 | |
| 392 | return answerVariables[0].length; | 454 | timer[step.ordinal()] += time; |
| 393 | } | 455 | } |
| 394 | 456 | ||
| 395 | public void addRelevantClauses(DLClause clause) { | 457 | public int getArity() { |
| 396 | relevantClauses.add(clause); | 458 | if(isDisposed()) throw new DisposedException(); |
| 397 | } | 459 | |
| 398 | 460 | return answerVariables[0].length; | |
| 399 | public Set<DLClause> getRelevantClauses() { | 461 | } |
| 400 | return relevantClauses; | 462 | |
| 401 | } | 463 | public void addRelevantClauses(DLClause clause) { |
| 402 | 464 | if(isDisposed()) throw new DisposedException(); | |
| 403 | public void clearClauses() { | 465 | |
| 404 | relevantClauses.clear(); | 466 | relevantClauses.add(clause); |
| 405 | } | 467 | } |
| 406 | 468 | ||
| 407 | public boolean isHorn() { | 469 | public Set<DLClause> getRelevantClauses() { |
| 408 | for (DLClause clause: relevantClauses) | 470 | if(isDisposed()) throw new DisposedException(); |
| 409 | if (clause.getHeadLength() > 1) | 471 | |
| 410 | return false; | 472 | return relevantClauses; |
| 411 | return true; | 473 | } |
| 412 | } | 474 | |
| 413 | 475 | public void clearClauses() { | |
| 414 | public void saveABoxInTurtle(String filename) { | 476 | if(isDisposed()) throw new DisposedException(); |
| 415 | try { | 477 | |
| 416 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename))); | 478 | relevantClauses.clear(); |
| 417 | OWLIndividual a, b; | 479 | } |
| 418 | StringBuilder builder = new StringBuilder(); | 480 | |
| 419 | for (OWLAxiom axiom: relevantOntology.getABoxAxioms(true)) { | 481 | public boolean isHorn() { |
| 420 | if (axiom instanceof OWLClassAssertionAxiom) { | 482 | if(isDisposed()) throw new DisposedException(); |
| 421 | OWLClassAssertionAxiom classAssertion = (OWLClassAssertionAxiom) axiom; | 483 | |
| 422 | OWLClass c = (OWLClass) classAssertion.getClassExpression(); | 484 | for(DLClause clause : relevantClauses) |
| 423 | a = classAssertion.getIndividual(); | 485 | if(clause.getHeadLength() > 1) |
| 424 | builder.append(a.toString()) | 486 | return false; |
| 425 | .append(" <") | 487 | return true; |
| 426 | .append(Namespace.RDF_TYPE) | 488 | } |
| 427 | .append("> ") | 489 | |
| 428 | .append(c.toString()); | 490 | public void saveABoxInTurtle(String filename) { |
| 429 | } | 491 | if(isDisposed()) throw new DisposedException(); |
| 430 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom) { | 492 | |
| 431 | OWLObjectPropertyAssertionAxiom propertyAssertion = (OWLObjectPropertyAssertionAxiom) axiom; | 493 | try { |
| 432 | OWLObjectProperty p = (OWLObjectProperty) propertyAssertion.getProperty(); | 494 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename))); |
| 433 | a = propertyAssertion.getSubject(); | 495 | OWLIndividual a, b; |
| 434 | b = propertyAssertion.getObject(); | 496 | StringBuilder builder = new StringBuilder(); |
| 435 | builder.append(a.toString()).append(" ").append(p.toString()).append(" ").append(b.toString()); | 497 | for(OWLAxiom axiom : relevantOntology.getABoxAxioms(true)) { |
| 436 | } | 498 | if(axiom instanceof OWLClassAssertionAxiom) { |
| 437 | else if (axiom instanceof OWLDataPropertyAssertionAxiom) { | 499 | OWLClassAssertionAxiom classAssertion = (OWLClassAssertionAxiom) axiom; |
| 438 | OWLDataPropertyAssertionAxiom propertyAssertion = (OWLDataPropertyAssertionAxiom) axiom; | 500 | OWLClass c = (OWLClass) classAssertion.getClassExpression(); |
| 439 | OWLDataProperty p = (OWLDataProperty) propertyAssertion.getProperty(); | 501 | a = classAssertion.getIndividual(); |
| 440 | a = propertyAssertion.getSubject(); | 502 | builder.append(a.toString()) |
| 441 | OWLLiteral l = propertyAssertion.getObject(); | 503 | .append(" <") |
| 442 | builder.append(a.toString()).append(" ").append(p.toString()).append(" ").append(l.toString()); | 504 | .append(Namespace.RDF_TYPE) |
| 443 | } | 505 | .append("> ") |
| 444 | 506 | .append(c.toString()); | |
| 445 | writer.write(builder.toString()); | 507 | } |
| 446 | writer.write(" ."); | 508 | else if(axiom instanceof OWLObjectPropertyAssertionAxiom) { |
| 447 | writer.newLine(); | 509 | OWLObjectPropertyAssertionAxiom propertyAssertion = (OWLObjectPropertyAssertionAxiom) axiom; |
| 448 | builder.setLength(0); | 510 | OWLObjectProperty p = (OWLObjectProperty) propertyAssertion.getProperty(); |
| 449 | } | 511 | a = propertyAssertion.getSubject(); |
| 450 | writer.close(); | 512 | b = propertyAssertion.getObject(); |
| 451 | } catch (IOException e) { | 513 | builder.append(a.toString()).append(" ").append(p.toString()).append(" ").append(b.toString()); |
| 452 | e.printStackTrace(); | 514 | } |
| 453 | } finally { | 515 | else if(axiom instanceof OWLDataPropertyAssertionAxiom) { |
| 454 | 516 | OWLDataPropertyAssertionAxiom propertyAssertion = (OWLDataPropertyAssertionAxiom) axiom; | |
| 455 | } | 517 | OWLDataProperty p = (OWLDataProperty) propertyAssertion.getProperty(); |
| 456 | } | 518 | a = propertyAssertion.getSubject(); |
| 457 | 519 | OWLLiteral l = propertyAssertion.getObject(); | |
| 458 | public void updateSubID() { | 520 | builder.append(a.toString()).append(" ").append(p.toString()).append(" ").append(l.toString()); |
| 459 | ++subID; | 521 | } |
| 460 | stringQueryID = String.valueOf(queryID) + "_" + subID; | 522 | |
| 461 | } | 523 | writer.write(builder.toString()); |
| 462 | 524 | writer.write(" ."); | |
| 463 | public DLClause getClause() { | 525 | writer.newLine(); |
| 464 | if (queryClause != null) | 526 | builder.setLength(0); |
| 465 | return queryClause; | 527 | } |
| 466 | return queryClause = DLClauseHelper.getQuery(queryText, null); | 528 | writer.close(); |
| 467 | } | 529 | } catch(IOException e) { |
| 468 | 530 | e.printStackTrace(); | |
| 469 | public boolean isBottom() { | 531 | } finally { |
| 470 | return queryID == 0; | 532 | |
| 471 | } | 533 | } |
| 472 | 534 | } | |
| 473 | public int getNoOfCompleteAnswers() { | 535 | |
| 474 | return soundAnswerTuples.size() + gapAnswerTuples.size(); | 536 | public void updateSubID() { |
| 475 | } | 537 | if(isDisposed()) throw new DisposedException(); |
| 476 | 538 | ||
| 477 | public int getSubID() { | 539 | ++subID; |
| 478 | return subID; | 540 | stringQueryID = String.valueOf(queryID) + "_" + subID; |
| 479 | } | 541 | } |
| 480 | 542 | ||
| 481 | public boolean hasSameGapAnswers(QueryRecord that) { | 543 | public DLClause getClause() { |
| 482 | return gapAnswerTuples.containsAll(that.gapAnswerTuples) && that.gapAnswerTuples.containsAll(gapAnswerTuples); | 544 | if(isDisposed()) throw new DisposedException(); |
| 483 | } | 545 | |
| 484 | 546 | if(queryClause != null) | |
| 485 | public void dispose() { | 547 | return queryClause; |
| 486 | m_manager.remove(queryText); | 548 | return queryClause = DLClauseHelper.getQuery(queryText, null); |
| 487 | if(gapAnswerTuples != null) gapAnswerTuples = null; | 549 | } |
| 488 | if(soundAnswerTuples != null) soundAnswerTuples = null; | 550 | |
| 489 | if (relevantClauses != null) relevantClauses.clear(); | 551 | public boolean isBottom() { |
| 490 | if (relevantOntology != null) | 552 | if(isDisposed()) throw new DisposedException(); |
| 491 | relevantOntology.getOWLOntologyManager().removeOntology(relevantOntology); | 553 | |
| 492 | answerVariables = null; | 554 | return queryID == 0; |
| 493 | } | 555 | } |
| 494 | 556 | ||
| 495 | public boolean canBeEncodedIntoAtom() { | 557 | public int getNoOfCompleteAnswers() { |
| 496 | // FIXME | 558 | if(isDisposed()) throw new DisposedException(); |
| 497 | return true; | 559 | |
| 560 | return soundAnswerTuples.size() + gapAnswerTuples.size(); | ||
| 561 | } | ||
| 562 | |||
| 563 | public int getSubID() { | ||
| 564 | if(isDisposed()) throw new DisposedException(); | ||
| 565 | |||
| 566 | return subID; | ||
| 567 | } | ||
| 568 | |||
| 569 | public boolean hasSameGapAnswers(QueryRecord that) { | ||
| 570 | if(isDisposed()) throw new DisposedException(); | ||
| 571 | |||
| 572 | return gapAnswerTuples.containsAll(that.gapAnswerTuples) && that.gapAnswerTuples.containsAll(gapAnswerTuples); | ||
| 573 | } | ||
| 574 | |||
| 575 | @Override | ||
| 576 | public void dispose() { | ||
| 577 | super.dispose(); | ||
| 578 | m_manager.remove(queryText); | ||
| 579 | if(gapAnswerTuples != null) gapAnswerTuples = null; | ||
| 580 | if(soundAnswerTuples != null) soundAnswerTuples = null; | ||
| 581 | if(relevantClauses != null) relevantClauses.clear(); | ||
| 582 | if(relevantOntology != null) | ||
| 583 | relevantOntology.getOWLOntologyManager().removeOntology(relevantOntology); | ||
| 584 | answerVariables = null; | ||
| 585 | } | ||
| 586 | |||
| 587 | public boolean canBeEncodedIntoAtom() { | ||
| 588 | if(isDisposed()) throw new DisposedException(); | ||
| 589 | |||
| 590 | // FIXME | ||
| 591 | return true; | ||
| 498 | // return false; | 592 | // return false; |
| 499 | } | 593 | } |
| 500 | 594 | ||
| 501 | public boolean isPredicate(AnswerTuple a, int i) { | 595 | public boolean isPredicate(AnswerTuple a, int i) { |
| 502 | Atom[] atoms = getClause().getBodyAtoms(); | 596 | if(isDisposed()) throw new DisposedException(); |
| 503 | Variable v = Variable.create(answerVariables[1][i]); | 597 | |
| 504 | String iri; | 598 | Atom[] atoms = getClause().getBodyAtoms(); |
| 505 | for(Atom atom : atoms) { | 599 | Variable v = Variable.create(answerVariables[1][i]); |
| 506 | DLPredicate p = atom.getDLPredicate(); | 600 | String iri; |
| 507 | if (p instanceof AtomicConcept) { | 601 | for(Atom atom : atoms) { |
| 508 | if(((AtomicConcept) p).getIRI().equals(v.toString())) return true; | 602 | DLPredicate p = atom.getDLPredicate(); |
| 509 | } | 603 | if(p instanceof AtomicConcept) { |
| 510 | else if (p instanceof AtomicRole) { | 604 | if(((AtomicConcept) p).getIRI().equals(v.toString())) return true; |
| 511 | iri = ((AtomicRole) p).getIRI(); | 605 | } |
| 512 | if (iri.equals(v.toString())) return true; | 606 | else if(p instanceof AtomicRole) { |
| 513 | if(iri.startsWith("?")) | 607 | iri = ((AtomicRole) p).getIRI(); |
| 514 | iri = a.getGroundTerm(i).toString(); | 608 | if(iri.equals(v.toString())) return true; |
| 515 | if(iri.equals(Namespace.RDF_TYPE) && atom.getArgument(1).equals(v)) return true; | 609 | if(iri.startsWith("?")) |
| 516 | } | 610 | iri = a.getGroundTerm(i).toString(); |
| 517 | } | 611 | if(iri.equals(Namespace.RDF_TYPE) && atom.getArgument(1).equals(v)) return true; |
| 518 | return false; | 612 | } |
| 519 | } | 613 | } |
| 520 | 614 | return false; | |
| 521 | // TODO remove fully extended query | 615 | } |
| 522 | public Tuple<String> getExtendedQueryText() { | 616 | |
| 617 | // TODO remove fully extended query | ||
| 618 | public Tuple<String> getExtendedQueryText() { | ||
| 619 | if(isDisposed()) throw new DisposedException(); | ||
| 620 | |||
| 523 | // String[] ret = new String[2];s | 621 | // String[] ret = new String[2];s |
| 524 | int index = queryText.toUpperCase().indexOf(" WHERE"); | 622 | int index = queryText.toUpperCase().indexOf(" WHERE"); |
| 525 | String extendedSelect = queryText.substring(0, index); | 623 | String extendedSelect = queryText.substring(0, index); |
| 526 | String extendedWhere= queryText.substring(index + 1), fullyExtendedWhere = queryText.substring(index + 1); | 624 | String extendedWhere = queryText.substring(index + 1), fullyExtendedWhere = queryText.substring(index + 1); |
| 527 | 625 | ||
| 528 | String sub, obj; | 626 | String sub, obj; |
| 529 | Map<String, Set<String>> links = new HashMap<String, Set<String>>(); | 627 | Map<String, Set<String>> links = new HashMap<String, Set<String>>(); |
| 530 | Set<String> list; | 628 | Set<String> list; |
| 531 | for (Atom atom: getClause().getBodyAtoms()) | 629 | for(Atom atom : getClause().getBodyAtoms()) |
| 532 | if (atom.getDLPredicate() instanceof AtomicRole && atom.getArgument(0) instanceof Variable && atom.getArgument(1) instanceof Variable) { | 630 | if(atom.getDLPredicate() instanceof AtomicRole && atom.getArgument(0) instanceof Variable && atom.getArgument(1) instanceof Variable) { |
| 533 | sub = atom.getArgumentVariable(0).getName(); | 631 | sub = atom.getArgumentVariable(0).getName(); |
| 534 | obj = atom.getArgumentVariable(1).getName(); | 632 | obj = atom.getArgumentVariable(1).getName(); |
| 535 | if((list = links.get(sub)) == null) | 633 | if((list = links.get(sub)) == null) |
| 536 | links.put(sub, list = new HashSet<String>()); | 634 | links.put(sub, list = new HashSet<String>()); |
| 537 | list.add(obj); | 635 | list.add(obj); |
| 538 | if((list = links.get(obj)) == null) | 636 | if((list = links.get(obj)) == null) |
| 539 | links.put(obj, list = new HashSet<String>()); | 637 | links.put(obj, list = new HashSet<String>()); |
| 540 | list.add(sub); | 638 | list.add(sub); |
| 541 | } | 639 | } |
| 542 | 640 | ||
| 543 | StringBuilder extra = new StringBuilder(), fullyExtra = new StringBuilder(); | 641 | StringBuilder extra = new StringBuilder(), fullyExtra = new StringBuilder(); |
| 544 | // if (answerVariables[0] != answerVariables[1]) { | 642 | // if (answerVariables[0] != answerVariables[1]) { |
| 545 | for (int i = answerVariables[0].length; i < answerVariables[1].length; ++i) { | 643 | for(int i = answerVariables[0].length; i < answerVariables[1].length; ++i) { |
| 546 | // for (int i = 0; i < answerVariables[1].length; ++i) { | 644 | // for (int i = 0; i < answerVariables[1].length; ++i) { |
| 547 | fullyExtra.append(" . ?") | 645 | fullyExtra.append(" . ?") |
| 548 | .append(answerVariables[1][i]) | 646 | .append(answerVariables[1][i]) |
| 549 | .append(" " + RDF_TYPE + " <") | 647 | .append(" " + RDF_TYPE + " <") |
| 550 | .append(Namespace.PAGODA_ORIGINAL) | 648 | .append(Namespace.PAGODA_ORIGINAL) |
| 551 | .append(">"); | 649 | .append(">"); |
| 552 | if ((list = links.get(answerVariables[1][i])) == null || list.size() < 2) ; | 650 | if((list = links.get(answerVariables[1][i])) == null || list.size() < 2) ; |
| 553 | else { | 651 | else { |
| 554 | extra.append(" . ?") | 652 | extra.append(" . ?") |
| 555 | .append(answerVariables[1][i]) | 653 | .append(answerVariables[1][i]) |
| 556 | .append(" " + RDF_TYPE + " <") | 654 | .append(" " + RDF_TYPE + " <") |
| 557 | .append(Namespace.PAGODA_ORIGINAL) | 655 | .append(Namespace.PAGODA_ORIGINAL) |
| 558 | .append(">"); | 656 | .append(">"); |
| 559 | } | 657 | } |
| 560 | } | 658 | } |
| 561 | 659 | ||
| 562 | if(extra.length() > 0) { | 660 | if(extra.length() > 0) { |
| 563 | extra.append(" }"); | 661 | extra.append(" }"); |
| 564 | extendedWhere = extendedWhere.replace(" }", extendedWhere.contains(". }") ? extra.substring(2) : extra.toString()); | 662 | extendedWhere = |
| 565 | } | 663 | extendedWhere.replace(" }", extendedWhere.contains(". }") ? extra.substring(2) : extra.toString()); |
| 566 | 664 | } | |
| 567 | if(fullyExtra.length() > 0) { | 665 | |
| 568 | fullyExtra.append(" }"); | 666 | if(fullyExtra.length() > 0) { |
| 569 | fullyExtendedWhere = fullyExtendedWhere.replace(" }", fullyExtendedWhere.contains(". }") ? fullyExtra.substring(2) : fullyExtra.toString()); | 667 | fullyExtra.append(" }"); |
| 570 | } | 668 | fullyExtendedWhere = |
| 669 | fullyExtendedWhere.replace(" }", fullyExtendedWhere.contains(". }") ? fullyExtra.substring(2) : fullyExtra | ||
| 670 | .toString()); | ||
| 671 | } | ||
| 571 | // } | 672 | // } |
| 572 | 673 | ||
| 573 | TupleBuilder result = new TupleBuilder(); | 674 | TupleBuilder result = new TupleBuilder(); |
| 574 | result.append(extendedSelect + " " + fullyExtendedWhere); | 675 | result.append(extendedSelect + " " + fullyExtendedWhere); |
| 575 | 676 | ||
| 576 | extra.setLength(0); | 677 | extra.setLength(0); |
| 577 | if (answerVariables[0] != answerVariables[1]) { | 678 | if(answerVariables[0] != answerVariables[1]) { |
| 578 | for (int i = answerVariables[0].length; i < answerVariables[1].length; ++i) | 679 | for(int i = answerVariables[0].length; i < answerVariables[1].length; ++i) |
| 579 | extra.append(" ?").append(answerVariables[1][i]); | 680 | extra.append(" ?").append(answerVariables[1][i]); |
| 580 | extendedSelect = extendedSelect + extra.toString(); | 681 | extendedSelect = extendedSelect + extra.toString(); |
| 581 | } | 682 | } |
| 582 | result.append(extendedSelect + " " + extendedWhere); | 683 | result.append(extendedSelect + " " + extendedWhere); |
| 583 | 684 | ||
| 584 | return result.build(); | 685 | return result.build(); |
| 585 | } | 686 | } |
| 586 | 687 | ||
| 587 | public boolean hasNonAnsDistinguishedVariables() { | 688 | public boolean hasNonAnsDistinguishedVariables() { |
| 588 | return answerVariables[1].length > answerVariables[0].length; | 689 | if(isDisposed()) throw new DisposedException(); |
| 589 | } | 690 | |
| 590 | 691 | return answerVariables[1].length > answerVariables[0].length; | |
| 591 | /** | 692 | } |
| 592 | * Two <tt>QueryRecords</tt> are equal iff | 693 | |
| 593 | * they have the same <tt>queryText</tt>, | 694 | /** |
| 594 | * <tt>soundAnswerTuples</tt>. | 695 | * Two <tt>QueryRecords</tt> are equal iff |
| 595 | */ | 696 | * they have the same <tt>queryText</tt>, |
| 596 | @Override | 697 | * <tt>soundAnswerTuples</tt>. |
| 597 | public boolean equals(Object o) { | 698 | */ |
| 598 | if(!o.getClass().equals(getClass())) return false; | 699 | @Override |
| 599 | QueryRecord that = (QueryRecord) o; | 700 | public boolean equals(Object o) { |
| 600 | return this.queryText.equals(that.queryText) | 701 | if(isDisposed()) throw new DisposedException(); |
| 601 | && soundAnswerTuples.equals(that.soundAnswerTuples); | 702 | |
| 602 | } | 703 | if(!o.getClass().equals(getClass())) return false; |
| 603 | 704 | QueryRecord that = (QueryRecord) o; | |
| 604 | @Override | 705 | return this.queryText.equals(that.queryText) |
| 605 | public int hashCode() { | 706 | && soundAnswerTuples.equals(that.soundAnswerTuples); |
| 606 | return Objects.hash(queryText, soundAnswerTuples); | 707 | } |
| 607 | } | 708 | |
| 608 | 709 | @Override | |
| 609 | public enum Step { | 710 | public int hashCode() { |
| 610 | LOWER_BOUND, | 711 | if(isDisposed()) throw new DisposedException(); |
| 611 | UPPER_BOUND, | 712 | |
| 612 | SIMPLE_UPPER_BOUND, | 713 | return Objects.hash(queryText, soundAnswerTuples); |
| 613 | LAZY_UPPER_BOUND, | 714 | } |
| 614 | L_SKOLEM_UPPER_BOUND, | 715 | |
| 615 | EL_LOWER_BOUND, | 716 | public enum Step { |
| 616 | FRAGMENT, | 717 | LOWER_BOUND, |
| 617 | FRAGMENT_REFINEMENT, | 718 | UPPER_BOUND, |
| 618 | SUMMARISATION, | 719 | SIMPLE_UPPER_BOUND, |
| 619 | DEPENDENCY, | 720 | LAZY_UPPER_BOUND, |
| 620 | FULL_REASONING | 721 | L_SKOLEM_UPPER_BOUND, |
| 621 | } | 722 | EL_LOWER_BOUND, |
| 622 | 723 | FRAGMENT, | |
| 623 | /** | 724 | FRAGMENT_REFINEMENT, |
| 624 | * A Json serializer, which considers the main attributes. | 725 | SUMMARISATION, |
| 625 | */ | 726 | DEPENDENCY, |
| 626 | public static class QueryRecordSerializer implements JsonSerializer<QueryRecord> { | 727 | FULL_REASONING |
| 627 | public JsonElement serialize(QueryRecord src, Type typeOfSrc, JsonSerializationContext context) { | 728 | } |
| 628 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); | 729 | |
| 629 | JsonObject object = new JsonObject(); | 730 | /** |
| 630 | object.addProperty("queryID", src.queryID); | 731 | * A Json serializer, which considers the main attributes. |
| 631 | object.addProperty("queryText", src.queryText); | 732 | */ |
| 733 | public static class QueryRecordSerializer implements JsonSerializer<QueryRecord> { | ||
| 734 | public JsonElement serialize(QueryRecord src, Type typeOfSrc, JsonSerializationContext context) { | ||
| 735 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
| 736 | JsonObject object = new JsonObject(); | ||
| 737 | object.addProperty("queryID", src.queryID); | ||
| 738 | object.addProperty("queryText", src.queryText); | ||
| 632 | // object.addProperty("difficulty", src.difficulty != null ? src.difficulty.toString() : ""); | 739 | // object.addProperty("difficulty", src.difficulty != null ? src.difficulty.toString() : ""); |
| 633 | 740 | ||
| 634 | object.add("answerVariables", context.serialize(src.getAnswerVariables())); | 741 | object.add("answerVariables", context.serialize(src.getAnswerVariables())); |
| 635 | object.add("answers", context.serialize(src.soundAnswerTuples)); | 742 | object.add("answers", context.serialize(src.soundAnswerTuples)); |
| 636 | // object.add("gapAnswers", context.serialize(src.gapAnswerTuples)); | 743 | // object.add("gapAnswers", context.serialize(src.gapAnswerTuples)); |
| 637 | 744 | ||
| 638 | return object; | 745 | return object; |
| 639 | } | 746 | } |
| 640 | } | 747 | } |
| 641 | 748 | ||
| 642 | /** | 749 | /** |
| 643 | * A Json deserializer, compliant to the output of the serializer defined above. | 750 | * A Json deserializer, compliant to the output of the serializer defined above. |
| 644 | */ | 751 | */ |
| 645 | public static class QueryRecordDeserializer implements JsonDeserializer<QueryRecord> { | 752 | public static class QueryRecordDeserializer implements JsonDeserializer<QueryRecord> { |
| 646 | public QueryRecord deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) | 753 | public QueryRecord deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) |
| 647 | throws JsonParseException { | 754 | throws JsonParseException { |
| 648 | 755 | ||
| 649 | QueryRecord record = new QueryRecord(); | 756 | QueryRecord record = new QueryRecord(); |
| 650 | JsonObject object = json.getAsJsonObject(); | 757 | JsonObject object = json.getAsJsonObject(); |
| 651 | record.queryID = object.getAsJsonPrimitive("queryID").getAsInt(); | 758 | record.queryID = object.getAsJsonPrimitive("queryID").getAsInt(); |
| 652 | record.queryText = object.getAsJsonPrimitive("queryText").getAsString(); | 759 | record.queryText = object.getAsJsonPrimitive("queryText").getAsString(); |
| 653 | // record.difficulty = Step.valueOf(object.getAsJsonPrimitive("difficulty").getAsString()); | 760 | // record.difficulty = Step.valueOf(object.getAsJsonPrimitive("difficulty").getAsString()); |
| 654 | 761 | ||
| 655 | JsonArray answerVariablesJson = object.getAsJsonArray("answerVariables"); | 762 | JsonArray answerVariablesJson = object.getAsJsonArray("answerVariables"); |
| 656 | record.answerVariables = new String[2][]; | 763 | record.answerVariables = new String[2][]; |
| 657 | record.answerVariables[0] = new String[answerVariablesJson.size()]; | 764 | record.answerVariables[0] = new String[answerVariablesJson.size()]; |
| 658 | for(int i = 0; i < answerVariablesJson.size(); i++) | 765 | for(int i = 0; i < answerVariablesJson.size(); i++) |
| 659 | record.answerVariables[0][i] = answerVariablesJson.get(i).getAsString(); | 766 | record.answerVariables[0][i] = answerVariablesJson.get(i).getAsString(); |
| 660 | 767 | ||
| 661 | record.soundAnswerTuples = new HashSet<>(); | 768 | record.soundAnswerTuples = new HashSet<>(); |
| 662 | // record.gapAnswerTuples = new HashSet<>(); | 769 | // record.gapAnswerTuples = new HashSet<>(); |
| 663 | Type type = new TypeToken<AnswerTuple>() { }.getType(); | 770 | Type type = new TypeToken<AnswerTuple>() { |
| 664 | for (JsonElement answer : object.getAsJsonArray("answers")) { | 771 | }.getType(); |
| 665 | record.soundAnswerTuples.add(context.deserialize(answer, type)); | 772 | for(JsonElement answer : object.getAsJsonArray("answers")) { |
| 666 | } | 773 | record.soundAnswerTuples.add(context.deserialize(answer, type)); |
| 774 | } | ||
| 667 | // for (JsonElement answer : object.getAsJsonArray("gapAnswers")) { | 775 | // for (JsonElement answer : object.getAsJsonArray("gapAnswers")) { |
| 668 | // record.soundAnswerTuples.add(context.deserialize(answer, type)); | 776 | // record.soundAnswerTuples.add(context.deserialize(answer, type)); |
| 669 | // } | 777 | // } |
| 670 | 778 | ||
| 671 | return record; | 779 | return record; |
| 672 | } | 780 | } |
| 673 | } | 781 | } |
| 674 | 782 | ||
| 675 | /** | 783 | /** |
| 676 | * Provides an instance (singleton) of Gson, having a specific configuration. | 784 | * Provides an instance (singleton) of Gson, having a specific configuration. |
| 677 | * */ | 785 | */ |
| 678 | public static class GsonCreator { | 786 | public static class GsonCreator { |
| 679 | 787 | ||
| 680 | private static Gson gson; | 788 | private static Gson gson; |
| 681 | 789 | ||
| 682 | private GsonCreator() {} | 790 | private GsonCreator() { |
| 683 | 791 | } | |
| 684 | public static Gson getInstance() { | 792 | |
| 685 | if(gson == null) { | 793 | public static Gson getInstance() { |
| 686 | gson = new GsonBuilder() | 794 | if(gson == null) { |
| 687 | .registerTypeAdapter(AnswerTuple.class, new AnswerTuple.AnswerTupleSerializer()) | 795 | gson = new GsonBuilder() |
| 688 | .registerTypeAdapter(QueryRecord.class, new QueryRecord.QueryRecordSerializer()) | 796 | .registerTypeAdapter(AnswerTuple.class, new AnswerTuple.AnswerTupleSerializer()) |
| 689 | .registerTypeAdapter(QueryRecord.class, new QueryRecord.QueryRecordDeserializer()) | 797 | .registerTypeAdapter(QueryRecord.class, new QueryRecord.QueryRecordSerializer()) |
| 690 | .registerTypeAdapter(AnswerTuple.class, new AnswerTuple.AnswerTupleDeserializer()) | 798 | .registerTypeAdapter(QueryRecord.class, new QueryRecord.QueryRecordDeserializer()) |
| 691 | .disableHtmlEscaping() | 799 | .registerTypeAdapter(AnswerTuple.class, new AnswerTuple.AnswerTupleDeserializer()) |
| 692 | .setPrettyPrinting() | 800 | .disableHtmlEscaping() |
| 693 | .create(); | 801 | .setPrettyPrinting() |
| 694 | } | 802 | .create(); |
| 695 | return gson; | 803 | } |
| 696 | } | 804 | return gson; |
| 805 | } | ||
| 697 | 806 | ||
| 698 | // public static void dispose() { | 807 | // public static void dispose() { |
| 699 | // gson = null; | 808 | // gson = null; |
| 700 | // } | 809 | // } |
| 701 | 810 | ||
| 702 | } | 811 | } |
| 703 | } | 812 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java index ef9338a..b4a1775 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java | |||
| @@ -22,10 +22,11 @@ import uk.ac.ox.cs.pagoda.tracking.QueryTracker; | |||
| 22 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder; | 22 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder; |
| 23 | import uk.ac.ox.cs.pagoda.util.Timer; | 23 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 24 | import uk.ac.ox.cs.pagoda.util.Utility; | 24 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 25 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; | ||
| 25 | 26 | ||
| 26 | import java.util.LinkedList; | 27 | import java.util.LinkedList; |
| 27 | 28 | ||
| 28 | public class ConsistencyManager { | 29 | public class ConsistencyManager extends Disposable { |
| 29 | 30 | ||
| 30 | protected MyQueryReasoner m_reasoner; | 31 | protected MyQueryReasoner m_reasoner; |
| 31 | protected QueryManager m_queryManager; | 32 | protected QueryManager m_queryManager; |
| @@ -40,7 +41,109 @@ public class ConsistencyManager { | |||
| 40 | m_reasoner = reasoner; | 41 | m_reasoner = reasoner; |
| 41 | m_queryManager = reasoner.getQueryManager(); | 42 | m_queryManager = reasoner.getQueryManager(); |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 45 | @Override | ||
| 46 | public void dispose() { | ||
| 47 | super.dispose(); | ||
| 48 | fullQueryRecord.dispose(); | ||
| 49 | } | ||
| 50 | |||
| 51 | public void extractBottomFragment() { | ||
| 52 | if(fragmentExtracted) return; | ||
| 53 | fragmentExtracted = true; | ||
| 54 | |||
| 55 | UpperDatalogProgram upperProgram = m_reasoner.program.getUpper(); | ||
| 56 | int number = upperProgram.getBottomNumber(); | ||
| 57 | |||
| 58 | if(number <= 1) { | ||
| 59 | botQueryRecords = new QueryRecord[]{fullQueryRecord}; | ||
| 60 | } | ||
| 61 | else { | ||
| 62 | QueryRecord[] tempQueryRecords = new QueryRecord[number - 1]; | ||
| 63 | QueryRecord record; | ||
| 64 | for(int i = 0; i < number - 1; ++i) { | ||
| 65 | tempQueryRecords[i] = record = | ||
| 66 | m_queryManager.create(QueryRecord.botQueryText.replace("Nothing", "Nothing" + (i + 1)), 0, i + 1); | ||
| 67 | AnswerTuples iter = null; | ||
| 68 | try { | ||
| 69 | iter = m_reasoner.trackingStore.evaluate(record.getQueryText(), record.getAnswerVariables()); | ||
| 70 | record.updateUpperBoundAnswers(iter); | ||
| 71 | } finally { | ||
| 72 | if(iter != null) iter.dispose(); | ||
| 73 | iter = null; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | int bottomNumber = 0; | ||
| 78 | int[] group = new int[number - 1]; | ||
| 79 | for(int i = 0; i < number - 1; ++i) group[i] = i; | ||
| 80 | for(int i = 0; i < number - 1; ++i) | ||
| 81 | if(tempQueryRecords[i].isProcessed()) tempQueryRecords[i].dispose(); | ||
| 82 | else if(group[i] == i) { | ||
| 83 | ++bottomNumber; | ||
| 84 | record = tempQueryRecords[i]; | ||
| 85 | for(int j = i + 1; j < number - 1; ++j) | ||
| 86 | if(record.hasSameGapAnswers(tempQueryRecords[j])) | ||
| 87 | group[j] = i; | ||
| 88 | } | ||
| 89 | |||
| 90 | Utility.logInfo("There are " + bottomNumber + " different bottom fragments."); | ||
| 91 | toAddClauses = new LinkedList<DLClause>(); | ||
| 92 | int bottomCounter = 0; | ||
| 93 | botQueryRecords = new QueryRecord[bottomNumber]; | ||
| 94 | Variable X = Variable.create("X"); | ||
| 95 | for(int i = 0; i < number - 1; ++i) | ||
| 96 | if(!tempQueryRecords[i].isDisposed() && !tempQueryRecords[i].isProcessed()) | ||
| 97 | if(group[i] == i) { | ||
| 98 | botQueryRecords[bottomCounter] = record = tempQueryRecords[i]; | ||
| 99 | record.resetInfo(QueryRecord.botQueryText.replace("Nothing", "Nothing_final" + (++bottomCounter)), 0, | ||
| 100 | group[i] = bottomCounter); | ||
| 101 | toAddClauses.add( | ||
| 102 | DLClause.create( | ||
| 103 | new Atom[]{Atom.create(AtomicConcept.create(AtomicConcept.NOTHING.getIRI() + "_final" + bottomCounter), X)}, | ||
| 104 | new Atom[]{Atom.create(AtomicConcept.create(AtomicConcept.NOTHING.getIRI() + (i + 1)), X)})); | ||
| 105 | } | ||
| 106 | else { | ||
| 107 | toAddClauses.add( | ||
| 108 | DLClause.create( | ||
| 109 | new Atom[]{Atom.create(AtomicConcept.create(AtomicConcept.NOTHING.getIRI() + "_final" + group[group[i]]), X)}, | ||
| 110 | new Atom[]{Atom.create(AtomicConcept.create(AtomicConcept.NOTHING.getIRI() + (i + 1)), X)})); | ||
| 111 | tempQueryRecords[i].dispose(); | ||
| 112 | } | ||
| 113 | |||
| 114 | upperProgram.updateDependencyGraph(toAddClauses); | ||
| 115 | } | ||
| 116 | |||
| 117 | String[] programs = collectTrackingProgramAndImport(); | ||
| 118 | if(programs.length == 0) | ||
| 119 | return; | ||
| 120 | |||
| 121 | DataStore store = m_reasoner.trackingStore.getDataStore(); | ||
| 122 | long oldTripleCount, tripleCount; | ||
| 123 | try { | ||
| 124 | Timer t1 = new Timer(); | ||
| 125 | oldTripleCount = store.getTriplesCount(); | ||
| 126 | for(String program : programs) | ||
| 127 | store.importRules(program, UpdateType.ScheduleForAddition); | ||
| 128 | store.applyReasoning(true); | ||
| 129 | tripleCount = store.getTriplesCount(); | ||
| 130 | |||
| 131 | Utility.logInfo("tracking store after materialising tracking program: " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)", | ||
| 132 | "tracking store finished the materialisation of tracking program in " + t1.duration() + " seconds."); | ||
| 133 | |||
| 134 | extractAxioms(); | ||
| 135 | store.clearRulesAndMakeFactsExplicit(); | ||
| 136 | } catch(JRDFStoreException e) { | ||
| 137 | e.printStackTrace(); | ||
| 138 | } catch(OWLOntologyCreationException e) { | ||
| 139 | e.printStackTrace(); | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | public QueryRecord[] getQueryRecords() { | ||
| 144 | return botQueryRecords; | ||
| 145 | } | ||
| 146 | |||
| 44 | boolean checkRLLowerBound() { | 147 | boolean checkRLLowerBound() { |
| 45 | fullQueryRecord = m_queryManager.create(QueryRecord.botQueryText, 0); | 148 | fullQueryRecord = m_queryManager.create(QueryRecord.botQueryText, 0); |
| 46 | AnswerTuples iter = null; | 149 | AnswerTuples iter = null; |
| @@ -59,9 +162,22 @@ public class ConsistencyManager { | |||
| 59 | return true; | 162 | return true; |
| 60 | } | 163 | } |
| 61 | 164 | ||
| 165 | // protected boolean unsatisfiability(double duration) { | ||
| 166 | // fullQueryRecord.dispose(); | ||
| 167 | // Utility.logDebug("The ontology and dataset is unsatisfiable."); | ||
| 168 | // return false; | ||
| 169 | // } | ||
| 170 | |||
| 171 | // protected boolean satisfiability(double duration) { | ||
| 172 | // fullQueryRecord.dispose(); | ||
| 173 | // Utility.logDebug("The ontology and dataset is satisfiable."); | ||
| 174 | // return true; | ||
| 175 | // } | ||
| 176 | |||
| 62 | boolean checkELLowerBound() { | 177 | boolean checkELLowerBound() { |
| 63 | fullQueryRecord.updateLowerBoundAnswers(m_reasoner.elLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables())); | 178 | fullQueryRecord.updateLowerBoundAnswers(m_reasoner.elLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord |
| 64 | if (fullQueryRecord.getNoOfSoundAnswers() > 0) { | 179 | .getAnswerVariables())); |
| 180 | if(fullQueryRecord.getNoOfSoundAnswers() > 0) { | ||
| 65 | Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); | 181 | Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); |
| 66 | return true; | 182 | return true; |
| 67 | } | 183 | } |
| @@ -69,39 +185,22 @@ public class ConsistencyManager { | |||
| 69 | } | 185 | } |
| 70 | 186 | ||
| 71 | boolean checkUpper(BasicQueryEngine upperStore) { | 187 | boolean checkUpper(BasicQueryEngine upperStore) { |
| 72 | if (upperStore != null) { | 188 | if(upperStore != null) { |
| 73 | AnswerTuples tuples = null; | 189 | AnswerTuples tuples = null; |
| 74 | try { | 190 | try { |
| 75 | tuples = upperStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); | 191 | tuples = upperStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); |
| 76 | if (!tuples.isValid()) { | 192 | if(!tuples.isValid()) { |
| 77 | Utility.logInfo("There are no contradictions derived in "+ upperStore.getName() +" materialisation."); | 193 | Utility.logInfo("There are no contradictions derived in " + upperStore.getName() + " materialisation."); |
| 78 | Utility.logDebug("The ontology and dataset is satisfiable."); | 194 | Utility.logDebug("The ontology and dataset is satisfiable."); |
| 79 | return true; | 195 | return true; |
| 80 | } | 196 | } |
| 81 | } | 197 | } finally { |
| 82 | finally { | 198 | if(tuples != null) tuples.dispose(); |
| 83 | if (tuples != null) tuples.dispose(); | ||
| 84 | } | 199 | } |
| 85 | } | 200 | } |
| 86 | return false; | 201 | return false; |
| 87 | } | 202 | } |
| 88 | 203 | ||
| 89 | void dispose() { | ||
| 90 | fullQueryRecord.dispose(); | ||
| 91 | } | ||
| 92 | |||
| 93 | // protected boolean unsatisfiability(double duration) { | ||
| 94 | // fullQueryRecord.dispose(); | ||
| 95 | // Utility.logDebug("The ontology and dataset is unsatisfiable."); | ||
| 96 | // return false; | ||
| 97 | // } | ||
| 98 | |||
| 99 | // protected boolean satisfiability(double duration) { | ||
| 100 | // fullQueryRecord.dispose(); | ||
| 101 | // Utility.logDebug("The ontology and dataset is satisfiable."); | ||
| 102 | // return true; | ||
| 103 | // } | ||
| 104 | |||
| 105 | boolean check() { | 204 | boolean check() { |
| 106 | // if (!checkRLLowerBound()) return false; | 205 | // if (!checkRLLowerBound()) return false; |
| 107 | // if (!checkELLowerBound()) return false; | 206 | // if (!checkELLowerBound()) return false; |
| @@ -148,148 +247,54 @@ public class ConsistencyManager { | |||
| 148 | return true; | 247 | return true; |
| 149 | } | 248 | } |
| 150 | 249 | ||
| 151 | public void extractBottomFragment() { | ||
| 152 | if (fragmentExtracted) return ; | ||
| 153 | fragmentExtracted = true; | ||
| 154 | |||
| 155 | UpperDatalogProgram upperProgram = m_reasoner.program.getUpper(); | ||
| 156 | int number = upperProgram.getBottomNumber(); | ||
| 157 | |||
| 158 | if (number <= 1) { | ||
| 159 | botQueryRecords = new QueryRecord[] { fullQueryRecord }; | ||
| 160 | } | ||
| 161 | else { | ||
| 162 | QueryRecord[] tempQueryRecords = new QueryRecord[number - 1]; | ||
| 163 | QueryRecord record; | ||
| 164 | for (int i = 0; i < number - 1; ++i) { | ||
| 165 | tempQueryRecords[i] = record = m_queryManager.create(QueryRecord.botQueryText.replace("Nothing", "Nothing" + (i + 1)), 0, i + 1); | ||
| 166 | AnswerTuples iter = null; | ||
| 167 | try { | ||
| 168 | iter = m_reasoner.trackingStore.evaluate(record.getQueryText(), record.getAnswerVariables()); | ||
| 169 | record.updateUpperBoundAnswers(iter); | ||
| 170 | } finally { | ||
| 171 | if (iter != null) iter.dispose(); | ||
| 172 | iter = null; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | int bottomNumber = 0; | ||
| 177 | int[] group = new int[number - 1]; | ||
| 178 | for (int i = 0; i < number - 1; ++i) group[i] = i; | ||
| 179 | for (int i = 0; i < number - 1; ++i) | ||
| 180 | if(tempQueryRecords[i].isProcessed()) tempQueryRecords[i].dispose(); | ||
| 181 | else if (group[i] == i) { | ||
| 182 | ++bottomNumber; | ||
| 183 | record = tempQueryRecords[i]; | ||
| 184 | for (int j = i + 1; j < number - 1; ++j) | ||
| 185 | if (record.hasSameGapAnswers(tempQueryRecords[j])) | ||
| 186 | group[j] = i; | ||
| 187 | } | ||
| 188 | |||
| 189 | Utility.logInfo("There are " + bottomNumber + " different bottom fragments."); | ||
| 190 | toAddClauses = new LinkedList<DLClause>(); | ||
| 191 | int bottomCounter = 0; | ||
| 192 | botQueryRecords = new QueryRecord[bottomNumber]; | ||
| 193 | Variable X = Variable.create("X"); | ||
| 194 | for (int i = 0; i < number - 1; ++i) | ||
| 195 | if(!tempQueryRecords[i].isProcessed()) | ||
| 196 | if (group[i] == i) { | ||
| 197 | botQueryRecords[bottomCounter] = record = tempQueryRecords[i]; | ||
| 198 | record.resetInfo(QueryRecord.botQueryText.replace("Nothing", "Nothing_final" + (++bottomCounter)), 0, group[i] = bottomCounter); | ||
| 199 | toAddClauses.add( | ||
| 200 | DLClause.create( | ||
| 201 | new Atom[] {Atom.create(AtomicConcept.create(AtomicConcept.NOTHING.getIRI() + "_final" + bottomCounter), X)}, | ||
| 202 | new Atom[] {Atom.create(AtomicConcept.create(AtomicConcept.NOTHING.getIRI() + (i + 1)), X)})); | ||
| 203 | } | ||
| 204 | else { | ||
| 205 | toAddClauses.add( | ||
| 206 | DLClause.create( | ||
| 207 | new Atom[] {Atom.create(AtomicConcept.create(AtomicConcept.NOTHING.getIRI() + "_final" + group[group[i]]), X)}, | ||
| 208 | new Atom[] {Atom.create(AtomicConcept.create(AtomicConcept.NOTHING.getIRI() + (i + 1)), X)})); | ||
| 209 | tempQueryRecords[i].dispose(); | ||
| 210 | } | ||
| 211 | |||
| 212 | upperProgram.updateDependencyGraph(toAddClauses); | ||
| 213 | } | ||
| 214 | |||
| 215 | String[] programs = collectTrackingProgramAndImport(); | ||
| 216 | if (programs.length == 0) | ||
| 217 | return ; | ||
| 218 | |||
| 219 | DataStore store = m_reasoner.trackingStore.getDataStore(); | ||
| 220 | long oldTripleCount, tripleCount; | ||
| 221 | try { | ||
| 222 | Timer t1 = new Timer(); | ||
| 223 | oldTripleCount = store.getTriplesCount(); | ||
| 224 | for (String program: programs) | ||
| 225 | store.importRules(program, UpdateType.ScheduleForAddition); | ||
| 226 | store.applyReasoning(true); | ||
| 227 | tripleCount = store.getTriplesCount(); | ||
| 228 | |||
| 229 | Utility.logInfo("tracking store after materialising tracking program: " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)", | ||
| 230 | "tracking store finished the materialisation of tracking program in " + t1.duration() + " seconds."); | ||
| 231 | |||
| 232 | extractAxioms(); | ||
| 233 | store.clearRulesAndMakeFactsExplicit(); | ||
| 234 | } catch (JRDFStoreException e) { | ||
| 235 | e.printStackTrace(); | ||
| 236 | } catch (OWLOntologyCreationException e) { | ||
| 237 | e.printStackTrace(); | ||
| 238 | } | ||
| 239 | } | ||
| 240 | |||
| 241 | private void extractAxioms4Full() throws OWLOntologyCreationException { | 250 | private void extractAxioms4Full() throws OWLOntologyCreationException { |
| 242 | OWLOntologyManager manager = m_reasoner.encoder.getProgram().getOntology().getOWLOntologyManager(); | 251 | OWLOntologyManager manager = m_reasoner.encoder.getProgram().getOntology().getOWLOntologyManager(); |
| 243 | OWLOntology fullOntology = manager.createOntology(); | 252 | OWLOntology fullOntology = manager.createOntology(); |
| 244 | for (QueryRecord record: botQueryRecords) { | 253 | for (QueryRecord record: botQueryRecords) { |
| 245 | for (DLClause clause: record.getRelevantClauses()) { | 254 | for (DLClause clause: record.getRelevantClauses()) { |
| 246 | fullQueryRecord.addRelevantClauses(clause); | 255 | fullQueryRecord.addRelevantClauses(clause); |
| 247 | } | 256 | } |
| 248 | manager.addAxioms(fullOntology, record.getRelevantOntology().getAxioms()); | 257 | manager.addAxioms(fullOntology, record.getRelevantOntology().getAxioms()); |
| 249 | } | 258 | } |
| 250 | fullQueryRecord.setRelevantOntology(fullOntology); | 259 | fullQueryRecord.setRelevantOntology(fullOntology); |
| 251 | } | 260 | } |
| 252 | 261 | ||
| 253 | private void extractAxioms() throws OWLOntologyCreationException { | 262 | private void extractAxioms() throws OWLOntologyCreationException { |
| 254 | OWLOntologyManager manager = m_reasoner.encoder.getProgram().getOntology().getOWLOntologyManager(); | 263 | OWLOntologyManager manager = m_reasoner.encoder.getProgram().getOntology().getOWLOntologyManager(); |
| 255 | for (QueryRecord record: botQueryRecords) { | 264 | for (QueryRecord record: botQueryRecords) { |
| 256 | record.setRelevantOntology(manager.createOntology()); | 265 | record.setRelevantOntology(manager.createOntology()); |
| 257 | QueryTracker tracker = new QueryTracker(m_reasoner.encoder, m_reasoner.rlLowerStore, record); | 266 | QueryTracker tracker = new QueryTracker(m_reasoner.encoder, m_reasoner.rlLowerStore, record); |
| 258 | m_reasoner.encoder.setCurrentQuery(record); | 267 | m_reasoner.encoder.setCurrentQuery(record); |
| 259 | tracker.extractAxioms(m_reasoner.trackingStore); | 268 | tracker.extractAxioms(m_reasoner.trackingStore); |
| 260 | // record.saveRelevantClause(); | 269 | // record.saveRelevantClause(); |
| 261 | // record.saveRelevantOntology("bottom" + record.getQueryID() + ".owl"); | 270 | // record.saveRelevantOntology("bottom" + record.getQueryID() + ".owl"); |
| 262 | Utility.logInfo("finish extracting axioms for bottom " + record.getQueryID()); | 271 | Utility.logInfo("finish extracting axioms for bottom " + record.getQueryID()); |
| 263 | } | 272 | } |
| 264 | } | 273 | } |
| 265 | 274 | ||
| 266 | private String[] collectTrackingProgramAndImport() { | 275 | private String[] collectTrackingProgramAndImport() { |
| 267 | String[] programs = new String[botQueryRecords.length]; | 276 | String[] programs = new String[botQueryRecords.length]; |
| 268 | TrackingRuleEncoder encoder = m_reasoner.encoder; | 277 | TrackingRuleEncoder encoder = m_reasoner.encoder; |
| 269 | 278 | ||
| 270 | StringBuilder builder; | 279 | StringBuilder builder; |
| 271 | LinkedList<DLClause> currentClauses = new LinkedList<DLClause>(); | 280 | LinkedList<DLClause> currentClauses = new LinkedList<DLClause>(); |
| 272 | 281 | ||
| 273 | for (int i = 0; i < botQueryRecords.length; ++i) { | 282 | for (int i = 0; i < botQueryRecords.length; ++i) { |
| 274 | encoder.setCurrentQuery(botQueryRecords[i]); | 283 | encoder.setCurrentQuery(botQueryRecords[i]); |
| 275 | builder = new StringBuilder(encoder.getTrackingProgram()); | 284 | builder = new StringBuilder(encoder.getTrackingProgram()); |
| 276 | // encoder.saveTrackingRules("tracking_bottom" + (i + 1) + ".dlog"); | 285 | // encoder.saveTrackingRules("tracking_bottom" + (i + 1) + ".dlog"); |
| 277 | 286 | ||
| 278 | for (DLClause clause: toAddClauses) | 287 | for (DLClause clause: toAddClauses) |
| 279 | if (clause.getHeadAtom(0).getDLPredicate().toString().contains("_final" + (i + 1))) | 288 | if (clause.getHeadAtom(0).getDLPredicate().toString().contains("_final" + (i + 1))) |
| 280 | currentClauses.add(clause); | 289 | currentClauses.add(clause); |
| 281 | 290 | ||
| 282 | builder.append(DLClauseHelper.toString(currentClauses)); | 291 | builder.append(DLClauseHelper.toString(currentClauses)); |
| 283 | programs[i] = builder.toString(); | 292 | programs[i] = builder.toString(); |
| 284 | 293 | ||
| 285 | currentClauses.clear(); | 294 | currentClauses.clear(); |
| 286 | } | 295 | } |
| 287 | |||
| 288 | return programs; | ||
| 289 | } | ||
| 290 | 296 | ||
| 291 | public QueryRecord[] getQueryRecords() { | 297 | return programs; |
| 292 | return botQueryRecords; | ||
| 293 | } | 298 | } |
| 294 | 299 | ||
| 295 | 300 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java index f5a8093..0a151bc 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java | |||
| @@ -10,86 +10,92 @@ import uk.ac.ox.cs.pagoda.reasoner.light.KarmaQueryEngine; | |||
| 10 | import uk.ac.ox.cs.pagoda.rules.LowerDatalogProgram; | 10 | import uk.ac.ox.cs.pagoda.rules.LowerDatalogProgram; |
| 11 | import uk.ac.ox.cs.pagoda.util.Timer; | 11 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 12 | import uk.ac.ox.cs.pagoda.util.Utility; | 12 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 13 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 13 | 14 | ||
| 14 | class ELHOQueryReasoner extends QueryReasoner { | 15 | class ELHOQueryReasoner extends QueryReasoner { |
| 15 | 16 | ||
| 16 | LowerDatalogProgram program; | 17 | LowerDatalogProgram program; |
| 17 | 18 | ||
| 18 | OWLOntology elho_ontology; | 19 | OWLOntology elho_ontology; |
| 19 | KarmaQueryEngine elLowerStore = null; | 20 | KarmaQueryEngine elLowerStore = null; |
| 20 | 21 | ||
| 21 | private Timer t = new Timer(); | 22 | private Timer t = new Timer(); |
| 22 | 23 | ||
| 23 | public ELHOQueryReasoner() { | 24 | public ELHOQueryReasoner() { |
| 24 | elLowerStore = new KarmaQueryEngine("el"); | 25 | elLowerStore = new KarmaQueryEngine("el"); |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | @Override | 28 | @Override |
| 28 | public void evaluate(QueryRecord queryRecord) { | 29 | public void evaluate(QueryRecord queryRecord) { |
| 29 | AnswerTuples elAnswer = null; | 30 | if(isDisposed()) throw new DisposedException(); |
| 30 | t.reset(); | 31 | AnswerTuples elAnswer = null; |
| 31 | try { | 32 | t.reset(); |
| 32 | elAnswer = elLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 33 | try { |
| 33 | queryRecord.updateLowerBoundAnswers(elAnswer); | 34 | elAnswer = elLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| 34 | } finally { | 35 | queryRecord.updateLowerBoundAnswers(elAnswer); |
| 35 | if (elAnswer != null) elAnswer.dispose(); | 36 | } finally { |
| 36 | } | 37 | if(elAnswer != null) elAnswer.dispose(); |
| 37 | queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); | 38 | } |
| 38 | 39 | queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); | |
| 39 | queryRecord.setDifficulty(Step.EL_LOWER_BOUND); | 40 | |
| 40 | queryRecord.markAsProcessed(); | 41 | queryRecord.setDifficulty(Step.EL_LOWER_BOUND); |
| 41 | } | 42 | queryRecord.markAsProcessed(); |
| 42 | 43 | } | |
| 43 | @Override | 44 | |
| 44 | public void evaluateUpper(QueryRecord queryRecord) { | 45 | @Override |
| 45 | evaluate(queryRecord); | 46 | public void evaluateUpper(QueryRecord queryRecord) { |
| 46 | } | 47 | if(isDisposed()) throw new DisposedException(); |
| 47 | 48 | evaluate(queryRecord); | |
| 48 | @Override | 49 | } |
| 49 | public void dispose() { | 50 | |
| 50 | if (elLowerStore != null) elLowerStore.dispose(); | 51 | @Override |
| 51 | super.dispose(); | 52 | public void dispose() { |
| 52 | } | 53 | super.dispose(); |
| 53 | 54 | if(elLowerStore != null) elLowerStore.dispose(); | |
| 54 | @Override | 55 | } |
| 55 | public void loadOntology(OWLOntology ontology) { | 56 | |
| 56 | program = new LowerDatalogProgram(properties.getToClassify()); | 57 | @Override |
| 57 | program.load(ontology, new UnaryBottom()); | 58 | public void loadOntology(OWLOntology ontology) { |
| 58 | program.transform(); | 59 | if(isDisposed()) throw new DisposedException(); |
| 59 | 60 | program = new LowerDatalogProgram(properties.getToClassify()); | |
| 60 | importData(program.getAdditionalDataFile()); | 61 | program.load(ontology, new UnaryBottom()); |
| 61 | 62 | program.transform(); | |
| 62 | elho_ontology = new ELHOProfile().getFragment(ontology); | 63 | |
| 63 | elLowerStore.processOntology(elho_ontology); | 64 | importData(program.getAdditionalDataFile()); |
| 64 | } | 65 | |
| 65 | 66 | elho_ontology = new ELHOProfile().getFragment(ontology); | |
| 66 | @Override | 67 | elLowerStore.processOntology(elho_ontology); |
| 67 | public boolean preprocess() { | 68 | } |
| 68 | elLowerStore.importRDFData("data", importedData.toString()); | 69 | |
| 69 | String rlLowerProgramText = program.toString(); | 70 | @Override |
| 71 | public boolean preprocess() { | ||
| 72 | if(isDisposed()) throw new DisposedException(); | ||
| 73 | elLowerStore.importRDFData("data", importedData.toString()); | ||
| 74 | String rlLowerProgramText = program.toString(); | ||
| 70 | // program.save(); | 75 | // program.save(); |
| 71 | elLowerStore.materialise("lower program", rlLowerProgramText); | 76 | elLowerStore.materialise("lower program", rlLowerProgramText); |
| 72 | elLowerStore.initialiseKarma(); | 77 | elLowerStore.initialiseKarma(); |
| 73 | 78 | ||
| 74 | if (!isConsistent()) { | 79 | if(!isConsistent()) { |
| 75 | Utility.logDebug("The dataset is not consistent with the ontology."); | 80 | Utility.logDebug("The dataset is not consistent with the ontology."); |
| 76 | return false; | 81 | return false; |
| 77 | } | 82 | } |
| 78 | return true; | 83 | return true; |
| 79 | } | 84 | } |
| 80 | 85 | ||
| 81 | @Override | 86 | @Override |
| 82 | public boolean isConsistent() { | 87 | public boolean isConsistent() { |
| 83 | String[] X = new String[] {"X"}; | 88 | if(isDisposed()) throw new DisposedException(); |
| 84 | AnswerTuples ans = null; | 89 | String[] X = new String[]{"X"}; |
| 85 | try { | 90 | AnswerTuples ans = null; |
| 86 | ans = elLowerStore.evaluate(QueryRecord.botQueryText, X); | 91 | try { |
| 87 | if (ans.isValid()) return false; | 92 | ans = elLowerStore.evaluate(QueryRecord.botQueryText, X); |
| 88 | } finally { | 93 | if(ans.isValid()) return false; |
| 89 | if (ans != null) ans.dispose(); | 94 | } finally { |
| 90 | } | 95 | if(ans != null) ans.dispose(); |
| 91 | 96 | } | |
| 92 | return true; | 97 | |
| 93 | } | 98 | return true; |
| 99 | } | ||
| 94 | 100 | ||
| 95 | } | 101 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java index c74ea58..771190e 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java | |||
| @@ -13,181 +13,187 @@ import uk.ac.ox.cs.pagoda.reasoner.light.KarmaQueryEngine; | |||
| 13 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | 13 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; |
| 14 | import uk.ac.ox.cs.pagoda.util.Timer; | 14 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 15 | import uk.ac.ox.cs.pagoda.util.Utility; | 15 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 16 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 16 | 17 | ||
| 17 | class ELHOUQueryReasoner extends QueryReasoner { | 18 | class ELHOUQueryReasoner extends QueryReasoner { |
| 18 | 19 | ||
| 19 | DatalogProgram program; | 20 | DatalogProgram program; |
| 20 | 21 | ||
| 21 | BasicQueryEngine rlLowerStore; | 22 | BasicQueryEngine rlLowerStore; |
| 22 | BasicQueryEngine rlUpperStore; | 23 | BasicQueryEngine rlUpperStore; |
| 23 | 24 | ||
| 24 | OWLOntology elho_ontology; | 25 | OWLOntology elho_ontology; |
| 25 | KarmaQueryEngine elLowerStore = null; | 26 | KarmaQueryEngine elLowerStore = null; |
| 26 | 27 | ||
| 27 | boolean multiStageTag, equalityTag; | 28 | boolean multiStageTag, equalityTag; |
| 28 | String originalMarkProgram; | 29 | String originalMarkProgram; |
| 29 | private Timer t = new Timer(); | 30 | private Timer t = new Timer(); |
| 30 | 31 | ||
| 31 | public ELHOUQueryReasoner(boolean multiStageTag, boolean considerEqualities) { | 32 | public ELHOUQueryReasoner(boolean multiStageTag, boolean considerEqualities) { |
| 32 | this.multiStageTag = multiStageTag; | 33 | this.multiStageTag = multiStageTag; |
| 33 | this.equalityTag = considerEqualities; | 34 | this.equalityTag = considerEqualities; |
| 34 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); | 35 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); |
| 35 | elLowerStore = new KarmaQueryEngine("el-lower-bound"); | 36 | elLowerStore = new KarmaQueryEngine("el-lower-bound"); |
| 36 | 37 | ||
| 37 | if(!multiStageTag) | 38 | if(!multiStageTag) |
| 38 | rlUpperStore = new BasicQueryEngine("rl-upper-bound"); | 39 | rlUpperStore = new BasicQueryEngine("rl-upper-bound"); |
| 39 | else | 40 | else |
| 40 | rlUpperStore = new MultiStageQueryEngine("rl-upper-bound", false); | 41 | rlUpperStore = new MultiStageQueryEngine("rl-upper-bound", false); |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | @Override | 44 | @Override |
| 44 | public void evaluate(QueryRecord queryRecord) { | 45 | public void evaluate(QueryRecord queryRecord) { |
| 45 | AnswerTuples rlAnswer = null; | 46 | if(isDisposed()) throw new DisposedException(); |
| 46 | t.reset(); | 47 | AnswerTuples rlAnswer = null; |
| 47 | try { | 48 | t.reset(); |
| 48 | rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 49 | try { |
| 49 | queryRecord.updateLowerBoundAnswers(rlAnswer); | 50 | rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| 50 | } finally { | 51 | queryRecord.updateLowerBoundAnswers(rlAnswer); |
| 51 | if(rlAnswer != null) rlAnswer.dispose(); | 52 | } finally { |
| 52 | } | 53 | if(rlAnswer != null) rlAnswer.dispose(); |
| 53 | queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration()); | 54 | } |
| 54 | 55 | queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration()); | |
| 55 | String extendedQueryText = queryRecord.getExtendedQueryText().get(0); | 56 | |
| 56 | String[] toQuery = queryRecord.getQueryText().equals(extendedQueryText) ? | 57 | String extendedQueryText = queryRecord.getExtendedQueryText().get(0); |
| 57 | new String[]{queryRecord.getQueryText()} : | 58 | String[] toQuery = queryRecord.getQueryText().equals(extendedQueryText) ? |
| 58 | new String[] {queryRecord.getQueryText(), extendedQueryText}; | 59 | new String[]{queryRecord.getQueryText()} : |
| 59 | 60 | new String[]{queryRecord.getQueryText(), extendedQueryText}; | |
| 60 | for (String queryText: toQuery) { | 61 | |
| 61 | rlAnswer = null; | 62 | for(String queryText : toQuery) { |
| 62 | t.reset(); | 63 | rlAnswer = null; |
| 63 | try { | 64 | t.reset(); |
| 64 | rlAnswer = rlUpperStore.evaluate(queryText, queryRecord.getAnswerVariables()); | 65 | try { |
| 65 | queryRecord.updateUpperBoundAnswers(rlAnswer); | 66 | rlAnswer = rlUpperStore.evaluate(queryText, queryRecord.getAnswerVariables()); |
| 66 | } finally { | 67 | queryRecord.updateUpperBoundAnswers(rlAnswer); |
| 67 | if(rlAnswer != null) rlAnswer.dispose(); | 68 | } finally { |
| 68 | } | 69 | if(rlAnswer != null) rlAnswer.dispose(); |
| 69 | queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration()); | 70 | } |
| 70 | 71 | queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration()); | |
| 71 | if(queryRecord.isProcessed()) { | 72 | |
| 72 | queryRecord.setDifficulty(Step.UPPER_BOUND); | 73 | if(queryRecord.isProcessed()) { |
| 73 | return; | 74 | queryRecord.setDifficulty(Step.UPPER_BOUND); |
| 74 | } | 75 | return; |
| 75 | } | 76 | } |
| 76 | 77 | } | |
| 77 | AnswerTuples elAnswer = null; | 78 | |
| 78 | t.reset(); | 79 | AnswerTuples elAnswer = null; |
| 79 | try { | 80 | t.reset(); |
| 80 | elAnswer = | 81 | try { |
| 81 | elLowerStore.evaluate(extendedQueryText, queryRecord.getAnswerVariables(), queryRecord.getLowerBoundAnswers()); | 82 | elAnswer = |
| 82 | queryRecord.updateLowerBoundAnswers(elAnswer); | 83 | elLowerStore.evaluate(extendedQueryText, queryRecord.getAnswerVariables(), queryRecord.getLowerBoundAnswers()); |
| 83 | } finally { | 84 | queryRecord.updateLowerBoundAnswers(elAnswer); |
| 84 | if (elAnswer != null) elAnswer.dispose(); | 85 | } finally { |
| 85 | } | 86 | if(elAnswer != null) elAnswer.dispose(); |
| 86 | queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); | 87 | } |
| 87 | } | 88 | queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); |
| 88 | 89 | } | |
| 89 | @Override | 90 | |
| 90 | public void evaluateUpper(QueryRecord queryRecord) { | 91 | @Override |
| 91 | AnswerTuples rlAnswer = null; | 92 | public void evaluateUpper(QueryRecord queryRecord) { |
| 92 | try { | 93 | if(isDisposed()) throw new DisposedException(); |
| 93 | rlAnswer = rlUpperStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 94 | AnswerTuples rlAnswer = null; |
| 94 | queryRecord.updateUpperBoundAnswers(rlAnswer, true); | 95 | try { |
| 95 | } finally { | 96 | rlAnswer = rlUpperStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| 96 | if(rlAnswer != null) rlAnswer.dispose(); | 97 | queryRecord.updateUpperBoundAnswers(rlAnswer, true); |
| 97 | } | 98 | } finally { |
| 98 | } | 99 | if(rlAnswer != null) rlAnswer.dispose(); |
| 99 | 100 | } | |
| 100 | @Override | 101 | } |
| 101 | public void dispose() { | 102 | |
| 102 | if (elLowerStore != null) elLowerStore.dispose(); | 103 | @Override |
| 103 | if(rlUpperStore != null) rlUpperStore.dispose(); | 104 | public void dispose() { |
| 104 | super.dispose(); | 105 | super.dispose(); |
| 105 | } | 106 | if(elLowerStore != null) elLowerStore.dispose(); |
| 106 | 107 | if(rlUpperStore != null) rlUpperStore.dispose(); | |
| 107 | @Override | 108 | } |
| 108 | public void loadOntology(OWLOntology o) { | 109 | |
| 109 | if (!equalityTag) { | 110 | @Override |
| 110 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); | 111 | public void loadOntology(OWLOntology o) { |
| 111 | o = eliminator.getOutputOntology(); | 112 | if(isDisposed()) throw new DisposedException(); |
| 112 | eliminator.save(); | 113 | if(!equalityTag) { |
| 113 | } | 114 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); |
| 114 | 115 | o = eliminator.getOutputOntology(); | |
| 115 | OWLOntology ontology = o; | 116 | eliminator.save(); |
| 116 | program = new DatalogProgram(ontology, properties.getToClassify()); | 117 | } |
| 117 | 118 | ||
| 118 | importData(program.getAdditionalDataFile()); | 119 | OWLOntology ontology = o; |
| 119 | 120 | program = new DatalogProgram(ontology, properties.getToClassify()); | |
| 120 | elho_ontology = new ELHOProfile().getFragment(ontology); | 121 | |
| 121 | elLowerStore.processOntology(elho_ontology); | 122 | importData(program.getAdditionalDataFile()); |
| 122 | originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); | 123 | |
| 123 | } | 124 | elho_ontology = new ELHOProfile().getFragment(ontology); |
| 124 | 125 | elLowerStore.processOntology(elho_ontology); | |
| 125 | @Override | 126 | originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); |
| 126 | public boolean preprocess() { | 127 | } |
| 127 | String name = "data", datafile = importedData.toString(); | 128 | |
| 128 | 129 | @Override | |
| 129 | String lowername = "lower program"; | 130 | public boolean preprocess() { |
| 130 | String rlLowerProgramText = program.getLower().toString(); | 131 | if(isDisposed()) throw new DisposedException(); |
| 131 | 132 | String name = "data", datafile = importedData.toString(); | |
| 132 | rlUpperStore.importRDFData(name, datafile); | 133 | |
| 133 | rlUpperStore.materialise("saturate named individuals", originalMarkProgram); | 134 | String lowername = "lower program"; |
| 134 | 135 | String rlLowerProgramText = program.getLower().toString(); | |
| 135 | int flag = rlUpperStore.materialiseRestrictedly(program, null); | 136 | |
| 136 | if (flag != 1) { | 137 | rlUpperStore.importRDFData(name, datafile); |
| 137 | if (flag == -1) return false; | 138 | rlUpperStore.materialise("saturate named individuals", originalMarkProgram); |
| 138 | rlUpperStore.dispose(); | 139 | |
| 139 | 140 | int flag = rlUpperStore.materialiseRestrictedly(program, null); | |
| 140 | if (!multiStageTag) | 141 | if(flag != 1) { |
| 141 | rlUpperStore = new BasicQueryEngine("rl-upper-bound"); | 142 | if(flag == -1) return false; |
| 142 | else | 143 | rlUpperStore.dispose(); |
| 143 | rlUpperStore = new MultiStageQueryEngine("rl-upper-bound", false); | 144 | |
| 144 | rlUpperStore.importRDFData(name, datafile); | 145 | if(!multiStageTag) |
| 145 | rlUpperStore.materialise("saturate named individuals", originalMarkProgram); | 146 | rlUpperStore = new BasicQueryEngine("rl-upper-bound"); |
| 146 | rlUpperStore.materialiseFoldedly(program, null); | 147 | else |
| 147 | } | 148 | rlUpperStore = new MultiStageQueryEngine("rl-upper-bound", false); |
| 148 | Utility.logInfo("upper store ready."); | 149 | rlUpperStore.importRDFData(name, datafile); |
| 149 | 150 | rlUpperStore.materialise("saturate named individuals", originalMarkProgram); | |
| 150 | rlLowerStore.importRDFData(name, datafile); | 151 | rlUpperStore.materialiseFoldedly(program, null); |
| 151 | rlLowerStore.materialise(lowername, rlLowerProgramText); | 152 | } |
| 152 | Utility.logInfo("lower store ready."); | 153 | Utility.logInfo("upper store ready."); |
| 153 | 154 | ||
| 154 | elLowerStore.importRDFData(name, datafile); | 155 | rlLowerStore.importRDFData(name, datafile); |
| 155 | elLowerStore.materialise("saturate named individuals", originalMarkProgram); | 156 | rlLowerStore.materialise(lowername, rlLowerProgramText); |
| 156 | elLowerStore.materialise(lowername, rlLowerProgramText); | 157 | Utility.logInfo("lower store ready."); |
| 157 | 158 | ||
| 158 | elLowerStore.initialiseKarma(); | 159 | elLowerStore.importRDFData(name, datafile); |
| 159 | Utility.logInfo("EL lower store ready."); | 160 | elLowerStore.materialise("saturate named individuals", originalMarkProgram); |
| 160 | 161 | elLowerStore.materialise(lowername, rlLowerProgramText); | |
| 161 | if (!isConsistent()) { | 162 | |
| 162 | Utility.logInfo("The dataset is not consistent with the ontology."); | 163 | elLowerStore.initialiseKarma(); |
| 163 | return false; | 164 | Utility.logInfo("EL lower store ready."); |
| 164 | } | 165 | |
| 165 | Utility.logInfo("The dataset is consistent."); | 166 | if(!isConsistent()) { |
| 166 | return true; | 167 | Utility.logInfo("The dataset is not consistent with the ontology."); |
| 167 | } | 168 | return false; |
| 168 | 169 | } | |
| 169 | @Override | 170 | Utility.logInfo("The dataset is consistent."); |
| 170 | public boolean isConsistent() { | 171 | return true; |
| 171 | Utility.logInfo("Start checking consistency... "); | 172 | } |
| 172 | String[] X = new String[] {"X"}; | 173 | |
| 173 | AnswerTuples ans = null; | 174 | @Override |
| 174 | try { | 175 | public boolean isConsistent() { |
| 175 | ans = rlUpperStore.evaluate(QueryRecord.botQueryText, X); | 176 | if(isDisposed()) throw new DisposedException(); |
| 176 | if (!ans.isValid()) return true; | 177 | Utility.logInfo("Start checking consistency... "); |
| 177 | } finally { | 178 | String[] X = new String[]{"X"}; |
| 178 | if (ans != null) ans.dispose(); | 179 | AnswerTuples ans = null; |
| 179 | } | 180 | try { |
| 180 | 181 | ans = rlUpperStore.evaluate(QueryRecord.botQueryText, X); | |
| 181 | ans = null; | 182 | if(!ans.isValid()) return true; |
| 182 | try { | 183 | } finally { |
| 183 | ans = elLowerStore.evaluate(QueryRecord.botQueryText, X); | 184 | if(ans != null) ans.dispose(); |
| 184 | if (ans.isValid()) return false; | 185 | } |
| 185 | } finally { | 186 | |
| 186 | if (ans != null) ans.dispose(); | 187 | ans = null; |
| 187 | } | 188 | try { |
| 188 | 189 | ans = elLowerStore.evaluate(QueryRecord.botQueryText, X); | |
| 189 | Utility.logDebug("The consistency of the data has not been determined yet."); | 190 | if(ans.isValid()) return false; |
| 190 | return true; | 191 | } finally { |
| 191 | } | 192 | if(ans != null) ans.dispose(); |
| 193 | } | ||
| 194 | |||
| 195 | Utility.logDebug("The consistency of the data has not been determined yet."); | ||
| 196 | return true; | ||
| 197 | } | ||
| 192 | 198 | ||
| 193 | } | 199 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java index d1856c9..78b9a0b 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/HermiTReasoner.java | |||
| @@ -10,6 +10,7 @@ import uk.ac.ox.cs.pagoda.query.*; | |||
| 10 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 10 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 11 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | 11 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; |
| 12 | import uk.ac.ox.cs.pagoda.util.Utility; | 12 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 13 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 13 | 14 | ||
| 14 | import java.io.File; | 15 | import java.io.File; |
| 15 | import java.io.IOException; | 16 | import java.io.IOException; |
| @@ -17,100 +18,105 @@ import java.util.HashSet; | |||
| 17 | import java.util.Set; | 18 | import java.util.Set; |
| 18 | 19 | ||
| 19 | class HermiTReasoner extends QueryReasoner { | 20 | class HermiTReasoner extends QueryReasoner { |
| 20 | 21 | ||
| 21 | Reasoner hermit; | 22 | Reasoner hermit; |
| 22 | 23 | ||
| 23 | BasicQueryEngine upperStore = null; | 24 | BasicQueryEngine upperStore = null; |
| 24 | 25 | ||
| 25 | OWLOntology onto; | 26 | OWLOntology onto; |
| 26 | OWLDataFactory factory; | 27 | OWLDataFactory factory; |
| 27 | 28 | ||
| 28 | String importedOntologyPath = null; | 29 | String importedOntologyPath = null; |
| 29 | 30 | ||
| 30 | QueryRoller roller; | 31 | QueryRoller roller; |
| 31 | boolean toCheckSatisfiability; | 32 | boolean toCheckSatisfiability; |
| 32 | 33 | ||
| 33 | public HermiTReasoner(boolean toCheckSatisfiability) { | 34 | public HermiTReasoner(boolean toCheckSatisfiability) { |
| 34 | this.toCheckSatisfiability = toCheckSatisfiability; | 35 | this.toCheckSatisfiability = toCheckSatisfiability; |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | @Override | 38 | @Override |
| 38 | public void loadOntology(OWLOntology ontology) { | 39 | public void loadOntology(OWLOntology ontology) { |
| 39 | onto = ontology; | 40 | if(isDisposed()) throw new DisposedException(); |
| 40 | } | 41 | onto = ontology; |
| 41 | 42 | } | |
| 42 | @Override | 43 | |
| 43 | public boolean preprocess() { | 44 | @Override |
| 44 | OWLOntology tbox = onto; | 45 | public boolean preprocess() { |
| 45 | try { | 46 | if(isDisposed()) throw new DisposedException(); |
| 46 | onto = OWLHelper.getImportedOntology(tbox, importedData.toString().split(ImportDataFileSeparator)); | 47 | OWLOntology tbox = onto; |
| 47 | importedOntologyPath = OWLHelper.getOntologyPath(onto); | 48 | try { |
| 48 | } catch(OWLOntologyCreationException | OWLOntologyStorageException | IOException e) { | 49 | onto = OWLHelper.getImportedOntology(tbox, importedData.toString().split(ImportDataFileSeparator)); |
| 49 | e.printStackTrace(); | 50 | importedOntologyPath = OWLHelper.getOntologyPath(onto); |
| 50 | } | 51 | } catch(OWLOntologyCreationException | OWLOntologyStorageException | IOException e) { |
| 51 | 52 | e.printStackTrace(); | |
| 52 | DatalogProgram datalogProgram = new DatalogProgram(tbox, false); | 53 | } |
| 53 | importData(datalogProgram.getAdditionalDataFile()); | 54 | |
| 54 | upperStore = new MultiStageQueryEngine("rl-upper", false); | 55 | DatalogProgram datalogProgram = new DatalogProgram(tbox, false); |
| 55 | upperStore.importRDFData("data", importedData.toString()); | 56 | importData(datalogProgram.getAdditionalDataFile()); |
| 56 | GapByStore4ID gap = new GapByStore4ID(upperStore); | 57 | upperStore = new MultiStageQueryEngine("rl-upper", false); |
| 57 | upperStore.materialiseFoldedly(datalogProgram, gap); | 58 | upperStore.importRDFData("data", importedData.toString()); |
| 58 | gap.clear(); | 59 | GapByStore4ID gap = new GapByStore4ID(upperStore); |
| 59 | 60 | upperStore.materialiseFoldedly(datalogProgram, gap); | |
| 60 | factory = onto.getOWLOntologyManager().getOWLDataFactory(); | 61 | gap.clear(); |
| 61 | roller = new QueryRoller(factory); | 62 | |
| 62 | 63 | factory = onto.getOWLOntologyManager().getOWLDataFactory(); | |
| 63 | hermit = new Reasoner(onto); | 64 | roller = new QueryRoller(factory); |
| 64 | return isConsistent(); | 65 | |
| 65 | } | 66 | hermit = new Reasoner(onto); |
| 66 | 67 | return isConsistent(); | |
| 67 | @Override | 68 | } |
| 68 | public boolean isConsistent() { | 69 | |
| 69 | if (toCheckSatisfiability) | 70 | @Override |
| 70 | return hermit.isConsistent(); | 71 | public boolean isConsistent() { |
| 71 | return true; | 72 | if(isDisposed()) throw new DisposedException(); |
| 72 | } | 73 | if(toCheckSatisfiability) |
| 73 | 74 | return hermit.isConsistent(); | |
| 74 | @Override | 75 | return true; |
| 75 | public void evaluate(QueryRecord record) { | 76 | } |
| 76 | String[] disVars = record.getDistinguishedVariables(); | 77 | |
| 77 | Set<OWLNamedIndividual> individuals = onto.getIndividualsInSignature(true); | 78 | @Override |
| 78 | if (disVars.length == 1) { | 79 | public void evaluate(QueryRecord record) { |
| 79 | OWLClassExpression clsExp = roller.rollUp(record.getClause(), record.getAnswerVariables()[0]); | 80 | if(isDisposed()) throw new DisposedException(); |
| 80 | Set<AnswerTuple> answers = new HashSet<AnswerTuple>(); | 81 | String[] disVars = record.getDistinguishedVariables(); |
| 81 | for (OWLNamedIndividual individual: individuals) { | 82 | Set<OWLNamedIndividual> individuals = onto.getIndividualsInSignature(true); |
| 82 | Utility.logDebug("checking ... " + individual); | 83 | if(disVars.length == 1) { |
| 83 | if (hermit.isEntailed(factory.getOWLClassAssertionAxiom(clsExp, individual))) { | 84 | OWLClassExpression clsExp = roller.rollUp(record.getClause(), record.getAnswerVariables()[0]); |
| 84 | answers.add(new AnswerTuple(new Individual[] {Individual.create(individual.toStringID())})); | 85 | Set<AnswerTuple> answers = new HashSet<AnswerTuple>(); |
| 85 | } | 86 | for(OWLNamedIndividual individual : individuals) { |
| 86 | } | 87 | Utility.logDebug("checking ... " + individual); |
| 87 | record.updateLowerBoundAnswers(new AnswerTuplesImp(record.getAnswerVariables(), answers)); | 88 | if(hermit.isEntailed(factory.getOWLClassAssertionAxiom(clsExp, individual))) { |
| 88 | record.markAsProcessed(); | 89 | answers.add(new AnswerTuple(new Individual[]{Individual.create(individual.toStringID())})); |
| 89 | } | 90 | } |
| 90 | else { | 91 | } |
| 91 | // FIXME join here | 92 | record.updateLowerBoundAnswers(new AnswerTuplesImp(record.getAnswerVariables(), answers)); |
| 92 | record.markAsProcessed(); | 93 | record.markAsProcessed(); |
| 93 | } | 94 | } |
| 94 | } | 95 | else { |
| 95 | 96 | // FIXME join here | |
| 96 | @Override | 97 | record.markAsProcessed(); |
| 97 | public void evaluateUpper(QueryRecord record) { | 98 | } |
| 98 | AnswerTuples rlAnswer = null; | 99 | } |
| 99 | try { | 100 | |
| 100 | rlAnswer = upperStore.evaluate(record.getQueryText(), record.getAnswerVariables()); | 101 | @Override |
| 101 | record.updateUpperBoundAnswers(rlAnswer, true); | 102 | public void evaluateUpper(QueryRecord record) { |
| 102 | } finally { | 103 | if(isDisposed()) throw new DisposedException(); |
| 103 | if (rlAnswer != null) rlAnswer.dispose(); | 104 | AnswerTuples rlAnswer = null; |
| 104 | } | 105 | try { |
| 105 | } | 106 | rlAnswer = upperStore.evaluate(record.getQueryText(), record.getAnswerVariables()); |
| 106 | 107 | record.updateUpperBoundAnswers(rlAnswer, true); | |
| 107 | @Override | 108 | } finally { |
| 108 | public void dispose() { | 109 | if(rlAnswer != null) rlAnswer.dispose(); |
| 109 | if (importedOntologyPath != null) { | 110 | } |
| 110 | File tmp = new File(importedOntologyPath); | 111 | } |
| 111 | if (tmp.exists()) tmp.delete(); | 112 | |
| 112 | } | 113 | @Override |
| 113 | super.dispose(); | 114 | public void dispose() { |
| 114 | } | 115 | super.dispose(); |
| 116 | if(importedOntologyPath != null) { | ||
| 117 | File tmp = new File(importedOntologyPath); | ||
| 118 | if(tmp.exists()) tmp.delete(); | ||
| 119 | } | ||
| 120 | } | ||
| 115 | 121 | ||
| 116 | } | 122 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index 618fb70..8445713 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | |||
| @@ -21,362 +21,364 @@ import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoderDisjVar1; | |||
| 21 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoderWithGap; | 21 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoderWithGap; |
| 22 | import uk.ac.ox.cs.pagoda.util.Timer; | 22 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 23 | import uk.ac.ox.cs.pagoda.util.Utility; | 23 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 24 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 24 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; | 25 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; |
| 25 | 26 | ||
| 26 | import java.util.Collection; | 27 | import java.util.Collection; |
| 27 | 28 | ||
| 28 | class MyQueryReasoner extends QueryReasoner { | 29 | class MyQueryReasoner extends QueryReasoner { |
| 29 | 30 | ||
| 30 | OWLOntology ontology; | 31 | OWLOntology ontology; |
| 31 | DatalogProgram program; | 32 | DatalogProgram program; |
| 32 | 33 | ||
| 33 | // String additonalDataFile; | 34 | // String additonalDataFile; |
| 34 | BasicQueryEngine rlLowerStore = null; | 35 | BasicQueryEngine rlLowerStore = null; |
| 35 | BasicQueryEngine lazyUpperStore = null; | 36 | BasicQueryEngine lazyUpperStore = null; |
| 36 | // BasicQueryEngine limitedSkolemUpperStore; | 37 | MultiStageQueryEngine limitedSkolemUpperStore; |
| 37 | OWLOntology elho_ontology; | 38 | OWLOntology elho_ontology; |
| 38 | // boolean[] namedIndividuals_lazyUpper; | 39 | // boolean[] namedIndividuals_lazyUpper; |
| 39 | KarmaQueryEngine elLowerStore = null; | 40 | KarmaQueryEngine elLowerStore = null; |
| 40 | BasicQueryEngine trackingStore = null; | 41 | BasicQueryEngine trackingStore = null; |
| 41 | // boolean[] namedIndividuals_tracking; | 42 | // boolean[] namedIndividuals_tracking; |
| 42 | TrackingRuleEncoder encoder; | 43 | TrackingRuleEncoder encoder; |
| 43 | private boolean equalityTag; | 44 | private boolean equalityTag; |
| 44 | private boolean multiStageTag; | 45 | private boolean multiStageTag; |
| 45 | private Timer t = new Timer(); | 46 | private Timer t = new Timer(); |
| 46 | private Collection<String> predicatesWithGap = null; | 47 | private Collection<String> predicatesWithGap = null; |
| 47 | private SatisfiabilityStatus satisfiable; | 48 | private SatisfiabilityStatus satisfiable; |
| 48 | private ConsistencyManager consistency = new ConsistencyManager(this); | 49 | private ConsistencyManager consistency = new ConsistencyManager(this); |
| 49 | private boolean useUpperStores = false; | 50 | private boolean useUpperStores = false; |
| 50 | public MyQueryReasoner() { | 51 | |
| 51 | setup(true, true); | 52 | public MyQueryReasoner() { |
| 52 | } | 53 | setup(true, true); |
| 53 | public MyQueryReasoner(boolean multiStageTag, boolean considerEqualities) { | 54 | } |
| 54 | setup(multiStageTag, considerEqualities); | 55 | |
| 55 | } | 56 | public MyQueryReasoner(boolean multiStageTag, boolean considerEqualities) { |
| 56 | 57 | setup(multiStageTag, considerEqualities); | |
| 57 | private BasicQueryEngine getUpperStore(String name, boolean checkValidity) { | 58 | } |
| 58 | if (multiStageTag) | 59 | |
| 59 | return new MultiStageQueryEngine(name, checkValidity); | 60 | public void setup(boolean multiStageTag, boolean considerEqualities) { |
| 60 | // return new TwoStageQueryEngine(name, checkValidity); | 61 | if(isDisposed()) throw new DisposedException(); |
| 61 | else | 62 | satisfiable = SatisfiabilityStatus.UNCHECKED; |
| 62 | return new BasicQueryEngine(name); | 63 | this.multiStageTag = multiStageTag; |
| 63 | } | 64 | this.equalityTag = considerEqualities; |
| 64 | 65 | ||
| 65 | public void setup(boolean multiStageTag, boolean considerEqualities) { | 66 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); |
| 66 | satisfiable = SatisfiabilityStatus.UNCHECKED; | 67 | elLowerStore = new KarmaQueryEngine("elho-lower-bound"); |
| 67 | this.multiStageTag = multiStageTag; | 68 | |
| 68 | this.equalityTag = considerEqualities; | 69 | trackingStore = getUpperStore("tracking", false); |
| 69 | 70 | } | |
| 70 | rlLowerStore = new BasicQueryEngine("rl-lower-bound"); | 71 | |
| 71 | elLowerStore = new KarmaQueryEngine("elho-lower-bound"); | 72 | @Override |
| 72 | 73 | public void loadOntology(OWLOntology o) { | |
| 73 | trackingStore = getUpperStore("tracking", false); | 74 | if(isDisposed()) throw new DisposedException(); |
| 74 | } | 75 | if(!equalityTag) { |
| 75 | 76 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); | |
| 76 | protected void internal_importDataFile(String name, String datafile) { | 77 | o = eliminator.getOutputOntology(); |
| 77 | // addDataFile(datafile); | 78 | eliminator.save(); |
| 78 | rlLowerStore.importRDFData(name, datafile); | 79 | } |
| 79 | if (lazyUpperStore != null) | 80 | |
| 80 | lazyUpperStore.importRDFData(name, datafile); | 81 | ontology = o; |
| 81 | elLowerStore.importRDFData(name, datafile); | 82 | program = new DatalogProgram(ontology, properties.getToClassify()); |
| 82 | trackingStore.importRDFData(name, datafile); | ||
| 83 | } | ||
| 84 | |||
| 85 | @Override | ||
| 86 | public void loadOntology(OWLOntology o) { | ||
| 87 | if(!equalityTag) { | ||
| 88 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); | ||
| 89 | o = eliminator.getOutputOntology(); | ||
| 90 | eliminator.save(); | ||
| 91 | } | ||
| 92 | |||
| 93 | ontology = o; | ||
| 94 | program = new DatalogProgram(ontology, properties.getToClassify()); | ||
| 95 | // program.getLower().save(); | 83 | // program.getLower().save(); |
| 96 | // program.getUpper().save(); | 84 | // program.getUpper().save(); |
| 97 | // program.getGeneral().save(); | 85 | // program.getGeneral().save(); |
| 98 | 86 | ||
| 99 | useUpperStores = multiStageTag && !program.getGeneral().isHorn(); | 87 | useUpperStores = multiStageTag && !program.getGeneral().isHorn(); |
| 100 | if(useUpperStores) { | 88 | if(useUpperStores) { |
| 101 | lazyUpperStore = getUpperStore("lazy-upper-bound", true); | 89 | lazyUpperStore = getUpperStore("lazy-upper-bound", true); |
| 102 | // limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); | 90 | limitedSkolemUpperStore = new MultiStageQueryEngine("limited-skolem-upper-bound", true); |
| 103 | } | 91 | } |
| 104 | 92 | ||
| 105 | importData(program.getAdditionalDataFile()); | 93 | importData(program.getAdditionalDataFile()); |
| 106 | 94 | ||
| 107 | elho_ontology = new ELHOProfile().getFragment(ontology); | 95 | elho_ontology = new ELHOProfile().getFragment(ontology); |
| 108 | elLowerStore.processOntology(elho_ontology); | 96 | elLowerStore.processOntology(elho_ontology); |
| 109 | } | 97 | } |
| 110 | 98 | ||
| 111 | public Collection<String> getPredicatesWithGap() { | 99 | public Collection<String> getPredicatesWithGap() { |
| 112 | return predicatesWithGap; | 100 | if(isDisposed()) throw new DisposedException(); |
| 113 | } | 101 | return predicatesWithGap; |
| 102 | } | ||
| 114 | 103 | ||
| 115 | @Override | 104 | @Override |
| 116 | public boolean preprocess() { | 105 | public boolean preprocess() { |
| 117 | t.reset(); | 106 | if(isDisposed()) throw new DisposedException(); |
| 118 | Utility.logInfo("Preprocessing... checking satisfiability... "); | 107 | t.reset(); |
| 108 | Utility.logInfo("Preprocessing... checking satisfiability... "); | ||
| 119 | 109 | ||
| 120 | String name = "data", datafile = importedData.toString(); | 110 | String name = "data", datafile = importedData.toString(); |
| 121 | rlLowerStore.importRDFData(name, datafile); | 111 | rlLowerStore.importRDFData(name, datafile); |
| 122 | rlLowerStore.materialise("lower program", program.getLower().toString()); | 112 | rlLowerStore.materialise("lower program", program.getLower().toString()); |
| 123 | // program.getLower().save(); | 113 | // program.getLower().save(); |
| 124 | if(!consistency.checkRLLowerBound()) return false; | 114 | if(!consistency.checkRLLowerBound()) return false; |
| 125 | Utility.logInfo("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber()); | 115 | Utility.logInfo("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber()); |
| 126 | 116 | ||
| 127 | String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); | 117 | String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); |
| 128 | 118 | ||
| 129 | elLowerStore.importRDFData(name, datafile); | 119 | elLowerStore.importRDFData(name, datafile); |
| 130 | elLowerStore.materialise("saturate named individuals", originalMarkProgram); | 120 | elLowerStore.materialise("saturate named individuals", originalMarkProgram); |
| 131 | elLowerStore.materialise("lower program", program.getLower().toString()); | 121 | elLowerStore.materialise("lower program", program.getLower().toString()); |
| 132 | elLowerStore.initialiseKarma(); | 122 | elLowerStore.initialiseKarma(); |
| 133 | if(!consistency.checkELLowerBound()) return false; | 123 | if(!consistency.checkELLowerBound()) return false; |
| 134 | 124 | ||
| 135 | if(lazyUpperStore != null) { | 125 | if(lazyUpperStore != null) { |
| 136 | lazyUpperStore.importRDFData(name, datafile); | 126 | lazyUpperStore.importRDFData(name, datafile); |
| 137 | lazyUpperStore.materialise("saturate named individuals", originalMarkProgram); | 127 | lazyUpperStore.materialise("saturate named individuals", originalMarkProgram); |
| 138 | int tag = lazyUpperStore.materialiseRestrictedly(program, null); | 128 | int tag = lazyUpperStore.materialiseRestrictedly(program, null); |
| 139 | if(tag != 1) { | 129 | if(tag != 1) { |
| 140 | lazyUpperStore.dispose(); | 130 | lazyUpperStore.dispose(); |
| 141 | lazyUpperStore = null; | 131 | lazyUpperStore = null; |
| 142 | } | 132 | } |
| 143 | if(tag == -1) return false; | 133 | if(tag == -1) return false; |
| 144 | } | 134 | } |
| 145 | if(consistency.checkUpper(lazyUpperStore)) { | 135 | if(consistency.checkUpper(lazyUpperStore)) { |
| 146 | satisfiable = SatisfiabilityStatus.SATISFIABLE; | 136 | satisfiable = SatisfiabilityStatus.SATISFIABLE; |
| 147 | Utility.logInfo("time for satisfiability checking: " + t.duration()); | 137 | Utility.logInfo("time for satisfiability checking: " + t.duration()); |
| 148 | } | 138 | } |
| 149 | 139 | ||
| 150 | // if(limitedSkolemUpperStore != null) { | 140 | if(limitedSkolemUpperStore != null) { |
| 151 | // limitedSkolemUpperStore.importRDFData(name, datafile); | 141 | limitedSkolemUpperStore.importRDFData(name, datafile); |
| 152 | // limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); | 142 | limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); |
| 153 | // int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); | 143 | int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); |
| 154 | // if(tag != 1) { | 144 | if(tag != 1) { |
| 155 | // limitedSkolemUpperStore.dispose(); | 145 | limitedSkolemUpperStore.dispose(); |
| 156 | // limitedSkolemUpperStore = null; | 146 | limitedSkolemUpperStore = null; |
| 157 | // } | 147 | } |
| 158 | // if(tag == -1) return false; | 148 | if(tag == -1) return false; |
| 159 | // } | 149 | } |
| 160 | // if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) { | 150 | if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) { |
| 161 | // satisfiable = SatisfiabilityStatus.SATISFIABLE; | 151 | satisfiable = SatisfiabilityStatus.SATISFIABLE; |
| 162 | // Utility.logInfo("time for satisfiability checking: " + t.duration()); | 152 | Utility.logInfo("time for satisfiability checking: " + t.duration()); |
| 163 | // } | 153 | } |
| 164 | 154 | ||
| 165 | trackingStore.importRDFData(name, datafile); | 155 | trackingStore.importRDFData(name, datafile); |
| 166 | trackingStore.materialise("saturate named individuals", originalMarkProgram); | 156 | trackingStore.materialise("saturate named individuals", originalMarkProgram); |
| 167 | 157 | ||
| 168 | // materialiseFullUpper(); | 158 | // materialiseFullUpper(); |
| 169 | // GapByStore4ID gap = new GapByStore4ID(trackingStore); | 159 | // GapByStore4ID gap = new GapByStore4ID(trackingStore); |
| 170 | GapByStore4ID gap = new GapByStore4ID2(trackingStore, rlLowerStore); | 160 | GapByStore4ID gap = new GapByStore4ID2(trackingStore, rlLowerStore); |
| 171 | trackingStore.materialiseFoldedly(program, gap); | 161 | trackingStore.materialiseFoldedly(program, gap); |
| 172 | predicatesWithGap = gap.getPredicatesWithGap(); | 162 | predicatesWithGap = gap.getPredicatesWithGap(); |
| 173 | gap.clear(); | 163 | gap.clear(); |
| 174 | 164 | ||
| 175 | if(program.getGeneral().isHorn()) | 165 | if(program.getGeneral().isHorn()) |
| 176 | encoder = new TrackingRuleEncoderWithGap(program.getUpper(), trackingStore); | 166 | encoder = new TrackingRuleEncoderWithGap(program.getUpper(), trackingStore); |
| 177 | else | 167 | else |
| 178 | encoder = new TrackingRuleEncoderDisjVar1(program.getUpper(), trackingStore); | 168 | encoder = new TrackingRuleEncoderDisjVar1(program.getUpper(), trackingStore); |
| 179 | // encoder = new TrackingRuleEncoderDisj1(program.getUpper(), trackingStore); | 169 | // encoder = new TrackingRuleEncoderDisj1(program.getUpper(), trackingStore); |
| 180 | // encoder = new TrackingRuleEncoderDisjVar2(program.getUpper(), trackingStore); | 170 | // encoder = new TrackingRuleEncoderDisjVar2(program.getUpper(), trackingStore); |
| 181 | // encoder = new TrackingRuleEncoderDisj2(program.getUpper(), trackingStore); | 171 | // encoder = new TrackingRuleEncoderDisj2(program.getUpper(), trackingStore); |
| 182 | 172 | ||
| 183 | program.deleteABoxTurtleFile(); | 173 | if(!isConsistent()) |
| 184 | 174 | return false; | |
| 185 | if(!isConsistent()) | 175 | |
| 186 | return false; | 176 | consistency.extractBottomFragment(); |
| 187 | 177 | consistency.dispose(); | |
| 188 | consistency.extractBottomFragment(); | 178 | |
| 189 | consistency.dispose(); | 179 | program.dispose(); |
| 190 | 180 | ||
| 191 | return true; | 181 | return true; |
| 192 | } | 182 | } |
| 193 | 183 | ||
| 194 | @Override | 184 | @Override |
| 195 | public boolean isConsistent() { | 185 | public boolean isConsistent() { |
| 196 | if(satisfiable == SatisfiabilityStatus.UNCHECKED) { | 186 | if(isDisposed()) throw new DisposedException(); |
| 197 | satisfiable = consistency.check() ? SatisfiabilityStatus.SATISFIABLE : SatisfiabilityStatus.UNSATISFIABLE; | 187 | if(satisfiable == SatisfiabilityStatus.UNCHECKED) { |
| 198 | Utility.logInfo("time for satisfiability checking: " + t.duration()); | 188 | satisfiable = consistency.check() ? SatisfiabilityStatus.SATISFIABLE : SatisfiabilityStatus.UNSATISFIABLE; |
| 199 | } | 189 | Utility.logInfo("time for satisfiability checking: " + t.duration()); |
| 200 | return satisfiable == SatisfiabilityStatus.SATISFIABLE; | 190 | } |
| 201 | } | 191 | return satisfiable == SatisfiabilityStatus.SATISFIABLE; |
| 202 | 192 | } | |
| 203 | /** | 193 | |
| 204 | * It deals with blanks nodes differently from variables | 194 | @Override |
| 205 | * according to SPARQL semantics for OWL2 Entailment Regime. | 195 | public void evaluate(QueryRecord queryRecord) { |
| 206 | * <p> | 196 | if(isDisposed()) throw new DisposedException(); |
| 207 | * In particular variables are matched only against named individuals, | 197 | if(queryBounds(queryRecord)) |
| 208 | * and blank nodes against named and anonymous individuals. | 198 | return; |
| 209 | */ | 199 | |
| 210 | private boolean queryUpperStore(BasicQueryEngine upperStore, QueryRecord queryRecord, | 200 | OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord); |
| 211 | Tuple<String> extendedQuery, Step step) { | 201 | |
| 212 | 202 | int aBoxCount = relevantOntologySubset.getABoxAxioms(true).size(); | |
| 213 | if(queryRecord.hasNonAnsDistinguishedVariables()) | 203 | Utility.logInfo("Relevant ontology subset: ABox_axioms=" + aBoxCount + " TBox_axioms=" + (relevantOntologySubset |
| 214 | queryUpperBound(upperStore, queryRecord, extendedQuery.get(0), queryRecord.getAnswerVariables()); | 204 | .getAxiomCount() - aBoxCount)); |
| 215 | else | 205 | // queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); |
| 216 | queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 206 | |
| 217 | 207 | if(querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord)) | |
| 218 | queryRecord.addProcessingTime(step, t.duration()); | 208 | return; |
| 219 | if(queryRecord.isProcessed()) { | 209 | |
| 220 | queryRecord.setDifficulty(step); | 210 | Timer t = new Timer(); |
| 221 | return true; | 211 | Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); |
| 222 | } | 212 | summarisedChecker.check(queryRecord.getGapAnswers()); |
| 223 | return false; | 213 | summarisedChecker.dispose(); |
| 224 | } | 214 | Utility.logDebug("Total time for full reasoner: " + t.duration()); |
| 225 | 215 | queryRecord.markAsProcessed(); | |
| 226 | /** | 216 | Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); |
| 227 | * Returns the part of the ontology relevant for Hermit, while computing the bound answers. | 217 | } |
| 228 | * */ | 218 | |
| 229 | private boolean queryBounds(QueryRecord queryRecord) { | 219 | @Override |
| 230 | AnswerTuples rlAnswer = null, elAnswer = null; | 220 | public void evaluateUpper(QueryRecord queryRecord) { |
| 231 | 221 | if(isDisposed()) throw new DisposedException(); | |
| 232 | t.reset(); | 222 | // TODO add new upper store |
| 233 | try { | 223 | AnswerTuples rlAnswer = null; |
| 234 | rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 224 | boolean useFull = queryRecord.isBottom() || lazyUpperStore == null; |
| 235 | Utility.logDebug(t.duration()); | 225 | try { |
| 236 | queryRecord.updateLowerBoundAnswers(rlAnswer); | 226 | rlAnswer = |
| 237 | } finally { | 227 | (useFull ? trackingStore : lazyUpperStore).evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| 238 | if (rlAnswer != null) rlAnswer.dispose(); | 228 | queryRecord.updateUpperBoundAnswers(rlAnswer, true); |
| 239 | } | 229 | } finally { |
| 240 | queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration()); | 230 | if(rlAnswer != null) rlAnswer.dispose(); |
| 241 | 231 | } | |
| 242 | t.reset(); | 232 | } |
| 243 | 233 | ||
| 244 | Tuple<String> extendedQueryTexts = queryRecord.getExtendedQueryText(); | 234 | @Override |
| 245 | 235 | public void dispose() { | |
| 246 | Utility.logDebug("Tracking store"); | 236 | super.dispose(); |
| 247 | if(queryUpperStore(trackingStore, queryRecord, extendedQueryTexts, Step.SIMPLE_UPPER_BOUND)) | 237 | |
| 248 | return true; | 238 | if(encoder != null) encoder.dispose(); |
| 249 | 239 | if(rlLowerStore != null) rlLowerStore.dispose(); | |
| 250 | if(!queryRecord.isBottom()) { | 240 | if(lazyUpperStore != null) lazyUpperStore.dispose(); |
| 251 | Utility.logDebug("Lazy store"); | 241 | if(elLowerStore != null) elLowerStore.dispose(); |
| 252 | if(lazyUpperStore != null && queryUpperStore(lazyUpperStore, queryRecord, extendedQueryTexts, Step.LAZY_UPPER_BOUND)) | 242 | if(trackingStore != null) trackingStore.dispose(); |
| 253 | return true; | 243 | if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose(); |
| 244 | |||
| 245 | } | ||
| 246 | |||
| 247 | private BasicQueryEngine getUpperStore(String name, boolean checkValidity) { | ||
| 248 | if(multiStageTag) | ||
| 249 | return new MultiStageQueryEngine(name, checkValidity); | ||
| 250 | // return new TwoStageQueryEngine(name, checkValidity); | ||
| 251 | else | ||
| 252 | return new BasicQueryEngine(name); | ||
| 253 | } | ||
| 254 | |||
| 255 | protected void internal_importDataFile(String name, String datafile) { | ||
| 256 | // addDataFile(datafile); | ||
| 257 | rlLowerStore.importRDFData(name, datafile); | ||
| 258 | if(lazyUpperStore != null) | ||
| 259 | lazyUpperStore.importRDFData(name, datafile); | ||
| 260 | elLowerStore.importRDFData(name, datafile); | ||
| 261 | trackingStore.importRDFData(name, datafile); | ||
| 262 | } | ||
| 263 | |||
| 264 | /** | ||
| 265 | * It deals with blanks nodes differently from variables | ||
| 266 | * according to SPARQL semantics for OWL2 Entailment Regime. | ||
| 267 | * <p> | ||
| 268 | * In particular variables are matched only against named individuals, | ||
| 269 | * and blank nodes against named and anonymous individuals. | ||
| 270 | */ | ||
| 271 | private boolean queryUpperStore(BasicQueryEngine upperStore, QueryRecord queryRecord, | ||
| 272 | Tuple<String> extendedQuery, Step step) { | ||
| 273 | |||
| 274 | if(queryRecord.hasNonAnsDistinguishedVariables()) | ||
| 275 | queryUpperBound(upperStore, queryRecord, extendedQuery.get(0), queryRecord.getAnswerVariables()); | ||
| 276 | else | ||
| 277 | queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | ||
| 278 | |||
| 279 | queryRecord.addProcessingTime(step, t.duration()); | ||
| 280 | if(queryRecord.isProcessed()) { | ||
| 281 | queryRecord.setDifficulty(step); | ||
| 282 | return true; | ||
| 283 | } | ||
| 284 | return false; | ||
| 285 | } | ||
| 286 | |||
| 287 | /** | ||
| 288 | * Returns the part of the ontology relevant for Hermit, while computing the bound answers. | ||
| 289 | */ | ||
| 290 | private boolean queryBounds(QueryRecord queryRecord) { | ||
| 291 | AnswerTuples rlAnswer = null, elAnswer = null; | ||
| 292 | |||
| 293 | t.reset(); | ||
| 294 | try { | ||
| 295 | rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | ||
| 296 | Utility.logDebug(t.duration()); | ||
| 297 | queryRecord.updateLowerBoundAnswers(rlAnswer); | ||
| 298 | } finally { | ||
| 299 | if(rlAnswer != null) rlAnswer.dispose(); | ||
| 300 | } | ||
| 301 | queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration()); | ||
| 302 | |||
| 303 | t.reset(); | ||
| 304 | |||
| 305 | Tuple<String> extendedQueryTexts = queryRecord.getExtendedQueryText(); | ||
| 306 | |||
| 307 | Utility.logDebug("Tracking store"); | ||
| 308 | if(queryUpperStore(trackingStore, queryRecord, extendedQueryTexts, Step.SIMPLE_UPPER_BOUND)) | ||
| 309 | return true; | ||
| 310 | |||
| 311 | if(!queryRecord.isBottom()) { | ||
| 312 | Utility.logDebug("Lazy store"); | ||
| 313 | if(lazyUpperStore != null && queryUpperStore(lazyUpperStore, queryRecord, extendedQueryTexts, Step.LAZY_UPPER_BOUND)) | ||
| 314 | return true; | ||
| 254 | // Utility.logDebug("Skolem store"); | 315 | // Utility.logDebug("Skolem store"); |
| 255 | // if(limitedSkolemUpperStore != null && queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts, Step.L_SKOLEM_UPPER_BOUND)) | 316 | // if(limitedSkolemUpperStore != null && queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts, Step.L_SKOLEM_UPPER_BOUND)) |
| 256 | // return null; | 317 | // return null; |
| 257 | } | 318 | } |
| 258 | 319 | ||
| 259 | t.reset(); | 320 | t.reset(); |
| 260 | try { | 321 | try { |
| 261 | elAnswer = elLowerStore.evaluate(extendedQueryTexts.get(0), | 322 | elAnswer = elLowerStore.evaluate(extendedQueryTexts.get(0), |
| 262 | queryRecord.getAnswerVariables(), | 323 | queryRecord.getAnswerVariables(), |
| 263 | queryRecord.getLowerBoundAnswers()); | 324 | queryRecord.getLowerBoundAnswers()); |
| 264 | Utility.logDebug(t.duration()); | 325 | Utility.logDebug(t.duration()); |
| 265 | queryRecord.updateLowerBoundAnswers(elAnswer); | 326 | queryRecord.updateLowerBoundAnswers(elAnswer); |
| 266 | } finally { | 327 | } finally { |
| 267 | if (elAnswer != null) elAnswer.dispose(); | 328 | if(elAnswer != null) elAnswer.dispose(); |
| 268 | } | 329 | } |
| 269 | queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); | 330 | queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); |
| 270 | 331 | ||
| 271 | if(queryRecord.isProcessed()) { | 332 | if(queryRecord.isProcessed()) { |
| 272 | queryRecord.setDifficulty(Step.EL_LOWER_BOUND); | 333 | queryRecord.setDifficulty(Step.EL_LOWER_BOUND); |
| 273 | return true; | 334 | return true; |
| 274 | } | 335 | } |
| 275 | 336 | ||
| 276 | return false; | 337 | return false; |
| 277 | } | 338 | } |
| 278 | 339 | ||
| 279 | private OWLOntology extractRelevantOntologySubset(QueryRecord queryRecord) { | 340 | private OWLOntology extractRelevantOntologySubset(QueryRecord queryRecord) { |
| 280 | t.reset(); | 341 | t.reset(); |
| 281 | 342 | ||
| 282 | QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord); | 343 | QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord); |
| 283 | OWLOntology relevantOntologySubset = tracker.extract(trackingStore, consistency.getQueryRecords(), true); | 344 | OWLOntology relevantOntologySubset = tracker.extract(trackingStore, consistency.getQueryRecords(), true); |
| 284 | 345 | ||
| 285 | queryRecord.addProcessingTime(Step.FRAGMENT, t.duration()); | 346 | queryRecord.addProcessingTime(Step.FRAGMENT, t.duration()); |
| 286 | 347 | ||
| 287 | return relevantOntologySubset; | 348 | return relevantOntologySubset; |
| 288 | } | 349 | } |
| 289 | 350 | ||
| 290 | private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) { | 351 | private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) { |
| 291 | AnswerTuples rlAnswer = null; | 352 | AnswerTuples rlAnswer = null; |
| 292 | try { | 353 | try { |
| 293 | Utility.logDebug(queryText); | 354 | Utility.logDebug(queryText); |
| 294 | rlAnswer = upperStore.evaluate(queryText, answerVariables); | 355 | rlAnswer = upperStore.evaluate(queryText, answerVariables); |
| 295 | Utility.logDebug(t.duration()); | 356 | Utility.logDebug(t.duration()); |
| 296 | queryRecord.updateUpperBoundAnswers(rlAnswer); | 357 | queryRecord.updateUpperBoundAnswers(rlAnswer); |
| 297 | } finally { | 358 | } finally { |
| 298 | if(rlAnswer != null) rlAnswer.dispose(); | 359 | if(rlAnswer != null) rlAnswer.dispose(); |
| 299 | } | 360 | } |
| 300 | } | 361 | } |
| 301 | 362 | ||
| 302 | @Override | 363 | private boolean querySkolemisedRelevantSubset(OWLOntology relevantSubset, QueryRecord queryRecord) { |
| 303 | public void evaluate(QueryRecord queryRecord) { | 364 | DatalogProgram relevantProgram = new DatalogProgram(relevantSubset, false); // toClassify is false |
| 304 | if(queryBounds(queryRecord)) | 365 | |
| 305 | return; | 366 | MultiStageQueryEngine relevantStore = |
| 306 | 367 | new MultiStageQueryEngine("Relevant-store", true); // checkValidity is true | |
| 307 | OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord); | 368 | // relevantStore.importRDFData("data", relevantProgram.getAdditionalDataFile()); // tried, doesn't work |
| 308 | 369 | relevantStore.importDataFromABoxOf(relevantSubset); | |
| 309 | int aBoxCount = relevantOntologySubset.getABoxAxioms(true).size(); | 370 | |
| 310 | Utility.logInfo("Relevant ontology subset: ABox_axioms=" + aBoxCount + " TBox_axioms=" + (relevantOntologySubset | 371 | int materialisationResult = relevantStore.materialiseSkolemly(relevantProgram, null); |
| 311 | .getAxiomCount() - aBoxCount)); | 372 | // int materialisationResult = relevantStore.materialiseRestrictedly(relevantProgram, null); // DOESN'T WORK!!! |
| 312 | // queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); | 373 | if(materialisationResult != 1) |
| 313 | 374 | throw new RuntimeException("Skolemised materialisation error"); // TODO check consistency | |
| 314 | if(querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord)) | ||
| 315 | return; | ||
| 316 | |||
| 317 | Timer t = new Timer(); | ||
| 318 | Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); | ||
| 319 | summarisedChecker.check(queryRecord.getGapAnswers()); | ||
| 320 | summarisedChecker.dispose(); | ||
| 321 | Utility.logDebug("Total time for full reasoner: " + t.duration()); | ||
| 322 | queryRecord.markAsProcessed(); | ||
| 323 | Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); | ||
| 324 | } | ||
| 325 | |||
| 326 | private boolean querySkolemisedRelevantSubset(OWLOntology relevantSubset, QueryRecord queryRecord) { | ||
| 327 | MultiStageQueryEngine relevantStore = | ||
| 328 | new MultiStageQueryEngine("Relevant-store", true); // checkValidity is true | ||
| 329 | DatalogProgram relevantProgram = new DatalogProgram(relevantSubset, false); // toClassify is false | ||
| 330 | |||
| 331 | // relevantStore.importRDFData("data", importedData.toString()); // 2 answers more | ||
| 332 | relevantStore.importDataFromABoxOf(relevantSubset); | ||
| 333 | |||
| 334 | int materialisationResult = relevantStore.materialiseSkolemly(relevantProgram, null); | ||
| 335 | if(materialisationResult != 1) | ||
| 336 | throw new RuntimeException("Skolemised materialisation error"); // TODO check consistency | ||
| 337 | // relevantStore.materialiseRestrictedly(relevantProgram, null); // it has been tried | 375 | // relevantStore.materialiseRestrictedly(relevantProgram, null); // it has been tried |
| 338 | 376 | ||
| 339 | return queryUpperStore(relevantStore, queryRecord, queryRecord.getExtendedQueryText(), Step.L_SKOLEM_UPPER_BOUND); | 377 | return queryUpperStore(relevantStore, queryRecord, queryRecord.getExtendedQueryText(), Step.L_SKOLEM_UPPER_BOUND); |
| 340 | 378 | ||
| 341 | // the following has been tried | 379 | // return queryUpperStore(limitedSkolemUpperStore, queryRecord, queryRecord.getExtendedQueryText(), Step.L_SKOLEM_UPPER_BOUND); |
| 342 | // Tuple<String> extendedQueryText = queryRecord.getExtendedQueryText(); | 380 | } |
| 343 | // if(queryRecord.hasNonAnsDistinguishedVariables()) { | 381 | |
| 344 | // queryUpperBound(relevantStore, queryRecord, extendedQueryText.get(0), queryRecord.getAnswerVariables()); | 382 | enum SatisfiabilityStatus {SATISFIABLE, UNSATISFIABLE, UNCHECKED} |
| 345 | // queryUpperBound(relevantStore, queryRecord, extendedQueryText.get(1), queryRecord.getDistinguishedVariables()); | ||
| 346 | // } | ||
| 347 | // else | ||
| 348 | // queryUpperBound(relevantStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | ||
| 349 | // | ||
| 350 | // return queryRecord.isProcessed(); | ||
| 351 | |||
| 352 | } | ||
| 353 | |||
| 354 | @Override | ||
| 355 | public void evaluateUpper(QueryRecord queryRecord) { | ||
| 356 | // TODO add new upper store | ||
| 357 | AnswerTuples rlAnswer = null; | ||
| 358 | boolean useFull = queryRecord.isBottom() || lazyUpperStore == null; | ||
| 359 | try { | ||
| 360 | rlAnswer = | ||
| 361 | (useFull ? trackingStore : lazyUpperStore).evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | ||
| 362 | queryRecord.updateUpperBoundAnswers(rlAnswer, true); | ||
| 363 | } finally { | ||
| 364 | if(rlAnswer != null) rlAnswer.dispose(); | ||
| 365 | } | ||
| 366 | } | ||
| 367 | |||
| 368 | @Override | ||
| 369 | public void dispose() { | ||
| 370 | if (encoder != null) encoder.dispose(); | ||
| 371 | if (rlLowerStore != null) rlLowerStore.dispose(); | ||
| 372 | if (lazyUpperStore != null) lazyUpperStore.dispose(); | ||
| 373 | if (elLowerStore != null) elLowerStore.dispose(); | ||
| 374 | if (trackingStore != null) trackingStore.dispose(); | ||
| 375 | |||
| 376 | // if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose(); | ||
| 377 | super.dispose(); | ||
| 378 | } | ||
| 379 | |||
| 380 | enum SatisfiabilityStatus {SATISFIABLE, UNSATISFIABLE, UNCHECKED} | ||
| 381 | 383 | ||
| 382 | } | 384 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryEngine.java index b9abf07..3200216 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryEngine.java | |||
| @@ -1,17 +1,15 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | 1 | package uk.ac.ox.cs.pagoda.reasoner; |
| 2 | 2 | ||
| 3 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 4 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; | ||
| 5 | |||
| 3 | import java.util.Collection; | 6 | import java.util.Collection; |
| 4 | 7 | ||
| 5 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 8 | public abstract class QueryEngine extends Disposable { |
| 9 | |||
| 10 | public abstract void evaluate(Collection<String> queryTexts, String answerFile); | ||
| 6 | 11 | ||
| 7 | public interface QueryEngine { | 12 | public abstract AnswerTuples evaluate(String queryText); |
| 8 | 13 | ||
| 9 | public void evaluate(Collection<String> queryTexts, String answerFile); | 14 | public abstract AnswerTuples evaluate(String queryText, String[] answerVariables); |
| 10 | |||
| 11 | public AnswerTuples evaluate(String queryText); | ||
| 12 | |||
| 13 | public AnswerTuples evaluate(String queryText, String[] answerVariables); | ||
| 14 | |||
| 15 | public void dispose(); | ||
| 16 | |||
| 17 | } | 15 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java index 118c1b2..962a78f 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | |||
| @@ -9,6 +9,8 @@ import uk.ac.ox.cs.pagoda.query.QueryRecord; | |||
| 9 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; | 9 | import uk.ac.ox.cs.pagoda.util.PagodaProperties; |
| 10 | import uk.ac.ox.cs.pagoda.util.Timer; | 10 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 11 | import uk.ac.ox.cs.pagoda.util.Utility; | 11 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 12 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; | ||
| 13 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 12 | 14 | ||
| 13 | import java.io.BufferedWriter; | 15 | import java.io.BufferedWriter; |
| 14 | import java.io.File; | 16 | import java.io.File; |
| @@ -18,230 +20,242 @@ import java.nio.file.Paths; | |||
| 18 | import java.util.Collection; | 20 | import java.util.Collection; |
| 19 | 21 | ||
| 20 | // TODO clean APIs | 22 | // TODO clean APIs |
| 21 | public abstract class QueryReasoner { | 23 | public abstract class QueryReasoner extends Disposable { |
| 22 | 24 | ||
| 23 | public static final String ImportDataFileSeparator = ";"; | 25 | public static final String ImportDataFileSeparator = ";"; |
| 24 | private static final boolean DEFAULT_MULTI_STAGES = true; | 26 | private static final boolean DEFAULT_MULTI_STAGES = true; |
| 25 | private static final boolean DEFAULT_EQUALITIES = true; | 27 | private static final boolean DEFAULT_EQUALITIES = true; |
| 26 | public boolean fullReasoner = this instanceof MyQueryReasoner; | 28 | public boolean fullReasoner = this instanceof MyQueryReasoner; |
| 27 | protected StringBuilder importedData = new StringBuilder(); | 29 | protected StringBuilder importedData = new StringBuilder(); |
| 28 | // protected boolean forSemFacet = false; | 30 | // protected boolean forSemFacet = false; |
| 29 | PagodaProperties properties; | 31 | PagodaProperties properties; |
| 30 | BufferedWriter answerWriter = null; | 32 | BufferedWriter answerWriter = null; |
| 31 | private QueryManager m_queryManager = new QueryManager(); | 33 | private QueryManager m_queryManager = new QueryManager(); |
| 32 | 34 | ||
| 33 | public static QueryReasoner getInstance(PagodaProperties p) { | 35 | public static QueryReasoner getInstance(PagodaProperties p) { |
| 34 | OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath()); | 36 | OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath()); |
| 35 | QueryReasoner pagoda = getInstance(ontology, p); | 37 | QueryReasoner pagoda = getInstance(ontology, p); |
| 36 | pagoda.properties = p; | 38 | pagoda.properties = p; |
| 37 | pagoda.loadOntology(ontology); | 39 | pagoda.loadOntology(ontology); |
| 38 | pagoda.importData(p.getDataPath()); | 40 | pagoda.importData(p.getDataPath()); |
| 39 | if (pagoda.preprocess()) { | 41 | if(pagoda.preprocess()) { |
| 40 | Utility.logInfo("The ontology is consistent!"); | 42 | Utility.logInfo("The ontology is consistent!"); |
| 41 | return pagoda; | 43 | return pagoda; |
| 42 | } | 44 | } |
| 43 | else { | 45 | else { |
| 44 | System.out.println("The ontology is inconsistent!"); | 46 | System.out.println("The ontology is inconsistent!"); |
| 45 | pagoda.dispose(); | 47 | pagoda.dispose(); |
| 46 | return null; | 48 | return null; |
| 47 | } | 49 | } |
| 48 | } | 50 | } |
| 49 | 51 | ||
| 50 | public static QueryReasoner getInstance(OWLOntology o) { | 52 | public static QueryReasoner getInstance(OWLOntology o) { |
| 51 | QueryReasoner pagoda = getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); | 53 | QueryReasoner pagoda = getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); |
| 52 | pagoda.properties = new PagodaProperties(); | 54 | pagoda.properties = new PagodaProperties(); |
| 53 | return pagoda; | 55 | return pagoda; |
| 54 | } | 56 | } |
| 55 | 57 | ||
| 56 | private static QueryReasoner getInstance(OWLOntology o, PagodaProperties p) { | 58 | private static QueryReasoner getInstance(OWLOntology o, PagodaProperties p) { |
| 57 | return getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); | 59 | return getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES); |
| 58 | } | 60 | } |
| 59 | 61 | ||
| 60 | public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) { | 62 | public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) { |
| 61 | // Utility.initialise(); | 63 | // Utility.initialise(); |
| 62 | QueryReasoner reasoner; | 64 | QueryReasoner reasoner; |
| 63 | if (OWLHelper.isInOWL2RL(o)) reasoner = new RLQueryReasoner(); | 65 | if(OWLHelper.isInOWL2RL(o)) reasoner = new RLQueryReasoner(); |
| 64 | else if (OWLHelper.isInELHO(o)) reasoner = new ELHOQueryReasoner(); | 66 | else if(OWLHelper.isInELHO(o)) reasoner = new ELHOQueryReasoner(); |
| 65 | else | 67 | else |
| 66 | switch (type) { | 68 | switch(type) { |
| 67 | case RLU: | 69 | case RLU: |
| 68 | reasoner = new RLUQueryReasoner(performMultiStages, considerEqualities); | 70 | reasoner = new RLUQueryReasoner(performMultiStages, considerEqualities); |
| 69 | break; | 71 | break; |
| 70 | case ELHOU: | 72 | case ELHOU: |
| 71 | reasoner = new ELHOUQueryReasoner(performMultiStages, considerEqualities); | 73 | reasoner = new ELHOUQueryReasoner(performMultiStages, considerEqualities); |
| 72 | break; | 74 | break; |
| 73 | default: | 75 | default: |
| 74 | reasoner = new MyQueryReasoner(performMultiStages, considerEqualities); | 76 | reasoner = new MyQueryReasoner(performMultiStages, considerEqualities); |
| 75 | } | 77 | } |
| 76 | return reasoner; | 78 | return reasoner; |
| 77 | } | 79 | } |
| 78 | 80 | ||
| 79 | public static QueryReasoner getHermiTReasoner(boolean toCheckSatisfiability) { | 81 | public static QueryReasoner getHermiTReasoner(boolean toCheckSatisfiability) { |
| 80 | return new HermiTReasoner(toCheckSatisfiability); | 82 | return new HermiTReasoner(toCheckSatisfiability); |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | public void setToClassify(boolean flag) { | 85 | public void setToClassify(boolean flag) { |
| 84 | properties.setToClassify(flag); | 86 | if(isDisposed()) throw new DisposedException(); |
| 85 | } | 87 | properties.setToClassify(flag); |
| 86 | 88 | } | |
| 87 | public void setToCallHermiT(boolean flag) { | 89 | |
| 88 | properties.setToCallHermiT(flag); | 90 | public void setToCallHermiT(boolean flag) { |
| 89 | } | 91 | if(isDisposed()) throw new DisposedException(); |
| 90 | 92 | properties.setToCallHermiT(flag); | |
| 91 | public void importData(String datafile) { | 93 | } |
| 92 | if (datafile != null && !datafile.equalsIgnoreCase("null")) | 94 | |
| 93 | importData(datafile.split(ImportDataFileSeparator)); | 95 | public void importData(String datafile) { |
| 94 | } | 96 | if(isDisposed()) throw new DisposedException(); |
| 95 | 97 | if(datafile != null && !datafile.equalsIgnoreCase("null")) | |
| 96 | public void importData(String[] datafiles) { | 98 | importData(datafile.split(ImportDataFileSeparator)); |
| 97 | if (datafiles != null) { | 99 | } |
| 98 | for (String datafile: datafiles) { | 100 | |
| 99 | File file = new File(datafile); | 101 | public void importData(String[] datafiles) { |
| 100 | if (file.exists()) { | 102 | if(isDisposed()) throw new DisposedException(); |
| 101 | if (file.isFile()) importDataFile(file); | 103 | if(datafiles != null) { |
| 102 | else importDataDirectory(file); | 104 | for(String datafile : datafiles) { |
| 103 | } | 105 | File file = new File(datafile); |
| 104 | else { | 106 | if(file.exists()) { |
| 105 | Utility.logError("warning: file " + datafile + " doesn't exists."); | 107 | if(file.isFile()) importDataFile(file); |
| 106 | } | 108 | else importDataDirectory(file); |
| 107 | } | 109 | } |
| 108 | } | 110 | else { |
| 109 | } | 111 | Utility.logError("warning: file " + datafile + " doesn't exists."); |
| 110 | 112 | } | |
| 111 | private void importDataDirectory(File file) { | 113 | } |
| 112 | for (File child: file.listFiles()) | 114 | } |
| 113 | if (child.isFile()) importDataFile(child); | 115 | } |
| 114 | else importDataDirectory(child); | 116 | |
| 115 | } | 117 | public abstract void loadOntology(OWLOntology ontology); |
| 116 | 118 | ||
| 117 | private void importDataFile(File file) { | 119 | public abstract boolean preprocess(); |
| 118 | String datafile; | 120 | |
| 119 | try { | 121 | public abstract boolean isConsistent(); |
| 120 | datafile = file.getCanonicalPath(); | 122 | |
| 121 | } catch (IOException e) { | 123 | public abstract void evaluate(QueryRecord record); |
| 122 | e.printStackTrace(); | 124 | |
| 123 | return; | 125 | public abstract void evaluateUpper(QueryRecord record); |
| 124 | } | 126 | |
| 125 | importDataFile(datafile); | 127 | public AnswerTuples evaluate(String queryText, boolean forFacetGeneration) { |
| 126 | } | 128 | if(isDisposed()) throw new DisposedException(); |
| 127 | 129 | if(forFacetGeneration) { | |
| 128 | protected final void importDataFile(String datafile) { | 130 | QueryRecord record = m_queryManager.create(queryText); |
| 129 | if (importedData.length() == 0) | 131 | Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText); |
| 130 | importedData.append(datafile); | 132 | if(!record.isProcessed()) |
| 131 | else | 133 | evaluateUpper(record); |
| 132 | importedData.append(ImportDataFileSeparator).append(datafile); | ||
| 133 | |||
| 134 | } | ||
| 135 | |||
| 136 | public abstract void loadOntology(OWLOntology ontology); | ||
| 137 | |||
| 138 | public abstract boolean preprocess(); | ||
| 139 | |||
| 140 | public abstract boolean isConsistent(); | ||
| 141 | |||
| 142 | public abstract void evaluate(QueryRecord record); | ||
| 143 | |||
| 144 | public abstract void evaluateUpper(QueryRecord record); | ||
| 145 | |||
| 146 | public AnswerTuples evaluate(String queryText, boolean forFacetGeneration) { | ||
| 147 | if (forFacetGeneration) { | ||
| 148 | QueryRecord record = m_queryManager.create(queryText); | ||
| 149 | Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText); | ||
| 150 | if(!record.isProcessed()) | ||
| 151 | evaluateUpper(record); | ||
| 152 | // AnswerTuples tuples = record.getUpperBoundAnswers(); | 134 | // AnswerTuples tuples = record.getUpperBoundAnswers(); |
| 153 | // for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) { | 135 | // for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) { |
| 154 | // tuple = tuples.getTuple(); | 136 | // tuple = tuples.getTuple(); |
| 155 | // if (tuple.toString().contains("NC")) | 137 | // if (tuple.toString().contains("NC")) |
| 156 | // System.out.println(tuple.toString()); | 138 | // System.out.println(tuple.toString()); |
| 157 | // } | 139 | // } |
| 158 | return record.getUpperBoundAnswers(); | 140 | return record.getUpperBoundAnswers(); |
| 159 | } else | 141 | } |
| 160 | return evaluate(queryText); | 142 | else |
| 161 | } | 143 | return evaluate(queryText); |
| 162 | 144 | } | |
| 163 | // public void evaluate(Collection<QueryRecord> queryRecords) { | 145 | |
| 164 | // evaluate(queryRecords); | 146 | public AnswerTuples evaluate(String queryText) { |
| 165 | // } | 147 | if(isDisposed()) throw new DisposedException(); |
| 148 | QueryRecord record = m_queryManager.create(queryText); | ||
| 149 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); | ||
| 150 | if(!record.isProcessed()) | ||
| 151 | evaluate(record); | ||
| 152 | AnswerTuples answer = record.getAnswers(); | ||
| 153 | record.dispose(); | ||
| 154 | return answer; | ||
| 155 | |||
| 156 | } | ||
| 157 | |||
| 158 | public void evaluate_shell(String queryText) { | ||
| 159 | if(isDisposed()) throw new DisposedException(); | ||
| 160 | QueryRecord record = m_queryManager.create(queryText); | ||
| 161 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); | ||
| 162 | if(!record.isProcessed()) | ||
| 163 | evaluate(record); | ||
| 164 | Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple()); | ||
| 165 | record.dispose(); | ||
| 166 | |||
| 167 | } | ||
| 166 | 168 | ||
| 167 | public AnswerTuples evaluate(String queryText) { | 169 | public void evaluate(Collection<QueryRecord> queryRecords) { |
| 168 | QueryRecord record = m_queryManager.create(queryText); | 170 | if(isDisposed()) throw new DisposedException(); |
| 169 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); | 171 | if(!isConsistent()) { |
| 170 | if(!record.isProcessed()) | 172 | Utility.logDebug("The ontology and dataset is inconsistent."); |
| 171 | evaluate(record); | 173 | return; |
| 172 | AnswerTuples answer = record.getAnswers(); | 174 | } |
| 173 | record.dispose(); | 175 | |
| 174 | return answer; | 176 | if(properties.getAnswerPath() != null && answerWriter == null) { |
| 175 | 177 | try { | |
| 176 | } | 178 | answerWriter = Files.newBufferedWriter(Paths.get(properties.getAnswerPath())); |
| 177 | 179 | } catch(IOException e) { | |
| 178 | public void evaluate_shell(String queryText) { | 180 | Utility.logError("The answer path is not valid!"); |
| 179 | QueryRecord record = m_queryManager.create(queryText); | 181 | e.printStackTrace(); |
| 180 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); | 182 | } |
| 181 | if(!record.isProcessed()) | 183 | } |
| 182 | evaluate(record); | 184 | |
| 183 | Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple()); | 185 | Timer t = new Timer(); |
| 184 | record.dispose(); | 186 | Gson gson = QueryRecord.GsonCreator.getInstance(); |
| 185 | 187 | for(QueryRecord record : queryRecords) { | |
| 186 | } | ||
| 187 | |||
| 188 | public void evaluate(Collection<QueryRecord> queryRecords) { | ||
| 189 | if (!isConsistent()) { | ||
| 190 | Utility.logDebug("The ontology and dataset is inconsistent."); | ||
| 191 | return; | ||
| 192 | } | ||
| 193 | |||
| 194 | if(properties.getAnswerPath() != null && answerWriter == null) { | ||
| 195 | try { | ||
| 196 | answerWriter = Files.newBufferedWriter(Paths.get(properties.getAnswerPath())); | ||
| 197 | } catch (IOException e) { | ||
| 198 | Utility.logError("The answer path is not valid!"); | ||
| 199 | e.printStackTrace(); | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | Timer t = new Timer(); | ||
| 204 | Gson gson = QueryRecord.GsonCreator.getInstance(); | ||
| 205 | for (QueryRecord record: queryRecords) { | ||
| 206 | // if (Integer.parseInt(record.getQueryID()) != 218) continue; | 188 | // if (Integer.parseInt(record.getQueryID()) != 218) continue; |
| 207 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", | 189 | Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", |
| 208 | record.getQueryText()); | 190 | record.getQueryText()); |
| 209 | if(!record.isProcessed()) { | 191 | if(!record.isProcessed()) { |
| 210 | t.reset(); | 192 | t.reset(); |
| 211 | if(!record.isProcessed()) | 193 | if(!record.isProcessed()) |
| 212 | evaluate(record); | 194 | evaluate(record); |
| 213 | Utility.logInfo("Total time to answer this query: " + t.duration()); | 195 | Utility.logInfo("Total time to answer this query: " + t.duration()); |
| 214 | if(!fullReasoner && !record.isProcessed()) { | 196 | if(!fullReasoner && !record.isProcessed()) { |
| 215 | Utility.logInfo("The query has not been fully answered in " + t.duration() + " seconds."); | 197 | Utility.logInfo("The query has not been fully answered in " + t.duration() + " seconds."); |
| 216 | continue; | 198 | continue; |
| 217 | } | 199 | } |
| 218 | } | 200 | } |
| 219 | record.outputAnswerStatistics(); | 201 | record.outputAnswerStatistics(); |
| 220 | record.outputTimes(); | 202 | record.outputTimes(); |
| 221 | } | 203 | } |
| 222 | /* TODO it can handle one call only | 204 | /* TODO it can handle one call only |
| 223 | if you call twice, you will end up with a json file with multiple roots */ | 205 | if you call twice, you will end up with a json file with multiple roots */ |
| 224 | if(answerWriter != null) gson.toJson(queryRecords, answerWriter); | 206 | if(answerWriter != null) gson.toJson(queryRecords, answerWriter); |
| 225 | // queryRecords.stream().forEach(record -> Utility.logDebug(gson.toJson(record))); | 207 | // queryRecords.stream().forEach(record -> Utility.logDebug(gson.toJson(record))); |
| 226 | queryRecords.stream().forEach(record -> record.dispose()); | 208 | queryRecords.stream().forEach(record -> record.dispose()); |
| 227 | } | 209 | } |
| 228 | 210 | ||
| 229 | public void dispose() { | 211 | // public void evaluate(Collection<QueryRecord> queryRecords) { |
| 230 | if (answerWriter != null) { | 212 | // evaluate(queryRecords); |
| 231 | try { | 213 | // } |
| 232 | answerWriter.close(); | 214 | |
| 233 | } catch (IOException e) { | 215 | @Override |
| 234 | e.printStackTrace(); | 216 | public void dispose() { |
| 235 | } | 217 | super.dispose(); |
| 236 | } | 218 | if(answerWriter != null) { |
| 219 | try { | ||
| 220 | answerWriter.close(); | ||
| 221 | } catch(IOException e) { | ||
| 222 | e.printStackTrace(); | ||
| 223 | } | ||
| 224 | } | ||
| 237 | // Utility.cleanup(); | 225 | // Utility.cleanup(); |
| 238 | } | 226 | } |
| 239 | 227 | ||
| 240 | public QueryManager getQueryManager() { | 228 | public QueryManager getQueryManager() { |
| 241 | return m_queryManager; | 229 | if(isDisposed()) throw new DisposedException(); |
| 242 | } | 230 | return m_queryManager; |
| 231 | } | ||
| 232 | |||
| 233 | private void importDataDirectory(File file) { | ||
| 234 | for(File child : file.listFiles()) | ||
| 235 | if(child.isFile()) importDataFile(child); | ||
| 236 | else importDataDirectory(child); | ||
| 237 | } | ||
| 238 | |||
| 239 | private void importDataFile(File file) { | ||
| 240 | String datafile; | ||
| 241 | try { | ||
| 242 | datafile = file.getCanonicalPath(); | ||
| 243 | } catch(IOException e) { | ||
| 244 | e.printStackTrace(); | ||
| 245 | return; | ||
| 246 | } | ||
| 247 | importDataFile(datafile); | ||
| 248 | } | ||
| 249 | |||
| 250 | protected final void importDataFile(String datafile) { | ||
| 251 | if(importedData.length() == 0) | ||
| 252 | importedData.append(datafile); | ||
| 253 | else | ||
| 254 | importedData.append(ImportDataFileSeparator).append(datafile); | ||
| 255 | |||
| 256 | } | ||
| 243 | 257 | ||
| 244 | 258 | ||
| 245 | public enum Type {Full, RLU, ELHOU} | 259 | public enum Type {Full, RLU, ELHOU} |
| 246 | 260 | ||
| 247 | } | 261 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java index bea5bbf..16e2627 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLQueryReasoner.java | |||
| @@ -9,6 +9,7 @@ import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | |||
| 9 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxQueryEngine; | 9 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxQueryEngine; |
| 10 | import uk.ac.ox.cs.pagoda.rules.LowerDatalogProgram; | 10 | import uk.ac.ox.cs.pagoda.rules.LowerDatalogProgram; |
| 11 | import uk.ac.ox.cs.pagoda.util.Timer; | 11 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 12 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 12 | 13 | ||
| 13 | class RLQueryReasoner extends QueryReasoner { | 14 | class RLQueryReasoner extends QueryReasoner { |
| 14 | 15 | ||
| @@ -16,13 +17,14 @@ class RLQueryReasoner extends QueryReasoner { | |||
| 16 | 17 | ||
| 17 | LowerDatalogProgram program; | 18 | LowerDatalogProgram program; |
| 18 | Timer t = new Timer(); | 19 | Timer t = new Timer(); |
| 19 | 20 | ||
| 20 | public RLQueryReasoner() { | 21 | public RLQueryReasoner() { |
| 21 | rlLowerStore = new BasicQueryEngine("rl"); | 22 | rlLowerStore = new BasicQueryEngine("rl"); |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | @Override | 25 | @Override |
| 25 | public void evaluate(QueryRecord queryRecord) { | 26 | public void evaluate(QueryRecord queryRecord) { |
| 27 | if(isDisposed()) throw new DisposedException(); | ||
| 26 | AnswerTuples rlAnswer = null; | 28 | AnswerTuples rlAnswer = null; |
| 27 | t.reset(); | 29 | t.reset(); |
| 28 | try { | 30 | try { |
| @@ -38,12 +40,13 @@ class RLQueryReasoner extends QueryReasoner { | |||
| 38 | 40 | ||
| 39 | @Override | 41 | @Override |
| 40 | public void dispose() { | 42 | public void dispose() { |
| 41 | if (rlLowerStore != null) rlLowerStore.dispose(); | ||
| 42 | super.dispose(); | 43 | super.dispose(); |
| 44 | if(rlLowerStore != null) rlLowerStore.dispose(); | ||
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | @Override | 47 | @Override |
| 46 | public void loadOntology(OWLOntology ontology) { | 48 | public void loadOntology(OWLOntology ontology) { |
| 49 | if(isDisposed()) throw new DisposedException(); | ||
| 47 | program = new LowerDatalogProgram(); | 50 | program = new LowerDatalogProgram(); |
| 48 | program.load(ontology, new UnaryBottom()); | 51 | program.load(ontology, new UnaryBottom()); |
| 49 | program.transform(); | 52 | program.transform(); |
| @@ -53,6 +56,7 @@ class RLQueryReasoner extends QueryReasoner { | |||
| 53 | 56 | ||
| 54 | @Override | 57 | @Override |
| 55 | public boolean preprocess() { | 58 | public boolean preprocess() { |
| 59 | if(isDisposed()) throw new DisposedException(); | ||
| 56 | rlLowerStore.importRDFData("data", importedData.toString()); | 60 | rlLowerStore.importRDFData("data", importedData.toString()); |
| 57 | rlLowerStore.materialise("lower program", program.toString()); | 61 | rlLowerStore.materialise("lower program", program.toString()); |
| 58 | 62 | ||
| @@ -61,6 +65,7 @@ class RLQueryReasoner extends QueryReasoner { | |||
| 61 | 65 | ||
| 62 | @Override | 66 | @Override |
| 63 | public boolean isConsistent() { | 67 | public boolean isConsistent() { |
| 68 | if(isDisposed()) throw new DisposedException(); | ||
| 64 | AnswerTuples ans = null; | 69 | AnswerTuples ans = null; |
| 65 | try { | 70 | try { |
| 66 | ans = rlLowerStore.evaluate(QueryRecord.botQueryText, new String[] {"X"}); | 71 | ans = rlLowerStore.evaluate(QueryRecord.botQueryText, new String[] {"X"}); |
| @@ -74,6 +79,7 @@ class RLQueryReasoner extends QueryReasoner { | |||
| 74 | 79 | ||
| 75 | @Override | 80 | @Override |
| 76 | public void evaluateUpper(QueryRecord record) { | 81 | public void evaluateUpper(QueryRecord record) { |
| 82 | if(isDisposed()) throw new DisposedException(); | ||
| 77 | evaluate(record); | 83 | evaluate(record); |
| 78 | } | 84 | } |
| 79 | 85 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java index 547140a..d0712e1 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java | |||
| @@ -10,6 +10,7 @@ import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | |||
| 10 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | 10 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; |
| 11 | import uk.ac.ox.cs.pagoda.util.Timer; | 11 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 12 | import uk.ac.ox.cs.pagoda.util.Utility; | 12 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 13 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 13 | 14 | ||
| 14 | class RLUQueryReasoner extends QueryReasoner { | 15 | class RLUQueryReasoner extends QueryReasoner { |
| 15 | 16 | ||
| @@ -19,7 +20,7 @@ class RLUQueryReasoner extends QueryReasoner { | |||
| 19 | 20 | ||
| 20 | boolean multiStageTag, equalityTag; | 21 | boolean multiStageTag, equalityTag; |
| 21 | Timer t = new Timer(); | 22 | Timer t = new Timer(); |
| 22 | 23 | ||
| 23 | public RLUQueryReasoner(boolean multiStageTag, boolean considerEqualities) { | 24 | public RLUQueryReasoner(boolean multiStageTag, boolean considerEqualities) { |
| 24 | this.multiStageTag = multiStageTag; | 25 | this.multiStageTag = multiStageTag; |
| 25 | this.equalityTag = considerEqualities; | 26 | this.equalityTag = considerEqualities; |
| @@ -32,6 +33,7 @@ class RLUQueryReasoner extends QueryReasoner { | |||
| 32 | 33 | ||
| 33 | @Override | 34 | @Override |
| 34 | public void evaluate(QueryRecord queryRecord) { | 35 | public void evaluate(QueryRecord queryRecord) { |
| 36 | if(isDisposed()) throw new DisposedException(); | ||
| 35 | AnswerTuples ans = null; | 37 | AnswerTuples ans = null; |
| 36 | t.reset(); | 38 | t.reset(); |
| 37 | try { | 39 | try { |
| @@ -60,6 +62,7 @@ class RLUQueryReasoner extends QueryReasoner { | |||
| 60 | 62 | ||
| 61 | @Override | 63 | @Override |
| 62 | public void evaluateUpper(QueryRecord queryRecord) { | 64 | public void evaluateUpper(QueryRecord queryRecord) { |
| 65 | if(isDisposed()) throw new DisposedException(); | ||
| 63 | AnswerTuples ans = null; | 66 | AnswerTuples ans = null; |
| 64 | try { | 67 | try { |
| 65 | ans = rlUpperStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 68 | ans = rlUpperStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| @@ -72,13 +75,14 @@ class RLUQueryReasoner extends QueryReasoner { | |||
| 72 | 75 | ||
| 73 | @Override | 76 | @Override |
| 74 | public void dispose() { | 77 | public void dispose() { |
| 78 | super.dispose(); | ||
| 75 | if (rlLowerStore != null) rlLowerStore.dispose(); | 79 | if (rlLowerStore != null) rlLowerStore.dispose(); |
| 76 | if (rlUpperStore != null) rlUpperStore.dispose(); | 80 | if (rlUpperStore != null) rlUpperStore.dispose(); |
| 77 | super.dispose(); | ||
| 78 | } | 81 | } |
| 79 | 82 | ||
| 80 | @Override | 83 | @Override |
| 81 | public void loadOntology(OWLOntology o) { | 84 | public void loadOntology(OWLOntology o) { |
| 85 | if(isDisposed()) throw new DisposedException(); | ||
| 82 | if (!equalityTag) { | 86 | if (!equalityTag) { |
| 83 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); | 87 | EqualitiesEliminator eliminator = new EqualitiesEliminator(o); |
| 84 | o = eliminator.getOutputOntology(); | 88 | o = eliminator.getOutputOntology(); |
| @@ -92,6 +96,7 @@ class RLUQueryReasoner extends QueryReasoner { | |||
| 92 | 96 | ||
| 93 | @Override | 97 | @Override |
| 94 | public boolean preprocess() { | 98 | public boolean preprocess() { |
| 99 | if(isDisposed()) throw new DisposedException(); | ||
| 95 | String datafile = importedData.toString(); | 100 | String datafile = importedData.toString(); |
| 96 | rlLowerStore.importRDFData("data", datafile); | 101 | rlLowerStore.importRDFData("data", datafile); |
| 97 | rlLowerStore.materialise("lower program", program.getLower().toString()); | 102 | rlLowerStore.materialise("lower program", program.getLower().toString()); |
| @@ -105,6 +110,7 @@ class RLUQueryReasoner extends QueryReasoner { | |||
| 105 | 110 | ||
| 106 | @Override | 111 | @Override |
| 107 | public boolean isConsistent() { | 112 | public boolean isConsistent() { |
| 113 | if(isDisposed()) throw new DisposedException(); | ||
| 108 | String[] X = new String[] { "X" }; | 114 | String[] X = new String[] { "X" }; |
| 109 | AnswerTuples ans = null; | 115 | AnswerTuples ans = null; |
| 110 | try { | 116 | try { |
| @@ -125,6 +131,5 @@ class RLUQueryReasoner extends QueryReasoner { | |||
| 125 | Utility.logDebug("The consistency of the data has not been determined yet."); | 131 | Utility.logDebug("The consistency of the data has not been determined yet."); |
| 126 | return true; | 132 | return true; |
| 127 | } | 133 | } |
| 128 | 134 | ||
| 129 | |||
| 130 | } | 135 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java index 79be8aa..fe43e09 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java | |||
| @@ -1,375 +1,377 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | 1 | package uk.ac.ox.cs.pagoda.reasoner.light; |
| 2 | 2 | ||
| 3 | import java.util.Arrays; | ||
| 4 | import java.util.Collection; | ||
| 5 | import java.util.HashSet; | ||
| 6 | import java.util.Iterator; | ||
| 7 | import java.util.Set; | ||
| 8 | |||
| 9 | import org.semanticweb.HermiT.model.DLClause; | 3 | import org.semanticweb.HermiT.model.DLClause; |
| 10 | 4 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | |
| 5 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 6 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 7 | import uk.ac.ox.cs.JRDFox.store.Parameters; | ||
| 8 | import uk.ac.ox.cs.JRDFox.store.TripleStatus; | ||
| 9 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | ||
| 11 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | 10 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; |
| 12 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 11 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 13 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; | 12 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; |
| 14 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | 13 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; |
| 15 | import uk.ac.ox.cs.pagoda.rules.Program; | 14 | import uk.ac.ox.cs.pagoda.rules.Program; |
| 16 | import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; | 15 | import uk.ac.ox.cs.pagoda.util.*; |
| 17 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 18 | import uk.ac.ox.cs.pagoda.util.Timer; | 16 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 19 | import uk.ac.ox.cs.pagoda.util.UFS; | 17 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; |
| 20 | import uk.ac.ox.cs.pagoda.util.Utility; | 18 | |
| 21 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 19 | import java.util.*; |
| 22 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 23 | import uk.ac.ox.cs.JRDFox.store.Parameters; | ||
| 24 | import uk.ac.ox.cs.JRDFox.store.TripleStatus; | ||
| 25 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | ||
| 26 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 27 | 20 | ||
| 28 | public class BasicQueryEngine extends RDFoxQueryEngine { | 21 | public class BasicQueryEngine extends RDFoxQueryEngine { |
| 29 | 22 | ||
| 30 | protected DataStore store; | 23 | protected DataStore store; |
| 31 | protected Parameters parameters = new Parameters(); | 24 | protected Parameters parameters = new Parameters(); |
| 32 | 25 | Set<DLClause> materialisedRules = new HashSet<DLClause>(); | |
| 33 | public BasicQueryEngine(String name) { | 26 | private UFS<String> equalityGroups = null; |
| 34 | super(name); | 27 | |
| 35 | store = RDFoxQueryEngine.createDataStore(); | 28 | public BasicQueryEngine(String name) { |
| 36 | parameters.m_allAnswersInRoot = true; | 29 | super(name); |
| 37 | parameters.m_useBushy = true; | 30 | store = RDFoxQueryEngine.createDataStore(); |
| 38 | } | 31 | parameters.m_allAnswersInRoot = true; |
| 39 | 32 | parameters.m_useBushy = true; | |
| 40 | public void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap) { | 33 | } |
| 41 | if (gap != null) { | 34 | |
| 42 | materialise("lower program", dProgram.getLower().toString()); | 35 | public void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap) { |
| 43 | String program = dProgram.getUpper().toString(); | 36 | if(isDisposed()) throw new DisposedException(); |
| 44 | try { | 37 | if(gap != null) { |
| 45 | gap.compile(program); | 38 | materialise("lower program", dProgram.getLower().toString()); |
| 46 | gap.addBackTo(); | 39 | String program = dProgram.getUpper().toString(); |
| 47 | getDataStore().clearRulesAndMakeFactsExplicit(); | 40 | try { |
| 48 | } catch (JRDFStoreException e) { | 41 | gap.compile(program); |
| 49 | e.printStackTrace(); | 42 | gap.addBackTo(); |
| 50 | } finally { | 43 | getDataStore().clearRulesAndMakeFactsExplicit(); |
| 51 | gap.clear(); | 44 | } catch(JRDFStoreException e) { |
| 52 | } | 45 | e.printStackTrace(); |
| 53 | } | 46 | } finally { |
| 54 | else | 47 | gap.clear(); |
| 55 | materialise("upper program", dProgram.getUpper().toString()); | 48 | } |
| 56 | } | 49 | } |
| 57 | 50 | else | |
| 58 | public int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap) { | 51 | materialise("upper program", dProgram.getUpper().toString()); |
| 59 | if (gap != null) { | 52 | } |
| 60 | materialise("lower program", dProgram.getLower().toString()); | 53 | |
| 61 | String program = dProgram.getUpper().toString(); | 54 | public int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap) { |
| 62 | try { | 55 | if(isDisposed()) throw new DisposedException(); |
| 63 | gap.compile(program); | 56 | if(gap != null) { |
| 64 | gap.addBackTo(); | 57 | materialise("lower program", dProgram.getLower().toString()); |
| 65 | getDataStore().clearRulesAndMakeFactsExplicit(); | 58 | String program = dProgram.getUpper().toString(); |
| 66 | } catch (JRDFStoreException e) { | 59 | try { |
| 67 | e.printStackTrace(); | 60 | gap.compile(program); |
| 68 | } finally { | 61 | gap.addBackTo(); |
| 69 | gap.clear(); | 62 | getDataStore().clearRulesAndMakeFactsExplicit(); |
| 70 | } | 63 | } catch(JRDFStoreException e) { |
| 71 | } | 64 | e.printStackTrace(); |
| 72 | else | 65 | } finally { |
| 73 | materialise("upper program", dProgram.getUpper().toString()); | 66 | gap.clear(); |
| 74 | 67 | } | |
| 75 | return 1; | 68 | } |
| 76 | } | 69 | else |
| 77 | 70 | materialise("upper program", dProgram.getUpper().toString()); | |
| 78 | @Override | 71 | |
| 79 | public AnswerTuples evaluate(String queryText) { | 72 | return 1; |
| 80 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0]); | 73 | } |
| 81 | } | 74 | |
| 82 | 75 | @Override | |
| 83 | @Override | 76 | public AnswerTuples evaluate(String queryText) { |
| 84 | public AnswerTuples evaluate(String queryText, String[] answerVars) { | 77 | if(isDisposed()) throw new DisposedException(); |
| 85 | TupleIterator tupleIterator; | 78 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0]); |
| 86 | try { | 79 | } |
| 87 | tupleIterator = store.compileQuery(queryText.replace("_:", "?"), prefixes, parameters); | 80 | |
| 88 | } catch (JRDFStoreException e) { | 81 | @Override |
| 89 | e.printStackTrace(); | 82 | public AnswerTuples evaluate(String queryText, String[] answerVars) { |
| 90 | return null; | 83 | if(isDisposed()) throw new DisposedException(); |
| 91 | } | 84 | TupleIterator tupleIterator; |
| 92 | return new RDFoxAnswerTuples(answerVars, tupleIterator); | 85 | try { |
| 93 | } | 86 | tupleIterator = store.compileQuery(queryText.replace("_:", "?"), prefixes, parameters); |
| 94 | 87 | } catch(JRDFStoreException e) { | |
| 95 | @Override | 88 | e.printStackTrace(); |
| 96 | public DataStore getDataStore() { | 89 | return null; |
| 97 | return store; | 90 | } |
| 98 | } | 91 | return new RDFoxAnswerTuples(answerVars, tupleIterator); |
| 99 | 92 | } | |
| 100 | @Override | 93 | |
| 101 | public void dispose() { | 94 | @Override |
| 102 | store.dispose(); | 95 | public DataStore getDataStore() { |
| 103 | } | 96 | if(isDisposed()) throw new DisposedException(); |
| 104 | 97 | return store; | |
| 105 | protected void outputClassAssertions(String filename) { | 98 | } |
| 106 | TupleIterator allTuples = null; | 99 | |
| 107 | boolean redirect = false; | 100 | @Override |
| 108 | try { | 101 | public void dispose() { |
| 109 | allTuples = getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X <" + Namespace.RDF_TYPE + "> ?Z }", prefixes, parameters); | 102 | super.dispose(); |
| 110 | redirect = Utility.redirectCurrentOut(filename); | 103 | store.dispose(); |
| 111 | for (long multi = allTuples.open(); multi != 0; multi = allTuples.getNext()) | 104 | } |
| 112 | System.out.println(RDFoxTripleManager.getQuotedTerm(allTuples.getResource(0)) + " " + RDFoxTripleManager.getQuotedTerm(allTuples.getResource(1))); | 105 | |
| 113 | } catch (JRDFStoreException e) { | 106 | public void outputInstance4BinaryPredicate(String iri, String filename) { |
| 114 | e.printStackTrace(); | 107 | Utility.redirectCurrentOut(filename); |
| 115 | } finally { | 108 | outputInstance4BinaryPredicate(iri); |
| 116 | if (redirect) Utility.closeCurrentOut(); | 109 | Utility.closeCurrentOut(); |
| 117 | if (allTuples != null) allTuples.dispose(); | 110 | } |
| 118 | } | 111 | |
| 119 | } | 112 | public void outputInstance4BinaryPredicate(String iri) { |
| 120 | 113 | outputAnswers("select ?x ?y where { ?x <" + iri + "> ?y . }"); | |
| 121 | public void outputInstance4BinaryPredicate(String iri, String filename) { | 114 | } |
| 122 | Utility.redirectCurrentOut(filename); | 115 | |
| 123 | outputInstance4BinaryPredicate(iri); | 116 | public void outputInstanceNumbers(String filename) { |
| 124 | Utility.closeCurrentOut(); | 117 | TupleIterator predicateTuples = null; |
| 125 | } | 118 | TupleIterator instanceTuples; |
| 126 | 119 | Set<String> number = new HashSet<String>(); | |
| 127 | public void outputInstance4BinaryPredicate(String iri) { | 120 | String predicate; |
| 128 | outputAnswers("select ?x ?y where { ?x <" + iri + "> ?y . }"); | 121 | try { |
| 129 | } | 122 | predicateTuples = |
| 130 | 123 | getDataStore().compileQuery("SELECT DISTINCT ?Y WHERE { ?X <" + Namespace.RDF_TYPE + "> ?Y }", prefixes, parameters); | |
| 131 | public void outputInstanceNumbers(String filename) { | 124 | for(long multi = predicateTuples.open(); multi != 0; multi = predicateTuples.getNext()) { |
| 132 | TupleIterator predicateTuples = null; | 125 | predicate = RDFoxTripleManager.getQuotedTerm(predicateTuples.getResource(0)); |
| 133 | TupleIterator instanceTuples; | 126 | instanceTuples = null; |
| 134 | Set<String> number = new HashSet<String>(); | 127 | try { |
| 135 | String predicate; | 128 | instanceTuples = |
| 136 | try { | 129 | getDataStore().compileQuery("SELECT ?X WHERE { ?X <" + Namespace.RDF_TYPE + "> " + predicate + " }", prefixes, parameters); |
| 137 | predicateTuples = getDataStore().compileQuery("SELECT DISTINCT ?Y WHERE { ?X <" + Namespace.RDF_TYPE + "> ?Y }", prefixes, parameters); | 130 | long totalCount = 0; |
| 138 | for (long multi = predicateTuples.open(); multi != 0; multi = predicateTuples.getNext()) { | 131 | for(long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) { |
| 139 | predicate = RDFoxTripleManager.getQuotedTerm(predicateTuples.getResource(0)); | 132 | totalCount += instanceTuples.getMultiplicity(); |
| 140 | instanceTuples = null; | 133 | } |
| 141 | try { | 134 | number.add(predicate + " * " + totalCount); |
| 142 | instanceTuples = getDataStore().compileQuery("SELECT ?X WHERE { ?X <" + Namespace.RDF_TYPE + "> " + predicate + " }", prefixes, parameters); | 135 | } finally { |
| 143 | long totalCount = 0; | 136 | if(instanceTuples != null) instanceTuples.dispose(); |
| 144 | for (long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) { | 137 | } |
| 145 | totalCount += instanceTuples.getMultiplicity(); | 138 | } |
| 146 | } | 139 | } catch(JRDFStoreException e) { |
| 147 | number.add(predicate + " * " + totalCount); | 140 | e.printStackTrace(); |
| 148 | } finally { | 141 | } finally { |
| 149 | if (instanceTuples != null) instanceTuples.dispose(); | 142 | if(predicateTuples != null) predicateTuples.dispose(); |
| 150 | } | 143 | predicateTuples = null; |
| 151 | } | 144 | } |
| 152 | } catch (JRDFStoreException e) { | 145 | |
| 153 | e.printStackTrace(); | 146 | try { |
| 154 | } finally { | 147 | predicateTuples = |
| 155 | if (predicateTuples != null) predicateTuples.dispose(); | 148 | getDataStore().compileQuery("SELECT DISTINCT ?Y WHERE { ?X ?Y ?Z }", prefixes, parameters); |
| 156 | predicateTuples = null; | 149 | for(long multi = predicateTuples.open(); multi != 0; multi = predicateTuples.getNext()) { |
| 157 | } | 150 | predicate = RDFoxTripleManager.getQuotedTerm(predicateTuples.getResource(0)); |
| 158 | 151 | instanceTuples = null; | |
| 159 | try { | 152 | try { |
| 160 | predicateTuples = getDataStore().compileQuery("SELECT DISTINCT ?Y WHERE { ?X ?Y ?Z }", prefixes, parameters); | 153 | instanceTuples = |
| 161 | for (long multi = predicateTuples.open(); multi != 0; multi = predicateTuples.getNext()) { | 154 | getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X " + predicate + " ?Z }", prefixes, parameters); |
| 162 | predicate = RDFoxTripleManager.getQuotedTerm(predicateTuples.getResource(0)); | 155 | long totalCount = 0; |
| 163 | instanceTuples = null; | 156 | for(long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) |
| 164 | try { | 157 | totalCount += instanceTuples.getMultiplicity(); |
| 165 | instanceTuples = getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X " + predicate + " ?Z }", prefixes, parameters); | 158 | number.add(predicate + " * " + totalCount); |
| 166 | ; | 159 | } finally { |
| 167 | long totalCount = 0; | 160 | if(instanceTuples != null) instanceTuples.dispose(); |
| 168 | for (long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) | 161 | } |
| 169 | totalCount += instanceTuples.getMultiplicity(); | 162 | } |
| 170 | number.add(predicate + " * " + totalCount); | 163 | |
| 171 | } finally { | 164 | } catch(JRDFStoreException e) { |
| 172 | if (instanceTuples != null) instanceTuples.dispose(); | 165 | e.printStackTrace(); |
| 173 | } | 166 | } finally { |
| 174 | } | 167 | if(predicateTuples != null) predicateTuples.dispose(); |
| 175 | 168 | predicateTuples = null; | |
| 176 | } catch (JRDFStoreException e) { | 169 | } |
| 177 | e.printStackTrace(); | 170 | |
| 178 | } finally { | 171 | Utility.redirectCurrentOut(filename); |
| 179 | if (predicateTuples != null) predicateTuples.dispose(); | 172 | String[] ordered = number.toArray(new String[0]); |
| 180 | predicateTuples = null; | 173 | Arrays.sort(ordered, new DLPredicateComparator()); |
| 181 | } | 174 | for(String line : ordered) System.out.println(line); |
| 182 | 175 | Utility.closeCurrentOut(); | |
| 183 | Utility.redirectCurrentOut(filename); | 176 | |
| 184 | String[] ordered = number.toArray(new String[0]); | 177 | } |
| 185 | Arrays.sort(ordered, new DLPredicateComparator()); | 178 | |
| 186 | for (String line: ordered) System.out.println(line); | 179 | public TupleIterator internal_evaluateAgainstIDBs(String queryText) throws JRDFStoreException { |
| 187 | Utility.closeCurrentOut(); | 180 | TupleIterator iter = |
| 188 | 181 | store.compileQuery(queryText, prefixes, parameters, TripleStatus.TUPLE_STATUS_IDB.union(TripleStatus.TUPLE_STATUS_EDB), TripleStatus.TUPLE_STATUS_IDB); | |
| 189 | } | 182 | // iter.open(); |
| 190 | 183 | return iter; | |
| 191 | public TupleIterator internal_evaluateAgainstIDBs(String queryText) throws JRDFStoreException { | 184 | } |
| 192 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters, TripleStatus.TUPLE_STATUS_IDB.union(TripleStatus.TUPLE_STATUS_EDB), TripleStatus.TUPLE_STATUS_IDB); | 185 | |
| 186 | public TupleIterator internal_evaluate(String queryText) throws JRDFStoreException { | ||
| 187 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); | ||
| 188 | // iter.open(); | ||
| 189 | return iter; | ||
| 190 | } | ||
| 191 | |||
| 192 | public void setExpandEquality(boolean flag) { | ||
| 193 | parameters.m_expandEquality = flag; | ||
| 194 | } | ||
| 195 | |||
| 196 | public TupleIterator internal_evaluateNotExpanded(String queryText) throws JRDFStoreException { | ||
| 197 | parameters.m_expandEquality = false; | ||
| 198 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); | ||
| 193 | // iter.open(); | 199 | // iter.open(); |
| 194 | return iter; | 200 | parameters.m_expandEquality = true; |
| 195 | } | 201 | return iter; |
| 196 | 202 | } | |
| 197 | public TupleIterator internal_evaluate(String queryText) throws JRDFStoreException { | 203 | |
| 198 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); | 204 | public TupleIterator internal_evaluate(String queryText, boolean incrementally) throws JRDFStoreException { |
| 199 | // iter.open(); | 205 | return incrementally ? internal_evaluateAgainstIDBs(queryText) : internal_evaluate(queryText); |
| 200 | return iter; | 206 | } |
| 201 | } | 207 | |
| 202 | 208 | public String getUnusedRules(Collection<DLClause> clauses, boolean toUpdate) { | |
| 203 | public void setExpandEquality(boolean flag) { | 209 | DLClause clause; |
| 204 | parameters.m_expandEquality = flag; | 210 | for(Iterator<DLClause> iter = clauses.iterator(); iter.hasNext(); ) { |
| 205 | } | 211 | if(materialisedRules.contains(clause = iter.next())) |
| 206 | 212 | iter.remove(); | |
| 207 | public TupleIterator internal_evaluateNotExpanded(String queryText) throws JRDFStoreException { | 213 | else if(toUpdate) materialisedRules.add(clause); |
| 208 | parameters.m_expandEquality = false; | 214 | } |
| 209 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); | 215 | |
| 210 | // iter.open(); | 216 | if(clauses.isEmpty()) return null; |
| 211 | parameters.m_expandEquality = true; | 217 | |
| 212 | return iter; | 218 | return Program.toString(clauses); |
| 213 | } | 219 | } |
| 214 | 220 | ||
| 215 | 221 | public void outputMaterialisedRules() { | |
| 216 | public TupleIterator internal_evaluate(String queryText, boolean incrementally) throws JRDFStoreException { | 222 | System.out.println(DLClauseHelper.toString(materialisedRules)); |
| 217 | return incrementally ? internal_evaluateAgainstIDBs(queryText) : internal_evaluate(queryText); | 223 | } |
| 218 | } | 224 | |
| 219 | 225 | public void outputAnswers(String query) { | |
| 220 | Set<DLClause> materialisedRules = new HashSet<DLClause>(); | 226 | TupleIterator iter = null; |
| 221 | 227 | try { | |
| 222 | public String getUnusedRules(Collection<DLClause> clauses, boolean toUpdate) { | 228 | iter = internal_evaluate(query); |
| 223 | DLClause clause; | 229 | System.out.println(query); |
| 224 | for (Iterator<DLClause> iter = clauses.iterator(); iter.hasNext(); ) { | 230 | int arity = iter.getArity(); |
| 225 | if (materialisedRules.contains(clause = iter.next())) | 231 | for(long multi = iter.open(); multi != 0; multi = iter.getNext()) { |
| 226 | iter.remove(); | 232 | for(int i = 0; i < arity; ++i) |
| 227 | else if (toUpdate) materialisedRules.add(clause); | 233 | System.out.print(RDFoxTripleManager.getQuotedTerm(iter.getResource(i)) + "\t"); |
| 228 | } | 234 | System.out.println(); |
| 229 | 235 | } | |
| 230 | if (clauses.isEmpty()) return null; | 236 | } catch(JRDFStoreException e) { |
| 231 | 237 | e.printStackTrace(); | |
| 232 | return Program.toString(clauses); | 238 | } finally { |
| 233 | } | 239 | if(iter != null) iter.dispose(); |
| 234 | 240 | } | |
| 235 | public void outputMaterialisedRules() { | 241 | } |
| 236 | System.out.println(DLClauseHelper.toString(materialisedRules)); | 242 | |
| 237 | } | 243 | public void outputInstance4UnaryPredicate(String iri) { |
| 238 | 244 | outputAnswers("select ?x where { ?x " | |
| 239 | public void outputAnswers(String query) { | 245 | + "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" |
| 240 | TupleIterator iter = null; | 246 | + iri |
| 241 | try { | 247 | + "> .}"); |
| 242 | iter = internal_evaluate(query); | 248 | } |
| 243 | System.out.println(query); | 249 | |
| 244 | int arity = iter.getArity(); | 250 | public void outputSubjects(String p, String o) { |
| 245 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) { | 251 | outputAnswers("select x where { ?x <" + p + "> <" + o + "> . }"); |
| 246 | for (int i = 0; i < arity; ++i) | 252 | } |
| 247 | System.out.print(RDFoxTripleManager.getQuotedTerm(iter.getResource(i)) + "\t"); | 253 | |
| 248 | System.out.println(); | 254 | public void outputObjects(String s, String p) { |
| 249 | } | 255 | outputAnswers("select ?x where { <" + s + "> <" + p + "> ?x . }"); |
| 250 | } catch (JRDFStoreException e) { | 256 | } |
| 251 | e.printStackTrace(); | 257 | |
| 252 | } finally { | 258 | public void outputIDBFacts() { |
| 253 | if (iter != null) iter.dispose(); | 259 | TupleIterator iter = null; |
| 254 | } | 260 | try { |
| 255 | } | 261 | iter = internal_evaluateAgainstIDBs("select distict ?x ?y ?z where { ?x ?y ?z }"); |
| 256 | 262 | for(long multi = iter.open(); multi != 0; multi = iter.getNext()) { | |
| 257 | public void outputInstance4UnaryPredicate(String iri) { | 263 | for(int i = 0; i < 3; ++i) |
| 258 | outputAnswers("select ?x where { ?x " | 264 | System.out.print(RDFoxTripleManager.getQuotedTerm(iter.getResource(i)) + "\t"); |
| 259 | + "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" | 265 | System.out.println(); |
| 260 | + iri | 266 | } |
| 261 | + "> .}"); | 267 | } catch(JRDFStoreException e) { |
| 262 | } | 268 | // TODO Auto-generated catch block |
| 263 | 269 | e.printStackTrace(); | |
| 264 | public void outputSubjects(String p, String o) { | 270 | } finally { |
| 265 | outputAnswers("select x where { ?x <" + p + "> <" + o + "> . }"); | 271 | if(iter != null) iter.dispose(); |
| 266 | } | 272 | } |
| 267 | 273 | ||
| 268 | public void outputObjects(String s, String p) { | 274 | } |
| 269 | outputAnswers("select ?x where { <" + s + "> <" + p + "> ?x . }"); | 275 | |
| 270 | } | 276 | public void outputType4Individual(String iri) { |
| 271 | 277 | outputAnswers("select ?z where { <" + iri + "> " + Namespace.RDF_TYPE_QUOTED + " ?z }"); | |
| 272 | public void outputIDBFacts() { | 278 | } |
| 273 | TupleIterator iter = null; | 279 | |
| 274 | try { | 280 | public int getSameAsNumber() { |
| 275 | iter = internal_evaluateAgainstIDBs("select distict ?x ?y ?z where { ?x ?y ?z }"); | 281 | TupleIterator iter = null; |
| 276 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) { | 282 | int counter = 0; |
| 277 | for (int i = 0; i < 3; ++i) | 283 | try { |
| 278 | System.out.print(RDFoxTripleManager.getQuotedTerm(iter.getResource(i)) + "\t"); | 284 | iter = internal_evaluate("select ?x ?y where {?x " + Namespace.EQUALITY_QUOTED + " ?y . }"); |
| 279 | System.out.println(); | 285 | for(long multi = iter.open(); multi != 0; multi = iter.getNext()) |
| 280 | } | 286 | if(iter.getResourceID(0) != iter.getResourceID(1)) |
| 281 | } catch (JRDFStoreException e) { | 287 | ++counter; |
| 282 | // TODO Auto-generated catch block | 288 | } catch(JRDFStoreException e) { |
| 283 | e.printStackTrace(); | 289 | e.printStackTrace(); |
| 284 | } finally { | 290 | } finally { |
| 285 | if (iter != null) iter.dispose(); | 291 | if(iter != null) iter.dispose(); |
| 286 | } | 292 | } |
| 287 | 293 | return counter; | |
| 288 | } | 294 | } |
| 289 | 295 | ||
| 290 | public void outputType4Individual(String iri) { | 296 | public UFS<String> getEqualityGroups(boolean reuse) { |
| 291 | outputAnswers("select ?z where { <" + iri + "> " + Namespace.RDF_TYPE_QUOTED + " ?z }"); | 297 | if(reuse && equalityGroups != null) return equalityGroups; |
| 292 | } | 298 | |
| 293 | 299 | equalityGroups = new UFS<String>(); | |
| 294 | public int getSameAsNumber() { | 300 | |
| 295 | TupleIterator iter = null; | 301 | TupleIterator answers = null; |
| 296 | int counter = 0; | 302 | try { |
| 297 | try { | 303 | Timer t = new Timer(); |
| 298 | iter = internal_evaluate("select ?x ?y where {?x " + Namespace.EQUALITY_QUOTED + " ?y . }"); | 304 | answers = internal_evaluate("select ?x ?z where {?x " + Namespace.EQUALITY_QUOTED + "?z . }"); |
| 299 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) | 305 | for(long multi = answers.open(); multi != 0; multi = answers.getNext()) { |
| 300 | if (iter.getResourceID(0) != iter.getResourceID(1)) | 306 | if(answers.getResourceID(0) != answers.getResourceID(1)) |
| 301 | ++counter; | 307 | equalityGroups.merge(answers.getResource(0).m_lexicalForm, answers.getResource(1).m_lexicalForm); |
| 302 | } catch (JRDFStoreException e) { | 308 | } |
| 303 | e.printStackTrace(); | 309 | Utility.logInfo("@Time to group individuals by equality: " + t.duration()); |
| 304 | } finally { | 310 | } catch(JRDFStoreException e) { |
| 305 | if (iter != null) iter.dispose(); | 311 | e.printStackTrace(); |
| 306 | } | 312 | } finally { |
| 307 | return counter; | 313 | if(answers != null) answers.dispose(); |
| 308 | } | 314 | } |
| 309 | 315 | ||
| 310 | private UFS<String> equalityGroups = null; | 316 | return equalityGroups; |
| 311 | 317 | } | |
| 312 | public UFS<String> getEqualityGroups(boolean reuse) { | 318 | |
| 313 | if (reuse && equalityGroups != null) return equalityGroups; | 319 | public void clearRulesAndIDBFacts(Collection<int[]> collection) { |
| 314 | 320 | // performDeletion(collection); | |
| 315 | equalityGroups = new UFS<String>(); | 321 | collection.clear(); |
| 316 | 322 | try { | |
| 317 | TupleIterator answers = null; | 323 | store.clearRulesAndMakeFactsExplicit(); |
| 318 | try { | 324 | } catch(JRDFStoreException e) { |
| 319 | Timer t = new Timer(); | 325 | e.printStackTrace(); |
| 320 | answers = internal_evaluate("select ?x ?z where {?x " + Namespace.EQUALITY_QUOTED + "?z . }"); | 326 | } |
| 321 | for (long multi = answers.open(); multi != 0; multi = answers.getNext()) { | 327 | } |
| 322 | if (answers.getResourceID(0) != answers.getResourceID(1)) | 328 | |
| 323 | equalityGroups.merge(answers.getResource(0).m_lexicalForm, answers.getResource(1).m_lexicalForm); | 329 | protected void outputClassAssertions(String filename) { |
| 324 | } | 330 | TupleIterator allTuples = null; |
| 325 | Utility.logInfo("@Time to group individuals by equality: " + t.duration()); | 331 | boolean redirect = false; |
| 326 | } catch (JRDFStoreException e) { | 332 | try { |
| 327 | e.printStackTrace(); | 333 | allTuples = |
| 328 | } finally { | 334 | getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X <" + Namespace.RDF_TYPE + "> ?Z }", prefixes, parameters); |
| 329 | if (answers != null) answers.dispose(); | 335 | redirect = Utility.redirectCurrentOut(filename); |
| 330 | } | 336 | for(long multi = allTuples.open(); multi != 0; multi = allTuples.getNext()) |
| 331 | 337 | System.out.println(RDFoxTripleManager.getQuotedTerm(allTuples.getResource(0)) + " " + RDFoxTripleManager | |
| 332 | return equalityGroups; | 338 | .getQuotedTerm(allTuples.getResource(1))); |
| 333 | } | 339 | } catch(JRDFStoreException e) { |
| 334 | 340 | e.printStackTrace(); | |
| 335 | public void clearRulesAndIDBFacts(Collection<int[]> collection) { | 341 | } finally { |
| 336 | // performDeletion(collection); | 342 | if(redirect) Utility.closeCurrentOut(); |
| 337 | collection.clear(); | 343 | if(allTuples != null) allTuples.dispose(); |
| 338 | try { | 344 | } |
| 339 | store.clearRulesAndMakeFactsExplicit(); | 345 | } |
| 340 | } catch (JRDFStoreException e) { | 346 | |
| 341 | e.printStackTrace(); | 347 | @SuppressWarnings("unused") |
| 342 | } | 348 | private void performDeletion(Collection<int[]> collection) { |
| 343 | } | 349 | Utility.logInfo("Remove all rules, idb facts and added staff..."); |
| 344 | 350 | Timer timer = new Timer(); | |
| 345 | @SuppressWarnings("unused") | 351 | TupleIterator iter = null; |
| 346 | private void performDeletion(Collection<int[]> collection) { | 352 | try { |
| 347 | Utility.logInfo("Remove all rules, idb facts and added staff..."); | 353 | UpdateType ut = UpdateType.ScheduleForDeletion; |
| 348 | Timer timer = new Timer(); | 354 | for(int[] t : collection) |
| 349 | TupleIterator iter = null; | 355 | store.addTriplesByResourceIDs(t, ut); |
| 350 | try { | 356 | |
| 351 | UpdateType ut = UpdateType.ScheduleForDeletion; | 357 | try { |
| 352 | for (int[] t: collection) | 358 | iter = internal_evaluateAgainstIDBs("select ?x ?y ?z where { ?x ?y ?z . }"); |
| 353 | store.addTriplesByResourceIDs(t, ut); | 359 | for(long multi = iter.open(); multi != 0; multi = iter.getNext()) { |
| 354 | 360 | int[] triple = new int[3]; | |
| 355 | try { | 361 | for(int i = 0; i < 3; ++i) |
| 356 | iter = internal_evaluateAgainstIDBs("select ?x ?y ?z where { ?x ?y ?z . }"); | 362 | triple[i] = iter.getResourceID(i); |
| 357 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) { | 363 | store.addTriplesByResourceIDs(triple, ut); |
| 358 | int[] triple = new int[3]; | 364 | } |
| 359 | for (int i = 0; i < 3; ++i) | 365 | } finally { |
| 360 | triple[i] = iter.getResourceID(i); | 366 | if(iter != null) iter.dispose(); |
| 361 | store.addTriplesByResourceIDs(triple, ut); | 367 | iter = null; |
| 362 | } | 368 | } |
| 363 | } finally { | 369 | store.applyReasoning(true); |
| 364 | if (iter != null) iter.dispose(); | 370 | } catch(JRDFStoreException e) { |
| 365 | iter = null; | 371 | e.printStackTrace(); |
| 366 | } | 372 | } |
| 367 | store.applyReasoning(true); | 373 | Utility.logInfo("Time for deletion: " + timer.duration()); |
| 368 | } catch (JRDFStoreException e) { | 374 | } |
| 369 | e.printStackTrace(); | ||
| 370 | } | ||
| 371 | Utility.logInfo("Time for deletion: " + timer.duration()); | ||
| 372 | } | ||
| 373 | 375 | ||
| 374 | 376 | ||
| 375 | } | 377 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java index f068164..98f0c35 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java | |||
| @@ -12,6 +12,7 @@ import uk.ac.ox.cs.pagoda.query.AnswerTuples; | |||
| 12 | import uk.ac.ox.cs.pagoda.query.AnswerTuplesImp; | 12 | import uk.ac.ox.cs.pagoda.query.AnswerTuplesImp; |
| 13 | import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; | 13 | import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; |
| 14 | import uk.ac.ox.cs.pagoda.util.Utility; | 14 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 15 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 15 | 16 | ||
| 16 | import java.io.File; | 17 | import java.io.File; |
| 17 | import java.io.FileNotFoundException; | 18 | import java.io.FileNotFoundException; |
| @@ -19,82 +20,90 @@ import java.nio.file.Paths; | |||
| 19 | import java.util.Set; | 20 | import java.util.Set; |
| 20 | 21 | ||
| 21 | public class KarmaQueryEngine extends RDFoxQueryEngine { | 22 | public class KarmaQueryEngine extends RDFoxQueryEngine { |
| 22 | 23 | ||
| 23 | private MyKarma reasoner = null; | 24 | String karmaDataFile = null, karmaRuleFile = null; |
| 24 | 25 | private MyKarma reasoner = null; | |
| 25 | String karmaDataFile = null, karmaRuleFile = null; | 26 | |
| 26 | 27 | public KarmaQueryEngine(String name) { | |
| 27 | public KarmaQueryEngine(String name) { | 28 | super(name); |
| 28 | super(name); | 29 | |
| 29 | |||
| 30 | // int Base = 1 << 6; | 30 | // int Base = 1 << 6; |
| 31 | // int index = (new Random().nextInt() % Base + Base) % Base; | 31 | // int index = (new Random().nextInt() % Base + Base) % Base; |
| 32 | // karmaDataFile = "karma_data" + index + ".ttl"; | 32 | // karmaDataFile = "karma_data" + index + ".ttl"; |
| 33 | // karmaRuleFile = "karma_rule" + index + ".dlog"; | 33 | // karmaRuleFile = "karma_rule" + index + ".dlog"; |
| 34 | karmaDataFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_data.ttl").toString(); | 34 | karmaDataFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_data.ttl").toString(); |
| 35 | karmaRuleFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_rule.dlog").toString(); | 35 | karmaRuleFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_rule.dlog").toString(); |
| 36 | 36 | ||
| 37 | reasoner = new MyKarma(); | 37 | reasoner = new MyKarma(); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | public MyKarma getReasoner() { | 40 | public MyKarma getReasoner() { |
| 41 | return reasoner; | 41 | if(isDisposed()) throw new DisposedException(); |
| 42 | } | 42 | return reasoner; |
| 43 | 43 | } | |
| 44 | public void processOntology(OWLOntology elhoOntology) { | 44 | |
| 45 | try { | 45 | public void processOntology(OWLOntology elhoOntology) { |
| 46 | OntologyProcesser.transformOntology(elhoOntology, new File(karmaDataFile), new File(karmaRuleFile)); | 46 | if(isDisposed()) throw new DisposedException(); |
| 47 | } catch (IllegalInputOntologyException e) { | 47 | try { |
| 48 | e.printStackTrace(); | 48 | OntologyProcesser.transformOntology(elhoOntology, new File(karmaDataFile), new File(karmaRuleFile)); |
| 49 | } | 49 | } catch(IllegalInputOntologyException e) { |
| 50 | } | 50 | e.printStackTrace(); |
| 51 | 51 | } | |
| 52 | @Override | 52 | } |
| 53 | public void dispose() { | 53 | |
| 54 | reasoner.dispose(); | 54 | @Override |
| 55 | } | 55 | public void dispose() { |
| 56 | 56 | super.dispose(); | |
| 57 | @Override | 57 | reasoner.dispose(); |
| 58 | public AnswerTuples evaluate(String queryText) { | 58 | } |
| 59 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0], null); | 59 | |
| 60 | } | 60 | @Override |
| 61 | 61 | public AnswerTuples evaluate(String queryText) { | |
| 62 | @Override | 62 | if(isDisposed()) throw new DisposedException(); |
| 63 | public AnswerTuples evaluate(String queryText, String[] answerVars) { | 63 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0], null); |
| 64 | return evaluate(queryText, answerVars, null); | 64 | } |
| 65 | } | 65 | |
| 66 | 66 | @Override | |
| 67 | public AnswerTuples evaluate(String queryText, AnswerTuples soundAnswerTuples) { | 67 | public AnswerTuples evaluate(String queryText, String[] answerVars) { |
| 68 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0], soundAnswerTuples); | 68 | if(isDisposed()) throw new DisposedException(); |
| 69 | } | 69 | return evaluate(queryText, answerVars, null); |
| 70 | 70 | } | |
| 71 | public AnswerTuples evaluate(String queryText, String[] answerVars, AnswerTuples soundAnswerTuples) { | 71 | |
| 72 | KarmaQuery karmaQuery = new KarmaQuery(queryText.replace("_:", "?")); | 72 | public AnswerTuples evaluate(String queryText, AnswerTuples soundAnswerTuples) { |
| 73 | reasoner.setConcurrence(false); | 73 | if(isDisposed()) throw new DisposedException(); |
| 74 | ConjunctiveQuery cq = karmaQuery.getConjunctiveQuery(); | 74 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0], soundAnswerTuples); |
| 75 | if (cq == null) return null; | 75 | } |
| 76 | Set<AnswerTuple> answers = reasoner.answerCQ(cq, soundAnswerTuples, !queryText.contains("_:")); | 76 | |
| 77 | return new AnswerTuplesImp(answerVars, answers); | 77 | public AnswerTuples evaluate(String queryText, String[] answerVars, AnswerTuples soundAnswerTuples) { |
| 78 | } | 78 | if(isDisposed()) throw new DisposedException(); |
| 79 | 79 | KarmaQuery karmaQuery = new KarmaQuery(queryText.replace("_:", "?")); | |
| 80 | @Override | 80 | reasoner.setConcurrence(false); |
| 81 | public DataStore getDataStore() { | 81 | ConjunctiveQuery cq = karmaQuery.getConjunctiveQuery(); |
| 82 | return reasoner.getStore(); | 82 | if(cq == null) return null; |
| 83 | } | 83 | Set<AnswerTuple> answers = reasoner.answerCQ(cq, soundAnswerTuples, !queryText.contains("_:")); |
| 84 | 84 | return new AnswerTuplesImp(answerVars, answers); | |
| 85 | public void initialiseKarma() { | 85 | } |
| 86 | try { | 86 | |
| 87 | reasoner.initializeData(new File(karmaDataFile)); | 87 | @Override |
| 88 | reasoner.materialise(new File(karmaRuleFile)); | 88 | public DataStore getDataStore() { |
| 89 | 89 | if(isDisposed()) throw new DisposedException(); | |
| 90 | File tmp; | 90 | return reasoner.getStore(); |
| 91 | if (karmaDataFile != null && ((tmp = new File(karmaDataFile)).exists())) tmp.delete(); | 91 | } |
| 92 | if (karmaRuleFile != null && ((tmp = new File(karmaRuleFile)).exists())) tmp.delete(); | 92 | |
| 93 | } catch (FileNotFoundException e) { | 93 | public void initialiseKarma() { |
| 94 | e.printStackTrace(); | 94 | if(isDisposed()) throw new DisposedException(); |
| 95 | } catch (JRDFStoreException e) { | 95 | try { |
| 96 | e.printStackTrace(); | 96 | reasoner.initializeData(new File(karmaDataFile)); |
| 97 | } | 97 | reasoner.materialise(new File(karmaRuleFile)); |
| 98 | } | 98 | |
| 99 | File tmp; | ||
| 100 | if(karmaDataFile != null && ((tmp = new File(karmaDataFile)).exists())) tmp.delete(); | ||
| 101 | if(karmaRuleFile != null && ((tmp = new File(karmaRuleFile)).exists())) tmp.delete(); | ||
| 102 | } catch(FileNotFoundException e) { | ||
| 103 | e.printStackTrace(); | ||
| 104 | } catch(JRDFStoreException e) { | ||
| 105 | e.printStackTrace(); | ||
| 106 | } | ||
| 107 | } | ||
| 99 | 108 | ||
| 100 | } | 109 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxAnswerTuples.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxAnswerTuples.java index dd71809..1e8181f 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxAnswerTuples.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxAnswerTuples.java | |||
| @@ -3,15 +3,14 @@ package uk.ac.ox.cs.pagoda.reasoner.light; | |||
| 3 | import org.semanticweb.HermiT.model.Constant; | 3 | import org.semanticweb.HermiT.model.Constant; |
| 4 | import org.semanticweb.HermiT.model.Individual; | 4 | import org.semanticweb.HermiT.model.Individual; |
| 5 | import org.semanticweb.HermiT.model.Term; | 5 | import org.semanticweb.HermiT.model.Term; |
| 6 | |||
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 9 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 10 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 6 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 11 | import uk.ac.ox.cs.JRDFox.model.GroundTerm; | 7 | import uk.ac.ox.cs.JRDFox.model.GroundTerm; |
| 12 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | 8 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; |
| 9 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 10 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 11 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 13 | 12 | ||
| 14 | public class RDFoxAnswerTuples implements AnswerTuples { | 13 | public class RDFoxAnswerTuples extends AnswerTuples { |
| 15 | 14 | ||
| 16 | long multi; | 15 | long multi; |
| 17 | TupleIterator m_iter; | 16 | TupleIterator m_iter; |
| @@ -22,7 +21,18 @@ public class RDFoxAnswerTuples implements AnswerTuples { | |||
| 22 | m_iter = iter; | 21 | m_iter = iter; |
| 23 | reset(); | 22 | reset(); |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 25 | public static Term getHermitTerm(GroundTerm t) { | ||
| 26 | if(t instanceof uk.ac.ox.cs.JRDFox.model.Individual) { | ||
| 27 | uk.ac.ox.cs.JRDFox.model.Individual individual = (uk.ac.ox.cs.JRDFox.model.Individual) t; | ||
| 28 | return Individual.create(individual.getIRI()); | ||
| 29 | } | ||
| 30 | else { | ||
| 31 | uk.ac.ox.cs.JRDFox.model.Literal literal = ((uk.ac.ox.cs.JRDFox.model.Literal) t); | ||
| 32 | return Constant.create(literal.getLexicalForm(), literal.getDatatype().getIRI()); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 26 | @Override | 36 | @Override |
| 27 | public boolean isValid() { | 37 | public boolean isValid() { |
| 28 | return multi != 0; | 38 | return multi != 0; |
| @@ -34,7 +44,7 @@ public class RDFoxAnswerTuples implements AnswerTuples { | |||
| 34 | return m_iter.getArity(); | 44 | return m_iter.getArity(); |
| 35 | } catch (JRDFStoreException e) { | 45 | } catch (JRDFStoreException e) { |
| 36 | e.printStackTrace(); | 46 | e.printStackTrace(); |
| 37 | return -1; | 47 | return -1; |
| 38 | } | 48 | } |
| 39 | } | 49 | } |
| 40 | 50 | ||
| @@ -44,15 +54,12 @@ public class RDFoxAnswerTuples implements AnswerTuples { | |||
| 44 | multi = m_iter.getNext(); | 54 | multi = m_iter.getNext(); |
| 45 | } catch (JRDFStoreException e) { | 55 | } catch (JRDFStoreException e) { |
| 46 | e.printStackTrace(); | 56 | e.printStackTrace(); |
| 47 | } | 57 | } |
| 48 | } | 58 | } |
| 49 | 59 | ||
| 50 | @Override | 60 | @Override |
| 51 | public void dispose() { | 61 | public void dispose() { |
| 52 | m_iter.dispose(); | 62 | super.dispose(); |
| 53 | } | ||
| 54 | |||
| 55 | protected void finalize() { | ||
| 56 | m_iter.dispose(); | 63 | m_iter.dispose(); |
| 57 | } | 64 | } |
| 58 | 65 | ||
| @@ -85,16 +92,9 @@ public class RDFoxAnswerTuples implements AnswerTuples { | |||
| 85 | public String[] getAnswerVariables() { | 92 | public String[] getAnswerVariables() { |
| 86 | return m_answerVars; | 93 | return m_answerVars; |
| 87 | } | 94 | } |
| 88 | 95 | ||
| 89 | public static Term getHermitTerm(GroundTerm t) { | 96 | protected void finalize() { |
| 90 | if (t instanceof uk.ac.ox.cs.JRDFox.model.Individual) { | 97 | m_iter.dispose(); |
| 91 | uk.ac.ox.cs.JRDFox.model.Individual individual = (uk.ac.ox.cs.JRDFox.model.Individual) t; | ||
| 92 | return Individual.create(individual.getIRI()); | ||
| 93 | } | ||
| 94 | else { | ||
| 95 | uk.ac.ox.cs.JRDFox.model.Literal literal = ((uk.ac.ox.cs.JRDFox.model.Literal) t); | ||
| 96 | return Constant.create(literal.getLexicalForm(), literal.getDatatype().getIRI()); | ||
| 97 | } | ||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | } | 100 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java index 61500f5..f835ba9 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java | |||
| @@ -13,119 +13,126 @@ import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | |||
| 13 | import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter; | 13 | import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter; |
| 14 | import uk.ac.ox.cs.pagoda.util.Timer; | 14 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 15 | import uk.ac.ox.cs.pagoda.util.Utility; | 15 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 16 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 16 | 17 | ||
| 17 | import java.io.File; | 18 | import java.io.File; |
| 18 | import java.util.Collection; | 19 | import java.util.Collection; |
| 19 | 20 | ||
| 20 | public abstract class RDFoxQueryEngine implements QueryEngine { | 21 | public abstract class RDFoxQueryEngine extends QueryEngine { |
| 21 | |||
| 22 | public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; | ||
| 23 | protected String name; | ||
| 24 | protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); | ||
| 25 | 22 | ||
| 26 | public RDFoxQueryEngine(String name) { | 23 | public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; |
| 27 | this.name = name; | 24 | protected String name; |
| 28 | } | 25 | protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); |
| 29 | 26 | ||
| 30 | public static DataStore createDataStore() { | 27 | public RDFoxQueryEngine(String name) { |
| 31 | DataStore instance = null; | 28 | this.name = name; |
| 32 | try { | 29 | } |
| 30 | |||
| 31 | public static DataStore createDataStore() { | ||
| 32 | DataStore instance = null; | ||
| 33 | try { | ||
| 33 | // instance = new DataStore("par-head-n"); | 34 | // instance = new DataStore("par-head-n"); |
| 34 | instance = new DataStore(StoreType.NarrowParallelHead); | 35 | instance = new DataStore(StoreType.NarrowParallelHead); |
| 35 | instance.setNumberOfThreads(matNoOfThreads); | 36 | instance.setNumberOfThreads(matNoOfThreads); |
| 36 | instance.initialize(); | 37 | instance.initialize(); |
| 37 | } catch(JRDFStoreException e) { | 38 | } catch(JRDFStoreException e) { |
| 38 | e.printStackTrace(); | 39 | e.printStackTrace(); |
| 39 | } | 40 | } |
| 40 | return instance; | 41 | return instance; |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | public String getName() { | 44 | public String getName() { |
| 44 | return name; | 45 | if(isDisposed()) throw new DisposedException(); |
| 45 | } | 46 | return name; |
| 46 | 47 | } | |
| 47 | public abstract DataStore getDataStore(); | 48 | |
| 48 | 49 | public abstract DataStore getDataStore(); | |
| 49 | public abstract void dispose(); | 50 | |
| 50 | 51 | public void importRDFData(String fileName, String importedFile) { | |
| 51 | public void importRDFData(String fileName, String importedFile) { | 52 | if(isDisposed()) throw new DisposedException(); |
| 52 | if(importedFile == null || importedFile.isEmpty()) return; | 53 | if(importedFile == null || importedFile.isEmpty()) return; |
| 53 | Timer t = new Timer(); | 54 | Timer t = new Timer(); |
| 54 | DataStore store = getDataStore(); | 55 | DataStore store = getDataStore(); |
| 55 | try { | 56 | try { |
| 56 | long oldTripleCount = store.getTriplesCount(), tripleCount; | 57 | long oldTripleCount = store.getTriplesCount(), tripleCount; |
| 57 | for (String file: importedFile.split(QueryReasoner.ImportDataFileSeparator)) { | 58 | for(String file : importedFile.split(QueryReasoner.ImportDataFileSeparator)) { |
| 58 | store.importTurtleFile(new File(file), prefixes); | 59 | store.importTurtleFile(new File(file), prefixes); |
| 59 | } | 60 | } |
| 60 | tripleCount = store.getTriplesCount(); | 61 | tripleCount = store.getTriplesCount(); |
| 61 | Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); | 62 | Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); |
| 62 | store.clearRulesAndMakeFactsExplicit(); | 63 | store.clearRulesAndMakeFactsExplicit(); |
| 63 | } catch (JRDFStoreException e) { | 64 | } catch(JRDFStoreException e) { |
| 64 | e.printStackTrace(); | 65 | e.printStackTrace(); |
| 65 | } | 66 | } |
| 66 | Utility.logDebug(name + " store finished importing " + fileName + " in " + t.duration() + " seconds."); | 67 | Utility.logDebug(name + " store finished importing " + fileName + " in " + t.duration() + " seconds."); |
| 67 | } | 68 | } |
| 68 | 69 | ||
| 69 | public void importDataFromABoxOf(OWLOntology ontology) { | 70 | public void importDataFromABoxOf(OWLOntology ontology) { |
| 70 | DataStore store = getDataStore(); | 71 | if(isDisposed()) throw new DisposedException(); |
| 71 | try { | 72 | DataStore store = getDataStore(); |
| 72 | long prevTriplesCount = store.getTriplesCount(); | 73 | try { |
| 73 | store.importOntology(ontology.getOWLOntologyManager().createOntology(ontology.getABoxAxioms(true))); | 74 | long prevTriplesCount = store.getTriplesCount(); |
| 74 | long loadedTriples = store.getTriplesCount() - prevTriplesCount; | 75 | store.importOntology(ontology.getOWLOntologyManager().createOntology(ontology.getABoxAxioms(true))); |
| 75 | Utility.logInfo(name + ": loaded " + loadedTriples + " triples from " + ontology.getABoxAxioms(true) | 76 | long loadedTriples = store.getTriplesCount() - prevTriplesCount; |
| 76 | .size() + " ABox axioms"); | 77 | Utility.logInfo(name + ": loaded " + loadedTriples + " triples from " + ontology.getABoxAxioms(true) |
| 77 | } catch(JRDFStoreException | OWLOntologyCreationException e) { | 78 | .size() + " ABox axioms"); |
| 78 | e.printStackTrace(); | 79 | } catch(JRDFStoreException | OWLOntologyCreationException e) { |
| 79 | System.exit(1); | 80 | e.printStackTrace(); |
| 80 | } | 81 | System.exit(1); |
| 81 | 82 | } | |
| 82 | } | 83 | |
| 83 | 84 | } | |
| 84 | public void materialise(String programName, String programText) { | 85 | |
| 85 | if(programText == null) return; | 86 | public void materialise(String programName, String programText) { |
| 86 | Timer t = new Timer(); | 87 | if(isDisposed()) throw new DisposedException(); |
| 87 | DataStore store = getDataStore(); | 88 | if(programText == null) return; |
| 88 | try { | 89 | Timer t = new Timer(); |
| 89 | long oldTripleCount = store.getTriplesCount(), tripleCount; | 90 | DataStore store = getDataStore(); |
| 91 | try { | ||
| 92 | long oldTripleCount = store.getTriplesCount(), tripleCount; | ||
| 90 | // store.addRules(new String[] {programText}); | 93 | // store.addRules(new String[] {programText}); |
| 91 | store.importRules(programText); | 94 | store.importRules(programText); |
| 92 | store.applyReasoning(); | 95 | store.applyReasoning(); |
| 93 | tripleCount = store.getTriplesCount(); | 96 | tripleCount = store.getTriplesCount(); |
| 94 | Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); | 97 | Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); |
| 95 | store.clearRulesAndMakeFactsExplicit(); | 98 | store.clearRulesAndMakeFactsExplicit(); |
| 96 | } catch (JRDFStoreException e) { | 99 | } catch(JRDFStoreException e) { |
| 97 | e.printStackTrace(); | 100 | e.printStackTrace(); |
| 98 | } | 101 | } |
| 99 | Utility.logDebug(name + " store finished the materialisation of " + programName + " in " + t.duration() + " seconds."); | 102 | Utility.logDebug(name + " store finished the materialisation of " + programName + " in " + t.duration() + " seconds."); |
| 100 | } | 103 | } |
| 101 | 104 | ||
| 102 | @Override | 105 | @Override |
| 103 | public void evaluate(Collection<String> queryTexts, String answerFile) { | 106 | public void evaluate(Collection<String> queryTexts, String answerFile) { |
| 104 | if (queryTexts == null) | 107 | if(isDisposed()) throw new DisposedException(); |
| 105 | return ; | 108 | if(queryTexts == null) |
| 106 | 109 | return; | |
| 107 | int queryID = 0; | 110 | |
| 108 | AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); | 111 | int queryID = 0; |
| 109 | AnswerTuples answerTuples; | 112 | AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); |
| 110 | Timer t = new Timer(); | 113 | AnswerTuples answerTuples; |
| 111 | try { | 114 | Timer t = new Timer(); |
| 112 | for (String query: queryTexts) { | 115 | try { |
| 113 | t.reset(); | 116 | for(String query : queryTexts) { |
| 114 | answerTuples = null; | 117 | t.reset(); |
| 115 | try { | 118 | answerTuples = null; |
| 116 | answerTuples = evaluate(query); | 119 | try { |
| 117 | Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration()); | 120 | answerTuples = evaluate(query); |
| 118 | answerWriter.write(answerTuples.getAnswerVariables(), answerTuples); | 121 | Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration()); |
| 119 | } finally { | 122 | answerWriter.write(answerTuples.getAnswerVariables(), answerTuples); |
| 120 | if (answerTuples != null) answerTuples.dispose(); | 123 | } finally { |
| 121 | } | 124 | if(answerTuples != null) answerTuples.dispose(); |
| 122 | } | 125 | } |
| 123 | } finally { | 126 | } |
| 124 | answerWriter.close(); | 127 | } finally { |
| 125 | } | 128 | answerWriter.close(); |
| 126 | 129 | } | |
| 127 | Utility.logDebug("done computing query answers by RDFox."); | 130 | |
| 128 | 131 | Utility.logDebug("done computing query answers by RDFox."); | |
| 129 | } | 132 | } |
| 130 | 133 | ||
| 134 | @Override | ||
| 135 | public void dispose() { | ||
| 136 | super.dispose(); | ||
| 137 | } | ||
| 131 | } | 138 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/DatalogProgram.java b/src/uk/ac/ox/cs/pagoda/rules/DatalogProgram.java index 1f7148c..29e74c2 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/DatalogProgram.java +++ b/src/uk/ac/ox/cs/pagoda/rules/DatalogProgram.java | |||
| @@ -1,64 +1,74 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.rules; | 1 | package uk.ac.ox.cs.pagoda.rules; |
| 2 | 2 | ||
| 3 | import org.semanticweb.owlapi.model.OWLOntology; | 3 | import org.semanticweb.owlapi.model.OWLOntology; |
| 4 | import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; | ||
| 5 | import uk.ac.ox.cs.pagoda.constraints.PredicateDependency; | ||
| 6 | import uk.ac.ox.cs.pagoda.constraints.UpperUnaryBottom; | ||
| 7 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; | ||
| 8 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 4 | 9 | ||
| 5 | import uk.ac.ox.cs.pagoda.constraints.*; | 10 | public class DatalogProgram extends Disposable { |
| 6 | 11 | ||
| 7 | public class DatalogProgram { | 12 | UpperDatalogProgram upperProgram = new UpperDatalogProgram(); |
| 13 | LowerDatalogProgram lowerProgram; | ||
| 14 | GeneralProgram program = new GeneralProgram(); | ||
| 8 | 15 | ||
| 9 | UpperDatalogProgram upperProgram = new UpperDatalogProgram(); | 16 | BottomStrategy upperBottom; |
| 10 | LowerDatalogProgram lowerProgram; | ||
| 11 | GeneralProgram program = new GeneralProgram(); | ||
| 12 | |||
| 13 | BottomStrategy upperBottom; | ||
| 14 | |||
| 15 | public DatalogProgram(OWLOntology o) { | ||
| 16 | lowerProgram = new LowerDatalogProgram(); | ||
| 17 | init(o, false); | ||
| 18 | } | ||
| 19 | |||
| 20 | public DatalogProgram(OWLOntology o, boolean toClassify) { | ||
| 21 | lowerProgram = new LowerDatalogProgram(toClassify); | ||
| 22 | init(o, toClassify); | ||
| 23 | } | ||
| 24 | 17 | ||
| 25 | private void init(OWLOntology o, boolean forSemFacet) { | 18 | public DatalogProgram(OWLOntology o) { |
| 26 | upperProgram.load(o, upperBottom = new UpperUnaryBottom()); | 19 | lowerProgram = new LowerDatalogProgram(); |
| 27 | // upperProgram.load(o, upperBottom = new UnaryBottom()); | 20 | init(o, false); |
| 28 | lowerProgram.clone(upperProgram); | 21 | } |
| 29 | program.clone(upperProgram); | 22 | |
| 30 | // program.botStrategy = new UnaryBottom(); | 23 | public DatalogProgram(OWLOntology o, boolean toClassify) { |
| 31 | 24 | lowerProgram = new LowerDatalogProgram(toClassify); | |
| 32 | upperProgram.transform(); | 25 | init(o, toClassify); |
| 33 | lowerProgram.transform(); | 26 | } |
| 34 | program.transform(); | 27 | |
| 35 | 28 | public LowerDatalogProgram getLower() { | |
| 36 | program.buildDependencyGraph(); | 29 | if(isDisposed()) throw new DisposedException(); |
| 37 | PredicateDependency graph = upperProgram.buildDependencyGraph(); | 30 | return lowerProgram; |
| 38 | lowerProgram.dependencyGraph = graph; | 31 | } |
| 39 | } | 32 | |
| 33 | public UpperDatalogProgram getUpper() { | ||
| 34 | if(isDisposed()) throw new DisposedException(); | ||
| 35 | return upperProgram; | ||
| 36 | } | ||
| 37 | |||
| 38 | public GeneralProgram getGeneral() { | ||
| 39 | if(isDisposed()) throw new DisposedException(); | ||
| 40 | return program; | ||
| 41 | } | ||
| 40 | 42 | ||
| 41 | public LowerDatalogProgram getLower() { | 43 | public String getAdditionalDataFile() { |
| 42 | return lowerProgram; | 44 | if(isDisposed()) throw new DisposedException(); |
| 43 | } | 45 | return upperProgram.getAdditionalDataFile(); |
| 44 | 46 | } | |
| 45 | public UpperDatalogProgram getUpper() { | 47 | |
| 46 | return upperProgram; | 48 | public BottomStrategy getUpperBottomStrategy() { |
| 47 | } | 49 | if(isDisposed()) throw new DisposedException(); |
| 48 | 50 | return upperBottom; | |
| 49 | public GeneralProgram getGeneral() { | 51 | } |
| 50 | return program; | 52 | |
| 51 | } | 53 | @Override |
| 52 | 54 | public void dispose() { | |
| 53 | public String getAdditionalDataFile() { | 55 | super.dispose(); |
| 54 | return upperProgram.getAdditionalDataFile(); | 56 | if(upperProgram != null) upperProgram.deleteABoxTurtleFile(); |
| 55 | } | 57 | } |
| 58 | |||
| 59 | private void init(OWLOntology o, boolean forSemFacet) { | ||
| 60 | upperProgram.load(o, upperBottom = new UpperUnaryBottom()); | ||
| 61 | // upperProgram.load(o, upperBottom = new UnaryBottom()); | ||
| 62 | lowerProgram.clone(upperProgram); | ||
| 63 | program.clone(upperProgram); | ||
| 64 | // program.botStrategy = new UnaryBottom(); | ||
| 56 | 65 | ||
| 57 | public BottomStrategy getUpperBottomStrategy() { | 66 | upperProgram.transform(); |
| 58 | return upperBottom; | 67 | lowerProgram.transform(); |
| 59 | } | 68 | program.transform(); |
| 60 | 69 | ||
| 61 | public void deleteABoxTurtleFile() { | 70 | program.buildDependencyGraph(); |
| 62 | if (upperProgram != null) upperProgram.deleteABoxTurtleFile(); | 71 | PredicateDependency graph = upperProgram.buildDependencyGraph(); |
| 63 | } | 72 | lowerProgram.dependencyGraph = graph; |
| 73 | } | ||
| 64 | } | 74 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/Program.java b/src/uk/ac/ox/cs/pagoda/rules/Program.java index 2e5302b..4e147bb 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/Program.java +++ b/src/uk/ac/ox/cs/pagoda/rules/Program.java | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.rules; | 1 | package uk.ac.ox.cs.pagoda.rules; |
| 2 | 2 | ||
| 3 | import org.apache.commons.io.FilenameUtils; | ||
| 3 | import org.semanticweb.HermiT.Configuration; | 4 | import org.semanticweb.HermiT.Configuration; |
| 4 | import org.semanticweb.HermiT.model.*; | 5 | import org.semanticweb.HermiT.model.*; |
| 5 | import org.semanticweb.HermiT.structural.OWLClausification; | 6 | import org.semanticweb.HermiT.structural.OWLClausification; |
| @@ -24,78 +25,180 @@ public abstract class Program implements KnowledgeBase { | |||
| 24 | protected OWLOntology ontology; | 25 | protected OWLOntology ontology; |
| 25 | protected DLOntology dlOntology; | 26 | protected DLOntology dlOntology; |
| 26 | protected BottomStrategy botStrategy; | 27 | protected BottomStrategy botStrategy; |
| 27 | |||
| 28 | private String additionalDataFile = null; | ||
| 29 | |||
| 30 | protected Collection<DLClause> clauses = new HashSet<DLClause>(); | 28 | protected Collection<DLClause> clauses = new HashSet<DLClause>(); |
| 31 | // protected Set<DLClause> used = new HashSet<DLClause>(); | 29 | // protected Set<DLClause> used = new HashSet<DLClause>(); |
| 32 | protected PredicateDependency dependencyGraph; | 30 | protected PredicateDependency dependencyGraph; |
| 33 | 31 | protected LinkedList<OWLTransitiveObjectPropertyAxiom> transitiveAxioms; | |
| 34 | /** | 32 | protected LinkedList<DLClause> transitiveClauses; |
| 35 | * clone all information of another program after load() | 33 | protected LinkedList<OWLSubPropertyChainOfAxiom> subPropChainAxioms; |
| 36 | * | 34 | protected LinkedList<DLClause> subPropChainClauses; |
| 37 | * @param program | 35 | private String additionalDataFile = null; |
| 38 | */ | 36 | |
| 39 | void clone(Program program) { | 37 | public static String toString(Collection<DLClause> clauses) { |
| 40 | this.ontologyDirectory = program.ontologyDirectory; | 38 | StringBuilder sb = new StringBuilder(DLClauseHelper.toString(clauses)); |
| 41 | this.ontology = program.ontology; | 39 | sb.insert(0, MyPrefixes.PAGOdAPrefixes.prefixesText()); |
| 42 | this.dlOntology = program.dlOntology; | 40 | return sb.toString(); |
| 43 | this.botStrategy = program.botStrategy; | ||
| 44 | this.additionalDataFile = program.additionalDataFile; | ||
| 45 | this.transitiveAxioms = program.transitiveAxioms; | ||
| 46 | this.transitiveClauses = program.transitiveClauses; | ||
| 47 | this.subPropChainAxioms = program.subPropChainAxioms; | ||
| 48 | this.subPropChainClauses = program.subPropChainClauses; | ||
| 49 | } | 41 | } |
| 50 | 42 | ||
| 51 | public void load(OWLOntology o, BottomStrategy botStrategy) { | 43 | public void load(OWLOntology o, BottomStrategy botStrategy) { |
| 52 | this.botStrategy = botStrategy; | 44 | this.botStrategy = botStrategy; |
| 53 | RLPlusOntology owlOntology = new RLPlusOntology(); | 45 | RLPlusOntology owlOntology = new RLPlusOntology(); |
| 54 | owlOntology.load(o, new NullaryBottom()); | 46 | owlOntology.load(o, new NullaryBottom()); |
| 55 | owlOntology.simplify(); | 47 | owlOntology.simplify(); |
| 56 | 48 | ||
| 57 | ontology = owlOntology.getTBox(); | 49 | ontology = owlOntology.getTBox(); |
| 58 | String ontologyPath = OWLHelper.getOntologyPath(ontology); | 50 | // String ontologyPath = OWLHelper.getOntologyPath(ontology); |
| 59 | ontologyDirectory = ontologyPath.substring(0, ontologyPath.lastIndexOf(Utility.JAVA_FILE_SEPARATOR)); | 51 | // ontologyDirectory = ontologyPath.substring(0, ontologyPath.lastIndexOf(Utility.JAVA_FILE_SEPARATOR)); |
| 60 | clausify(); | 52 | String ontologyPath = ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology).toURI().getPath(); |
| 61 | 53 | ontologyDirectory = FilenameUtils.getFullPath(ontologyPath); | |
| 54 | clausify(); | ||
| 55 | |||
| 62 | String aboxOWLFile = owlOntology.getABoxPath(); | 56 | String aboxOWLFile = owlOntology.getABoxPath(); |
| 63 | OWLOntology abox = OWLHelper.loadOntology(aboxOWLFile); | 57 | OWLOntology abox = OWLHelper.loadOntology(aboxOWLFile); |
| 64 | OWLOntologyManager manager = abox.getOWLOntologyManager(); | 58 | OWLOntologyManager manager = abox.getOWLOntologyManager(); |
| 65 | OWLAxiom axiom; | 59 | OWLAxiom axiom; |
| 66 | for (Atom atom: dlOntology.getPositiveFacts()) { | 60 | for (Atom atom: dlOntology.getPositiveFacts()) { |
| 67 | if ((axiom = OWLHelper.getABoxAssertion(manager.getOWLDataFactory(), atom)) != null) | 61 | if ((axiom = OWLHelper.getABoxAssertion(manager.getOWLDataFactory(), atom)) != null) |
| 68 | manager.addAxiom(abox, axiom); | 62 | manager.addAxiom(abox, axiom); |
| 69 | } | 63 | } |
| 70 | 64 | ||
| 71 | try { | 65 | try { |
| 72 | FileOutputStream out = new FileOutputStream(aboxOWLFile); | 66 | FileOutputStream out = new FileOutputStream(aboxOWLFile); |
| 73 | manager.saveOntology(abox, out); | 67 | manager.saveOntology(abox, out); |
| 74 | out.close(); | 68 | out.close(); |
| 75 | } catch (OWLOntologyStorageException e) { | 69 | } catch(IOException | OWLOntologyStorageException e) { |
| 76 | // TODO Auto-generated catch block | ||
| 77 | e.printStackTrace(); | ||
| 78 | } catch (FileNotFoundException e) { | ||
| 79 | // TODO Auto-generated catch block | ||
| 80 | e.printStackTrace(); | ||
| 81 | } catch (IOException e) { | ||
| 82 | // TODO Auto-generated catch block | ||
| 83 | e.printStackTrace(); | 70 | e.printStackTrace(); |
| 71 | System.exit(1); | ||
| 84 | } | 72 | } |
| 85 | 73 | ||
| 86 | if (!abox.isEmpty()) { | 74 | if (!abox.isEmpty()) { |
| 87 | SimpleETL rewriter = new SimpleETL(owlOntology.getOntologyIRI(), aboxOWLFile); | 75 | SimpleETL rewriter = new SimpleETL(owlOntology.getOntologyIRI(), aboxOWLFile); |
| 88 | try { | 76 | try { |
| 89 | rewriter.rewrite(); | 77 | rewriter.rewrite(); |
| 90 | } catch (Exception e) { | 78 | } catch (Exception e) { |
| 91 | e.printStackTrace(); | 79 | e.printStackTrace(); |
| 92 | } | 80 | } |
| 93 | additionalDataFile = rewriter.getExportedFile(); | 81 | additionalDataFile = rewriter.getExportedFile(); |
| 94 | new File(aboxOWLFile).delete(); | 82 | new File(aboxOWLFile).delete(); |
| 95 | } | 83 | } |
| 96 | 84 | ||
| 85 | } | ||
| 86 | |||
| 87 | public String getAdditionalDataFile() { | ||
| 88 | return additionalDataFile; | ||
| 89 | } | ||
| 90 | |||
| 91 | @Override | ||
| 92 | public void transform() { | ||
| 93 | for(DLClause dlClause : dlOntology.getDLClauses()) { | ||
| 94 | DLClause simplifiedDLClause = DLClauseHelper.removeNominalConcept(dlClause); | ||
| 95 | simplifiedDLClause = removeAuxiliaryBodyAtoms(simplifiedDLClause); | ||
| 96 | simplifiedDLClause = DLClauseHelper.replaceWithDataValue(simplifiedDLClause); | ||
| 97 | convert(simplifiedDLClause); | ||
| 98 | } | ||
| 99 | |||
| 100 | addingTransitiveAxioms(); | ||
| 101 | addingSubPropertyChainAxioms(); | ||
| 102 | |||
| 103 | Collection<DLClause> botRelated = new LinkedList<DLClause>(); | ||
| 104 | Variable X = Variable.create("X"); | ||
| 105 | botRelated.add(DLClause.create(new Atom[0], new Atom[]{Atom.create(Inequality.INSTANCE, X, X)})); | ||
| 106 | clauses.addAll(botStrategy.process(botRelated)); | ||
| 107 | |||
| 108 | if(this instanceof GeneralProgram) | ||
| 109 | Utility.logInfo("The number of rules: " + (clauses.size() - 1)); | ||
| 97 | } | 110 | } |
| 98 | 111 | ||
| 112 | @Override | ||
| 113 | public void save() { | ||
| 114 | try { | ||
| 115 | BufferedWriter ruleWriter = new BufferedWriter(new OutputStreamWriter( | ||
| 116 | new FileOutputStream(getOutputPath()))); | ||
| 117 | ruleWriter.write(toString()); | ||
| 118 | ruleWriter.close(); | ||
| 119 | } catch(IOException e) { | ||
| 120 | e.printStackTrace(); | ||
| 121 | } | ||
| 122 | Utility.logDebug("The rules are saved in " + getOutputPath() + "."); | ||
| 123 | } | ||
| 124 | |||
| 125 | @Override | ||
| 126 | public String toString() { | ||
| 127 | return toString(clauses); | ||
| 128 | } | ||
| 129 | |||
| 130 | public final void convert(DLClause clause) { | ||
| 131 | Collection<DLClause> tempClauses = convert2Clauses(clause); | ||
| 132 | clauses.addAll(tempClauses); | ||
| 133 | } | ||
| 134 | |||
| 135 | public abstract Collection<DLClause> convert2Clauses(DLClause clause); | ||
| 136 | |||
| 137 | public abstract String getOutputPath(); | ||
| 138 | |||
| 139 | public OWLOntology getOntology() { | ||
| 140 | return ontology; | ||
| 141 | } | ||
| 142 | |||
| 143 | public Collection<DLClause> getClauses() { | ||
| 144 | return clauses; | ||
| 145 | } | ||
| 146 | |||
| 147 | public Collection<DLClause> getClauses(DLClause queryClause) { | ||
| 148 | // if (true) return new HashSet<DLClause>(clauses); | ||
| 149 | Set<DLPredicate> predicates = new HashSet<DLPredicate>(); | ||
| 150 | predicates.addAll(dependencyGraph.collectPredicate(queryClause.getBodyAtoms())); | ||
| 151 | |||
| 152 | Set<DLPredicate> dependence = new HashSet<DLPredicate>(); | ||
| 153 | for(DLPredicate predicate : predicates) | ||
| 154 | dependence.addAll(dependencyGraph.getAncesters(predicate)); | ||
| 155 | |||
| 156 | Collection<DLClause> relevantClauses = new LinkedList<DLClause>(); | ||
| 157 | for(DLClause clause : clauses) { | ||
| 158 | if(relevant(clause, dependence)) | ||
| 159 | relevantClauses.add(clause); | ||
| 160 | |||
| 161 | } | ||
| 162 | return relevantClauses; | ||
| 163 | } | ||
| 164 | |||
| 165 | public PredicateDependency buildDependencyGraph() { | ||
| 166 | if(dependencyGraph == null) | ||
| 167 | return dependencyGraph = new PredicateDependency(clauses); | ||
| 168 | else | ||
| 169 | return dependencyGraph; | ||
| 170 | } | ||
| 171 | |||
| 172 | public void getDependencyGraph(PredicateDependency g) { | ||
| 173 | dependencyGraph = g; | ||
| 174 | } | ||
| 175 | |||
| 176 | public final String getDirectory() { | ||
| 177 | return Utility.getGlobalTempDirAbsolutePath(); | ||
| 178 | } | ||
| 179 | |||
| 180 | public void deleteABoxTurtleFile() { | ||
| 181 | if(additionalDataFile != null) | ||
| 182 | new File(additionalDataFile).delete(); | ||
| 183 | } | ||
| 184 | |||
| 185 | /** | ||
| 186 | * clone all information of another program after load() | ||
| 187 | * | ||
| 188 | * @param program | ||
| 189 | */ | ||
| 190 | void clone(Program program) { | ||
| 191 | this.ontologyDirectory = program.ontologyDirectory; | ||
| 192 | this.ontology = program.ontology; | ||
| 193 | this.dlOntology = program.dlOntology; | ||
| 194 | this.botStrategy = program.botStrategy; | ||
| 195 | this.additionalDataFile = program.additionalDataFile; | ||
| 196 | this.transitiveAxioms = program.transitiveAxioms; | ||
| 197 | this.transitiveClauses = program.transitiveClauses; | ||
| 198 | this.subPropChainAxioms = program.subPropChainAxioms; | ||
| 199 | this.subPropChainClauses = program.subPropChainClauses; | ||
| 200 | } | ||
| 201 | |||
| 99 | private void clausify() { | 202 | private void clausify() { |
| 100 | Configuration conf = new Configuration(); | 203 | Configuration conf = new Configuration(); |
| 101 | OWLClausification clausifier = new OWLClausification(conf); | 204 | OWLClausification clausifier = new OWLClausification(conf); |
| @@ -103,121 +206,94 @@ public abstract class Program implements KnowledgeBase { | |||
| 103 | OWLOntologyManager manager = ontology.getOWLOntologyManager(); | 206 | OWLOntologyManager manager = ontology.getOWLOntologyManager(); |
| 104 | try { | 207 | try { |
| 105 | filteredOntology = manager.createOntology(); | 208 | filteredOntology = manager.createOntology(); |
| 106 | } catch (OWLOntologyCreationException e) { | 209 | } catch(OWLOntologyCreationException e) { |
| 107 | e.printStackTrace(); | 210 | e.printStackTrace(); |
| 108 | } | 211 | } |
| 109 | 212 | ||
| 110 | transitiveAxioms = new LinkedList<OWLTransitiveObjectPropertyAxiom>(); | 213 | transitiveAxioms = new LinkedList<OWLTransitiveObjectPropertyAxiom>(); |
| 111 | subPropChainAxioms = new LinkedList<OWLSubPropertyChainOfAxiom>(); | 214 | subPropChainAxioms = new LinkedList<OWLSubPropertyChainOfAxiom>(); |
| 112 | 215 | ||
| 113 | OWLDatatype date = ontology.getOWLOntologyManager().getOWLDataFactory().getOWLDatatype(IRI.create("http://www.w3.org/2001/XMLSchema#date")); | 216 | OWLDatatype date = ontology.getOWLOntologyManager() |
| 114 | int noOfDataPropertyRangeAxioms = 0, noOfAxioms = 0; | 217 | .getOWLDataFactory() |
| 115 | for (OWLOntology onto: ontology.getImportsClosure()) | 218 | .getOWLDatatype(IRI.create("http://www.w3.org/2001/XMLSchema#date")); |
| 116 | for (OWLAxiom axiom: onto.getAxioms()) { | 219 | int noOfDataPropertyRangeAxioms = 0, noOfAxioms = 0; |
| 117 | if (axiom instanceof OWLTransitiveObjectPropertyAxiom) | 220 | for(OWLOntology onto : ontology.getImportsClosure()) |
| 221 | for(OWLAxiom axiom : onto.getAxioms()) { | ||
| 222 | if(axiom instanceof OWLTransitiveObjectPropertyAxiom) | ||
| 118 | transitiveAxioms.add((OWLTransitiveObjectPropertyAxiom) axiom); | 223 | transitiveAxioms.add((OWLTransitiveObjectPropertyAxiom) axiom); |
| 119 | else if (axiom instanceof OWLSubPropertyChainOfAxiom) | 224 | else if(axiom instanceof OWLSubPropertyChainOfAxiom) |
| 120 | subPropChainAxioms.add((OWLSubPropertyChainOfAxiom) axiom); | 225 | subPropChainAxioms.add((OWLSubPropertyChainOfAxiom) axiom); |
| 121 | // TODO to filter out datatype axioms | 226 | // TODO to filter out datatype axioms |
| 122 | else if (axiom instanceof OWLDataPropertyRangeAxiom) { | 227 | else if(axiom instanceof OWLDataPropertyRangeAxiom) { |
| 123 | ++noOfDataPropertyRangeAxioms; | 228 | ++noOfDataPropertyRangeAxioms; |
| 124 | Utility.logInfo("The axiom: " + axiom + " is being ignored."); | 229 | Utility.logInfo("The axiom: " + axiom + " is being ignored."); |
| 125 | } | 230 | } |
| 126 | else { | 231 | else { |
| 127 | if (axiom.getDatatypesInSignature().contains(date)) { | 232 | if(axiom.getDatatypesInSignature().contains(date)) { |
| 128 | Utility.logInfo("The axiom: " + axiom + " is being ignored."); | 233 | Utility.logInfo("The axiom: " + axiom + " is being ignored."); |
| 129 | } | 234 | } |
| 130 | else manager.addAxiom(filteredOntology, axiom); | 235 | else manager.addAxiom(filteredOntology, axiom); |
| 131 | } | 236 | } |
| 132 | 237 | ||
| 133 | if (axiom instanceof OWLAnnotationAssertionAxiom || | 238 | if(axiom instanceof OWLAnnotationAssertionAxiom || |
| 134 | axiom instanceof OWLSubAnnotationPropertyOfAxiom || | 239 | axiom instanceof OWLSubAnnotationPropertyOfAxiom || |
| 135 | axiom instanceof OWLDeclarationAxiom || | 240 | axiom instanceof OWLDeclarationAxiom || |
| 136 | axiom instanceof OWLDataPropertyRangeAxiom) { | 241 | axiom instanceof OWLDataPropertyRangeAxiom) { |
| 137 | } | 242 | } |
| 138 | else { | 243 | else { |
| 139 | // System.out.println(axiom); | 244 | // System.out.println(axiom); |
| 140 | ++noOfAxioms; | 245 | ++noOfAxioms; |
| 141 | } | 246 | } |
| 142 | 247 | ||
| 143 | } | 248 | } |
| 144 | Utility.logInfo("The number of data property range axioms that are ignored: " + noOfDataPropertyRangeAxioms + "(" + noOfAxioms + ")"); | 249 | Utility.logInfo("The number of data property range axioms that are ignored: " + noOfDataPropertyRangeAxioms + "(" + noOfAxioms + ")"); |
| 145 | 250 | ||
| 146 | dlOntology = (DLOntology)clausifier.preprocessAndClausify(filteredOntology, null)[1]; | 251 | dlOntology = (DLOntology) clausifier.preprocessAndClausify(filteredOntology, null)[1]; |
| 147 | clausifier = null; | 252 | clausifier = null; |
| 148 | } | 253 | } |
| 149 | |||
| 150 | public String getAdditionalDataFile() { | ||
| 151 | return additionalDataFile; | ||
| 152 | } | ||
| 153 | |||
| 154 | protected LinkedList<OWLTransitiveObjectPropertyAxiom> transitiveAxioms; | ||
| 155 | protected LinkedList<DLClause> transitiveClauses; | ||
| 156 | |||
| 157 | protected LinkedList<OWLSubPropertyChainOfAxiom> subPropChainAxioms; | ||
| 158 | protected LinkedList<DLClause> subPropChainClauses; | ||
| 159 | |||
| 160 | @Override | ||
| 161 | public void transform() { | ||
| 162 | for (DLClause dlClause: dlOntology.getDLClauses()) { | ||
| 163 | DLClause simplifiedDLClause = DLClauseHelper.removeNominalConcept(dlClause); | ||
| 164 | simplifiedDLClause = removeAuxiliaryBodyAtoms(simplifiedDLClause); | ||
| 165 | simplifiedDLClause = DLClauseHelper.replaceWithDataValue(simplifiedDLClause); | ||
| 166 | convert(simplifiedDLClause); | ||
| 167 | } | ||
| 168 | 254 | ||
| 169 | addingTransitiveAxioms(); | ||
| 170 | addingSubPropertyChainAxioms(); | ||
| 171 | |||
| 172 | Collection<DLClause> botRelated = new LinkedList<DLClause>(); | ||
| 173 | Variable X = Variable.create("X"); | ||
| 174 | botRelated.add(DLClause.create(new Atom[0], new Atom[] {Atom.create(Inequality.INSTANCE, X, X)})); | ||
| 175 | clauses.addAll(botStrategy.process(botRelated)); | ||
| 176 | |||
| 177 | if (this instanceof GeneralProgram) | ||
| 178 | Utility.logInfo("The number of rules: " + (clauses.size() - 1)); | ||
| 179 | } | ||
| 180 | |||
| 181 | private DLClause removeAuxiliaryBodyAtoms(DLClause dlClause) { | 255 | private DLClause removeAuxiliaryBodyAtoms(DLClause dlClause) { |
| 182 | Collection<Atom> newBodyAtoms = new LinkedList<Atom>(); | 256 | Collection<Atom> newBodyAtoms = new LinkedList<Atom>(); |
| 183 | DLPredicate p; | 257 | DLPredicate p; |
| 184 | for (Atom bodyAtom: dlClause.getBodyAtoms()) { | 258 | for(Atom bodyAtom : dlClause.getBodyAtoms()) { |
| 185 | p = bodyAtom.getDLPredicate(); | 259 | p = bodyAtom.getDLPredicate(); |
| 186 | if (p instanceof AtomicConcept || | 260 | if(p instanceof AtomicConcept || |
| 187 | p instanceof AtomicRole || p instanceof InverseRole || | 261 | p instanceof AtomicRole || p instanceof InverseRole || |
| 188 | p instanceof Equality || p instanceof AnnotatedEquality || p instanceof Inequality) | 262 | p instanceof Equality || p instanceof AnnotatedEquality || p instanceof Inequality) |
| 189 | newBodyAtoms.add(bodyAtom); | 263 | newBodyAtoms.add(bodyAtom); |
| 190 | } | 264 | } |
| 191 | LinkedList<Atom> newHeadAtoms = new LinkedList<Atom>(); | 265 | LinkedList<Atom> newHeadAtoms = new LinkedList<Atom>(); |
| 192 | Map<Variable, Term> assign = new HashMap<Variable, Term>(); | 266 | Map<Variable, Term> assign = new HashMap<Variable, Term>(); |
| 193 | for (Atom headAtom: dlClause.getHeadAtoms()) { | 267 | for(Atom headAtom : dlClause.getHeadAtoms()) { |
| 194 | p = headAtom.getDLPredicate(); | 268 | p = headAtom.getDLPredicate(); |
| 195 | if (p instanceof AtomicNegationDataRange) { | 269 | if(p instanceof AtomicNegationDataRange) { |
| 196 | AtomicDataRange positive = ((AtomicNegationDataRange) p).getNegatedDataRange(); | 270 | AtomicDataRange positive = ((AtomicNegationDataRange) p).getNegatedDataRange(); |
| 197 | if (!(positive instanceof ConstantEnumeration)) | 271 | if(!(positive instanceof ConstantEnumeration)) |
| 198 | newBodyAtoms.add(Atom.create(positive, headAtom.getArgument(0))); | 272 | newBodyAtoms.add(Atom.create(positive, headAtom.getArgument(0))); |
| 199 | else if (((ConstantEnumeration) positive).getNumberOfConstants() == 1) { | 273 | else if(((ConstantEnumeration) positive).getNumberOfConstants() == 1) { |
| 200 | assign.put((Variable) headAtom.getArgument(0), ((ConstantEnumeration) positive).getConstant(0)); | 274 | assign.put((Variable) headAtom.getArgument(0), ((ConstantEnumeration) positive).getConstant(0)); |
| 201 | // newBodyAtoms.add(Atom.create(Equality.INSTANCE, headAtom.getArgument(0), ((ConstantEnumeration) positive).getConstant(0))); | 275 | // newBodyAtoms.add(Atom.create(Equality.INSTANCE, headAtom.getArgument(0), ((ConstantEnumeration) positive).getConstant(0))); |
| 202 | } | 276 | } |
| 203 | else newHeadAtoms.add(headAtom); | 277 | else newHeadAtoms.add(headAtom); |
| 204 | } | 278 | } |
| 205 | else | 279 | else |
| 206 | newHeadAtoms.add(headAtom); | 280 | newHeadAtoms.add(headAtom); |
| 207 | } | 281 | } |
| 208 | 282 | ||
| 209 | if (assign.isEmpty() && newHeadAtoms.isEmpty() && newBodyAtoms.size() == dlClause.getBodyLength()) | 283 | if(assign.isEmpty() && newHeadAtoms.isEmpty() && newBodyAtoms.size() == dlClause.getBodyLength()) |
| 210 | return dlClause; | 284 | return dlClause; |
| 211 | 285 | ||
| 212 | Atom[] headArray = newHeadAtoms.size() == dlClause.getHeadLength() ? dlClause.getHeadAtoms() : newHeadAtoms.toArray(new Atom[0]); | 286 | Atom[] headArray = |
| 213 | Atom[] bodyArray = newBodyAtoms.size() == dlClause.getBodyLength() ? dlClause.getBodyAtoms() : newBodyAtoms.toArray(new Atom[0]); | 287 | newHeadAtoms.size() == dlClause.getHeadLength() ? dlClause.getHeadAtoms() : newHeadAtoms.toArray(new Atom[0]); |
| 214 | if (!assign.isEmpty()) { | 288 | Atom[] bodyArray = |
| 215 | for (int i = 0; i < headArray.length; ++i) | 289 | newBodyAtoms.size() == dlClause.getBodyLength() ? dlClause.getBodyAtoms() : newBodyAtoms.toArray(new Atom[0]); |
| 216 | headArray[i] = DLClauseHelper.getInstance(headArray[i], assign); | 290 | if(!assign.isEmpty()) { |
| 217 | for (int i = 0; i < bodyArray.length; ++i) | 291 | for(int i = 0; i < headArray.length; ++i) |
| 218 | bodyArray[i] = DLClauseHelper.getInstance(bodyArray[i], assign); | 292 | headArray[i] = DLClauseHelper.getInstance(headArray[i], assign); |
| 293 | for(int i = 0; i < bodyArray.length; ++i) | ||
| 294 | bodyArray[i] = DLClauseHelper.getInstance(bodyArray[i], assign); | ||
| 219 | } | 295 | } |
| 220 | return DLClause.create(headArray, bodyArray); | 296 | return DLClause.create(headArray, bodyArray); |
| 221 | } | 297 | } |
| 222 | 298 | ||
| 223 | private void addingTransitiveAxioms() { | 299 | private void addingTransitiveAxioms() { |
| @@ -225,136 +301,58 @@ public abstract class Program implements KnowledgeBase { | |||
| 225 | Atom headAtom; | 301 | Atom headAtom; |
| 226 | Variable X = Variable.create("X"), Y = Variable.create("Y"), Z = Variable.create("Z"); | 302 | Variable X = Variable.create("X"), Y = Variable.create("Y"), Z = Variable.create("Z"); |
| 227 | transitiveClauses = new LinkedList<DLClause>(); | 303 | transitiveClauses = new LinkedList<DLClause>(); |
| 228 | for (OWLTransitiveObjectPropertyAxiom axiom: transitiveAxioms) { | 304 | for(OWLTransitiveObjectPropertyAxiom axiom : transitiveAxioms) { |
| 229 | OWLObjectPropertyExpression objExp = axiom.getProperty(); | 305 | OWLObjectPropertyExpression objExp = axiom.getProperty(); |
| 230 | headAtom = getAtom(objExp, X, Z); | 306 | headAtom = getAtom(objExp, X, Z); |
| 231 | Atom[] bodyAtoms = new Atom[2]; | 307 | Atom[] bodyAtoms = new Atom[2]; |
| 232 | bodyAtoms[0] = getAtom(objExp, X, Y); | 308 | bodyAtoms[0] = getAtom(objExp, X, Y); |
| 233 | bodyAtoms[1] = getAtom(objExp, Y, Z); | 309 | bodyAtoms[1] = getAtom(objExp, Y, Z); |
| 234 | transitiveClause = DLClause.create(new Atom[] {headAtom}, bodyAtoms); | 310 | transitiveClause = DLClause.create(new Atom[]{headAtom}, bodyAtoms); |
| 235 | clauses.add(transitiveClause); | 311 | clauses.add(transitiveClause); |
| 236 | transitiveClauses.add(transitiveClause); | 312 | transitiveClauses.add(transitiveClause); |
| 237 | } | 313 | } |
| 238 | } | 314 | } |
| 239 | 315 | ||
| 240 | private Atom getAtom(OWLObjectPropertyExpression exp, Variable x, Variable y) { | 316 | private Atom getAtom(OWLObjectPropertyExpression exp, Variable x, Variable y) { |
| 241 | if (exp instanceof OWLObjectProperty) | 317 | if(exp instanceof OWLObjectProperty) |
| 242 | return Atom.create(AtomicRole.create(((OWLObjectProperty) exp).toStringID()), x, y); | 318 | return Atom.create(AtomicRole.create(((OWLObjectProperty) exp).toStringID()), x, y); |
| 243 | OWLObjectInverseOf inverseOf; | 319 | OWLObjectInverseOf inverseOf; |
| 244 | if (exp instanceof OWLObjectInverseOf && (inverseOf = (OWLObjectInverseOf) exp).getInverse() instanceof OWLObjectProperty) | 320 | if(exp instanceof OWLObjectInverseOf && (inverseOf = |
| 321 | (OWLObjectInverseOf) exp).getInverse() instanceof OWLObjectProperty) | ||
| 245 | return Atom.create(AtomicRole.create(((OWLObjectProperty) inverseOf).toStringID()), x, y); | 322 | return Atom.create(AtomicRole.create(((OWLObjectProperty) inverseOf).toStringID()), x, y); |
| 246 | return null; | 323 | return null; |
| 247 | } | 324 | } |
| 248 | 325 | ||
| 249 | private void addingSubPropertyChainAxioms() { | 326 | private void addingSubPropertyChainAxioms() { |
| 250 | DLClause dlClause; | 327 | DLClause dlClause; |
| 251 | subPropChainClauses = new LinkedList<DLClause>(); | 328 | subPropChainClauses = new LinkedList<DLClause>(); |
| 252 | Atom headAtom; | 329 | Atom headAtom; |
| 253 | Iterator<OWLObjectPropertyExpression> iterExp; | 330 | Iterator<OWLObjectPropertyExpression> iterExp; |
| 254 | OWLObjectPropertyExpression objExp; | 331 | OWLObjectPropertyExpression objExp; |
| 255 | for (OWLSubPropertyChainOfAxiom axiom: subPropChainAxioms) { | 332 | for(OWLSubPropertyChainOfAxiom axiom : subPropChainAxioms) { |
| 256 | objExp = axiom.getSuperProperty(); | 333 | objExp = axiom.getSuperProperty(); |
| 257 | List<OWLObjectPropertyExpression> objs = axiom.getPropertyChain(); | 334 | List<OWLObjectPropertyExpression> objs = axiom.getPropertyChain(); |
| 258 | headAtom = getAtom(objExp, Variable.create("X"), Variable.create("X" + objs.size())); | 335 | headAtom = getAtom(objExp, Variable.create("X"), Variable.create("X" + objs.size())); |
| 259 | iterExp = objs.iterator(); | 336 | iterExp = objs.iterator(); |
| 260 | int index = 1; | 337 | int index = 1; |
| 261 | Atom[] bodyAtoms = new Atom[objs.size()]; | 338 | Atom[] bodyAtoms = new Atom[objs.size()]; |
| 262 | bodyAtoms[0] = getAtom(iterExp.next(), Variable.create("X"), Variable.create("X1")); | 339 | bodyAtoms[0] = getAtom(iterExp.next(), Variable.create("X"), Variable.create("X1")); |
| 263 | while (index < objs.size()) { | 340 | while(index < objs.size()) { |
| 264 | bodyAtoms[index] = getAtom(iterExp.next(), Variable.create("X" + index), Variable.create("X" + (index + 1))); | 341 | bodyAtoms[index] = |
| 265 | ++index; | 342 | getAtom(iterExp.next(), Variable.create("X" + index), Variable.create("X" + (index + 1))); |
| 343 | ++index; | ||
| 266 | } | 344 | } |
| 267 | dlClause = DLClause.create(new Atom[] {headAtom}, bodyAtoms); | 345 | dlClause = DLClause.create(new Atom[]{headAtom}, bodyAtoms); |
| 268 | clauses.add(dlClause); | 346 | clauses.add(dlClause); |
| 269 | subPropChainClauses.add(dlClause); | 347 | subPropChainClauses.add(dlClause); |
| 270 | } | 348 | } |
| 271 | } | 349 | } |
| 272 | 350 | ||
| 273 | @Override | ||
| 274 | public void save() { | ||
| 275 | try { | ||
| 276 | BufferedWriter ruleWriter = new BufferedWriter(new OutputStreamWriter( | ||
| 277 | new FileOutputStream(getOutputPath()))); | ||
| 278 | ruleWriter.write(toString()); | ||
| 279 | ruleWriter.close(); | ||
| 280 | } catch (IOException e) { | ||
| 281 | e.printStackTrace(); | ||
| 282 | } | ||
| 283 | Utility.logDebug("The rules are saved in " + getOutputPath() + "."); | ||
| 284 | } | ||
| 285 | |||
| 286 | @Override | ||
| 287 | public String toString() { | ||
| 288 | return toString(clauses); | ||
| 289 | } | ||
| 290 | |||
| 291 | public static String toString(Collection<DLClause> clauses) { | ||
| 292 | StringBuilder sb = new StringBuilder(DLClauseHelper.toString(clauses)); | ||
| 293 | sb.insert(0, MyPrefixes.PAGOdAPrefixes.prefixesText()); | ||
| 294 | return sb.toString(); | ||
| 295 | } | ||
| 296 | |||
| 297 | public final void convert(DLClause clause) { | ||
| 298 | Collection<DLClause> tempClauses = convert2Clauses(clause); | ||
| 299 | clauses.addAll(tempClauses); | ||
| 300 | } | ||
| 301 | |||
| 302 | public abstract Collection<DLClause> convert2Clauses(DLClause clause); | ||
| 303 | |||
| 304 | public abstract String getOutputPath(); | ||
| 305 | |||
| 306 | |||
| 307 | public OWLOntology getOntology() { | ||
| 308 | return ontology; | ||
| 309 | } | ||
| 310 | |||
| 311 | public Collection<DLClause> getClauses() { | ||
| 312 | return clauses; | ||
| 313 | } | ||
| 314 | |||
| 315 | public Collection<DLClause> getClauses(DLClause queryClause) { | ||
| 316 | // if (true) return new HashSet<DLClause>(clauses); | ||
| 317 | Set<DLPredicate> predicates = new HashSet<DLPredicate>(); | ||
| 318 | predicates.addAll(dependencyGraph.collectPredicate(queryClause.getBodyAtoms())); | ||
| 319 | |||
| 320 | Set<DLPredicate> dependence = new HashSet<DLPredicate>(); | ||
| 321 | for (DLPredicate predicate: predicates) | ||
| 322 | dependence.addAll(dependencyGraph.getAncesters(predicate)); | ||
| 323 | |||
| 324 | Collection<DLClause> relevantClauses = new LinkedList<DLClause>(); | ||
| 325 | for (DLClause clause: clauses) { | ||
| 326 | if (relevant(clause, dependence)) | ||
| 327 | relevantClauses.add(clause); | ||
| 328 | |||
| 329 | } | ||
| 330 | return relevantClauses; | ||
| 331 | } | ||
| 332 | |||
| 333 | private boolean relevant(DLClause clause, Set<DLPredicate> set) { | 351 | private boolean relevant(DLClause clause, Set<DLPredicate> set) { |
| 334 | for (DLPredicate p: dependencyGraph.collectPredicate(clause.getHeadAtoms())) | 352 | for(DLPredicate p : dependencyGraph.collectPredicate(clause.getHeadAtoms())) |
| 335 | if (set.contains(p)) | 353 | if(set.contains(p)) |
| 336 | return true; | 354 | return true; |
| 337 | return false; | 355 | return false; |
| 338 | } | ||
| 339 | |||
| 340 | public PredicateDependency buildDependencyGraph() { | ||
| 341 | if (dependencyGraph == null) | ||
| 342 | return dependencyGraph = new PredicateDependency(clauses); | ||
| 343 | else | ||
| 344 | return dependencyGraph; | ||
| 345 | } | ||
| 346 | |||
| 347 | public void getDependencyGraph(PredicateDependency g) { | ||
| 348 | dependencyGraph = g; | ||
| 349 | } | ||
| 350 | |||
| 351 | public final String getDirectory() { | ||
| 352 | return Utility.getGlobalTempDirAbsolutePath(); | ||
| 353 | } | ||
| 354 | |||
| 355 | public void deleteABoxTurtleFile() { | ||
| 356 | if (additionalDataFile != null) | ||
| 357 | new File(additionalDataFile).delete(); | ||
| 358 | } | 356 | } |
| 359 | 357 | ||
| 360 | } | 358 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoder.java b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoder.java index f3cc937..d8ebc55 100644 --- a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoder.java +++ b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoder.java | |||
| @@ -1,387 +1,387 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.tracking; | 1 | package uk.ac.ox.cs.pagoda.tracking; |
| 2 | 2 | ||
| 3 | import java.io.BufferedWriter; | 3 | import org.semanticweb.HermiT.model.*; |
| 4 | import java.io.FileOutputStream; | ||
| 5 | import java.io.IOException; | ||
| 6 | import java.io.OutputStreamWriter; | ||
| 7 | import java.util.Collection; | ||
| 8 | import java.util.HashMap; | ||
| 9 | import java.util.HashSet; | ||
| 10 | import java.util.LinkedList; | ||
| 11 | import java.util.Map; | ||
| 12 | import java.util.Set; | ||
| 13 | |||
| 14 | import org.semanticweb.HermiT.model.AnnotatedEquality; | ||
| 15 | import org.semanticweb.HermiT.model.Atom; | ||
| 16 | import org.semanticweb.HermiT.model.AtomicConcept; | ||
| 17 | import org.semanticweb.HermiT.model.AtomicRole; | ||
| 18 | import org.semanticweb.HermiT.model.Constant; | ||
| 19 | import org.semanticweb.HermiT.model.DLClause; | ||
| 20 | import org.semanticweb.HermiT.model.DLPredicate; | ||
| 21 | import org.semanticweb.HermiT.model.DatatypeRestriction; | ||
| 22 | import org.semanticweb.HermiT.model.Equality; | ||
| 23 | import org.semanticweb.HermiT.model.Individual; | ||
| 24 | import org.semanticweb.HermiT.model.Inequality; | ||
| 25 | import org.semanticweb.HermiT.model.Variable; | ||
| 26 | import org.semanticweb.owlapi.model.OWLOntology; | 4 | import org.semanticweb.owlapi.model.OWLOntology; |
| 27 | |||
| 28 | import uk.ac.ox.cs.JRDFox.model.Datatype; | 5 | import uk.ac.ox.cs.JRDFox.model.Datatype; |
| 29 | import uk.ac.ox.cs.JRDFox.model.GroundTerm; | 6 | import uk.ac.ox.cs.JRDFox.model.GroundTerm; |
| 30 | import uk.ac.ox.cs.JRDFox.model.Literal; | 7 | import uk.ac.ox.cs.JRDFox.model.Literal; |
| 31 | import uk.ac.ox.cs.pagoda.MyPrefixes; | 8 | import uk.ac.ox.cs.pagoda.MyPrefixes; |
| 32 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | 9 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; |
| 33 | import uk.ac.ox.cs.pagoda.query.*; | 10 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; |
| 11 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 12 | import uk.ac.ox.cs.pagoda.query.GapTupleIterator; | ||
| 13 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 34 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 14 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 35 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; | 15 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; |
| 36 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; | 16 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; |
| 37 | import uk.ac.ox.cs.pagoda.util.Namespace; | 17 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 38 | import uk.ac.ox.cs.pagoda.util.Utility; | 18 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 19 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; | ||
| 20 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 21 | |||
| 22 | import java.io.BufferedWriter; | ||
| 23 | import java.io.FileOutputStream; | ||
| 24 | import java.io.IOException; | ||
| 25 | import java.io.OutputStreamWriter; | ||
| 26 | import java.util.*; | ||
| 27 | |||
| 28 | public abstract class TrackingRuleEncoder extends Disposable { | ||
| 29 | public static final String trackingPredicateRelation = Namespace.PAGODA_AUX + "isTrackingPredicateFor"; | ||
| 30 | public static final String QueryPredicate = Namespace.PAGODA_AUX + "Query"; | ||
| 31 | protected BasicQueryEngine store; | ||
| 32 | protected QueryRecord currentQuery; | ||
| 33 | protected Set<String> unaryPredicates = new HashSet<String>(); | ||
| 34 | protected Set<String> binaryPredicates = new HashSet<String>(); | ||
| 35 | UpperDatalogProgram program; | ||
| 36 | Collection<DLClause> trackingClauses = new HashSet<DLClause>(); | ||
| 37 | Collection<DLClause> queryClauses = new LinkedList<DLClause>(); | ||
| 38 | Map<Integer, DLClause> index2clause = new HashMap<Integer, DLClause>(); | ||
| 39 | Map<DLClause, Integer> clause2index = new HashMap<DLClause, Integer>(); | ||
| 40 | String equalityRelatedRuleText = null; | ||
| 41 | boolean ruleEncoded = false; | ||
| 42 | DLPredicate selected; | ||
| 43 | private boolean queryEncoded = false; | ||
| 44 | private LinkedList<int[]> addedData = new LinkedList<int[]>(); | ||
| 45 | private String trackingSuffix; | ||
| 46 | |||
| 47 | public TrackingRuleEncoder(UpperDatalogProgram program, BasicQueryEngine store) { | ||
| 48 | this.program = program; | ||
| 49 | this.store = store; | ||
| 50 | } | ||
| 51 | |||
| 52 | public static String getRawTerm(GroundTerm r) { | ||
| 53 | if(r instanceof uk.ac.ox.cs.JRDFox.model.Individual) | ||
| 54 | return ((uk.ac.ox.cs.JRDFox.model.Individual) r).getIRI(); | ||
| 55 | else { | ||
| 56 | Literal l = (Literal) r; | ||
| 57 | if(l.getDatatype().equals(Datatype.XSD_STRING) && l.getDatatype().equals(Datatype.RDF_PLAIN_LITERAL)) | ||
| 58 | return "\"" + l.getLexicalForm() + "\""; | ||
| 59 | else | ||
| 60 | return "\"" + l.getLexicalForm() + "\"^^<" + l.getDatatype().getIRI() + ">"; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | protected static String getTrackingSuffix(String queryID) { | ||
| 65 | return "_AUXt" + queryID; | ||
| 66 | } | ||
| 67 | |||
| 68 | public boolean encodingRules() { | ||
| 69 | if(isDisposed()) throw new DisposedException(); | ||
| 70 | if(ruleEncoded) return false; | ||
| 71 | ruleEncoded = true; | ||
| 39 | 72 | ||
| 40 | public abstract class TrackingRuleEncoder { | ||
| 41 | UpperDatalogProgram program; | ||
| 42 | Collection<DLClause> trackingClauses = new HashSet<DLClause>(); | ||
| 43 | Collection<DLClause> queryClauses = new LinkedList<DLClause>(); | ||
| 44 | |||
| 45 | Map<Integer, DLClause> index2clause = new HashMap<Integer, DLClause>(); | ||
| 46 | Map<DLClause, Integer> clause2index = new HashMap<DLClause, Integer>(); | ||
| 47 | |||
| 48 | String equalityRelatedRuleText = null; | ||
| 49 | protected BasicQueryEngine store; | ||
| 50 | |||
| 51 | public TrackingRuleEncoder(UpperDatalogProgram program, BasicQueryEngine store) { | ||
| 52 | this.program = program; | ||
| 53 | this.store = store; | ||
| 54 | } | ||
| 55 | |||
| 56 | protected abstract String getEqualityRelatedRuleText(); | ||
| 57 | |||
| 58 | boolean ruleEncoded = false; | ||
| 59 | |||
| 60 | public boolean encodingRules() { | ||
| 61 | if (ruleEncoded) return false; | ||
| 62 | ruleEncoded = true; | ||
| 63 | |||
| 64 | // for (DLClause clause: program.getClauses(currentQuery.getClause())) { | 73 | // for (DLClause clause: program.getClauses(currentQuery.getClause())) { |
| 65 | for (DLClause clause: program.getClauses()) { | 74 | for(DLClause clause : program.getClauses()) { |
| 66 | encodingRule(clause); | 75 | encodingRule(clause); |
| 67 | } | 76 | } |
| 68 | return true; | 77 | return true; |
| 69 | } | 78 | } |
| 70 | 79 | ||
| 71 | protected String getIRI(String name) { | 80 | public Collection<int[]> getAddedData() { |
| 72 | return program.getOntology().getOntologyID().getOntologyIRI().toString() + "#" + name; | 81 | if(isDisposed()) throw new DisposedException(); |
| 73 | } | 82 | return addedData; |
| 74 | 83 | } | |
| 75 | protected abstract void encodingRule(DLClause clause); | 84 | |
| 76 | 85 | public String getTrackingPredicate(String predicateIRI) { | |
| 77 | protected Individual getIndividual4GeneralRule(DLClause clause) { | 86 | if(isDisposed()) throw new DisposedException(); |
| 78 | clause = program.getCorrespondingClause(clause); | 87 | if(predicateIRI.startsWith("<")) |
| 88 | return predicateIRI.replace(">", getTrackingSuffix(currentQuery.getQueryID()) + ">"); | ||
| 89 | else | ||
| 90 | return predicateIRI + getTrackingSuffix(currentQuery.getQueryID()); | ||
| 91 | } | ||
| 92 | |||
| 93 | public void setCurrentQuery(QueryRecord record) { | ||
| 94 | if(isDisposed()) throw new DisposedException(); | ||
| 95 | deprecateTrackingAndQueryRules(); | ||
| 96 | currentQuery = record; | ||
| 97 | selected = AtomicConcept.create(getSelectedPredicate()); | ||
| 98 | trackingSuffix = "_AUXt" + currentQuery.getQueryID(); | ||
| 99 | } | ||
| 100 | |||
| 101 | @Override | ||
| 102 | public void dispose() { | ||
| 103 | super.dispose(); | ||
| 104 | deprecateTrackingAndQueryRules(); | ||
| 105 | } | ||
| 106 | |||
| 107 | public String getTrackingProgram() { | ||
| 108 | if(isDisposed()) throw new DisposedException(); | ||
| 109 | StringBuilder sb = getTrackingProgramBody(); | ||
| 110 | sb.insert(0, MyPrefixes.PAGOdAPrefixes.prefixesText()); | ||
| 111 | return sb.toString(); | ||
| 112 | } | ||
| 113 | |||
| 114 | public void saveTrackingRules(String fileName) { | ||
| 115 | if(isDisposed()) throw new DisposedException(); | ||
| 116 | BufferedWriter writer = null; | ||
| 117 | try { | ||
| 118 | writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))); | ||
| 119 | writer.write(getTrackingProgram()); | ||
| 120 | writer.close(); | ||
| 121 | } catch(IOException e) { | ||
| 122 | e.printStackTrace(); | ||
| 123 | return; | ||
| 124 | } | ||
| 125 | Utility.logDebug("The tracking rules are saved in " + fileName + "."); | ||
| 126 | } | ||
| 127 | |||
| 128 | public String getSelectedPredicate() { | ||
| 129 | if(isDisposed()) throw new DisposedException(); | ||
| 130 | return getIRI("_selected" + currentQuery.getQueryID()); | ||
| 131 | } | ||
| 132 | |||
| 133 | public DLClause getSelectedClause(String iri) { | ||
| 134 | if(isDisposed()) throw new DisposedException(); | ||
| 135 | int index = iri.lastIndexOf("_r") + 2; | ||
| 136 | int ruleIndex = Integer.parseInt(iri.substring(index)); | ||
| 137 | return index2clause.get(ruleIndex); | ||
| 138 | } | ||
| 139 | |||
| 140 | /** | ||
| 141 | * SELECT ?X | ||
| 142 | * WHERE { | ||
| 143 | * ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#:type> :_selected? | ||
| 144 | * } | ||
| 145 | */ | ||
| 146 | public String getSelectedSPARQLQuery() { | ||
| 147 | if(isDisposed()) throw new DisposedException(); | ||
| 148 | StringBuilder builder = new StringBuilder(); | ||
| 149 | builder.append("SELECT ?X\nWHERE {\n?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "); | ||
| 150 | builder.append(selected.toString()).append("\n}"); | ||
| 151 | return builder.toString(); | ||
| 152 | } | ||
| 153 | |||
| 154 | public OWLOntology getOntology() { | ||
| 155 | if(isDisposed()) throw new DisposedException(); | ||
| 156 | return program.getOntology(); | ||
| 157 | } | ||
| 158 | |||
| 159 | public UpperDatalogProgram getProgram() { | ||
| 160 | if(isDisposed()) throw new DisposedException(); | ||
| 161 | return program; | ||
| 162 | } | ||
| 163 | |||
| 164 | public String getOriginalPredicate(String p) { | ||
| 165 | if(isDisposed()) throw new DisposedException(); | ||
| 166 | if(p.startsWith("<")) { | ||
| 167 | if(!p.endsWith(trackingSuffix + ">")) return null; | ||
| 168 | } | ||
| 169 | else if(!p.endsWith(trackingSuffix)) return null; | ||
| 170 | |||
| 171 | return p.replace(trackingSuffix, ""); | ||
| 172 | } | ||
| 173 | |||
| 174 | public boolean isAuxPredicate(String p) { | ||
| 175 | if(isDisposed()) throw new DisposedException(); | ||
| 176 | return false; | ||
| 177 | } | ||
| 178 | |||
| 179 | protected abstract String getEqualityRelatedRuleText(); | ||
| 180 | |||
| 181 | protected String getIRI(String name) { | ||
| 182 | return program.getOntology().getOntologyID().getOntologyIRI().toString() + "#" + name; | ||
| 183 | } | ||
| 184 | |||
| 185 | protected abstract void encodingRule(DLClause clause); | ||
| 186 | |||
| 187 | protected Individual getIndividual4GeneralRule(DLClause clause) { | ||
| 188 | clause = program.getCorrespondingClause(clause); | ||
| 79 | // if (clause == null) | 189 | // if (clause == null) |
| 80 | // return Individual.create(getIRI("_r0")); | 190 | // return Individual.create(getIRI("_r0")); |
| 81 | 191 | ||
| 82 | int index; | 192 | int index; |
| 83 | if (clause2index.containsKey(clause)) | 193 | if(clause2index.containsKey(clause)) |
| 84 | index = clause2index.get(clause); | 194 | index = clause2index.get(clause); |
| 85 | else { | 195 | else { |
| 86 | index = clause2index.size() + 1; | 196 | index = clause2index.size() + 1; |
| 87 | index2clause.put(index, clause); | 197 | index2clause.put(index, clause); |
| 88 | clause2index.put(clause, index); | 198 | clause2index.put(clause, index); |
| 89 | } | 199 | } |
| 90 | 200 | ||
| 91 | return Individual.create(getIRI("_r" + index)); | 201 | return Individual.create(getIRI("_r" + index)); |
| 92 | } | 202 | } |
| 93 | 203 | ||
| 94 | private boolean queryEncoded = false; | 204 | private void encodingQuery(QueryRecord[] botQuerRecords) { |
| 95 | private LinkedList<int[]> addedData = new LinkedList<int[]>(); | 205 | if(queryEncoded) return; |
| 96 | 206 | queryEncoded = true; | |
| 97 | public Collection<int[]> getAddedData() { | 207 | |
| 98 | return addedData; | 208 | if(currentQuery.getArity() > 0 && currentQuery.getArity() < 3) { |
| 99 | } | 209 | encodingAtomicQuery(botQuerRecords); |
| 100 | 210 | ||
| 101 | private void encodingQuery(QueryRecord[] botQuerRecords) { | 211 | } |
| 102 | if (queryEncoded) return ; | 212 | else { |
| 103 | queryEncoded = true; | 213 | DLClause queryClause = currentQuery.getClause(); |
| 104 | 214 | Atom[] bodyAtoms = queryClause.getBodyAtoms(); | |
| 105 | if (currentQuery.getArity() > 0 && currentQuery.getArity() < 3) { | 215 | for(Atom bodyAtom : bodyAtoms) |
| 106 | encodingAtomicQuery(botQuerRecords); | 216 | addQueryRule(bodyAtom, bodyAtoms); |
| 107 | 217 | } | |
| 108 | } else { | 218 | } |
| 109 | DLClause queryClause = currentQuery.getClause(); | 219 | |
| 110 | Atom[] bodyAtoms = queryClause.getBodyAtoms(); | 220 | private void addQueryRule(Atom atom, Atom[] atoms) { |
| 111 | for (Atom bodyAtom: bodyAtoms) | 221 | DLClause newClause; |
| 112 | addQueryRule(bodyAtom, bodyAtoms); | 222 | Atom headAtom; |
| 113 | } | 223 | |
| 114 | } | 224 | headAtom = Atom.create( |
| 115 | 225 | getTrackingDLPredicate(atom.getDLPredicate()), | |
| 116 | private void addQueryRule(Atom atom, Atom[] atoms) { | 226 | DLClauseHelper.getArguments(atom)); |
| 117 | DLClause newClause; | 227 | newClause = DLClause.create(new Atom[]{headAtom}, atoms); |
| 118 | Atom headAtom; | 228 | queryClauses.add(newClause); |
| 119 | 229 | } | |
| 120 | headAtom = Atom.create( | 230 | |
| 121 | getTrackingDLPredicate(atom.getDLPredicate()), | 231 | protected String getCurrentQueryPredicate() { |
| 122 | DLClauseHelper.getArguments(atom)); | 232 | return QueryPredicate + currentQuery.getQueryID(); |
| 123 | newClause = DLClause.create(new Atom[] {headAtom}, atoms); | 233 | } |
| 124 | queryClauses.add(newClause); | 234 | |
| 125 | } | 235 | protected void encodingAtomicQuery(QueryRecord[] botQuerRecords) { |
| 126 | 236 | encodingAtomicQuery(botQuerRecords, false); | |
| 127 | public static final String trackingPredicateRelation = Namespace.PAGODA_AUX + "isTrackingPredicateFor"; | 237 | } |
| 128 | 238 | ||
| 129 | public static final String QueryPredicate = Namespace.PAGODA_AUX + "Query"; | 239 | protected void encodingAtomicQuery(QueryRecord[] botQuerRecords, boolean includingBottom) { |
| 130 | 240 | DLClause queryClause = currentQuery.getClause(); | |
| 131 | protected String getCurrentQueryPredicate() { | 241 | AnswerTuples answerTuples = currentQuery.getGapAnswers(); |
| 132 | return QueryPredicate + currentQuery.getQueryID(); | 242 | String[] answerVariables = currentQuery.getAnswerVariables(); |
| 133 | } | 243 | |
| 134 | 244 | String currentQueryPredicate = getCurrentQueryPredicate(); | |
| 135 | protected void encodingAtomicQuery(QueryRecord[] botQuerRecords) { | 245 | Atom newAtom; |
| 136 | encodingAtomicQuery(botQuerRecords, false); | 246 | if(answerVariables.length == 1) { |
| 137 | } | 247 | AtomicConcept queryConcept = AtomicConcept.create(currentQueryPredicate); |
| 138 | 248 | newAtom = Atom.create(queryConcept, Variable.create(answerVariables[0])); | |
| 139 | protected void encodingAtomicQuery(QueryRecord[] botQuerRecords, boolean includingBottom) { | 249 | } |
| 140 | DLClause queryClause = currentQuery.getClause(); | 250 | else { |
| 141 | AnswerTuples answerTuples = currentQuery.getGapAnswers(); | 251 | AtomicRole queryRole = AtomicRole.create(currentQueryPredicate); |
| 142 | String[] answerVariables = currentQuery.getAnswerVariables(); | 252 | newAtom = Atom.create(queryRole, Variable.create(answerVariables[0]), Variable.create(answerVariables[1])); |
| 143 | 253 | } | |
| 144 | String currentQueryPredicate = getCurrentQueryPredicate(); | 254 | |
| 145 | Atom newAtom; | 255 | Atom[] bodyAtoms = queryClause.getBodyAtoms(); |
| 146 | if (answerVariables.length == 1) { | 256 | Atom[] newBodyAtoms = new Atom[queryClause.getBodyLength() + 1]; |
| 147 | AtomicConcept queryConcept = AtomicConcept.create(currentQueryPredicate); | 257 | for(int i = 0; i < bodyAtoms.length; ++i) |
| 148 | newAtom = Atom.create(queryConcept, Variable.create(answerVariables[0])); | 258 | newBodyAtoms[i + 1] = bodyAtoms[i]; |
| 149 | } | 259 | newBodyAtoms[0] = newAtom; |
| 150 | else { | 260 | |
| 151 | AtomicRole queryRole = AtomicRole.create(currentQueryPredicate); | 261 | for(Atom bodyAtom : bodyAtoms) |
| 152 | newAtom = Atom.create(queryRole, Variable.create(answerVariables[0]), Variable.create(answerVariables[1])); | 262 | addQueryRule(bodyAtom, newBodyAtoms); |
| 153 | } | 263 | |
| 154 | 264 | RDFoxTripleManager tripleManager = new RDFoxTripleManager(store.getDataStore(), true); | |
| 155 | Atom[] bodyAtoms = queryClause.getBodyAtoms(); | ||
| 156 | Atom[] newBodyAtoms = new Atom[queryClause.getBodyLength() + 1]; | ||
| 157 | for (int i = 0; i < bodyAtoms.length; ++i) | ||
| 158 | newBodyAtoms[i + 1] = bodyAtoms[i]; | ||
| 159 | newBodyAtoms[0] = newAtom; | ||
| 160 | |||
| 161 | for (Atom bodyAtom: bodyAtoms) | ||
| 162 | addQueryRule(bodyAtom, newBodyAtoms); | ||
| 163 | |||
| 164 | RDFoxTripleManager tripleManager = new RDFoxTripleManager(store.getDataStore(), true); | ||
| 165 | // MyPrefixes prefixes = MyPrefixes.PAGOdAPrefixes; | 265 | // MyPrefixes prefixes = MyPrefixes.PAGOdAPrefixes; |
| 166 | int[] triple; | 266 | int[] triple; |
| 167 | int predicate = tripleManager.getResourceID(AtomicConcept.create(currentQueryPredicate)); | 267 | int predicate = tripleManager.getResourceID(AtomicConcept.create(currentQueryPredicate)); |
| 168 | int rdftype = tripleManager.getResourceID(AtomicRole.create(Namespace.RDF_TYPE)); | 268 | int rdftype = tripleManager.getResourceID(AtomicRole.create(Namespace.RDF_TYPE)); |
| 169 | if (answerVariables.length == 1) { | 269 | if(answerVariables.length == 1) { |
| 170 | for (AnswerTuple answer; answerTuples.isValid(); answerTuples.moveNext()) { | 270 | for(AnswerTuple answer; answerTuples.isValid(); answerTuples.moveNext()) { |
| 171 | answer = answerTuples.getTuple(); | 271 | answer = answerTuples.getTuple(); |
| 172 | triple = new int[] { tripleManager.getResourceID(getRawTerm(answer.getGroundTerm(0))), rdftype, predicate }; | 272 | triple = |
| 173 | addedData.add(triple); | 273 | new int[]{tripleManager.getResourceID(getRawTerm(answer.getGroundTerm(0))), rdftype, predicate}; |
| 174 | tripleManager.addTripleByID(triple); | 274 | addedData.add(triple); |
| 175 | // System.out.println("To be removed ... \n" + tripleManager.getRawTerm(tripleManager.getResourceID(prefixes.expandIRI(answer.getRawTerm(0)))) + " " + tripleManager.getRawTerm(rdftype) + " " + tripleManager.getRawTerm(predicate)); | 275 | tripleManager.addTripleByID(triple); |
| 176 | } | 276 | // System.out.println("To be removed ... \n" + tripleManager.getRawTerm(tripleManager.getResourceID(prefixes.expandIRI(answer.getRawTerm(0)))) + " " + tripleManager.getRawTerm(rdftype) + " " + tripleManager.getRawTerm(predicate)); |
| 177 | } | 277 | } |
| 178 | else { | 278 | } |
| 179 | for (AnswerTuple answer; answerTuples.isValid(); answerTuples.moveNext()) { | 279 | else { |
| 180 | answer = answerTuples.getTuple(); | 280 | for(AnswerTuple answer; answerTuples.isValid(); answerTuples.moveNext()) { |
| 181 | triple = new int[] { tripleManager.getResourceID(getRawTerm(answer.getGroundTerm(0))), predicate, tripleManager.getResourceID(getRawTerm(answer.getGroundTerm(1))) }; | 281 | answer = answerTuples.getTuple(); |
| 182 | addedData.add(triple); | 282 | triple = |
| 183 | tripleManager.addTripleByID(triple); | 283 | new int[]{tripleManager.getResourceID(getRawTerm(answer.getGroundTerm(0))), predicate, tripleManager |
| 184 | } | 284 | .getResourceID(getRawTerm(answer.getGroundTerm(1)))}; |
| 185 | } | 285 | addedData.add(triple); |
| 186 | answerTuples.dispose(); | 286 | tripleManager.addTripleByID(triple); |
| 187 | 287 | } | |
| 188 | if (includingBottom && botQuerRecords != null) { | 288 | } |
| 189 | int index = 0; | 289 | // answerTuples.dispose(); |
| 190 | GroundTerm t; | 290 | |
| 191 | String raw; | 291 | if(includingBottom && botQuerRecords != null) { |
| 192 | for (QueryRecord botQueryRecord: botQuerRecords) { | 292 | int index = 0; |
| 193 | answerTuples = botQueryRecord.getGapAnswers(); | 293 | GroundTerm t; |
| 194 | int subID = 0;//botQueryRecord.getSubID(); | 294 | String raw; |
| 195 | String p = subID == 0 ? AtomicConcept.NOTHING.getIRI() : Namespace.OWL_NS + "Nothing_final" + (++index); | 295 | for(QueryRecord botQueryRecord : botQuerRecords) { |
| 196 | predicate = tripleManager.getResourceID(AtomicConcept.create(p = getTrackingPredicate(p))); | 296 | answerTuples = botQueryRecord.getGapAnswers(); |
| 197 | for (AnswerTuple answer; answerTuples.isValid(); answerTuples.moveNext()) { | 297 | int subID = 0;//botQueryRecord.getSubID(); |
| 198 | answer = answerTuples.getTuple(); | 298 | String p = subID == 0 ? AtomicConcept.NOTHING.getIRI() : Namespace.OWL_NS + "Nothing_final" + (++index); |
| 299 | predicate = tripleManager.getResourceID(AtomicConcept.create(p = getTrackingPredicate(p))); | ||
| 300 | for(AnswerTuple answer; answerTuples.isValid(); answerTuples.moveNext()) { | ||
| 301 | answer = answerTuples.getTuple(); | ||
| 199 | // System.out.println("To be removed ... " + answer.getRawTerm(0)); | 302 | // System.out.println("To be removed ... " + answer.getRawTerm(0)); |
| 200 | raw = ((t = answer.getGroundTerm(0)) instanceof uk.ac.ox.cs.JRDFox.model.Individual) ? ((uk.ac.ox.cs.JRDFox.model.Individual) t).getIRI() : t.toString(); | 303 | raw = ((t = |
| 201 | triple = new int[] { tripleManager.getResourceID(raw), rdftype, predicate }; | 304 | answer.getGroundTerm(0)) instanceof uk.ac.ox.cs.JRDFox.model.Individual) ? ((uk.ac.ox.cs.JRDFox.model.Individual) t) |
| 202 | addedData.add(triple); | 305 | .getIRI() : t.toString(); |
| 203 | tripleManager.addTripleByID(triple); | 306 | triple = new int[]{tripleManager.getResourceID(raw), rdftype, predicate}; |
| 204 | } | 307 | addedData.add(triple); |
| 205 | answerTuples.dispose(); | 308 | tripleManager.addTripleByID(triple); |
| 206 | } | 309 | } |
| 207 | } | 310 | // answerTuples.dispose(); |
| 208 | 311 | } | |
| 209 | Utility.logInfo(addedData.size() + " triples are added into the store."); | 312 | } |
| 210 | } | 313 | |
| 211 | 314 | Utility.logInfo(addedData.size() + " triples are added into the store."); | |
| 212 | public static String getRawTerm(GroundTerm r) { | 315 | } |
| 213 | if (r instanceof uk.ac.ox.cs.JRDFox.model.Individual) | 316 | |
| 214 | return ((uk.ac.ox.cs.JRDFox.model.Individual) r).getIRI(); | 317 | protected DLPredicate getGapDLPredicate(DLPredicate dlPredicate) { |
| 215 | else { | 318 | return getDLPredicate(dlPredicate, GapTupleIterator.gapPredicateSuffix); |
| 216 | Literal l = (Literal) r; | 319 | } |
| 217 | if (l.getDatatype().equals(Datatype.XSD_STRING) && l.getDatatype().equals(Datatype.RDF_PLAIN_LITERAL)) | 320 | |
| 218 | return "\"" + l.getLexicalForm() + "\""; | 321 | DLPredicate getDLPredicate(DLPredicate p, String suffix) { |
| 219 | else | 322 | if(isDisposed()) throw new DisposedException(); |
| 220 | return "\"" + l.getLexicalForm() + "\"^^<" + l.getDatatype().getIRI() + ">"; | 323 | if(p instanceof AtomicConcept) |
| 221 | } | 324 | return AtomicConcept.create(((AtomicConcept) p).getIRI() + suffix); |
| 222 | } | 325 | else if(p instanceof DatatypeRestriction) { |
| 223 | 326 | DatatypeRestriction restriction = (DatatypeRestriction) p; | |
| 224 | protected DLPredicate getGapDLPredicate(DLPredicate dlPredicate) { | 327 | String newURI = restriction.getDatatypeURI() + suffix; |
| 225 | return getDLPredicate(dlPredicate, GapTupleIterator.gapPredicateSuffix); | 328 | return getDatatypeRestriction(restriction, newURI); |
| 226 | } | 329 | } |
| 227 | 330 | else if(p instanceof AtomicRole) | |
| 228 | DLPredicate getDLPredicate(DLPredicate p, String suffix) { | 331 | return AtomicRole.create(((AtomicRole) p).getIRI() + suffix); |
| 229 | if (p instanceof AtomicConcept) | 332 | else if(p instanceof AnnotatedEquality || p instanceof Equality) |
| 230 | return AtomicConcept.create(((AtomicConcept) p).getIRI() + suffix); | 333 | return AtomicRole.create(Namespace.EQUALITY + suffix); |
| 231 | else if (p instanceof DatatypeRestriction) { | 334 | else if(p instanceof Inequality) |
| 232 | DatatypeRestriction restriction = (DatatypeRestriction) p; | 335 | return AtomicRole.create(Namespace.INEQUALITY + suffix); |
| 233 | String newURI = restriction.getDatatypeURI() + suffix; | 336 | else if(p instanceof DatatypeRestriction) |
| 234 | return getDatatypeRestriction(restriction, newURI); | 337 | return AtomicConcept.create(((DatatypeRestriction) p).getDatatypeURI() + suffix); |
| 235 | } | 338 | else { |
| 236 | else if (p instanceof AtomicRole) | 339 | Utility.logDebug("strange DL predicate appeared ... " + p, |
| 237 | return AtomicRole.create(((AtomicRole) p).getIRI() + suffix); | 340 | "the program paused here in TrackingRuleEncoderDisj.java"); |
| 238 | else if (p instanceof AnnotatedEquality || p instanceof Equality) | 341 | return null; |
| 239 | return AtomicRole.create(Namespace.EQUALITY + suffix); | 342 | } |
| 240 | else if (p instanceof Inequality) | 343 | } |
| 241 | return AtomicRole.create(Namespace.INEQUALITY + suffix); | 344 | |
| 242 | else if (p instanceof DatatypeRestriction) | 345 | protected DLPredicate getTrackingDLPredicate(DLPredicate dlPredicate) { |
| 243 | return AtomicConcept.create(((DatatypeRestriction) p).getDatatypeURI() + suffix); | 346 | return getDLPredicate(dlPredicate, getTrackingSuffix(currentQuery.getQueryID())); |
| 244 | else { | 347 | } |
| 245 | Utility.logDebug("strange DL predicate appeared ... " + p, | 348 | |
| 246 | "the program paused here in TrackingRuleEncoderDisj.java"); | 349 | protected DLPredicate getDatatypeRestriction(DatatypeRestriction restriction, String newName) { |
| 247 | return null; | 350 | int length = restriction.getNumberOfFacetRestrictions(); |
| 248 | } | 351 | String[] facets = new String[length]; |
| 249 | } | 352 | Constant[] values = new Constant[length]; |
| 250 | 353 | for(int i = 0; i < length; ++i) { | |
| 251 | protected DLPredicate getTrackingDLPredicate(DLPredicate dlPredicate) { | 354 | facets[i] = restriction.getFacetURI(i); |
| 252 | return getDLPredicate(dlPredicate, getTrackingSuffix(currentQuery.getQueryID())); | 355 | values[i] = restriction.getFacetValue(i); |
| 253 | } | 356 | } |
| 254 | 357 | return DatatypeRestriction.create(newName, facets, values); | |
| 255 | protected static String getTrackingSuffix(String queryID) { | 358 | } |
| 256 | return "_AUXt" + queryID; | 359 | |
| 257 | } | 360 | private String getTrackingRuleText() { |
| 258 | 361 | return DLClauseHelper.toString(trackingClauses); | |
| 259 | public String getTrackingPredicate(String predicateIRI) { | 362 | } |
| 260 | if (predicateIRI.startsWith("<")) | 363 | |
| 261 | return predicateIRI.replace(">", getTrackingSuffix(currentQuery.getQueryID()) + ">"); | 364 | private String getQueryRuleText() { |
| 262 | else | 365 | return DLClauseHelper.toString(queryClauses); |
| 263 | return predicateIRI + getTrackingSuffix(currentQuery.getQueryID()); | 366 | } |
| 264 | } | 367 | |
| 265 | 368 | protected StringBuilder getTrackingProgramBody() { | |
| 266 | protected DLPredicate getDatatypeRestriction(DatatypeRestriction restriction, String newName) { | 369 | encodingRules(); |
| 267 | int length = restriction.getNumberOfFacetRestrictions(); | 370 | encodingQuery(new QueryRecord[0]); |
| 268 | String[] facets = new String[length]; | 371 | |
| 269 | Constant[] values = new Constant[length]; | 372 | StringBuilder sb = new StringBuilder(); |
| 270 | for (int i = 0; i < length; ++i) { | 373 | sb.append(getTrackingRuleText()); |
| 271 | facets[i] = restriction.getFacetURI(i); | 374 | sb.append(getEqualityRelatedRuleText()); |
| 272 | values[i] = restriction.getFacetValue(i); | 375 | sb.append(getQueryRuleText()); |
| 273 | } | 376 | return sb; |
| 274 | return DatatypeRestriction.create(newName, facets, values); | 377 | } |
| 275 | } | 378 | |
| 276 | 379 | private void deprecateTrackingAndQueryRules() { | |
| 277 | protected QueryRecord currentQuery; | 380 | trackingClauses.clear(); |
| 278 | DLPredicate selected; | 381 | queryClauses.clear(); |
| 279 | 382 | addedData.clear(); | |
| 280 | public void setCurrentQuery(QueryRecord record) { | 383 | ruleEncoded = false; |
| 281 | deprecateTrackingAndQueryRules(); | 384 | queryEncoded = false; |
| 282 | currentQuery = record; | 385 | } |
| 283 | selected = AtomicConcept.create(getSelectedPredicate()); | 386 | |
| 284 | trackingSuffix = "_AUXt" + currentQuery.getQueryID(); | ||
| 285 | } | ||
| 286 | |||
| 287 | public void dispose() { | ||
| 288 | deprecateTrackingAndQueryRules(); | ||
| 289 | } | ||
| 290 | |||
| 291 | private String getTrackingRuleText() { | ||
| 292 | return DLClauseHelper.toString(trackingClauses); | ||
| 293 | } | ||
| 294 | |||
| 295 | private String getQueryRuleText() { | ||
| 296 | return DLClauseHelper.toString(queryClauses); | ||
| 297 | } | ||
| 298 | |||
| 299 | public String getTrackingProgram() { | ||
| 300 | StringBuilder sb = getTrackingProgramBody(); | ||
| 301 | sb.insert(0, MyPrefixes.PAGOdAPrefixes.prefixesText()); | ||
| 302 | return sb.toString(); | ||
| 303 | } | ||
| 304 | |||
| 305 | protected StringBuilder getTrackingProgramBody() { | ||
| 306 | encodingRules(); | ||
| 307 | encodingQuery(new QueryRecord[0]); | ||
| 308 | |||
| 309 | StringBuilder sb = new StringBuilder(); | ||
| 310 | sb.append(getTrackingRuleText()); | ||
| 311 | sb.append(getEqualityRelatedRuleText()); | ||
| 312 | sb.append(getQueryRuleText()); | ||
| 313 | return sb; | ||
| 314 | } | ||
| 315 | |||
| 316 | public void saveTrackingRules(String fileName) { | ||
| 317 | BufferedWriter writer = null; | ||
| 318 | try { | ||
| 319 | writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))); | ||
| 320 | writer.write(getTrackingProgram()); | ||
| 321 | writer.close(); | ||
| 322 | } catch (IOException e) { | ||
| 323 | e.printStackTrace(); | ||
| 324 | return ; | ||
| 325 | } | ||
| 326 | Utility.logDebug("The tracking rules are saved in " + fileName + "."); | ||
| 327 | } | ||
| 328 | |||
| 329 | private void deprecateTrackingAndQueryRules() { | ||
| 330 | trackingClauses.clear(); | ||
| 331 | queryClauses.clear(); | ||
| 332 | addedData.clear(); | ||
| 333 | ruleEncoded = false; | ||
| 334 | queryEncoded = false; | ||
| 335 | } | ||
| 336 | |||
| 337 | public String getSelectedPredicate() { | ||
| 338 | return getIRI("_selected" + currentQuery.getQueryID()); | ||
| 339 | } | ||
| 340 | |||
| 341 | public DLClause getSelectedClause(String iri) { | ||
| 342 | int index = iri.lastIndexOf("_r") + 2; | ||
| 343 | int ruleIndex = Integer.parseInt(iri.substring(index)); | ||
| 344 | return index2clause.get(ruleIndex); | ||
| 345 | } | ||
| 346 | |||
| 347 | /** | ||
| 348 | * SELECT ?X | ||
| 349 | * WHERE { | ||
| 350 | * ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#:type> :_selected? | ||
| 351 | * } | ||
| 352 | */ | ||
| 353 | public String getSelectedSPARQLQuery() { | ||
| 354 | StringBuilder builder = new StringBuilder(); | ||
| 355 | builder.append("SELECT ?X\nWHERE {\n?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "); | ||
| 356 | builder.append(selected.toString()).append("\n}"); | ||
| 357 | return builder.toString(); | ||
| 358 | } | ||
| 359 | |||
| 360 | public OWLOntology getOntology() { | ||
| 361 | return program.getOntology(); | ||
| 362 | } | ||
| 363 | |||
| 364 | public UpperDatalogProgram getProgram() { | ||
| 365 | return program; | ||
| 366 | } | ||
| 367 | |||
| 368 | private String trackingSuffix; | ||
| 369 | |||
| 370 | public String getOriginalPredicate(String p) { | ||
| 371 | if (p.startsWith("<")) { | ||
| 372 | if (!p.endsWith(trackingSuffix + ">")) return null; | ||
| 373 | } | ||
| 374 | else | ||
| 375 | if (!p.endsWith(trackingSuffix)) return null; | ||
| 376 | |||
| 377 | return p.replace(trackingSuffix, ""); | ||
| 378 | } | ||
| 379 | |||
| 380 | public boolean isAuxPredicate(String p) { | ||
| 381 | return false; | ||
| 382 | } | ||
| 383 | |||
| 384 | protected Set<String> unaryPredicates = new HashSet<String>(); | ||
| 385 | protected Set<String> binaryPredicates = new HashSet<String>(); | ||
| 386 | |||
| 387 | } | 387 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java index c3694ad..4ece796 100644 --- a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java +++ b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java | |||
| @@ -17,7 +17,7 @@ import java.util.LinkedList; | |||
| 17 | import java.util.Set; | 17 | import java.util.Set; |
| 18 | 18 | ||
| 19 | public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { | 19 | public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { |
| 20 | 20 | ||
| 21 | public TrackingRuleEncoderWithGap(UpperDatalogProgram program, BasicQueryEngine store) { | 21 | public TrackingRuleEncoderWithGap(UpperDatalogProgram program, BasicQueryEngine store) { |
| 22 | super(program, store); | 22 | super(program, store); |
| 23 | } | 23 | } |
| @@ -113,6 +113,4 @@ public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { | |||
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | } | 115 | } |
| 116 | |||
| 117 | |||
| 118 | } | 116 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithoutGap.java b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithoutGap.java index be9e45c..f898114 100644 --- a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithoutGap.java +++ b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithoutGap.java | |||
| @@ -1,24 +1,19 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.tracking; | 1 | package uk.ac.ox.cs.pagoda.tracking; |
| 2 | 2 | ||
| 3 | import java.util.Collection; | 3 | import org.semanticweb.HermiT.model.*; |
| 4 | import java.util.LinkedList; | ||
| 5 | |||
| 6 | import org.semanticweb.HermiT.model.Atom; | ||
| 7 | import org.semanticweb.HermiT.model.AtomicConcept; | ||
| 8 | import org.semanticweb.HermiT.model.AtomicRole; | ||
| 9 | import org.semanticweb.HermiT.model.DLClause; | ||
| 10 | import org.semanticweb.HermiT.model.Variable; | ||
| 11 | import org.semanticweb.owlapi.model.OWLClass; | 4 | import org.semanticweb.owlapi.model.OWLClass; |
| 12 | import org.semanticweb.owlapi.model.OWLObjectProperty; | 5 | import org.semanticweb.owlapi.model.OWLObjectProperty; |
| 13 | import org.semanticweb.owlapi.model.OWLOntology; | 6 | import org.semanticweb.owlapi.model.OWLOntology; |
| 14 | |||
| 15 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | 7 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; |
| 16 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 8 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 17 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; | 9 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; |
| 18 | import uk.ac.ox.cs.pagoda.util.Namespace; | 10 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 19 | 11 | ||
| 12 | import java.util.Collection; | ||
| 13 | import java.util.LinkedList; | ||
| 14 | |||
| 20 | public class TrackingRuleEncoderWithoutGap extends TrackingRuleEncoder { | 15 | public class TrackingRuleEncoderWithoutGap extends TrackingRuleEncoder { |
| 21 | 16 | ||
| 22 | public TrackingRuleEncoderWithoutGap(UpperDatalogProgram program, BasicQueryEngine store) { | 17 | public TrackingRuleEncoderWithoutGap(UpperDatalogProgram program, BasicQueryEngine store) { |
| 23 | super(program, store); | 18 | super(program, store); |
| 24 | } | 19 | } |
| @@ -105,5 +100,4 @@ public class TrackingRuleEncoderWithoutGap extends TrackingRuleEncoder { | |||
| 105 | } | 100 | } |
| 106 | 101 | ||
| 107 | } | 102 | } |
| 108 | |||
| 109 | } | 103 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java b/src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java new file mode 100644 index 0000000..b208cc3 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.util.disposable; | ||
| 2 | |||
| 3 | |||
| 4 | /** | ||
| 5 | * Every public method of a subclass of this class, | ||
| 6 | * as first instruction, should check if the object has already been disposed | ||
| 7 | * and, if so, should throw a <tt>DisposedException</tt>. | ||
| 8 | */ | ||
| 9 | public abstract class Disposable { | ||
| 10 | |||
| 11 | private boolean disposed = false; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * This method must be called after the use of the object. | ||
| 15 | * <p> | ||
| 16 | * Every overriding method must call <tt>super.dispose()</tt> as first instruction. | ||
| 17 | */ | ||
| 18 | public void dispose() { | ||
| 19 | if(isDisposed()) throw new AlreadyDisposedException(); | ||
| 20 | disposed = true; | ||
| 21 | } | ||
| 22 | |||
| 23 | public final boolean isDisposed() { | ||
| 24 | return disposed; | ||
| 25 | } | ||
| 26 | |||
| 27 | private class AlreadyDisposedException extends RuntimeException { | ||
| 28 | |||
| 29 | public AlreadyDisposedException() { | ||
| 30 | super(); | ||
| 31 | } | ||
| 32 | |||
| 33 | public AlreadyDisposedException(String msg) { | ||
| 34 | super(msg); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | } | ||
diff --git a/src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java b/src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java new file mode 100644 index 0000000..eb8c039 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.util.disposable; | ||
| 2 | |||
| 3 | public class DisposedException extends RuntimeException { | ||
| 4 | |||
| 5 | public DisposedException() { | ||
| 6 | super(); | ||
| 7 | } | ||
| 8 | |||
| 9 | public DisposedException(String msg) { | ||
| 10 | super(msg); | ||
| 11 | } | ||
| 12 | } | ||
diff --git a/test/resources/LightTests.xml b/test/resources/LightTests.xml index a30c436..ccafa25 100644 --- a/test/resources/LightTests.xml +++ b/test/resources/LightTests.xml | |||
| @@ -10,8 +10,8 @@ | |||
| 10 | </groups> | 10 | </groups> |
| 11 | 11 | ||
| 12 | <classes> | 12 | <classes> |
| 13 | <class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaUOBM"/> | 13 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaUOBM"/>--> |
| 14 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaLUBM"/>--> | 14 | <class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaLUBM"/> |
| 15 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaFLY"/>--> | 15 | <!--<class name="uk.ac.ox.cs.pagoda.global_tests.TestPagodaFLY"/>--> |
| 16 | </classes> | 16 | </classes> |
| 17 | </test> | 17 | </test> |
