diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/ELHOQueryReasoner.java | 160 |
1 files changed, 83 insertions, 77 deletions
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 | } |
