diff options
| author | yzhou <yzhou@krr-linux.cs.ox.ac.uk> | 2015-04-29 18:57:39 +0100 |
|---|---|---|
| committer | yzhou <yzhou@krr-linux.cs.ox.ac.uk> | 2015-04-29 18:57:39 +0100 |
| commit | 68ae342b2a4923bc7b3f378c6a489f2355d85279 (patch) | |
| tree | 3a5983964de88ed8aa6c5f3aa56db8ac0b02cfa3 | |
| parent | 6c5d9406d0c9b9dc96bb9599c152256fc9807940 (diff) | |
| download | ACQuA-68ae342b2a4923bc7b3f378c6a489f2355d85279.tar.gz ACQuA-68ae342b2a4923bc7b3f378c6a489f2355d85279.zip | |
added top answers optimisation back
| -rw-r--r-- | config/fly.conf | 1 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java | 3 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | 9 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java | 71 | ||||
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java | 4 |
5 files changed, 46 insertions, 42 deletions
diff --git a/config/fly.conf b/config/fly.conf index 68c36b6..88c85c3 100644 --- a/config/fly.conf +++ b/config/fly.conf | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #ONTOLOGY variable points to the file that stores ontology of interest | 1 | #ONTOLOGY variable points to the file that stores ontology of interest |
| 2 | ONTOLOGY=data/fly/fly_anatomy_XP_with_GJ_FC_individuals.owl | 2 | ONTOLOGY=data/fly/fly_anatomy_XP_with_GJ_FC_individuals.owl |
| 3 | #ONTOLOGY=data/fly/fbbt_vfb_ind_pr_nr.owl | ||
| 3 | 4 | ||
| 4 | #QUERY variable points to the file that stores all queries | 5 | #QUERY variable points to the file that stores all queries |
| 5 | QUERY=data/fly/fly.sparql | 6 | QUERY=data/fly/fly.sparql |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java index 63fe246..9b862ce 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java | |||
| @@ -23,6 +23,7 @@ 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.JRDFox.JRDFStoreException; | 24 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 25 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 25 | import uk.ac.ox.cs.JRDFox.store.DataStore; |
| 26 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 26 | 27 | ||
| 27 | public class ConsistencyManager { | 28 | public class ConsistencyManager { |
| 28 | 29 | ||
| @@ -218,7 +219,7 @@ public class ConsistencyManager { | |||
| 218 | Timer t1 = new Timer(); | 219 | Timer t1 = new Timer(); |
| 219 | oldTripleCount = store.getTriplesCount(); | 220 | oldTripleCount = store.getTriplesCount(); |
| 220 | for (String program: programs) | 221 | for (String program: programs) |
| 221 | store.importRules(program); | 222 | store.importRules(program, UpdateType.ScheduleForAddition); |
| 222 | store.applyReasoning(true); | 223 | store.applyReasoning(true); |
| 223 | tripleCount = store.getTriplesCount(); | 224 | tripleCount = store.getTriplesCount(); |
| 224 | 225 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java index 4970e7a..d5796ad 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | |||
| @@ -21,7 +21,10 @@ import uk.ac.ox.cs.pagoda.util.Utility; | |||
| 21 | public abstract class QueryReasoner { | 21 | public abstract class QueryReasoner { |
| 22 | 22 | ||
| 23 | // protected boolean forSemFacet = false; | 23 | // protected boolean forSemFacet = false; |
| 24 | Properties properties; | 24 | Properties properties; |
| 25 | |||
| 26 | private static boolean defaultMultiStages = true; | ||
| 27 | private static boolean defaultEqualities = true; | ||
| 25 | 28 | ||
| 26 | public static enum Type { Full, RLU, ELHOU }; | 29 | public static enum Type { Full, RLU, ELHOU }; |
| 27 | 30 | ||
| @@ -43,7 +46,7 @@ public abstract class QueryReasoner { | |||
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | public static QueryReasoner getInstance(OWLOntology o) { | 48 | public static QueryReasoner getInstance(OWLOntology o) { |
| 46 | QueryReasoner pagoda = getInstance(Type.Full, o, true, true); | 49 | QueryReasoner pagoda = getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); |
| 47 | pagoda.properties = new Properties(); | 50 | pagoda.properties = new Properties(); |
| 48 | return pagoda; | 51 | return pagoda; |
| 49 | } | 52 | } |
| @@ -57,7 +60,7 @@ public abstract class QueryReasoner { | |||
| 57 | } | 60 | } |
| 58 | 61 | ||
| 59 | private static QueryReasoner getInstance(OWLOntology o, Properties p) { | 62 | private static QueryReasoner getInstance(OWLOntology o, Properties p) { |
| 60 | return getInstance(Type.Full, o, true, true); | 63 | return getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); |
| 61 | } | 64 | } |
| 62 | 65 | ||
| 63 | public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) { | 66 | public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) { |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java b/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java index 4dd11d8..5dcf0f8 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java | |||
| @@ -77,8 +77,7 @@ public class HermitChecker implements Checker { | |||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | private int tag = 0; | 79 | private int tag = 0; |
| 80 | // AnswerTuple topAnswerTuple = null; | 80 | AnswerTuple topAnswerTuple = null, botAnswerTuple = null; |
| 81 | AnswerTuple botAnswerTuple = null; | ||
| 82 | 81 | ||
| 83 | private void initialiseReasoner() { | 82 | private void initialiseReasoner() { |
| 84 | qGraph = new QueryGraph(queryClause.getBodyAtoms(), answerVariable[1], ontology); | 83 | qGraph = new QueryGraph(queryClause.getBodyAtoms(), answerVariable[1], ontology); |
| @@ -88,17 +87,20 @@ public class HermitChecker implements Checker { | |||
| 88 | if (hermit != null) hermit.dispose(); | 87 | if (hermit != null) hermit.dispose(); |
| 89 | 88 | ||
| 90 | if (dGraph != null && answerVariable[1].length == 1 && (dGraph.getExits().size() > 1 || dGraph.getEntrances().size() > 1)) { | 89 | if (dGraph != null && answerVariable[1].length == 1 && (dGraph.getExits().size() > 1 || dGraph.getEntrances().size() > 1)) { |
| 91 | Set<OWLAxiom> axioms = new HashSet<OWLAxiom>(); | 90 | Set<OWLAxiom> topAxioms = new HashSet<OWLAxiom>(); |
| 92 | addTopAndBotTuple(axioms); | 91 | Set<OWLAxiom> botAxioms = new HashSet<OWLAxiom>(); |
| 93 | manager.addAxioms(ontology, axioms); | 92 | addTopAndBotTuple(topAxioms, botAxioms); |
| 93 | manager.addAxioms(ontology, topAxioms); | ||
| 94 | manager.addAxioms(ontology, botAxioms); | ||
| 94 | hermit = new Reasoner(ontology); | 95 | hermit = new Reasoner(ontology); |
| 95 | if (!hermit.isConsistent()) { | 96 | boolean topValid = true; |
| 97 | if (!hermit.isConsistent() || topAnswerTuple != null && (topValid = check(topAnswerTuple))) { | ||
| 96 | hermit.dispose(); | 98 | hermit.dispose(); |
| 97 | manager.removeAxioms(ontology, axioms); | 99 | manager.removeAxioms(ontology, topAxioms); |
| 98 | hermit = new Reasoner(ontology); | 100 | hermit = new Reasoner(ontology); |
| 99 | } else { | 101 | } else { |
| 100 | // if (topAnswerTuple != null && !check(topAnswerTuple)) tag = -1; | 102 | if (!topValid) tag = -1; |
| 101 | // else | 103 | else |
| 102 | if (botAnswerTuple != null && check(botAnswerTuple)) tag = 1; | 104 | if (botAnswerTuple != null && check(botAnswerTuple)) tag = 1; |
| 103 | } | 105 | } |
| 104 | } | 106 | } |
| @@ -106,23 +108,20 @@ public class HermitChecker implements Checker { | |||
| 106 | hermit = new Reasoner(ontology); | 108 | hermit = new Reasoner(ontology); |
| 107 | } | 109 | } |
| 108 | 110 | ||
| 109 | private void addTopAndBotTuple(Set<OWLAxiom> axioms) { | 111 | private void addTopAndBotTuple(Set<OWLAxiom> topAxioms, Set<OWLAxiom> botAxioms) { |
| 110 | // String top_str = Namespace.PAGODA_ANONY + "top"; | 112 | String top_str = Namespace.PAGODA_ANONY + "top", bot_str = Namespace.PAGODA_ANONY + "bot"; |
| 111 | String bot_str = Namespace.PAGODA_ANONY + "bot"; | 113 | topAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(top_str) } ); |
| 112 | // topAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(top_str) } ); | ||
| 113 | botAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(bot_str) } ); | 114 | botAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(bot_str) } ); |
| 114 | // OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)); | 115 | OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)), bot_ind = factory.getOWLNamedIndividual(IRI.create(bot_str)); |
| 115 | OWLIndividual bot_ind = factory.getOWLNamedIndividual(IRI.create(bot_str)); | ||
| 116 | Map<OWLAxiom, Integer> counter = new HashMap<OWLAxiom, Integer>(); | 116 | Map<OWLAxiom, Integer> counter = new HashMap<OWLAxiom, Integer>(); |
| 117 | 117 | ||
| 118 | // Set<String> topAnswers = new HashSet<String>(); | 118 | Set<String> topAnswers = new HashSet<String>(), botAnswers = new HashSet<String>(); |
| 119 | Set<String> botAnswers = new HashSet<String>(); | ||
| 120 | OWLIndividual sub, obj; | 119 | OWLIndividual sub, obj; |
| 121 | // if (dGraph.getExits().size() > 1) { | 120 | if (dGraph.getExits().size() > 1) { |
| 122 | // for (Clique answerClique: dGraph.getExits()) | 121 | for (Clique answerClique: dGraph.getExits()) |
| 123 | // topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative().getAnswerTuple().getGroundTerm(0)).getIRI()); | 122 | topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative().getAnswerTuple().getGroundTerm(0)).getIRI()); |
| 124 | // } | 123 | } |
| 125 | // else topAnswerTuple = null; | 124 | else topAnswerTuple = null; |
| 126 | 125 | ||
| 127 | if (dGraph.getEntrances().size() > 1) { | 126 | if (dGraph.getEntrances().size() > 1) { |
| 128 | for (Clique answerClique: dGraph.getEntrances()) | 127 | for (Clique answerClique: dGraph.getEntrances()) |
| @@ -134,23 +133,23 @@ public class HermitChecker implements Checker { | |||
| 134 | if (axiom instanceof OWLClassAssertionAxiom) { | 133 | if (axiom instanceof OWLClassAssertionAxiom) { |
| 135 | OWLClassAssertionAxiom ca = (OWLClassAssertionAxiom) axiom; | 134 | OWLClassAssertionAxiom ca = (OWLClassAssertionAxiom) axiom; |
| 136 | sub = ca.getIndividual(); | 135 | sub = ca.getIndividual(); |
| 137 | // if (topAnswers.contains(sub.toStringID())) | 136 | if (topAnswers.contains(sub.toStringID())) |
| 138 | // axioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind)); | 137 | topAxioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind)); |
| 139 | if (botAnswers.contains(sub.toStringID())) | 138 | if (botAnswers.contains(sub.toStringID())) |
| 140 | inc(counter, factory.getOWLClassAssertionAxiom(ca.getClassExpression(), bot_ind)); | 139 | inc(counter, factory.getOWLClassAssertionAxiom(ca.getClassExpression(), bot_ind)); |
| 141 | } | 140 | } |
| 142 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom) { | 141 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom) { |
| 143 | OWLObjectPropertyAssertionAxiom oa = (OWLObjectPropertyAssertionAxiom) axiom; | 142 | OWLObjectPropertyAssertionAxiom oa = (OWLObjectPropertyAssertionAxiom) axiom; |
| 144 | sub = oa.getSubject(); obj = oa.getObject(); | 143 | sub = oa.getSubject(); obj = oa.getObject(); |
| 145 | //// if (topAnswers.contains(sub.toStringID())) | 144 | if (topAnswers.contains(sub.toStringID())) |
| 146 | //// if (topAnswers.contains(obj.toStringID())) | 145 | if (topAnswers.contains(obj.toStringID())) |
| 147 | //// axioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind)); | 146 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind)); |
| 148 | //// else | 147 | else |
| 149 | //// axioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj)); | 148 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj)); |
| 150 | //// else { | 149 | else { |
| 151 | //// if (topAnswers.contains(obj.toStringID())) | 150 | if (topAnswers.contains(obj.toStringID())) |
| 152 | //// axioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind)); | 151 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind)); |
| 153 | //// } | 152 | } |
| 154 | 153 | ||
| 155 | if (botAnswers.contains(sub.toStringID())) | 154 | if (botAnswers.contains(sub.toStringID())) |
| 156 | if (botAnswers.contains(obj.toStringID())) | 155 | if (botAnswers.contains(obj.toStringID())) |
| @@ -166,8 +165,8 @@ public class HermitChecker implements Checker { | |||
| 166 | else if (axiom instanceof OWLDataPropertyAssertionAxiom) { | 165 | else if (axiom instanceof OWLDataPropertyAssertionAxiom) { |
| 167 | OWLDataPropertyAssertionAxiom da = (OWLDataPropertyAssertionAxiom) axiom; | 166 | OWLDataPropertyAssertionAxiom da = (OWLDataPropertyAssertionAxiom) axiom; |
| 168 | sub = da.getSubject(); | 167 | sub = da.getSubject(); |
| 169 | // if (topAnswers.contains(sub.toStringID())) | 168 | if (topAnswers.contains(sub.toStringID())) |
| 170 | // axioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject())); | 169 | topAxioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject())); |
| 171 | 170 | ||
| 172 | if (botAnswers.contains(sub.toStringID())) | 171 | if (botAnswers.contains(sub.toStringID())) |
| 173 | inc(counter, factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), bot_ind, da.getObject())); | 172 | inc(counter, factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), bot_ind, da.getObject())); |
| @@ -176,7 +175,7 @@ public class HermitChecker implements Checker { | |||
| 176 | int number = botAnswers.size(); | 175 | int number = botAnswers.size(); |
| 177 | for (Map.Entry<OWLAxiom, Integer> entry: counter.entrySet()) { | 176 | for (Map.Entry<OWLAxiom, Integer> entry: counter.entrySet()) { |
| 178 | if (entry.getValue() == number) | 177 | if (entry.getValue() == number) |
| 179 | axioms.add(entry.getKey()); | 178 | botAxioms.add(entry.getKey()); |
| 180 | } | 179 | } |
| 181 | } | 180 | } |
| 182 | 181 | ||
diff --git a/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java b/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java index d50a18b..a803d63 100644 --- a/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java +++ b/test/uk/ac/ox/cs/pagoda/tester/PagodaTester.java | |||
| @@ -99,7 +99,7 @@ public class PagodaTester { | |||
| 99 | // args = new String[] {dbpedia_tbox, dbpedia_abox, dbpedia_query}; | 99 | // args = new String[] {dbpedia_tbox, dbpedia_abox, dbpedia_query}; |
| 100 | // args = new String[] {travel_tbox, null, dbpedia_query274}; | 100 | // args = new String[] {travel_tbox, null, dbpedia_query274}; |
| 101 | // args = new String[] {fly, null, fly_query}; | 101 | // args = new String[] {fly, null, fly_query}; |
| 102 | args = new String[] {npd_tbox, npd_abox, npd_query}; | 102 | // args = new String[] {npd_tbox, npd_abox, npd_query}; |
| 103 | // args = new String[] {npd_bench_tbox, npd_bench_abox, npd_bench_query}; | 103 | // args = new String[] {npd_bench_tbox, npd_bench_abox, npd_bench_query}; |
| 104 | // args = new String[] {"../SemFacet/WebContent/WEB-INF/data/dbpedia.owl", "../SemFacet/WebContent/WEB-INF/data/dbpediaA.nt", null}; | 104 | // args = new String[] {"../SemFacet/WebContent/WEB-INF/data/dbpedia.owl", "../SemFacet/WebContent/WEB-INF/data/dbpediaA.nt", null}; |
| 105 | // args = new String[] {"../core/WebContent/WEB-INF/data/fly.owl", "../core/WebContent/WEB-INF/data/fly-data.nt", null}; | 105 | // args = new String[] {"../core/WebContent/WEB-INF/data/fly.owl", "../core/WebContent/WEB-INF/data/fly-data.nt", null}; |
| @@ -119,7 +119,7 @@ public class PagodaTester { | |||
| 119 | // args[2] = args[2].replace(".sparql", "_pellet.sparql"); | 119 | // args[2] = args[2].replace(".sparql", "_pellet.sparql"); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | Properties properties = new Properties("config/uobm.conf"); | 122 | Properties properties = new Properties("config/fly.conf"); |
| 123 | 123 | ||
| 124 | int index = 0; | 124 | int index = 0; |
| 125 | if (args.length > index) properties.setOntologyPath(args[index++]); | 125 | if (args.length > index) properties.setOntologyPath(args[index++]); |
