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: DIGQueryRoleAncestorsTranslator.java,v $
010: * Revision $Revision: 1.12 $
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 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 role ancestors/desendants queries in response to a find queries:
031: * <pre>
032: * :X rdf:subPropertyOf *
033: * * rdf:subPropertyOf :X
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: DIGQueryRoleAncestorsTranslator.java,v 1.12 2008/01/02 12:07:11 andy_seaborne Exp $
040: */
041: public class DIGQueryRoleAncestorsTranslator extends DIGQueryTranslator {
042:
043: // Constants
044: //////////////////////////////////
045:
046: // Static variables
047: //////////////////////////////////
048:
049: // Instance variables
050: //////////////////////////////////
051:
052: /** Flag for querying for ancestors */
053: protected boolean m_ancestors;
054:
055: // Constructors
056: //////////////////////////////////
057:
058: /**
059: * <p>Construct a translator for the DIG query 'rparents'.</p>
060: * @param predicate The predicate URI to trigger on
061: * @param ancestors If true, we are searching for parents of the class; if false, the descendants
062: */
063: public DIGQueryRoleAncestorsTranslator(String predicate,
064: boolean ancestors) {
065: super ((ancestors ? null : ALL), predicate, (ancestors ? ALL
066: : null));
067: m_ancestors = ancestors;
068: }
069:
070: // External signature methods
071: //////////////////////////////////
072:
073: /**
074: * <p>Answer a query that will generate the class hierachy for a concept</p>
075: */
076: public Document translatePattern(TriplePattern pattern,
077: DIGAdapter da) {
078: DIGConnection dc = da.getConnection();
079: Document query = dc.createDigVerb(DIGProfile.ASKS, da
080: .getProfile());
081:
082: if (m_ancestors) {
083: Element parents = da.createQueryElement(query,
084: DIGProfile.RANCESTORS);
085: da.addNamedElement(parents, DIGProfile.RATOM, pattern
086: .getSubject().getURI());
087: } else {
088: Element descendants = da.createQueryElement(query,
089: DIGProfile.RDESCENDANTS);
090: da.addNamedElement(descendants, DIGProfile.RATOM, pattern
091: .getObject().getURI());
092: }
093:
094: return query;
095: }
096:
097: /**
098: * <p>Answer an iterator of triples that match the original find query.</p>
099: */
100: public ExtendedIterator translateResponseHook(Document response,
101: TriplePattern query, DIGAdapter da) {
102: // translate the concept set to triples, but then we must add :a rdfs:subPropertyOf :a to match owl semantics
103: return translateRoleSetResponse(response, query, m_ancestors);
104: }
105:
106: public Document translatePattern(TriplePattern pattern,
107: DIGAdapter da, Model premises) {
108: // not used
109: return null;
110: }
111:
112: public boolean checkSubject(com.hp.hpl.jena.graph.Node subject,
113: DIGAdapter da, Model premises) {
114: return !m_ancestors || da.isRole(subject, premises);
115: }
116:
117: public boolean checkObject(com.hp.hpl.jena.graph.Node object,
118: DIGAdapter da, Model premises) {
119: return m_ancestors || da.isRole(object, premises);
120: }
121:
122: // Internal implementation methods
123: //////////////////////////////////
124:
125: //==============================================================================
126: // Inner class definitions
127: //==============================================================================
128:
129: }
130:
131: /*
132: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
133: * All rights reserved.
134: *
135: * Redistribution and use in source and binary forms, with or without
136: * modification, are permitted provided that the following conditions
137: * are met:
138: * 1. Redistributions of source code must retain the above copyright
139: * notice, this list of conditions and the following disclaimer.
140: * 2. Redistributions in binary form must reproduce the above copyright
141: * notice, this list of conditions and the following disclaimer in the
142: * documentation and/or other materials provided with the distribution.
143: * 3. The name of the author may not be used to endorse or promote products
144: * derived from this software without specific prior written permission.
145: *
146: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
147: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
148: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
149: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
150: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
151: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
152: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
153: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
154: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
155: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
156: */
|