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: DIGQueryIsConceptTranslator.java,v $
010: * Revision $Revision: 1.8 $
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 java.util.*;
023:
024: import org.w3c.dom.Document;
025:
026: import com.hp.hpl.jena.graph.Node;
027: import com.hp.hpl.jena.graph.Node_Concrete;
028: import com.hp.hpl.jena.rdf.model.Model;
029: import com.hp.hpl.jena.reasoner.TriplePattern;
030: import com.hp.hpl.jena.util.iterator.*;
031: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
032: import com.hp.hpl.jena.vocabulary.RDF;
033:
034: /**
035: * <p>
036: * Translator that generates a DIG query to test whether a ground name is a class atom
037: * <pre>
038: * x rdf:type owl:Class
039: * </pre>
040: * or similar.
041: * </p>
042: *
043: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
044: * @version Release @release@ ($Id: DIGQueryIsConceptTranslator.java,v 1.8 2008/01/02 12:07:11 andy_seaborne Exp $)
045: */
046: public class DIGQueryIsConceptTranslator extends DIGQueryTranslator {
047:
048: // Constants
049: //////////////////////////////////
050:
051: // Static variables
052: //////////////////////////////////
053:
054: // Instance variables
055: //////////////////////////////////
056:
057: // Constructors
058: //////////////////////////////////
059:
060: /**
061: * <p>Construct a translator for the DIG for a concept name.</p>
062: */
063: public DIGQueryIsConceptTranslator() {
064: super (null, RDF.type.getURI(), null);
065: }
066:
067: // External signature methods
068: //////////////////////////////////
069:
070: /**
071: * <p>Since known concept names are cached by the adapter, we can just look up the
072: * current set and map directly to triples</p>
073: * @param pattern The pattern to translate to a DIG query
074: * @param da The DIG adapter through which we communicate with a DIG reasoner
075: */
076: public ExtendedIterator find(TriplePattern pattern, DIGAdapter da) {
077: List result = new ArrayList();
078: if (da.isConcept(pattern.getSubject(), null)) {
079: result.add(pattern.asTriple());
080: }
081:
082: return WrappedIterator.create(result.iterator());
083: }
084:
085: /** For this translation, we ignore premises */
086: public ExtendedIterator find(TriplePattern pattern, DIGAdapter da,
087: Model premises) {
088: return find(pattern, da);
089: }
090:
091: public Document translatePattern(TriplePattern pattern,
092: DIGAdapter da) {
093: // not used
094: return null;
095: }
096:
097: public Document translatePattern(TriplePattern pattern,
098: DIGAdapter da, Model premises) {
099: // not used
100: return null;
101: }
102:
103: public ExtendedIterator translateResponseHook(Document response,
104: TriplePattern query, DIGAdapter da) {
105: // not used
106: return null;
107: }
108:
109: public boolean checkObject(Node object, DIGAdapter da,
110: Model premises) {
111: return da.getOntLanguage().CLASS().asNode().equals(object);
112: }
113:
114: public boolean checkSubject(Node subject, DIGAdapter da,
115: Model premises) {
116: return subject instanceof Node_Concrete;
117: }
118:
119: // Internal implementation methods
120: //////////////////////////////////
121:
122: //==============================================================================
123: // Inner class definitions
124: //==============================================================================
125:
126: }
127:
128: /*
129: * (c) Copyright 2001-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: */
|