diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java deleted file mode 100644 index 8b22919..0000000 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java +++ /dev/null | |||
| @@ -1,138 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | ||
| 2 | |||
| 3 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 4 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| 5 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 6 | import uk.ac.ox.cs.JRDFox.Prefixes; | ||
| 7 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 8 | import uk.ac.ox.cs.JRDFox.store.DataStore.StoreType; | ||
| 9 | import uk.ac.ox.cs.pagoda.MyPrefixes; | ||
| 10 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 11 | import uk.ac.ox.cs.pagoda.reasoner.QueryEngine; | ||
| 12 | import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | ||
| 13 | import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter; | ||
| 14 | import uk.ac.ox.cs.pagoda.util.Timer; | ||
| 15 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 16 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 17 | |||
| 18 | import java.io.File; | ||
| 19 | import java.util.Collection; | ||
| 20 | |||
| 21 | public abstract class RDFoxQueryEngine extends QueryEngine { | ||
| 22 | |||
| 23 | public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; | ||
| 24 | protected String name; | ||
| 25 | protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); | ||
| 26 | |||
| 27 | public RDFoxQueryEngine(String name) { | ||
| 28 | this.name = name; | ||
| 29 | } | ||
| 30 | |||
| 31 | public static DataStore createDataStore() { | ||
| 32 | DataStore instance = null; | ||
| 33 | try { | ||
| 34 | // instance = new DataStore("par-head-n"); | ||
| 35 | instance = new DataStore(StoreType.NarrowParallelHead); | ||
| 36 | instance.setNumberOfThreads(matNoOfThreads); | ||
| 37 | instance.initialize(); | ||
| 38 | } catch(JRDFStoreException e) { | ||
| 39 | e.printStackTrace(); | ||
| 40 | } | ||
| 41 | return instance; | ||
| 42 | } | ||
| 43 | |||
| 44 | public String getName() { | ||
| 45 | if(isDisposed()) throw new DisposedException(); | ||
| 46 | return name; | ||
| 47 | } | ||
| 48 | |||
| 49 | public abstract DataStore getDataStore(); | ||
| 50 | |||
| 51 | public void importRDFData(String fileName, String importedFile) { | ||
| 52 | if(isDisposed()) throw new DisposedException(); | ||
| 53 | if(importedFile == null || importedFile.isEmpty()) return; | ||
| 54 | Timer t = new Timer(); | ||
| 55 | DataStore store = getDataStore(); | ||
| 56 | try { | ||
| 57 | long oldTripleCount = store.getTriplesCount(), tripleCount; | ||
| 58 | for(String file : importedFile.split(QueryReasoner.ImportDataFileSeparator)) { | ||
| 59 | store.importTurtleFile(new File(file), prefixes); | ||
| 60 | } | ||
| 61 | tripleCount = store.getTriplesCount(); | ||
| 62 | Utility.logDebug(name + " store after importing " + fileName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); | ||
| 63 | store.clearRulesAndMakeFactsExplicit(); | ||
| 64 | } catch(JRDFStoreException e) { | ||
| 65 | e.printStackTrace(); | ||
| 66 | } | ||
| 67 | Utility.logDebug(name + " store finished importing " + fileName + " in " + t.duration() + " seconds."); | ||
| 68 | } | ||
| 69 | |||
| 70 | public void importDataFromABoxOf(OWLOntology ontology) { | ||
| 71 | if(isDisposed()) throw new DisposedException(); | ||
| 72 | DataStore store = getDataStore(); | ||
| 73 | try { | ||
| 74 | long prevTriplesCount = store.getTriplesCount(); | ||
| 75 | store.importOntology(ontology.getOWLOntologyManager().createOntology(ontology.getABoxAxioms(true))); | ||
| 76 | long loadedTriples = store.getTriplesCount() - prevTriplesCount; | ||
| 77 | Utility.logDebug(name + ": loaded " + loadedTriples + " triples from " + ontology.getABoxAxioms(true) | ||
| 78 | .size() + " ABox axioms"); | ||
| 79 | } catch(JRDFStoreException | OWLOntologyCreationException e) { | ||
| 80 | e.printStackTrace(); | ||
| 81 | System.exit(1); | ||
| 82 | } | ||
| 83 | |||
| 84 | } | ||
| 85 | |||
| 86 | public void materialise(String programName, String programText) { | ||
| 87 | if(isDisposed()) throw new DisposedException(); | ||
| 88 | if(programText == null) return; | ||
| 89 | Timer t = new Timer(); | ||
| 90 | DataStore store = getDataStore(); | ||
| 91 | try { | ||
| 92 | long oldTripleCount = store.getTriplesCount(), tripleCount; | ||
| 93 | // store.addRules(new String[] {programText}); | ||
| 94 | store.importRules(programText); | ||
| 95 | store.applyReasoning(); | ||
| 96 | tripleCount = store.getTriplesCount(); | ||
| 97 | Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)"); | ||
| 98 | store.clearRulesAndMakeFactsExplicit(); | ||
| 99 | } catch(JRDFStoreException e) { | ||
| 100 | e.printStackTrace(); | ||
| 101 | } | ||
| 102 | Utility.logDebug(name + " store finished the materialisation of " + programName + " in " + t.duration() + " seconds."); | ||
| 103 | } | ||
| 104 | |||
| 105 | @Override | ||
| 106 | public void evaluate(Collection<String> queryTexts, String answerFile) { | ||
| 107 | if(isDisposed()) throw new DisposedException(); | ||
| 108 | if(queryTexts == null) | ||
| 109 | return; | ||
| 110 | |||
| 111 | int queryID = 0; | ||
| 112 | AnswerTuplesWriter answerWriter = new AnswerTuplesWriter(answerFile); | ||
| 113 | AnswerTuples answerTuples; | ||
| 114 | Timer t = new Timer(); | ||
| 115 | try { | ||
| 116 | for(String query : queryTexts) { | ||
| 117 | t.reset(); | ||
| 118 | answerTuples = null; | ||
| 119 | try { | ||
| 120 | answerTuples = evaluate(query); | ||
| 121 | Utility.logDebug("time to answer Query " + ++queryID + ": " + t.duration()); | ||
| 122 | answerWriter.write(answerTuples.getAnswerVariables(), answerTuples); | ||
| 123 | } finally { | ||
| 124 | if(answerTuples != null) answerTuples.dispose(); | ||
| 125 | } | ||
| 126 | } | ||
| 127 | } finally { | ||
| 128 | answerWriter.close(); | ||
| 129 | } | ||
| 130 | |||
| 131 | Utility.logDebug("done computing query answers by RDFox."); | ||
| 132 | } | ||
| 133 | |||
| 134 | @Override | ||
| 135 | public void dispose() { | ||
| 136 | super.dispose(); | ||
| 137 | } | ||
| 138 | } | ||
