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