From 68ae342b2a4923bc7b3f378c6a489f2355d85279 Mon Sep 17 00:00:00 2001 From: yzhou Date: Wed, 29 Apr 2015 18:57:39 +0100 Subject: added top answers optimisation back --- .../ox/cs/pagoda/reasoner/ConsistencyManager.java | 3 +- src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | 9 ++- .../ox/cs/pagoda/reasoner/full/HermitChecker.java | 71 +++++++++++----------- 3 files changed, 43 insertions(+), 40 deletions(-) (limited to 'src') 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; import uk.ac.ox.cs.pagoda.util.Utility; import uk.ac.ox.cs.JRDFox.JRDFStoreException; import uk.ac.ox.cs.JRDFox.store.DataStore; +import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; public class ConsistencyManager { @@ -218,7 +219,7 @@ public class ConsistencyManager { Timer t1 = new Timer(); oldTripleCount = store.getTriplesCount(); for (String program: programs) - store.importRules(program); + store.importRules(program, UpdateType.ScheduleForAddition); store.applyReasoning(true); tripleCount = store.getTriplesCount(); 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; public abstract class QueryReasoner { // protected boolean forSemFacet = false; - Properties properties; + Properties properties; + + private static boolean defaultMultiStages = true; + private static boolean defaultEqualities = true; public static enum Type { Full, RLU, ELHOU }; @@ -43,7 +46,7 @@ public abstract class QueryReasoner { } public static QueryReasoner getInstance(OWLOntology o) { - QueryReasoner pagoda = getInstance(Type.Full, o, true, true); + QueryReasoner pagoda = getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); pagoda.properties = new Properties(); return pagoda; } @@ -57,7 +60,7 @@ public abstract class QueryReasoner { } private static QueryReasoner getInstance(OWLOntology o, Properties p) { - return getInstance(Type.Full, o, true, true); + return getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); } 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 { } private int tag = 0; -// AnswerTuple topAnswerTuple = null; - AnswerTuple botAnswerTuple = null; + AnswerTuple topAnswerTuple = null, botAnswerTuple = null; private void initialiseReasoner() { qGraph = new QueryGraph(queryClause.getBodyAtoms(), answerVariable[1], ontology); @@ -88,17 +87,20 @@ public class HermitChecker implements Checker { if (hermit != null) hermit.dispose(); if (dGraph != null && answerVariable[1].length == 1 && (dGraph.getExits().size() > 1 || dGraph.getEntrances().size() > 1)) { - Set axioms = new HashSet(); - addTopAndBotTuple(axioms); - manager.addAxioms(ontology, axioms); + Set topAxioms = new HashSet(); + Set botAxioms = new HashSet(); + addTopAndBotTuple(topAxioms, botAxioms); + manager.addAxioms(ontology, topAxioms); + manager.addAxioms(ontology, botAxioms); hermit = new Reasoner(ontology); - if (!hermit.isConsistent()) { + boolean topValid = true; + if (!hermit.isConsistent() || topAnswerTuple != null && (topValid = check(topAnswerTuple))) { hermit.dispose(); - manager.removeAxioms(ontology, axioms); + manager.removeAxioms(ontology, topAxioms); hermit = new Reasoner(ontology); } else { -// if (topAnswerTuple != null && !check(topAnswerTuple)) tag = -1; -// else + if (!topValid) tag = -1; + else if (botAnswerTuple != null && check(botAnswerTuple)) tag = 1; } } @@ -106,23 +108,20 @@ public class HermitChecker implements Checker { hermit = new Reasoner(ontology); } - private void addTopAndBotTuple(Set axioms) { -// String top_str = Namespace.PAGODA_ANONY + "top"; - String bot_str = Namespace.PAGODA_ANONY + "bot"; -// topAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(top_str) } ); + private void addTopAndBotTuple(Set topAxioms, Set botAxioms) { + String top_str = Namespace.PAGODA_ANONY + "top", bot_str = Namespace.PAGODA_ANONY + "bot"; + topAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(top_str) } ); botAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(bot_str) } ); -// OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)); - OWLIndividual bot_ind = factory.getOWLNamedIndividual(IRI.create(bot_str)); + OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)), bot_ind = factory.getOWLNamedIndividual(IRI.create(bot_str)); Map counter = new HashMap(); -// Set topAnswers = new HashSet(); - Set botAnswers = new HashSet(); + Set topAnswers = new HashSet(), botAnswers = new HashSet(); OWLIndividual sub, obj; -// if (dGraph.getExits().size() > 1) { -// for (Clique answerClique: dGraph.getExits()) -// topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative().getAnswerTuple().getGroundTerm(0)).getIRI()); -// } -// else topAnswerTuple = null; + if (dGraph.getExits().size() > 1) { + for (Clique answerClique: dGraph.getExits()) + topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative().getAnswerTuple().getGroundTerm(0)).getIRI()); + } + else topAnswerTuple = null; if (dGraph.getEntrances().size() > 1) { for (Clique answerClique: dGraph.getEntrances()) @@ -134,23 +133,23 @@ public class HermitChecker implements Checker { if (axiom instanceof OWLClassAssertionAxiom) { OWLClassAssertionAxiom ca = (OWLClassAssertionAxiom) axiom; sub = ca.getIndividual(); -// if (topAnswers.contains(sub.toStringID())) -// axioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind)); + if (topAnswers.contains(sub.toStringID())) + topAxioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind)); if (botAnswers.contains(sub.toStringID())) inc(counter, factory.getOWLClassAssertionAxiom(ca.getClassExpression(), bot_ind)); } else if (axiom instanceof OWLObjectPropertyAssertionAxiom) { OWLObjectPropertyAssertionAxiom oa = (OWLObjectPropertyAssertionAxiom) axiom; sub = oa.getSubject(); obj = oa.getObject(); -//// if (topAnswers.contains(sub.toStringID())) -//// if (topAnswers.contains(obj.toStringID())) -//// axioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind)); -//// else -//// axioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj)); -//// else { -//// if (topAnswers.contains(obj.toStringID())) -//// axioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind)); -//// } + if (topAnswers.contains(sub.toStringID())) + if (topAnswers.contains(obj.toStringID())) + topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind)); + else + topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj)); + else { + if (topAnswers.contains(obj.toStringID())) + topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind)); + } if (botAnswers.contains(sub.toStringID())) if (botAnswers.contains(obj.toStringID())) @@ -166,8 +165,8 @@ public class HermitChecker implements Checker { else if (axiom instanceof OWLDataPropertyAssertionAxiom) { OWLDataPropertyAssertionAxiom da = (OWLDataPropertyAssertionAxiom) axiom; sub = da.getSubject(); -// if (topAnswers.contains(sub.toStringID())) -// axioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject())); + if (topAnswers.contains(sub.toStringID())) + topAxioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject())); if (botAnswers.contains(sub.toStringID())) inc(counter, factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), bot_ind, da.getObject())); @@ -176,7 +175,7 @@ public class HermitChecker implements Checker { int number = botAnswers.size(); for (Map.Entry entry: counter.entrySet()) { if (entry.getValue() == number) - axioms.add(entry.getKey()); + botAxioms.add(entry.getKey()); } } -- cgit v1.2.3