diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner/light')
3 files changed, 64 insertions, 38 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 index f70dde9..f068164 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/KarmaQueryEngine.java | |||
| @@ -1,20 +1,22 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | 1 | package uk.ac.ox.cs.pagoda.reasoner.light; |
| 2 | 2 | ||
| 3 | import java.io.File; | 3 | import org.semanticweb.karma2.MyKarma; |
| 4 | import java.io.FileNotFoundException; | ||
| 5 | import java.util.*; | ||
| 6 | |||
| 7 | import org.semanticweb.karma2.*; | ||
| 8 | import org.semanticweb.karma2.clausifier.OntologyProcesser; | 4 | import org.semanticweb.karma2.clausifier.OntologyProcesser; |
| 9 | import org.semanticweb.karma2.exception.IllegalInputOntologyException; | 5 | import org.semanticweb.karma2.exception.IllegalInputOntologyException; |
| 10 | import org.semanticweb.karma2.model.ConjunctiveQuery; | 6 | import org.semanticweb.karma2.model.ConjunctiveQuery; |
| 11 | import org.semanticweb.owlapi.model.OWLOntology; | 7 | import org.semanticweb.owlapi.model.OWLOntology; |
| 12 | |||
| 13 | import uk.ac.ox.cs.pagoda.query.*; | ||
| 14 | import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; | ||
| 15 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 16 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 8 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 17 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 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 | |||
| 16 | import java.io.File; | ||
| 17 | import java.io.FileNotFoundException; | ||
| 18 | import java.nio.file.Paths; | ||
| 19 | import java.util.Set; | ||
| 18 | 20 | ||
| 19 | public class KarmaQueryEngine extends RDFoxQueryEngine { | 21 | public class KarmaQueryEngine extends RDFoxQueryEngine { |
| 20 | 22 | ||
| @@ -29,8 +31,8 @@ public class KarmaQueryEngine extends RDFoxQueryEngine { | |||
| 29 | // int index = (new Random().nextInt() % Base + Base) % Base; | 31 | // int index = (new Random().nextInt() % Base + Base) % Base; |
| 30 | // karmaDataFile = "karma_data" + index + ".ttl"; | 32 | // karmaDataFile = "karma_data" + index + ".ttl"; |
| 31 | // karmaRuleFile = "karma_rule" + index + ".dlog"; | 33 | // karmaRuleFile = "karma_rule" + index + ".dlog"; |
| 32 | karmaDataFile = Utility.TempDirectory + "karma_data.ttl"; | 34 | karmaDataFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_data.ttl").toString(); |
| 33 | karmaRuleFile = Utility.TempDirectory + "karma_rule.dlog"; | 35 | karmaRuleFile = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "karma_rule.dlog").toString(); |
| 34 | 36 | ||
| 35 | reasoner = new MyKarma(); | 37 | reasoner = new MyKarma(); |
| 36 | } | 38 | } |
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 70d0cc9..63773d9 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxQueryEngine.java | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | 1 | package uk.ac.ox.cs.pagoda.reasoner.light; |
| 2 | 2 | ||
| 3 | import java.io.File; | 3 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 4 | import java.util.Collection; | 4 | import uk.ac.ox.cs.JRDFox.Prefixes; |
| 5 | 5 | import uk.ac.ox.cs.JRDFox.store.DataStore; | |
| 6 | import uk.ac.ox.cs.JRDFox.store.DataStore.StoreType; | ||
| 6 | import uk.ac.ox.cs.pagoda.MyPrefixes; | 7 | import uk.ac.ox.cs.pagoda.MyPrefixes; |
| 7 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 8 | import uk.ac.ox.cs.pagoda.reasoner.QueryEngine; | 9 | import uk.ac.ox.cs.pagoda.reasoner.QueryEngine; |
| @@ -10,16 +11,19 @@ import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner; | |||
| 10 | import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter; | 11 | import uk.ac.ox.cs.pagoda.tracking.AnswerTuplesWriter; |
| 11 | import uk.ac.ox.cs.pagoda.util.Timer; | 12 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 12 | import uk.ac.ox.cs.pagoda.util.Utility; | 13 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 13 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 14 | |
| 14 | import uk.ac.ox.cs.JRDFox.Prefixes; | 15 | import java.io.File; |
| 15 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 16 | import java.util.Collection; |
| 16 | import uk.ac.ox.cs.JRDFox.store.DataStore.StoreType; | ||
| 17 | 17 | ||
| 18 | public abstract class RDFoxQueryEngine implements QueryEngine { | 18 | public abstract class RDFoxQueryEngine implements QueryEngine { |
| 19 | 19 | ||
| 20 | public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; | 20 | public static final int matNoOfThreads = Runtime.getRuntime().availableProcessors() * 2; |
| 21 | 21 | ||
| 22 | protected String name; | 22 | public String getName() { |
| 23 | return name; | ||
| 24 | } | ||
| 25 | |||
| 26 | protected String name; | ||
| 23 | protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); | 27 | protected Prefixes prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); |
| 24 | 28 | ||
| 25 | public RDFoxQueryEngine(String name) { | 29 | public RDFoxQueryEngine(String name) { |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java index 232bc31..85f8ef9 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | 1 | package uk.ac.ox.cs.pagoda.reasoner.light; |
| 2 | 2 | ||
| 3 | import net.sf.ehcache.Cache; | ||
| 4 | import net.sf.ehcache.CacheManager; | ||
| 5 | import net.sf.ehcache.Element; | ||
| 3 | import org.semanticweb.HermiT.model.*; | 6 | import org.semanticweb.HermiT.model.*; |
| 4 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 7 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 5 | import uk.ac.ox.cs.JRDFox.model.Datatype; | 8 | import uk.ac.ox.cs.JRDFox.model.Datatype; |
| @@ -11,11 +14,20 @@ import uk.ac.ox.cs.JRDFox.store.Resource; | |||
| 11 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | 14 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; |
| 12 | import uk.ac.ox.cs.pagoda.util.Namespace; | 15 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 13 | 16 | ||
| 14 | import java.util.*; | 17 | import java.util.Collection; |
| 18 | import java.util.HashMap; | ||
| 19 | import java.util.Map; | ||
| 15 | 20 | ||
| 16 | public class RDFoxTripleManager { | 21 | public class RDFoxTripleManager { |
| 17 | 22 | ||
| 18 | UpdateType m_incrementally; | 23 | private final Cache termsCache; |
| 24 | private static final int TERMS_CACHE_SIZE = 10000; | ||
| 25 | private static final int CACHE_TTL_DEFAULT = 0; | ||
| 26 | private static final int CACHE_TTI_DEFAULT = 0; | ||
| 27 | private static final boolean CACHE_ETERNAL = true; | ||
| 28 | private static final boolean CACHE_USE_DISK = false; | ||
| 29 | |||
| 30 | UpdateType m_incrementally; | ||
| 19 | // boolean m_incrementally; | 31 | // boolean m_incrementally; |
| 20 | 32 | ||
| 21 | DataStore m_store; | 33 | DataStore m_store; |
| @@ -24,7 +36,19 @@ public class RDFoxTripleManager { | |||
| 24 | 36 | ||
| 25 | public RDFoxTripleManager(DataStore store, boolean incrementally) { | 37 | public RDFoxTripleManager(DataStore store, boolean incrementally) { |
| 26 | m_store = store; | 38 | m_store = store; |
| 27 | // m_incrementally = incrementally; | 39 | // m_incrementally = incrementally; |
| 40 | |||
| 41 | CacheManager cacheManager = CacheManager.getInstance(); | ||
| 42 | String cacheName = "RDFoxTripleManager_" + store.hashCode(); | ||
| 43 | if(! cacheManager.cacheExists(cacheName)) { | ||
| 44 | termsCache = new Cache(cacheName, | ||
| 45 | TERMS_CACHE_SIZE, CACHE_USE_DISK, CACHE_ETERNAL, | ||
| 46 | CACHE_TTL_DEFAULT, CACHE_TTI_DEFAULT); | ||
| 47 | cacheManager.addCache(termsCache); | ||
| 48 | } | ||
| 49 | else | ||
| 50 | termsCache = cacheManager.getCache(cacheName); | ||
| 51 | |||
| 28 | if (incrementally) | 52 | if (incrementally) |
| 29 | m_incrementally = UpdateType.ScheduleForAddition; | 53 | m_incrementally = UpdateType.ScheduleForAddition; |
| 30 | else | 54 | else |
| @@ -164,29 +188,25 @@ public class RDFoxTripleManager { | |||
| 164 | return m_dict.resolveResources(lexicalForms, types)[0]; | 188 | return m_dict.resolveResources(lexicalForms, types)[0]; |
| 165 | } | 189 | } |
| 166 | 190 | ||
| 167 | Map<Term, Integer> termCache = new HashMap<Term, Integer>(); | 191 | // Map<Term, Integer> termCache = new HashMap<Term, Integer>(); |
| 168 | Queue<Term> termList = new LinkedList<Term>(); | 192 | // Queue<Term> termQueue = new LinkedList<Term>(); |
| 169 | int sizeLimit = 10000; | ||
| 170 | 193 | ||
| 171 | private int getResourceID(Term arg, Map<Variable, Integer> assignment) { | 194 | private int getResourceID(Term arg, Map<Variable, Integer> assignment) { |
| 172 | // FIXME infinite loop | ||
| 173 | // while (termCache.size() > sizeLimit) | ||
| 174 | // termCache.remove(termList.poll()); | ||
| 175 | |||
| 176 | if (arg instanceof Variable) return assignment.get(arg); | 195 | if (arg instanceof Variable) return assignment.get(arg); |
| 177 | Integer id = null; | 196 | int id = -1; |
| 178 | if ((id = termCache.get(arg)) != null) | 197 | if(termsCache.isKeyInCache(arg)) |
| 179 | return id; | 198 | return ((int) termsCache.get(arg).getObjectValue()); |
| 180 | 199 | ||
| 181 | // if (arg instanceof Individual) { | 200 | // if (arg instanceof Individual) { |
| 182 | try { | 201 | try { |
| 183 | if (arg instanceof Individual) | 202 | if (arg instanceof Individual) |
| 184 | termCache.put(arg, id = resolveResource(((Individual) arg).getIRI(), Datatype.IRI_REFERENCE.value())); | 203 | termsCache.put(new Element(arg, id = resolveResource(((Individual) arg).getIRI(), Datatype.IRI_REFERENCE.value()))); |
| 185 | else if (arg instanceof Constant) | 204 | else if (arg instanceof Constant) |
| 186 | termCache.put(arg, id = resolveResource(((Constant) arg).getLexicalForm(), getDatatypeID(((Constant) arg).getDatatypeURI()))); | 205 | termsCache.put(new Element(arg, id = resolveResource(((Constant) arg).getLexicalForm(), getDatatypeID(((Constant) arg).getDatatypeURI())))); |
| 187 | 206 | ||
| 188 | } catch (JRDFStoreException e) { | 207 | } catch (JRDFStoreException e) { |
| 189 | e.printStackTrace(); | 208 | e.printStackTrace(); |
| 209 | System.exit(1); | ||
| 190 | } | 210 | } |
| 191 | // } | 211 | // } |
| 192 | 212 | ||
