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 DIGQuerySubsumesTranslator 49 extends DIGQueryTranslator 50 { 51 52 55 58 61 64 68 public DIGQuerySubsumesTranslator( String predicate ) { 69 super( null, predicate, null ); 70 } 71 72 73 76 77 80 public Document translatePattern( TriplePattern pattern, DIGAdapter da ) { 81 DIGConnection dc = da.getConnection(); 82 Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() ); 83 Element subsumes = da.createQueryElement( query, DIGProfile.SUBSUMES ); 84 85 da.addClassDescription( subsumes, pattern.getObject() ); 87 da.addClassDescription( subsumes, pattern.getSubject() ); 88 89 return query; 90 } 91 92 93 97 public Document translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) { 98 DIGConnection dc = da.getConnection(); 99 Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() ); 100 Element subsumes = da.createQueryElement( query, DIGProfile.SUBSUMES ); 101 102 if (pattern.getObject().isBlank()) { 104 da.addClassDescription( subsumes, pattern.getObject(), premises ); 105 } 106 else { 107 da.addClassDescription( subsumes, pattern.getObject() ); 108 } 109 110 if (pattern.getSubject().isBlank()) { 111 da.addClassDescription( subsumes, pattern.getSubject(), premises ); 112 } 113 else { 114 da.addClassDescription( subsumes, pattern.getSubject() ); 115 } 116 117 return query; 118 } 119 120 121 124 public ExtendedIterator translateResponseHook( Document response, TriplePattern query, DIGAdapter da ) { 125 return isTrue( response ) ? (ExtendedIterator) new SingletonIterator( query.asTriple() ) : NullIterator.instance; 126 } 127 128 public boolean checkSubject( com.hp.hpl.jena.graph.Node subject, DIGAdapter da, Model premises ) { 129 boolean isSubjectConcept = da.isConcept( subject, premises ); 130 return isSubjectConcept; 131 } 132 133 public boolean checkObject( com.hp.hpl.jena.graph.Node object, DIGAdapter da, Model premises ) { 134 boolean isObjectConcept = da.isConcept( object, premises ); 135 return isObjectConcept; 136 } 137 138 141 145 } 146 147 148 174 | Popular Tags |