1 19 20 package com.hp.hpl.jena.reasoner.dig; 23 24 25 import org.apache.commons.logging.LogFactory; 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.Element ; 30 31 import com.hp.hpl.jena.graph.Node; 32 import com.hp.hpl.jena.rdf.model.*; 33 import com.hp.hpl.jena.reasoner.TriplePattern; 34 import com.hp.hpl.jena.util.iterator.*; 35 36 37 48 public class DIGQueryIsEquivalentTranslator 49 extends DIGQueryTranslator 50 { 51 54 57 60 61 protected String m_predicate; 62 63 protected Node m_qSubject; 64 protected Node m_qObject; 65 66 67 70 74 public DIGQueryIsEquivalentTranslator( String predicate ) { 75 super( null, null, null ); 76 m_predicate = predicate; 77 } 78 79 80 83 86 public Document translatePattern( TriplePattern pattern, DIGAdapter da ) { 87 return translatePattern( pattern, da, null ); 88 } 89 90 91 public Document translatePattern( TriplePattern pattern, DIGAdapter da, Model premises ) { 92 DIGConnection dc = da.getConnection(); 93 Document query = dc.createDigVerb( DIGProfile.ASKS, da.getProfile() ); 94 95 m_qSubject = pattern.getSubject(); 98 m_qObject = pattern.getObject(); 99 100 if (m_qSubject.isBlank() && m_qObject.isBlank()) { 101 LogFactory.getLog( getClass() ).warn( "DIG 1.1 cannot handle isConcept query with two expressions" ); 102 return null; 103 } 104 else if (m_qObject.isBlank()) { 105 Node temp = m_qSubject; 107 m_qSubject = m_qObject; 108 m_qObject = temp; 109 } 110 111 Node p = pattern.getPredicate(); 114 if (!m_qObject.isBlank() && 115 (p.getURI().equals( da.getOntLanguage().UNION_OF().getURI()) || 116 p.getURI().equals( da.getOntLanguage().INTERSECTION_OF().getURI()) || 117 p.getURI().equals( da.getOntLanguage().COMPLEMENT_OF().getURI()) ) || 118 p.getURI().equals( da.getOntLanguage().ONE_OF().getURI()) 119 ) 120 { 121 if (premises == null) { 122 LogFactory.getLog( getClass() ).warn( "Cannot add comprehension axiom bNode for query because premises model is null" ); 123 } 124 else { 125 Resource comp = premises.createResource( da.getOntLanguage().CLASS() ); 127 premises.add( comp, premises.getProperty( p.getURI() ), premises.getRDFNode( m_qSubject ) ); 128 m_qSubject = comp.getNode(); 129 } 130 } 131 132 Element equivalents = da.createQueryElement( query, DIGProfile.EQUIVALENTS ); 133 da.addClassDescription( equivalents, m_qSubject, premises ); 134 135 return query; 136 } 137 138 139 142 public ExtendedIterator translateResponseHook( Document response, TriplePattern query, DIGAdapter da ) { 143 return conceptSetNameCheck( response, da, m_qObject, query.asTriple() ); 144 } 145 146 147 155 public boolean checkTriple( TriplePattern pattern, DIGAdapter da, Model premises ) { 156 Node object = pattern.getObject(); 157 Node subject = pattern.getSubject(); 158 Node pred = pattern.getPredicate(); 159 160 boolean pass = subject.isConcrete() && object.isConcrete() && pred.isConcrete(); 162 163 pass = pass && ((object.isBlank() || da.isConcept( object, premises )) && 165 (subject.isBlank()) || da.isConcept( subject, premises ) && 166 (!subject.isBlank() || !object.isBlank())); 167 168 pass = pass && 170 (pred.getURI().equals( m_predicate ) || 171 pred.getURI().equals( da.getOntLanguage().UNION_OF().getURI() ) || 172 pred.getURI().equals( da.getOntLanguage().INTERSECTION_OF().getURI() ) || 173 pred.getURI().equals( da.getOntLanguage().COMPLEMENT_OF().getURI() ) || 174 pred.getURI().equals( da.getOntLanguage().ONE_OF().getURI() ) 175 ); 176 177 return pass; 178 } 179 180 public boolean trigger( TriplePattern pattern, DIGAdapter da, Model premises ) { 181 return super.trigger( pattern, da, premises ); 182 } 183 184 187 191 } 192 193 194 220 | Popular Tags |