1 19 20 package com.hp.hpl.jena.reasoner.dig; 23 24 25 import org.w3c.dom.*; 28 29 import com.hp.hpl.jena.graph.Triple; 30 import com.hp.hpl.jena.rdf.model.Model; 31 import com.hp.hpl.jena.reasoner.TriplePattern; 32 import com.hp.hpl.jena.util.iterator.*; 33 34 35 36 49 public class DIGQueryAncestorsTranslator 50 extends DIGQueryTranslator 51 { 52 53 56 59 62 63 protected boolean m_ancestors; 64 65 66 69 74 public DIGQueryAncestorsTranslator( String predicate, boolean ancestors ) { 75 this( (ancestors ? null : ALL), predicate, (ancestors ? ALL : null), ancestors ); 76 } 77 78 82 protected DIGQueryAncestorsTranslator( String subj, String pred, String obj, boolean anc ) { 83 super( subj, pred, obj ); 84 m_ancestors = anc; 85 } 86 87 88 91 92 95 public Document translatePattern( TriplePattern pattern, DIGAdapter da ) { 96 DIGConnection dc = da.getConnection(); 97 Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() ); 98 99 if (m_ancestors) { 100 Element ancestors = da.createQueryElement( query, DIGProfile.ANCESTORS ); 101 da.addClassDescription( ancestors, pattern.getSubject() ); 102 } 103 else { 104 Element descendants = da.createQueryElement( query, DIGProfile.DESCENDANTS ); 105 da.addClassDescription( descendants, pattern.getObject() ); 106 } 107 108 return query; 109 } 110 111 112 115 public ExtendedIterator translateResponseHook( Document response, TriplePattern query, DIGAdapter da ) { 116 return translateConceptSetResponse( response, query, m_ancestors, da ) 118 .andThen( new SingletonIterator( 119 new Triple( m_ancestors ? query.getSubject() : query.getObject(), 120 query.getPredicate(), 121 m_ancestors ? query.getSubject() : query.getObject() ) ) ); 122 } 123 124 125 public Document translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) { 126 return null; 128 } 129 130 public boolean checkSubject( com.hp.hpl.jena.graph.Node subject, DIGAdapter da, Model premises ) { 131 return !m_ancestors || da.isConcept( subject, premises ); 132 } 133 134 public boolean checkObject( com.hp.hpl.jena.graph.Node object, DIGAdapter da, Model premises ) { 135 return m_ancestors || da.isConcept( object, premises ); 136 } 137 138 139 142 146 } 147 148 149 175 | Popular Tags |