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: DIGQueryTypesTranslator.java,v $
010: * Revision $Revision: 1.10 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:07:09 $
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 'types' queries in response to a find queries:
031: * <pre>
032: * :i rdf:type *
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: DIGQueryTypesTranslator.java,v 1.10 2008/01/02 12:07:09 andy_seaborne Exp $
039: */
040: public class DIGQueryTypesTranslator 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 DIGQueryTypesTranslator(String predicate) {
059: super (null, predicate, ALL);
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 types = da.createQueryElement(query, DIGProfile.TYPES);
075: da.addNamedElement(types, DIGProfile.INDIVIDUAL, da
076: .getNodeID(pattern.getSubject()));
077:
078: return query;
079: }
080:
081: /**
082: * <p>Answer an iterator of triples that match the original find query.</p>
083: */
084: public ExtendedIterator translateResponseHook(Document response,
085: TriplePattern query, DIGAdapter da) {
086: // translate the concept set to triples, but then we must add :a rdfs:subClassOf :a to match owl semantics
087: return translateConceptSetResponse(response, query, true, da);
088: }
089:
090: public Document translatePattern(TriplePattern pattern,
091: DIGAdapter da, Model premises) {
092: // not used
093: return null;
094: }
095:
096: public boolean checkSubject(com.hp.hpl.jena.graph.Node subject,
097: DIGAdapter da, Model premises) {
098: return subject.isConcrete() && da.isIndividual(subject);
099: }
100:
101: // Internal implementation methods
102: //////////////////////////////////
103:
104: //==============================================================================
105: // Inner class definitions
106: //==============================================================================
107:
108: }
109:
110: /*
111: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
112: * All rights reserved.
113: *
114: * Redistribution and use in source and binary forms, with or without
115: * modification, are permitted provided that the following conditions
116: * are met:
117: * 1. Redistributions of source code must retain the above copyright
118: * notice, this list of conditions and the following disclaimer.
119: * 2. Redistributions in binary form must reproduce the above copyright
120: * notice, this list of conditions and the following disclaimer in the
121: * documentation and/or other materials provided with the distribution.
122: * 3. The name of the author may not be used to endorse or promote products
123: * derived from this software without specific prior written permission.
124: *
125: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
126: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
127: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
128: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
129: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
130: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
131: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
132: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
133: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
134: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135: */
|