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