KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > FGraph


1 /******************************************************************
2  * File: FGraph.java
3  * Created by: Dave Reynolds
4  * Created on: 22-Jan-03
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: FGraph.java,v 1.9 2005/02/21 12:16:13 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner;
11
12 import com.hp.hpl.jena.graph.Graph;
13 import com.hp.hpl.jena.util.iterator.*;
14
15 /**
16  * Wrapper round a Graph to implement the slighly modified Finder
17  * interface.
18  *
19  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
20  * @version $Revision: 1.9 $ on $Date: 2005/02/21 12:16:13 $
21  */

22 public class FGraph implements Finder {
23
24     /** The graph being searched */
25     protected Graph graph;
26     
27     /**
28      * Constructor
29      */

30     public FGraph(Graph graph) {
31         this.graph = graph;
32     }
33     
34     /**
35      * Basic pattern lookup interface.
36      * @param pattern a TriplePattern to be matched against the data
37      * @return a ClosableIterator over all Triples in the data set
38      * that match the pattern
39      */

40     public ExtendedIterator find(TriplePattern pattern) {
41         if (graph == null) return WrappedIterator.create(new NullIterator());
42         return graph.find(pattern.asTripleMatch());
43     }
44     
45     /**
46      * Extended find interface used in situations where the implementator
47      * may or may not be able to answer the complete query. It will
48      * attempt to answer the pattern but if its answers are not known
49      * to be complete then it will also pass the request on to the nested
50      * Finder to append more results.
51      * @param pattern a TriplePattern to be matched against the data
52      * @param continuation either a Finder or a normal Graph which
53      * will be asked for additional match results if the implementor
54      * may not have completely satisfied the query.
55      */

56     public ExtendedIterator findWithContinuation(TriplePattern pattern, Finder continuation) {
57         if (graph == null) return WrappedIterator.create(new NullIterator());
58         if (continuation == null) {
59             return graph.find(pattern.asTripleMatch());
60         } else {
61             return graph.find(pattern.asTripleMatch()).andThen(continuation.find(pattern));
62         }
63     }
64
65     /**
66      * Returns the graph.
67      * @return Graph
68      */

69     public Graph getGraph() {
70         return graph;
71     }
72
73     /**
74      * Return true if the given pattern occurs somewhere in the find sequence.
75      */

76     public boolean contains(TriplePattern pattern) {
77         return graph.contains(pattern.getSubject(), pattern.getPredicate(), pattern.getObject());
78     }
79
80 }
81
82 /*
83     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
84     All rights reserved.
85
86     Redistribution and use in source and binary forms, with or without
87     modification, are permitted provided that the following conditions
88     are met:
89
90     1. Redistributions of source code must retain the above copyright
91        notice, this list of conditions and the following disclaimer.
92
93     2. Redistributions in binary form must reproduce the above copyright
94        notice, this list of conditions and the following disclaimer in the
95        documentation and/or other materials provided with the distribution.
96
97     3. The name of the author may not be used to endorse or promote products
98        derived from this software without specific prior written permission.
99
100     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
101     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
102     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
103     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
104     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
105     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
106     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
107     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
108     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
109     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
110 */

111
112
Popular Tags