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: DIGQueryInstancesTranslator.java,v $
010: * Revision $Revision: 1.10 $
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.reasoner.TriplePattern;
026: import com.hp.hpl.jena.util.iterator.*;
027:
028: /**
029: * <p>
030: * Translator that generates DIG instances queries in response to a find queries:
031: * <pre>
032: * * rdf:type :C
033: * </pre>
034: * or similar.
035: * </p>
036: *
037: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
038: * @version CVS $Id: DIGQueryInstancesTranslator.java,v 1.10 2008/01/02 12:07:11 andy_seaborne Exp $
039: */
040: public class DIGQueryInstancesTranslator extends DIGQueryTranslator {
041:
042: // Constants
043: //////////////////////////////////
044:
045: // Static variables
046: //////////////////////////////////
047:
048: // Instance variables
049: //////////////////////////////////
050:
051: // Constructors
052: //////////////////////////////////
053:
054: /**
055: * <p>Construct a translator for the DIG query 'instances'.</p>
056: * @param predicate The predicate URI to trigger on
057: */
058: public DIGQueryInstancesTranslator(String predicate) {
059: super (ALL, predicate, null);
060: }
061:
062: // External signature methods
063: //////////////////////////////////
064:
065: /**
066: * <p>Answer a query that will list the instances of a concept</p>
067: */
068: public Document translatePattern(TriplePattern pattern,
069: DIGAdapter da) {
070: DIGConnection dc = da.getConnection();
071: Document query = dc.createDigVerb(DIGProfile.ASKS, da
072: .getProfile());
073:
074: Element instances = da.createQueryElement(query,
075: DIGProfile.INSTANCES);
076: da.addClassDescription(instances, pattern.getObject());
077:
078: return query;
079: }
080:
081: /**
082: * <p>Answer a query that will list the instances of a given concept, optionally defined
083: * as a class expression in the premises.</p>
084: */
085: public Document translatePattern(TriplePattern pattern,
086: DIGAdapter da, Model premises) {
087: DIGConnection dc = da.getConnection();
088: Document query = dc.createDigVerb(DIGProfile.ASKS, da
089: .getProfile());
090:
091: Element instances = da.createQueryElement(query,
092: DIGProfile.INSTANCES);
093:
094: if (pattern.getObject().isBlank()) {
095: da.addClassDescription(instances, pattern.getObject(),
096: premises);
097: } else {
098: da.addClassDescription(instances, pattern.getObject());
099: }
100:
101: return query;
102: }
103:
104: /**
105: * <p>Answer an iterator of triples that match the original find query.</p>
106: */
107: public ExtendedIterator translateResponseHook(Document response,
108: TriplePattern query, DIGAdapter da) {
109: // translate the concept set to triples, but then we must add :a rdfs:subClassOf :a to match owl semantics
110: return translateIndividualSetResponse(response, query, false);
111: }
112:
113: public boolean checkObject(com.hp.hpl.jena.graph.Node object,
114: DIGAdapter da, Model premises) {
115: return da.isConcept(object, premises);
116: }
117:
118: // Internal implementation methods
119: //////////////////////////////////
120:
121: //==============================================================================
122: // Inner class definitions
123: //==============================================================================
124:
125: }
126:
127: /*
128: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
129: * All rights reserved.
130: *
131: * Redistribution and use in source and binary forms, with or without
132: * modification, are permitted provided that the following conditions
133: * are met:
134: * 1. Redistributions of source code must retain the above copyright
135: * notice, this list of conditions and the following disclaimer.
136: * 2. Redistributions in binary form must reproduce the above copyright
137: * notice, this list of conditions and the following disclaimer in the
138: * documentation and/or other materials provided with the distribution.
139: * 3. The name of the author may not be used to endorse or promote products
140: * derived from this software without specific prior written permission.
141: *
142: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
143: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
144: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
145: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
146: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
147: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
148: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
149: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
150: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
151: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
152: */
|