001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email Ian.Dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created July 19th 2003
009: * Filename $RCSfile: DIGQueryRoleFillersTranslator.java,v $
010: * Revision $Revision: 1.12 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:07:11 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * [See end of file]
018: * ****************************************************************************/package com.hp.hpl.jena.reasoner.dig;
019:
020: // Imports
021: ///////////////
022: import org.w3c.dom.*;
023:
024: import com.hp.hpl.jena.rdf.model.Model;
025: import com.hp.hpl.jena.rdf.model.Resource;
026: import com.hp.hpl.jena.reasoner.TriplePattern;
027: import com.hp.hpl.jena.util.iterator.*;
028: import com.hp.hpl.jena.vocabulary.*;
029: import com.hp.hpl.jena.vocabulary.RDF;
030:
031: /**
032: * <p>
033: * Translator that generates DIG roleFillers queries in response to a find queries:
034: * <pre>
035: * :a :r *
036: * </pre>
037: * or similar.
038: * </p>
039: *
040: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
041: * @version CVS $Id: DIGQueryRoleFillersTranslator.java,v 1.12 2008/01/02 12:07:11 andy_seaborne Exp $
042: */
043: public class DIGQueryRoleFillersTranslator extends DIGQueryTranslator {
044:
045: // Constants
046: //////////////////////////////////
047:
048: // Static variables
049: //////////////////////////////////
050:
051: // Instance variables
052: //////////////////////////////////
053:
054: // Constructors
055: //////////////////////////////////
056:
057: /**
058: * <p>Construct a translator for the DIG query 'roleFillers'.</p>
059: */
060: public DIGQueryRoleFillersTranslator() {
061: super (null, null, ALL);
062: }
063:
064: // External signature methods
065: //////////////////////////////////
066:
067: /**
068: * <p>Answer a query that will list the role fillers for an individual-role pair</p>
069: */
070: public Document translatePattern(TriplePattern pattern,
071: DIGAdapter da) {
072: DIGConnection dc = da.getConnection();
073: Document query = dc.createDigVerb(DIGProfile.ASKS, da
074: .getProfile());
075:
076: Element instances = da.createQueryElement(query,
077: DIGProfile.ROLE_FILLERS);
078: da.addNamedElement(instances, DIGProfile.INDIVIDUAL, da
079: .getNodeID(pattern.getSubject()));
080: da.addNamedElement(instances, DIGProfile.RATOM, da
081: .getNodeID(pattern.getPredicate()));
082:
083: return query;
084: }
085:
086: /**
087: * <p>Answer an iterator of triples that match the original find query.</p>
088: */
089: public ExtendedIterator translateResponseHook(Document response,
090: TriplePattern query, DIGAdapter da) {
091: // translate the concept set to triples, but then we must add :a rdfs:subClassOf :a to match owl semantics
092: return translateIndividualSetResponse(response, query, true);
093: }
094:
095: public Document translatePattern(TriplePattern pattern,
096: DIGAdapter da, Model premises) {
097: // not used
098: return null;
099: }
100:
101: public boolean checkSubject(com.hp.hpl.jena.graph.Node subject,
102: DIGAdapter da, Model premises) {
103: return subject.isConcrete() && da.isIndividual(subject);
104: }
105:
106: public boolean checkPredicate(com.hp.hpl.jena.graph.Node predicate,
107: DIGAdapter da, Model premises) {
108: // check that the predicate is not a datatype property
109: if (predicate.isConcrete()) {
110: Resource p = (Resource) da.m_sourceData
111: .getRDFNode(predicate);
112: String pNS = p.getNameSpace();
113: return !(da.m_sourceData.contains(p, RDF.type,
114: da.m_sourceData.getProfile().DATATYPE_PROPERTY())
115: || RDFS.getURI().equals(pNS)
116: || RDF.getURI().equals(pNS) || OWL.getURI().equals(
117: pNS));
118: } else {
119: return false;
120: }
121: }
122:
123: // Internal implementation methods
124: //////////////////////////////////
125:
126: //==============================================================================
127: // Inner class definitions
128: //==============================================================================
129:
130: }
131:
132: /*
133: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
134: * All rights reserved.
135: *
136: * Redistribution and use in source and binary forms, with or without
137: * modification, are permitted provided that the following conditions
138: * are met:
139: * 1. Redistributions of source code must retain the above copyright
140: * notice, this list of conditions and the following disclaimer.
141: * 2. Redistributions in binary form must reproduce the above copyright
142: * notice, this list of conditions and the following disclaimer in the
143: * documentation and/or other materials provided with the distribution.
144: * 3. The name of the author may not be used to endorse or promote products
145: * derived from this software without specific prior written permission.
146: *
147: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
148: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
149: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
150: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
151: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
152: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
153: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
154: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
155: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
156: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
157: */
|