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 April 23rd 2006
009: * Filename $RCSfile: DIGQueryRelatedIndividualsTranslator.java,v $
010: * Revision $Revision: 1.3 $
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 relatedIndividuals queries in response to a find queries:
034: * <pre>
035: * * :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: DIGQueryRelatedIndividualsTranslator.java,v 1.3 2008/01/02 12:07:11 andy_seaborne Exp $
042: */
043: public class DIGQueryRelatedIndividualsTranslator extends
044: DIGQueryTranslator {
045:
046: // Constants
047: //////////////////////////////////
048:
049: // Static variables
050: //////////////////////////////////
051:
052: // Instance variables
053: //////////////////////////////////
054:
055: // Constructors
056: //////////////////////////////////
057:
058: /**
059: * <p>Construct a translator for the DIG query 'relatedIndividuals'.</p>
060: */
061: public DIGQueryRelatedIndividualsTranslator() {
062: super (ALL, null, ALL);
063: }
064:
065: // External signature methods
066: //////////////////////////////////
067:
068: /**
069: * <p>Answer a query that will list the role fillers for an individual-role pair</p>
070: */
071: public Document translatePattern(TriplePattern pattern,
072: DIGAdapter da) {
073: DIGConnection dc = da.getConnection();
074: Document query = dc.createDigVerb(DIGProfile.ASKS, da
075: .getProfile());
076:
077: Element instances = da.createQueryElement(query,
078: DIGProfile.RELATED_INDIVIDUALS);
079: da.addNamedElement(instances, DIGProfile.RATOM, da
080: .getNodeID(pattern.getPredicate()));
081:
082: return query;
083: }
084:
085: /**
086: * <p>Answer an iterator of triples that match the original find query.</p>
087: */
088: public ExtendedIterator translateResponseHook(Document response,
089: TriplePattern query, DIGAdapter da) {
090: return translateIndividualPairSetResponse(response, query);
091: }
092:
093: public Document translatePattern(TriplePattern pattern,
094: DIGAdapter da, Model premises) {
095: // not used
096: return null;
097: }
098:
099: public boolean checkPredicate(com.hp.hpl.jena.graph.Node predicate,
100: DIGAdapter da, Model premises) {
101: // check that the predicate is not a datatype property
102: if (predicate.isConcrete()) {
103: Resource p = (Resource) da.m_sourceData
104: .getRDFNode(predicate);
105: String pNS = p.getNameSpace();
106: return !(da.m_sourceData.contains(p, RDF.type,
107: da.m_sourceData.getProfile().DATATYPE_PROPERTY())
108: || RDFS.getURI().equals(pNS)
109: || RDF.getURI().equals(pNS) || OWL.getURI().equals(
110: pNS));
111: } else {
112: return false;
113: }
114: }
115:
116: // Internal implementation methods
117: //////////////////////////////////
118:
119: //==============================================================================
120: // Inner class definitions
121: //==============================================================================
122:
123: }
124:
125: /*
126: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
127: * All rights reserved.
128: *
129: * Redistribution and use in source and binary forms, with or without
130: * modification, are permitted provided that the following conditions
131: * are met:
132: * 1. Redistributions of source code must retain the above copyright
133: * notice, this list of conditions and the following disclaimer.
134: * 2. Redistributions in binary form must reproduce the above copyright
135: * notice, this list of conditions and the following disclaimer in the
136: * documentation and/or other materials provided with the distribution.
137: * 3. The name of the author may not be used to endorse or promote products
138: * derived from this software without specific prior written permission.
139: *
140: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
141: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
142: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
143: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
144: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
145: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
146: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
147: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
148: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
149: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
150: */
|