diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java deleted file mode 100644 index 98f0c35..0000000 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java +++ /dev/null | |||
| @@ -1,109 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | ||
| 2 | |||
| 3 | import org.semanticweb.karma2.MyKarma; | ||
| 4 | import org.semanticweb.karma2.clausifier.OntologyProcesser; | ||
| 5 | import org.semanticweb.karma2.exception.IllegalInputOntologyException; | ||
| 6 | import org.semanticweb.karma2.model.ConjunctiveQuery; | ||
| 7 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 8 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 9 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 10 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | ||
| 11 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | ||
| 12 | import uk.ac.ox.cs.pagoda.query.AnswerTuplesImp; | ||
| 13 | import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; | ||
| 14 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 15 | import uk.ac.ox.cs.pagoda.util.disposable.DisposedException; | ||
| 16 | |||
| 17 | import java.io.File; | ||
| 18 | import java.io.FileNotFoundException; | ||
| 19 | import java.nio.file.Paths; | ||
| 20 | import java.util.Set; | ||
| 21 | |||
| 22 | public class KarmaQueryEngine extends RDFoxQueryEngine { | ||
| 23 | |||
| 24 | String karmaDataFile = null, karmaRuleFile = null; | ||
| 25 | private MyKarma reasoner = null; | ||
| 26 | |||
| 27 | public KarmaQueryEngine(String name) { | ||
| 28 | super(name); | ||
| 29 | |||
| 30 | // int Base = 1 << 6; | ||
| 31 | // int index = (new Random().nextInt() % Base + Base) % Base; | ||
| 32 | // karmaDataFile = "karma_data" + index + ".ttl"; | ||
| 33 | // karmaRuleFile = "karma_rule" + index + ".dlog"; | ||
| 34 | karmaDataFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_data.ttl").toString(); | ||
| 35 | karmaRuleFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_rule.dlog").toString(); | ||
| 36 | |||
| 37 | reasoner = new MyKarma(); | ||
| 38 | } | ||
| 39 | |||
| 40 | public MyKarma getReasoner() { | ||
| 41 | if(isDisposed()) throw new DisposedException(); | ||
| 42 | return reasoner; | ||
| 43 | } | ||
| 44 | |||
| 45 | public void processOntology(OWLOntology elhoOntology) { | ||
| 46 | if(isDisposed()) throw new DisposedException(); | ||
| 47 | try { | ||
| 48 | OntologyProcesser.transformOntology(elhoOntology, new File(karmaDataFile), new File(karmaRuleFile)); | ||
| 49 | } catch(IllegalInputOntologyException e) { | ||
| 50 | e.printStackTrace(); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | @Override | ||
| 55 | public void dispose() { | ||
| 56 | super.dispose(); | ||
| 57 | reasoner.dispose(); | ||
| 58 | } | ||
| 59 | |||
| 60 | @Override | ||
| 61 | public AnswerTuples evaluate(String queryText) { | ||
| 62 | if(isDisposed()) throw new DisposedException(); | ||
| 63 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0], null); | ||
| 64 | } | ||
| 65 | |||
| 66 | @Override | ||
| 67 | public AnswerTuples evaluate(String queryText, String[] answerVars) { | ||
| 68 | if(isDisposed()) throw new DisposedException(); | ||
| 69 | return evaluate(queryText, answerVars, null); | ||
| 70 | } | ||
| 71 | |||
| 72 | public AnswerTuples evaluate(String queryText, AnswerTuples soundAnswerTuples) { | ||
| 73 | if(isDisposed()) throw new DisposedException(); | ||
| 74 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0], soundAnswerTuples); | ||
| 75 | } | ||
| 76 | |||
| 77 | public AnswerTuples evaluate(String queryText, String[] answerVars, AnswerTuples soundAnswerTuples) { | ||
| 78 | if(isDisposed()) throw new DisposedException(); | ||
| 79 | KarmaQuery karmaQuery = new KarmaQuery(queryText.replace("_:", "?")); | ||
| 80 | reasoner.setConcurrence(false); | ||
| 81 | ConjunctiveQuery cq = karmaQuery.getConjunctiveQuery(); | ||
| 82 | if(cq == null) return null; | ||
| 83 | Set<AnswerTuple> answers = reasoner.answerCQ(cq, soundAnswerTuples, !queryText.contains("_:")); | ||
| 84 | return new AnswerTuplesImp(answerVars, answers); | ||
| 85 | } | ||
| 86 | |||
| 87 | @Override | ||
| 88 | public DataStore getDataStore() { | ||
| 89 | if(isDisposed()) throw new DisposedException(); | ||
| 90 | return reasoner.getStore(); | ||
| 91 | } | ||
| 92 | |||
| 93 | public void initialiseKarma() { | ||
| 94 | if(isDisposed()) throw new DisposedException(); | ||
| 95 | try { | ||
| 96 | reasoner.initializeData(new File(karmaDataFile)); | ||
| 97 | reasoner.materialise(new File(karmaRuleFile)); | ||
| 98 | |||
| 99 | File tmp; | ||
| 100 | if(karmaDataFile != null && ((tmp = new File(karmaDataFile)).exists())) tmp.delete(); | ||
| 101 | if(karmaRuleFile != null && ((tmp = new File(karmaRuleFile)).exists())) tmp.delete(); | ||
| 102 | } catch(FileNotFoundException e) { | ||
| 103 | e.printStackTrace(); | ||
| 104 | } catch(JRDFStoreException e) { | ||
| 105 | e.printStackTrace(); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | } | ||
