1 10 package com.hp.hpl.jena.reasoner.transitiveReasoner; 11 12 import com.hp.hpl.jena.reasoner.BaseInfGraph; 13 import com.hp.hpl.jena.reasoner.*; 14 import com.hp.hpl.jena.graph.*; 15 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 16 import com.hp.hpl.jena.util.iterator.UniqueExtendedIterator; 17 18 32 public class TransitiveInfGraph extends BaseInfGraph { 33 34 35 protected TransitiveEngine transitiveEngine; 36 37 38 protected Finder tbox = null; 39 40 41 protected Finder dataFind; 42 43 50 public TransitiveInfGraph(Graph data, TransitiveReasoner reasoner) { 51 super(data, reasoner); 52 } 53 54 62 public void prepare() { 63 tbox = ((TransitiveReasoner)reasoner).getTbox(); 64 transitiveEngine = new TransitiveEngine(((TransitiveReasoner)reasoner).getSubClassCache(), 66 ((TransitiveReasoner)reasoner).getSubPropertyCache()); 67 68 dataFind = transitiveEngine.insert(tbox, fdata); 70 transitiveEngine.setCaching(true, true); 71 72 isPrepared = true; 73 } 74 75 78 public Graph getSchemaGraph() { 79 if (tbox == null) return null; 80 if (tbox instanceof FGraph) { 81 return ((FGraph)tbox).getGraph(); 82 } else { 83 throw new ReasonerException("Transitive reasoner got into an illegal state"); 84 } 85 } 86 87 98 public ExtendedIterator findWithContinuation(TriplePattern pattern, Finder continuation) { 99 checkOpen(); 100 if (!isPrepared) prepare(); 101 Finder cascade = transitiveEngine.getFinder(pattern, FinderUtil.cascade(tbox, continuation)); 102 return new UniqueExtendedIterator(cascade.find(pattern)); 103 } 104 105 108 public ExtendedIterator graphBaseFind(Node subject, Node property, Node object) { 109 return findWithContinuation(new TriplePattern(subject, property, object), fdata); 110 } 111 112 118 public ExtendedIterator find(TriplePattern pattern) { 119 return findWithContinuation(pattern, fdata); 120 } 121 122 126 public synchronized void performAdd(Triple t) { 127 if (!isPrepared) prepare(); 128 fdata.getGraph().add(t); 129 transitiveEngine.add(t); 130 } 131 132 135 public void performDelete(Triple t) { 136 fdata.getGraph().delete(t); 137 if (isPrepared) { 138 transitiveEngine.delete(t); 139 } 140 } 141 144 public Capabilities getCapabilities() 145 { 146 if (capabilities == null) capabilities = new InfFindSafeCapabilities(); 147 return capabilities; 148 } 149 150 } 151 152 178 179 | Popular Tags |