001: /*
002: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: Reifier.java,v 1.35 2008/01/02 12:06:55 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph;
008:
009: import com.hp.hpl.jena.shared.*;
010: import com.hp.hpl.jena.util.iterator.*;
011: import com.hp.hpl.jena.vocabulary.RDF;
012:
013: /**
014: This interface represents the type of things that can hold reified triples
015: for a Jena Graph.
016:
017: @author kers
018: */
019:
020: public interface Reifier extends GetTriple {
021: /**
022: Answer an iterator over all the reification triples in this Reifier that match
023: <code>m</code>.
024: */
025: ExtendedIterator find(TripleMatch m);
026:
027: /**
028: Answer an iterator over all the reification triples that this Reifier exposes
029: (ie all if Standard, none otherwise) that match m.
030: */
031: ExtendedIterator findExposed(TripleMatch m);
032:
033: /**
034: Answer an iterator over the reification triples of this Reifier, or an empty
035: iterator - if showHidden is false, only the exposed triples, otherwise only
036: the concealed ones.
037: */
038: ExtendedIterator findEither(TripleMatch m, boolean showHidden);
039:
040: /**
041: Answer the number of exposed reification quadlets held in this reifier.
042: */
043: int size();
044:
045: /**
046: Answer this reifier's style.
047: */
048: ReificationStyle getStyle();
049:
050: /**
051: get the Graph which uses this reifier.
052: */
053: Graph getParentGraph();
054:
055: /**
056: note the triple _t_ as reified using _n_ as its representing node.
057: If _n_ is already reifying something, a AlreadyReifiedException is thrown.
058: */
059: Node reifyAs(Node n, Triple t);
060:
061: /**
062: true iff _n_ is associated with some triple.
063: */
064: boolean hasTriple(Node n);
065:
066: /**
067: @return true iff there's > 0 mappings to this triple
068: */
069: boolean hasTriple(Triple t);
070:
071: /**
072: return an iterator over all the nodes that are reifiying something in
073: this reifier.
074: */
075: ExtendedIterator allNodes();
076:
077: /**
078: return an iterator over all the nodes that are reifiying t in
079: this reifier.
080: */
081: ExtendedIterator allNodes(Triple t);
082:
083: /**
084: remove any existing binding for _n_; hasNode(n) will return false
085: and getTriple(n) will return null. This only removes *unique, single* bindings.
086: */
087: void remove(Node n, Triple t);
088:
089: /**
090: remove all bindings which map to this triple.
091: */
092: void remove(Triple t);
093:
094: /**
095: true iff the Reifier has handled an add of the triple _t_.
096: */
097: boolean handledAdd(Triple t);
098:
099: /**
100: true iff the Reifier has handled a remove of the triple _t_.
101: */
102: boolean handledRemove(Triple t);
103:
104: /**
105: The reifier will no longer be used. Further operations on it are not defined
106: by this interface.
107: */
108: void close();
109:
110: public static class Util {
111: public static boolean isReificationPredicate(Node node) {
112: return node.equals(RDF.Nodes.subject)
113: || node.equals(RDF.Nodes.predicate)
114: || node.equals(RDF.Nodes.object);
115: }
116:
117: public static boolean couldBeStatement(Node node) {
118: return node.isVariable() || node.equals(Node.ANY)
119: || node.equals(RDF.Nodes.Statement);
120: }
121:
122: public static boolean isReificationType(Node P, Node O) {
123: return P.equals(RDF.Nodes.type) && couldBeStatement(O);
124: }
125: }
126: }
127:
128: /*
129: (c) Copyright 2002, 2003, 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:
136: 1. Redistributions of source code must retain the above copyright
137: notice, this list of conditions and the following disclaimer.
138:
139: 2. Redistributions in binary form must reproduce the above copyright
140: notice, this list of conditions and the following disclaimer in the
141: documentation and/or other materials provided with the distribution.
142:
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: */
|