1 19 20 package com.hp.hpl.jena.reasoner.dig; 23 24 25 26 27 28 import java.util.Iterator ; 31 32 import com.hp.hpl.jena.graph.*; 33 import com.hp.hpl.jena.graph.compose.MultiUnion; 34 import com.hp.hpl.jena.ontology.OntModel; 35 import com.hp.hpl.jena.ontology.Profile; 36 import com.hp.hpl.jena.rdf.model.*; 37 import com.hp.hpl.jena.reasoner.*; 38 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 39 import com.hp.hpl.jena.vocabulary.RDF; 40 41 42 51 public class DIGInfGraph 52 extends BaseInfGraph 53 { 54 57 58 61 62 65 66 protected DIGAdapter m_adapter; 67 68 69 72 78 public DIGInfGraph( Graph data, DIGReasoner reasoner ) { 79 super( data, reasoner ); 80 81 if (reasoner.getSchema() != null) { 83 fdata = new FGraph( new MultiUnion( new Graph[] {data, reasoner.getSchema()} ) ); 84 } 85 86 DIGConnection conn = DIGConnectionPool.getInstance().allocate( reasoner.getReasonerURL() ); 88 m_adapter = new DIGAdapter( reasoner.getOntLangModelSpec(), fdata.getGraph(), conn, reasoner.getAxioms() ); 89 } 90 91 92 95 103 public void prepare() { 104 if (!isPrepared) { 105 m_adapter.resetKB(); 106 m_adapter.uploadKB(); 107 isPrepared = true; 108 } 109 } 110 111 128 public ExtendedIterator findWithContinuation(TriplePattern pattern, Finder continuation) { 129 prepare(); 130 return m_adapter.find( pattern ); 131 } 132 133 134 151 public ExtendedIterator find( Node subject, Node property, Node object, Graph param ) { 152 OntModel premises = ModelFactory.createOntologyModel( m_adapter.getSourceSpecification(), 153 ModelFactory.createModelForGraph( param ) ); 154 premises.setStrictMode( false ); 155 prepare(); 156 return m_adapter.find( new TriplePattern( subject, property, object ), premises ); 157 } 158 159 162 public Graph getSchemaGraph() { 163 return ((DIGReasoner) reasoner).getSchema(); 164 } 165 166 168 173 public synchronized void performAdd(Triple t) { 174 fdata.getGraph().add(t); 175 isPrepared = false; 176 } 177 178 183 public void performDelete(Triple t) { 184 fdata.getGraph().delete(t); 185 isPrepared = false; 186 } 187 188 195 public void rebind( Graph data ) { 196 if (getSchemaGraph() == null) { 197 fdata = new FGraph(data); 198 } 199 else { 200 fdata = new FGraph( new MultiUnion( new Graph[] {data, getSchemaGraph()} ) ); 201 } 202 203 isPrepared = false; 204 } 205 206 207 210 public void setDerivationLogging(boolean logOn) { 211 throw new UnsupportedOperationException ( "Cannot set derivation logging on DIG reasoner" ); 212 } 213 214 215 220 public ValidityReport validate() { 221 checkOpen(); 222 prepare(); 223 StandardValidityReport report = new StandardValidityReport(); 224 225 try { 227 m_adapter.collectNamedTerms( DIGProfile.ALL_INDIVIDUALS, 228 new String [] {DIGProfile.INDIVIDUAL_SET, DIGProfile.INDIVIDUAL} ); 229 } 230 catch (DIGErrorResponseException e) { 231 report.add( true, "DIG KB incoherent", e.getMessage() ); 232 } 233 234 Profile p = m_adapter.getOntLanguage(); 236 Node nothing = p.NOTHING().asNode(); 237 Property equivClass = p.EQUIVALENT_CLASS(); 238 DIGQueryEquivalentsTranslator q = new DIGQueryEquivalentsTranslator( equivClass.getURI(), true ); 239 ExtendedIterator i = q.find( new TriplePattern( null, equivClass.asNode(), p.NOTHING().asNode() ), m_adapter ); 240 241 while (i.hasNext()) { 242 Triple t = (Triple) i.next(); 243 Node subj = t.getSubject(); 244 if (subj != nothing) { 245 report.add( true, "unsatisfiable class", (subj.isBlank() ? subj.getBlankNodeId().toString() : subj.getURI()), t.getSubject() ); 246 } 247 } 248 249 DIGQueryTypesTranslator q1 = new DIGQueryTypesTranslator( RDF.type.getURI() ); 251 DIGValueToNodeMapper vMap = new DIGValueToNodeMapper(); 252 for (Iterator j = m_adapter.getKnownIndividuals().iterator(); j.hasNext(); ) { 253 String ind = (String ) j.next(); 254 Node indNode = (Node) vMap.map1( ind ); 255 256 try { 257 ExtendedIterator i1 = q1.find( new TriplePattern( indNode, RDF.type.asNode(), null ), m_adapter ); 258 } 259 catch (DIGErrorResponseException e) { 260 report.add( true, "meaningless individual", (indNode.isBlank() ? indNode.getBlankNodeId().toString() : indNode.getURI()), ind ); 262 } 263 } 264 265 return report; 266 } 267 268 269 270 273 274 278 279 280 } 281 282 283 309 | Popular Tags |