1 19 20 package com.hp.hpl.jena.reasoner.dig; 23 24 25 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import org.w3c.dom.*; 31 32 import com.hp.hpl.jena.rdf.model.Model; 33 import com.hp.hpl.jena.rdf.model.Resource; 34 import com.hp.hpl.jena.reasoner.TriplePattern; 35 import com.hp.hpl.jena.util.iterator.*; 36 import com.hp.hpl.jena.util.xml.SimpleXMLPath; 37 import com.hp.hpl.jena.vocabulary.*; 38 import com.hp.hpl.jena.vocabulary.RDF; 39 import com.hp.hpl.jena.vocabulary.RDFS; 40 41 42 43 55 public class DIGQueryRoleFillerTranslator 56 extends DIGQueryTranslator 57 { 58 59 62 65 68 69 72 75 public DIGQueryRoleFillerTranslator() { 76 super( null, null, null ); 77 } 78 79 80 83 84 87 public Document translatePattern( TriplePattern pattern, DIGAdapter da ) { 88 DIGConnection dc = da.getConnection(); 89 Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() ); 90 91 Element instances = da.createQueryElement( query, DIGProfile.ROLE_FILLERS ); 92 da.addNamedElement( instances, DIGProfile.INDIVIDUAL, da.getNodeID( pattern.getSubject() ) ); 93 da.addNamedElement( instances, DIGProfile.RATOM, da.getNodeID( pattern.getPredicate() ) ); 94 95 return query; 96 } 97 98 99 102 public ExtendedIterator translateResponseHook( Document response, TriplePattern query, DIGAdapter da ) { 103 SimpleXMLPath p = new SimpleXMLPath( true ); 105 p.appendElementPath( DIGProfile.INDIVIDUAL_SET ); 106 p.appendElementPath( DIGProfile.INDIVIDUAL ); 107 p.appendAttrPath( DIGProfile.NAME ); 108 109 List matches = new ArrayList (); 111 ExtendedIterator iNodes = p.getAll( response ).mapWith( new DIGValueToNodeMapper() ); 112 try { 113 while (iNodes.hasNext()) { 114 com.hp.hpl.jena.graph.Node result = (com.hp.hpl.jena.graph.Node) iNodes.next(); 115 if (result.equals( query.getObject() )) { 116 matches.add( query.asTriple() ); 117 break; 118 } 119 } 120 } 121 finally { 122 iNodes.close(); 123 } 124 125 return WrappedIterator.create( matches.iterator() ); 127 } 128 129 130 public Document translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) { 131 return translatePattern( pattern, da ); 132 } 133 134 public boolean checkSubject( com.hp.hpl.jena.graph.Node subject, DIGAdapter da, Model premises ) { 135 return subject.isConcrete() && da.isIndividual( subject ); 136 } 137 138 public boolean checkObject( com.hp.hpl.jena.graph.Node object, DIGAdapter da, Model premises ) { 139 return object.isConcrete() && da.isIndividual( object ); 140 } 141 142 public boolean checkPredicate( com.hp.hpl.jena.graph.Node predicate, DIGAdapter da, Model premises ) { 143 if (predicate.isConcrete()) { 146 Resource p = (Resource) da.m_sourceData.getRDFNode( predicate ); 147 String pNS = p.getNameSpace(); 148 return !(da.m_sourceData.contains( p, RDF.type, da.m_sourceData.getProfile().DATATYPE_PROPERTY() ) || 149 RDFS.getURI().equals( pNS ) || 150 RDF.getURI().equals( pNS ) || 151 OWL.getURI().equals( pNS )); 152 } 153 else { 154 return false; 155 } 156 } 157 158 159 162 166 } 167 168 169 195 | Popular Tags |