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