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