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