From 4b7253559c290b6fdd1c4122830f153fda85dd62 Mon Sep 17 00:00:00 2001 From: RncLsn Date: Fri, 29 May 2015 18:35:51 +0100 Subject: Disposable. --- .../cs/pagoda/reasoner/light/RDFoxQueryEngine.java | 219 +++++++++++---------- 1 file changed, 113 insertions(+), 106 deletions(-) (limited to 'src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java') 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; import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter; import uk.ac.ox.cs.pagoda.util.Timer; import uk.ac.ox.cs.pagoda.util.Utility; +import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; import java.io.File; import java.util.Collection; -public abstract class RDFoxQueryEngine implements QueryEngine { - - public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; - protected String name; - protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); +public abstract class RDFoxQueryEngine extends QueryEngine { - public RDFoxQueryEngine(String name) { - this.name = name; - } + public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; + protected String name; + protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); - public static DataStore createDataStore() { - DataStore instance = null; - try { + public RDFoxQueryEngine(String name) { + 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 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(); - try { - long oldTripleCount = store.getTriplesCount(), tripleCount; - for (String file: importedFile.split(QueryReasoner.ImportDataFileSeparator)) { - store.importTurtleFile(new File(file), prefixes); - } - tripleCount = store.getTriplesCount(); - Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); - store.clearRulesAndMakeFactsExplicit(); - } catch (JRDFStoreException e) { - e.printStackTrace(); - } - 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; - Timer t = new Timer(); - DataStore store = getDataStore(); - try { - long oldTripleCount = store.getTriplesCount(), tripleCount; + instance = new DataStore(StoreType.NarrowParallelHead); + instance.setNumberOfThreads(matNoOfThreads); + instance.initialize(); + } catch(JRDFStoreException e) { + e.printStackTrace(); + } + return instance; + } + + public String getName() { + if(isDisposed()) throw new DisposedException(); + return name; + } + + public abstract DataStore getDataStore(); + + public void importRDFData(String fileName, String importedFile) { + if(isDisposed()) throw new DisposedException(); + 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(); + Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); + store.clearRulesAndMakeFactsExplicit(); + } catch(JRDFStoreException e) { + e.printStackTrace(); + } + Utility.logDebug(name + " store finished importing " + fileName + " in " + t.duration() + " seconds."); + } + + public void importDataFromABoxOf(OWLOntology ontology) { + if(isDisposed()) throw new DisposedException(); + 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(isDisposed()) throw new DisposedException(); + if(programText == null) return; + Timer t = new Timer(); + DataStore store = getDataStore(); + try { + long oldTripleCount = store.getTriplesCount(), tripleCount; // store.addRules(new String[] {programText}); - store.importRules(programText); - store.applyReasoning(); - tripleCount = store.getTriplesCount(); - Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); - store.clearRulesAndMakeFactsExplicit(); - } catch (JRDFStoreException e) { - e.printStackTrace(); - } - Utility.logDebug(name + " store finished the materialisation of " + programName + " in " + t.duration() + " seconds."); - } - - @Override - public void evaluate(Collection queryTexts, String answerFile) { - if (queryTexts == null) - return ; - - int queryID = 0; - AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); - AnswerTuples answerTuples; - Timer t = new Timer(); - try { - for (String query: queryTexts) { - t.reset(); - answerTuples = null; - try { - answerTuples = evaluate(query); - Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration()); - answerWriter.write(answerTuples.getAnswerVariables(), answerTuples); - } finally { - if (answerTuples != null) answerTuples.dispose(); - } - } - } finally { - answerWriter.close(); - } - - Utility.logDebug("done computing query answers by RDFox."); - - } + store.importRules(programText); + store.applyReasoning(); + tripleCount = store.getTriplesCount(); + Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); + store.clearRulesAndMakeFactsExplicit(); + } catch(JRDFStoreException e) { + e.printStackTrace(); + } + Utility.logDebug(name + " store finished the materialisation of " + programName + " in " + t.duration() + " seconds."); + } + + @Override + public void evaluate(Collection queryTexts, String answerFile) { + if(isDisposed()) throw new DisposedException(); + if(queryTexts == null) + return; + + int queryID = 0; + AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); + AnswerTuples answerTuples; + Timer t = new Timer(); + try { + for(String query : queryTexts) { + t.reset(); + answerTuples = null; + try { + answerTuples = evaluate(query); + Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration()); + answerWriter.write(answerTuples.getAnswerVariables(), answerTuples); + } finally { + if(answerTuples != null) answerTuples.dispose(); + } + } + } finally { + answerWriter.close(); + } + + Utility.logDebug("done computing query answers by RDFox."); + } + @Override + public void dispose() { + super.dispose(); + } } -- cgit v1.2.3