From 2e069a4966e6305194c4168d6fc5c406123d7f64 Mon Sep 17 00:00:00 2001 From: RncLsn Date: Thu, 28 May 2015 10:29:11 +0100 Subject: NOT-WORKING: trying to add query-dependent Skolemisation. --- .../ox/cs/pagoda/reasoner/ConsistencyManager.java | 114 ++++++++-------- .../ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java | 2 +- .../ox/cs/pagoda/reasoner/IterativeRefinement.java | 26 ++-- .../ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | 145 ++++++++++----------- src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java | 12 +- .../ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java | 4 +- .../cs/pagoda/reasoner/light/RDFoxQueryEngine.java | 94 +++++++------ 7 files changed, 202 insertions(+), 195 deletions(-) (limited to 'src/uk/ac/ox/cs/pagoda/reasoner') diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java index 409a2c9..ef9338a 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java @@ -30,43 +30,42 @@ public class ConsistencyManager { protected MyQueryReasoner m_reasoner; protected QueryManager m_queryManager; - Timer t = new Timer(); + Timer t = new Timer(); + QueryRecord fullQueryRecord; + QueryRecord[] botQueryRecords; + LinkedList toAddClauses; + boolean fragmentExtracted = false; public ConsistencyManager(MyQueryReasoner reasoner) { - m_reasoner = reasoner; - m_queryManager = reasoner.getQueryManager(); + m_reasoner = reasoner; + m_queryManager = reasoner.getQueryManager(); } - QueryRecord fullQueryRecord; - QueryRecord[] botQueryRecords; - - LinkedList toAddClauses; - boolean checkRLLowerBound() { fullQueryRecord = m_queryManager.create(QueryRecord.botQueryText, 0); - AnswerTuples iter = null; - + AnswerTuples iter = null; + try { iter = m_reasoner.rlLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); fullQueryRecord.updateLowerBoundAnswers(iter); } finally { iter.dispose(); } - + if (fullQueryRecord.getNoOfSoundAnswers() > 0) { - Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); + Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); return false; } - return true; + return true; } - + boolean checkELLowerBound() { fullQueryRecord.updateLowerBoundAnswers(m_reasoner.elLowerStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables())); if (fullQueryRecord.getNoOfSoundAnswers() > 0) { - Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); + Utility.logInfo("Answers to bottom in the lower bound: ", fullQueryRecord.outputSoundAnswerTuple()); return true; } - return true; + return true; } boolean checkUpper(BasicQueryEngine upperStore) { @@ -91,65 +90,64 @@ public class ConsistencyManager { fullQueryRecord.dispose(); } +// protected boolean unsatisfiability(double duration) { +// fullQueryRecord.dispose(); +// Utility.logDebug("The ontology and dataset is unsatisfiable."); +// return false; +// } + +// protected boolean satisfiability(double duration) { +// fullQueryRecord.dispose(); +// Utility.logDebug("The ontology and dataset is satisfiable."); +// return true; +// } + boolean check() { -// if (!checkRLLowerBound()) return false; -// if (!checkELLowerBound()) return false; -// if (checkLazyUpper()) return true; - AnswerTuples iter = null; - +// if (!checkRLLowerBound()) return false; +// if (!checkELLowerBound()) return false; +// if (checkLazyUpper()) return true; + AnswerTuples iter = null; + try { - iter = m_reasoner.trackingStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); + iter = + m_reasoner.trackingStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); fullQueryRecord.updateUpperBoundAnswers(iter); } finally { - if (iter != null) iter.dispose(); + if(iter != null) iter.dispose(); } - - if (fullQueryRecord.getNoOfCompleteAnswers() == 0) + + if(fullQueryRecord.getNoOfCompleteAnswers() == 0) return true; - + extractBottomFragment(); - + try { extractAxioms4Full(); - } catch (OWLOntologyCreationException e) { + } catch(OWLOntologyCreationException e) { e.printStackTrace(); } // fullQueryRecord.saveRelevantClause(); - - boolean satisfiability; - - Checker checker; - for (QueryRecord r: getQueryRecords()) { - // TODO to be removed ... + + boolean satisfiability; + + Checker checker; + for(QueryRecord r : getQueryRecords()) { + // TODO to be removed ... // r.saveRelevantOntology("bottom" + r.getQueryID() + ".owl"); checker = new HermitSummaryFilter(r, true); // m_reasoner.factory.getSummarisedReasoner(r); - satisfiability = checker.isConsistent(); + satisfiability = checker.isConsistent(); checker.dispose(); - if (!satisfiability) return false; + if(!satisfiability) return false; } - -// Checker checker = m_reasoner.factory.getSummarisedReasoner(fullQueryRecord); -// boolean satisfiable = checker.isConsistent(); + +// Checker checker = m_reasoner.factory.getSummarisedReasoner(fullQueryRecord); +// boolean satisfiable = checker.isConsistent(); // checker.dispose(); -// if (!satisfiable) return unsatisfiability(t.duration()); - +// if (!satisfiable) return unsatisfiability(t.duration()); + return true; } -// protected boolean unsatisfiability(double duration) { -// fullQueryRecord.dispose(); -// Utility.logDebug("The ontology and dataset is unsatisfiable."); -// return false; -// } - -// protected boolean satisfiability(double duration) { -// fullQueryRecord.dispose(); -// Utility.logDebug("The ontology and dataset is satisfiable."); -// return true; -// } - - boolean fragmentExtracted = false; - public void extractBottomFragment() { if (fragmentExtracted) return ; fragmentExtracted = true; @@ -179,7 +177,7 @@ public class ConsistencyManager { int[] group = new int[number - 1]; for (int i = 0; i < number - 1; ++i) group[i] = i; for (int i = 0; i < number - 1; ++i) - if (tempQueryRecords[i].processed()) tempQueryRecords[i].dispose(); + if(tempQueryRecords[i].isProcessed()) tempQueryRecords[i].dispose(); else if (group[i] == i) { ++bottomNumber; record = tempQueryRecords[i]; @@ -193,8 +191,8 @@ public class ConsistencyManager { int bottomCounter = 0; botQueryRecords = new QueryRecord[bottomNumber]; Variable X = Variable.create("X"); - for (int i = 0; i < number - 1; ++i) - if (!tempQueryRecords[i].processed()) + for (int i = 0; i < number - 1; ++i) + if(!tempQueryRecords[i].isProcessed()) if (group[i] == i) { botQueryRecords[bottomCounter] = record = tempQueryRecords[i]; record.resetInfo(QueryRecord.botQueryText.replace("Nothing", "Nothing_final" + (++bottomCounter)), 0, group[i] = bottomCounter); diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java index 34742c8..c74ea58 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ELHOUQueryReasoner.java @@ -68,7 +68,7 @@ class ELHOUQueryReasoner extends QueryReasoner { } queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration()); - if (queryRecord.processed()) { + if(queryRecord.isProcessed()) { queryRecord.setDifficulty(Step.UPPER_BOUND); return; } diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java b/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java index 447a92d..7847e7c 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/IterativeRefinement.java @@ -1,9 +1,6 @@ package uk.ac.ox.cs.pagoda.reasoner; -import java.io.File; - import org.semanticweb.owlapi.model.OWLOntology; - import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; import uk.ac.ox.cs.pagoda.constraints.UpperUnaryBottom; import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; @@ -14,6 +11,8 @@ import uk.ac.ox.cs.pagoda.rules.GeneralProgram; import uk.ac.ox.cs.pagoda.tracking.QueryTracker; import uk.ac.ox.cs.pagoda.util.Utility; +import java.io.File; + public class IterativeRefinement { private static final int depthLimit = 1; @@ -23,16 +22,15 @@ public class IterativeRefinement { BasicQueryEngine m_trackingStore; QueryRecord[] botQueryRecords; - int m_depth = 0; - + int m_depth = 0; + String tempDataFile = "temp.ttl"; + public IterativeRefinement(QueryRecord queryRecord, QueryTracker tracker, BasicQueryEngine trackingStore, QueryRecord[] botQueryRecords) { - m_record = queryRecord; - m_tracker = tracker; + m_record = queryRecord; + m_tracker = tracker; m_trackingStore = trackingStore; - this.botQueryRecords = botQueryRecords; + this.botQueryRecords = botQueryRecords; } - - String tempDataFile = "temp.ttl"; public OWLOntology extractWithFullABox(String dataset, BottomStrategy upperBottom) { GeneralProgram program; @@ -58,8 +56,8 @@ public class IterativeRefinement { } finally { tEngine.dispose(); } - - if (m_record.processed()) + + if(m_record.isProcessed()) return null; if (!update) break; @@ -95,8 +93,8 @@ public class IterativeRefinement { } finally { tEngine.dispose(); } - - if (m_record.processed()) + + if(m_record.isProcessed()) return null; if (!update) break; diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index cc0e647..b5b9534 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java @@ -23,7 +23,6 @@ import uk.ac.ox.cs.pagoda.util.Utility; import uk.ac.ox.cs.pagoda.util.tuples.Tuple; import java.util.Collection; -import java.util.HashMap; class MyQueryReasoner extends QueryReasoner { @@ -33,7 +32,7 @@ class MyQueryReasoner extends QueryReasoner { // String additonalDataFile; BasicQueryEngine rlLowerStore = null; BasicQueryEngine lazyUpperStore = null; - BasicQueryEngine limitedSkolemUpperStore; + // BasicQueryEngine limitedSkolemUpperStore; OWLOntology elho_ontology; // boolean[] namedIndividuals_lazyUpper; KarmaQueryEngine elLowerStore = null; @@ -99,7 +98,7 @@ class MyQueryReasoner extends QueryReasoner { useUpperStores = multiStageTag && !program.getGeneral().isHorn(); if(useUpperStores) { lazyUpperStore = getUpperStore("lazy-upper-bound", true); - limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); +// limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); } importData(program.getAdditionalDataFile()); @@ -147,20 +146,20 @@ class MyQueryReasoner extends QueryReasoner { Utility.logInfo("time for satisfiability checking: " + t.duration()); } - if(limitedSkolemUpperStore != null) { - limitedSkolemUpperStore.importRDFData(name, datafile); - limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); - int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); - if(tag != 1) { - limitedSkolemUpperStore.dispose(); - limitedSkolemUpperStore = null; - } - if(tag == -1) return false; - } - if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) { - satisfiable = SatisfiabilityStatus.SATISFIABLE; - Utility.logInfo("time for satisfiability checking: " + t.duration()); - } +// if(limitedSkolemUpperStore != null) { +// limitedSkolemUpperStore.importRDFData(name, datafile); +// limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); +// int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); +// if(tag != 1) { +// limitedSkolemUpperStore.dispose(); +// limitedSkolemUpperStore = null; +// } +// if(tag == -1) return false; +// } +// if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) { +// satisfiable = SatisfiabilityStatus.SATISFIABLE; +// Utility.logInfo("time for satisfiability checking: " + t.duration()); +// } trackingStore.importRDFData(name, datafile); trackingStore.materialise("saturate named individuals", originalMarkProgram); @@ -214,7 +213,7 @@ class MyQueryReasoner extends QueryReasoner { queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); queryRecord.addProcessingTime(step, t.duration()); - if(queryRecord.processed()) { + if(queryRecord.isProcessed()) { queryRecord.setDifficulty(step); return true; } @@ -224,7 +223,7 @@ class MyQueryReasoner extends QueryReasoner { /** * Returns the part of the ontology relevant for Hermit, while computing the bound answers. * */ - private OWLOntology relevantPart(QueryRecord queryRecord) { + private boolean queryBounds(QueryRecord queryRecord) { AnswerTuples rlAnswer = null, elAnswer = null; t.reset(); @@ -243,15 +242,15 @@ class MyQueryReasoner extends QueryReasoner { Utility.logDebug("Tracking store"); if(queryUpperStore(trackingStore, queryRecord, extendedQueryTexts, Step.SIMPLE_UPPER_BOUND)) - return null; + return true; if(!queryRecord.isBottom()) { Utility.logDebug("Lazy store"); if(lazyUpperStore != null && queryUpperStore(lazyUpperStore, queryRecord, extendedQueryTexts, Step.LAZY_UPPER_BOUND)) - return null; - Utility.logDebug("Skolem store"); - if(limitedSkolemUpperStore != null && queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts, Step.L_SKOLEM_UPPER_BOUND)) - return null; + return true; +// Utility.logDebug("Skolem store"); +// if(limitedSkolemUpperStore != null && queryUpperStore(limitedSkolemUpperStore, queryRecord, extendedQueryTexts, Step.L_SKOLEM_UPPER_BOUND)) +// return null; } t.reset(); @@ -266,52 +265,23 @@ class MyQueryReasoner extends QueryReasoner { } queryRecord.addProcessingTime(Step.EL_LOWER_BOUND, t.duration()); - if (queryRecord.processed()) { + if(queryRecord.isProcessed()) { queryRecord.setDifficulty(Step.EL_LOWER_BOUND); - return null; + return true; } + return false; + } + + private OWLOntology extractRelevantOntologySubset(QueryRecord queryRecord) { t.reset(); QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord); + OWLOntology relevantOntologySubset = tracker.extract(trackingStore, consistency.getQueryRecords(), true); - OWLOntology knowledgeBase; - t.reset(); -// if (program.getGeneral().isHorn()) { -// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true); -// queryRecord.addProcessingTime(Step.Fragment, t.duration()); -// return knowledgebase; -// } -// else { - knowledgeBase = tracker.extract(trackingStore, consistency.getQueryRecords(), true); queryRecord.addProcessingTime(Step.FRAGMENT, t.duration()); -// } - - if(knowledgeBase.isEmpty() || queryRecord.isBottom()) - return knowledgeBase; - - if(program.getGeneral().isHorn()) return knowledgeBase; -// t.reset(); -// if (queryRecord.isHorn() && lazyUpperStore != null) { -//// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true); -// } else if (queryRecord.getArity() < 3) { -// IterativeRefinement iterativeRefinement = new IterativeRefinement(queryRecord, tracker, trackingStore, consistency.getQueryRecords()); -// knowledgebase = iterativeRefinement.extractWithFullABox(importedData.toString(), program.getUpperBottomStrategy()); -// } -// -// queryRecord.addProcessingTime(Step.FRAGMENT_REFINEMENT, t.duration()); -// -// if (knowledgebase == null) -// queryRecord.setDifficulty(Step.FRAGMENT_REFINEMENT); - - return knowledgeBase; - } - - private String toJsonKeyValuePair(String key, Object value) { - HashMap map = new HashMap<>(); - map.put(key, value); - return QueryRecord.GsonCreator.getInstance().toJson(map); + return relevantOntologySubset; } private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) { @@ -323,35 +293,59 @@ class MyQueryReasoner extends QueryReasoner { queryRecord.updateUpperBoundAnswers(rlAnswer); } finally { if(rlAnswer != null) rlAnswer.dispose(); - rlAnswer = null; } } -// int counter = 0; - @Override public void evaluate(QueryRecord queryRecord) { - OWLOntology knowledgeBase = relevantPart(queryRecord); - - if(knowledgeBase == null) { - Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); + if(queryBounds(queryRecord)) return; - } - int aBoxCount = knowledgeBase.getABoxAxioms(true).size(); - Utility.logDebug("ABox axioms: " + aBoxCount + " TBox axioms: " + (knowledgeBase.getAxiomCount() - aBoxCount)); + OWLOntology relevantOntologySubset = extractRelevantOntologySubset(queryRecord); + + int aBoxCount = relevantOntologySubset.getABoxAxioms(true).size(); + Utility.logInfo("Relevant ontology subset: ABox_axioms=" + aBoxCount + " TBox_axioms=" + (relevantOntologySubset + .getAxiomCount() - aBoxCount)); // queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); + if(querySkolemisedRelevantSubset(relevantOntologySubset, queryRecord)) + return; + Timer t = new Timer(); Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); -// int validNumber = summarisedChecker.check(queryRecord.getGapAnswers()); summarisedChecker.dispose(); Utility.logDebug("Total time for full reasoner: " + t.duration()); -// if (validNumber == 0) { queryRecord.markAsProcessed(); Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); -// } + } + + private boolean querySkolemisedRelevantSubset(OWLOntology relevantSubset, QueryRecord queryRecord) { + MultiStageQueryEngine relevantStore = + new MultiStageQueryEngine("Relevant-store", true); // checkValidity is true + DatalogProgram relevantProgram = new DatalogProgram(relevantSubset, false); // toClassify is false + +// relevantStore.importRDFData("data", importedData.toString()); // 2 answers more + relevantStore.importDataFromABoxOf(relevantSubset); + + int materialisationResult = relevantStore.materialiseSkolemly(relevantProgram, null); + if(materialisationResult != 1) + throw new RuntimeException("Skolemised materialisation error"); // TODO check consistency +// relevantStore.materialiseRestrictedly(relevantProgram, null); // it has been tried + + return queryUpperStore(relevantStore, queryRecord, queryRecord.getExtendedQueryText(), Step.L_SKOLEM_UPPER_BOUND); + + // the following has been tried +// Tuple extendedQueryText = queryRecord.getExtendedQueryText(); +// if(queryRecord.hasNonAnsDistinguishedVariables()) { +// queryUpperBound(relevantStore, queryRecord, extendedQueryText.get(0), queryRecord.getAnswerVariables()); +// queryUpperBound(relevantStore, queryRecord, extendedQueryText.get(1), queryRecord.getDistinguishedVariables()); +// } +// else +// queryUpperBound(relevantStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); +// +// return queryRecord.isProcessed(); + } @Override @@ -375,7 +369,8 @@ class MyQueryReasoner extends QueryReasoner { if (lazyUpperStore != null) lazyUpperStore.dispose(); if (elLowerStore != null) elLowerStore.dispose(); if (trackingStore != null) trackingStore.dispose(); - if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose(); + +// if(limitedSkolemUpperStore != null) limitedSkolemUpperStore.dispose(); super.dispose(); } diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java index 64945e8..118c1b2 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java @@ -147,7 +147,7 @@ PagodaProperties properties; if (forFacetGeneration) { QueryRecord record = m_queryManager.create(queryText); Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText); - if(!record.processed()) + if(!record.isProcessed()) evaluateUpper(record); // AnswerTuples tuples = record.getUpperBoundAnswers(); // for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) { @@ -167,7 +167,7 @@ PagodaProperties properties; public AnswerTuples evaluate(String queryText) { QueryRecord record = m_queryManager.create(queryText); Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); - if(!record.processed()) + if(!record.isProcessed()) evaluate(record); AnswerTuples answer = record.getAnswers(); record.dispose(); @@ -178,7 +178,7 @@ PagodaProperties properties; public void evaluate_shell(String queryText) { QueryRecord record = m_queryManager.create(queryText); Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); - if(!record.processed()) + if(!record.isProcessed()) evaluate(record); Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple()); record.dispose(); @@ -206,12 +206,12 @@ PagodaProperties properties; // if (Integer.parseInt(record.getQueryID()) != 218) continue; Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", record.getQueryText()); - if (!record.processed()) { + if(!record.isProcessed()) { t.reset(); - if (!record.processed()) + if(!record.isProcessed()) evaluate(record); Utility.logInfo("Total time to answer this query: " + t.duration()); - if (!fullReasoner && !record.processed()) { + if(!fullReasoner && !record.isProcessed()) { Utility.logInfo("The query has not been fully answered in " + t.duration() + " seconds."); continue; } diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java index bdef436..547140a 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java @@ -53,8 +53,8 @@ class RLUQueryReasoner extends QueryReasoner { if (ans != null) ans.dispose(); } queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration()); - - if (queryRecord.processed()) + + if(queryRecord.isProcessed()) queryRecord.setDifficulty(Step.UPPER_BOUND); } 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 63773d9..61500f5 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java @@ -1,5 +1,7 @@ package uk.ac.ox.cs.pagoda.reasoner.light; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; import uk.ac.ox.cs.JRDFox.JRDFStoreException; import uk.ac.ox.cs.JRDFox.Prefixes; import uk.ac.ox.cs.JRDFox.store.DataStore; @@ -18,32 +20,44 @@ import java.util.Collection; public abstract class RDFoxQueryEngine implements QueryEngine { public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; - - public String getName() { - return name; - } - protected String name; protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); public RDFoxQueryEngine(String name) { - this.name = name; - } - - public abstract DataStore getDataStore(); + this.name = name; + } + + public static DataStore createDataStore() { + DataStore instance = null; + try { +// instance = new DataStore("par-head-n"); + instance = new DataStore(StoreType.NarrowParallelHead); + instance.setNumberOfThreads(matNoOfThreads); + instance.initialize(); + } catch(JRDFStoreException e) { + e.printStackTrace(); + } + return instance; + } - public abstract void dispose(); + public String getName() { + return name; + } + public abstract DataStore getDataStore(); + + public abstract void dispose(); + public void importRDFData(String fileName, String importedFile) { - if (importedFile == null || importedFile.isEmpty()) return ; - Timer t = new Timer(); - DataStore store = getDataStore(); + if(importedFile == null || importedFile.isEmpty()) return; + Timer t = new Timer(); + DataStore store = getDataStore(); try { long oldTripleCount = store.getTriplesCount(), tripleCount; for (String file: importedFile.split(QueryReasoner.ImportDataFileSeparator)) { store.importTurtleFile(new File(file), prefixes); } - tripleCount = store.getTriplesCount(); + tripleCount = store.getTriplesCount(); Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); store.clearRulesAndMakeFactsExplicit(); } catch (JRDFStoreException e) { @@ -51,17 +65,32 @@ public abstract class RDFoxQueryEngine implements QueryEngine { } Utility.logDebug(name + " store finished importing " + fileName + " in " + t.duration() + " seconds."); } - + + public void importDataFromABoxOf(OWLOntology ontology) { + DataStore store = getDataStore(); + try { + long prevTriplesCount = store.getTriplesCount(); + store.importOntology(ontology.getOWLOntologyManager().createOntology(ontology.getABoxAxioms(true))); + long loadedTriples = store.getTriplesCount() - prevTriplesCount; + Utility.logInfo(name + ": loaded " + loadedTriples + " triples from " + ontology.getABoxAxioms(true) + .size() + " ABox axioms"); + } catch(JRDFStoreException | OWLOntologyCreationException e) { + e.printStackTrace(); + System.exit(1); + } + + } + public void materialise(String programName, String programText) { - if (programText == null) return ; + if(programText == null) return; Timer t = new Timer(); - DataStore store = getDataStore(); + DataStore store = getDataStore(); try { long oldTripleCount = store.getTriplesCount(), tripleCount; // store.addRules(new String[] {programText}); store.importRules(programText); store.applyReasoning(); - tripleCount = store.getTriplesCount(); + tripleCount = store.getTriplesCount(); Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); store.clearRulesAndMakeFactsExplicit(); } catch (JRDFStoreException e) { @@ -74,17 +103,17 @@ public abstract class RDFoxQueryEngine implements QueryEngine { public void evaluate(Collection queryTexts, String answerFile) { if (queryTexts == null) return ; - - int queryID = 0; - AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); + + int queryID = 0; + AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); AnswerTuples answerTuples; - Timer t = new Timer(); + Timer t = new Timer(); try { for (String query: queryTexts) { t.reset(); - answerTuples = null; + answerTuples = null; try { - answerTuples = evaluate(query); + answerTuples = evaluate(query); Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration()); answerWriter.write(answerTuples.getAnswerVariables(), answerTuples); } finally { @@ -94,22 +123,9 @@ public abstract class RDFoxQueryEngine implements QueryEngine { } finally { answerWriter.close(); } - + Utility.logDebug("done computing query answers by RDFox."); - - } - - public static DataStore createDataStore() { - DataStore instance = null; - try { -// instance = new DataStore("par-head-n"); - instance = new DataStore(StoreType.NarrowParallelHead); - instance.setNumberOfThreads(matNoOfThreads); - instance.initialize(); - } catch (JRDFStoreException e) { - e.printStackTrace(); - } - return instance; + } } -- cgit v1.2.3