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: DIGQueryClassHierarchyTranslator.java,v $
010: * Revision $Revision: 1.8 $
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 java.util.Iterator;
023:
024: import com.hp.hpl.jena.graph.*;
025: import com.hp.hpl.jena.graph.Triple;
026: import com.hp.hpl.jena.reasoner.TriplePattern;
027: import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable;
028: import com.hp.hpl.jena.util.iterator.*;
029: import com.hp.hpl.jena.vocabulary.RDF;
030:
031: /**
032: * <p>
033: * Translator that generates DIG queries in response to find queries that search the entire class
034: * hierarchy:
035: * <pre>
036: * * rdf:subClassOf *
037: * </pre>
038: * or similar.
039: * </p>
040: *
041: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
042: * @version CVS $Id: DIGQueryClassHierarchyTranslator.java,v 1.8 2008/01/02 12:07:09 andy_seaborne Exp $
043: */
044: public class DIGQueryClassHierarchyTranslator extends
045: DIGIteratedQueryTranslator {
046:
047: // Constants
048: //////////////////////////////////
049:
050: // Static variables
051: //////////////////////////////////
052:
053: // Instance variables
054: //////////////////////////////////
055:
056: // Constructors
057: //////////////////////////////////
058:
059: /**
060: * <p>Construct a translator for the DIG class hierarchy queries.</p>
061: * @param predicate The predicate URI to trigger on
062: */
063: public DIGQueryClassHierarchyTranslator(String predicate) {
064: super (ALL, predicate, ALL);
065: }
066:
067: // External signature methods
068: //////////////////////////////////
069:
070: /**
071: * <p>To query the entire concept hierarchy, we need to know every super-class of every class.</p>
072: * @param pattern The incoming pattern
073: * @param da The current DIG adapter
074: */
075: protected Iterator expandQuery(TriplePattern pattern, DIGAdapter da) {
076: final Node pred = pattern.getPredicate();
077:
078: // find all concepts, and use them to replace the lhs nodes in the pattern
079: return new DIGQueryAllConceptsTranslator(null, null).find(
080: new TriplePattern(null, RDF.type.asNode(), null), da)
081: .mapWith(new Map1() {
082: public Object map1(Object x) {
083: Triple triple = (Triple) x;
084: return new TriplePattern(triple.getSubject(),
085: pred, Node_RuleVariable.WILD);
086: }
087: });
088: }
089:
090: // Internal implementation methods
091: //////////////////////////////////
092:
093: //==============================================================================
094: // Inner class definitions
095: //==============================================================================
096:
097: }
098:
099: /*
100: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
101: * All rights reserved.
102: *
103: * Redistribution and use in source and binary forms, with or without
104: * modification, are permitted provided that the following conditions
105: * are met:
106: * 1. Redistributions of source code must retain the above copyright
107: * notice, this list of conditions and the following disclaimer.
108: * 2. Redistributions in binary form must reproduce the above copyright
109: * notice, this list of conditions and the following disclaimer in the
110: * documentation and/or other materials provided with the distribution.
111: * 3. The name of the author may not be used to endorse or promote products
112: * derived from this software without specific prior written permission.
113: *
114: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
115: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
116: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
117: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
118: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
119: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
120: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
121: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
122: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
123: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
124: */
|