1 19 20 package com.hp.hpl.jena.reasoner.dig; 23 24 25 import org.w3c.dom.Element ; 28 import org.w3c.dom.Document ; 29 30 import com.hp.hpl.jena.graph.Node; 31 import com.hp.hpl.jena.graph.Triple; 32 import com.hp.hpl.jena.reasoner.TriplePattern; 33 import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable; 34 import com.hp.hpl.jena.util.iterator.Filter; 35 36 37 38 51 public class DIGQueryParentsTranslator 52 extends DIGQueryAncestorsTranslator 53 { 54 55 58 61 64 65 68 73 public DIGQueryParentsTranslator( String predicate, boolean parents ) { 74 super( predicate, parents ); 75 } 76 77 78 86 public DIGQueryParentsTranslator( String subject, String predicate, String object, boolean parents ) { 87 super( subject, predicate, object, parents ); 88 } 89 90 91 94 95 98 public Document translatePattern( TriplePattern pattern, DIGAdapter da ) { 99 DIGConnection dc = da.getConnection(); 100 Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() ); 101 102 if (m_ancestors) { 103 Element parents = da.createQueryElement( query, DIGProfile.PARENTS ); 104 da.addClassDescription( parents, pattern.getSubject() ); 105 } 106 else { 107 Element descendants = da.createQueryElement( query, DIGProfile.CHILDREN ); 108 da.addClassDescription( descendants, pattern.getObject() ); 109 } 110 111 return query; 112 } 113 114 119 protected Filter getResultsTripleFilter( TriplePattern query ) { 120 return new FilterSubjectAndObject( query.getSubject(), query.getObject() ); 121 } 122 123 124 127 131 private class FilterSubjectAndObject 132 implements Filter 133 { 134 private Node m_subj; 135 private Node m_obj; 136 137 private FilterSubjectAndObject( Node subj, Node obj ) { 138 m_subj = subj; 139 m_obj = obj; 140 } 141 142 public boolean accept( Object o ) { 143 Triple t = (Triple) o; 144 return ((m_subj == null) || 145 (m_subj == Node_RuleVariable.WILD) || 146 (m_subj == Node.ANY) || 147 (t.getSubject().equals( m_subj ))) && 148 ((m_obj == null) || 149 (m_obj == Node_RuleVariable.WILD) || 150 (m_obj == Node.ANY) || 151 (t.getObject().equals( m_obj ))); 152 } 153 154 } 155 } 156 157 158 184 | Popular Tags |