1 19 20 package com.hp.hpl.jena.reasoner.dig; 23 24 25 import org.w3c.dom.*; 28 29 import com.hp.hpl.jena.rdf.model.Model; 30 import com.hp.hpl.jena.reasoner.TriplePattern; 31 import com.hp.hpl.jena.util.iterator.*; 32 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 33 34 35 36 48 public class DIGQueryInstanceTranslator 49 extends DIGQueryTranslator 50 { 51 52 55 58 61 64 68 public DIGQueryInstanceTranslator( String predicate ) { 69 super( null, predicate, null ); 70 } 71 72 73 76 77 81 public Document translatePattern( TriplePattern pattern, DIGAdapter da ) { 82 DIGConnection dc = da.getConnection(); 83 Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() ); 84 Element instance = da.createQueryElement( query, DIGProfile.INSTANCE ); 85 da.addNamedElement( instance, DIGProfile.INDIVIDUAL, da.getNodeID( pattern.getSubject() ) ); 86 da.addClassDescription( instance, pattern.getObject() ); 87 88 return query; 89 } 90 91 92 96 public Document translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) { 97 DIGConnection dc = da.getConnection(); 98 Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() ); 99 Element instance = da.createQueryElement( query, DIGProfile.INSTANCE ); 100 101 da.addNamedElement( instance, DIGProfile.INDIVIDUAL, da.getNodeID( pattern.getSubject() ) ); 102 103 if (pattern.getObject().isBlank()) { 104 da.addClassDescription( instance, pattern.getObject(), premises ); 105 } 106 else { 107 da.addClassDescription( instance, pattern.getObject() ); 108 } 109 return query; 110 } 111 112 113 116 public ExtendedIterator translateResponseHook( Document response, TriplePattern query, DIGAdapter da ) { 117 return isFalse( response ) ? NullIterator.instance : (ExtendedIterator) new SingletonIterator( query.asTriple() ); 118 } 119 120 public boolean checkObject( com.hp.hpl.jena.graph.Node object, DIGAdapter da, Model premises ) { 121 return da.isConcept( object, premises ); 122 } 123 124 127 131 } 132 133 134 160 | Popular Tags |