diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/light/RDFoxTripleManager.java | 54 |
1 files changed, 37 insertions, 17 deletions
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 | ||
