01: /*
02: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: [See end of file]
04: $Id: Pattern.java,v 1.15 2008/01/02 12:07:57 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.graph.query;
08:
09: import com.hp.hpl.jena.graph.*;
10:
11: /**
12: A Pattern represents a matching triple; it is composed of S, P, and O Elements.
13:
14: @author hedgehog
15: */
16:
17: public class Pattern {
18: public final Element S;
19: public final Element P;
20: public final Element O;
21:
22: public Pattern(Element S, Element P, Element O) {
23: this .S = S;
24: this .P = P;
25: this .O = O;
26: }
27:
28: /**
29: Convert a Pattern into a TripleMatch by making a Triple who's Nodes are the
30: conversions of the constituent elements.
31: */
32: public TripleMatch asTripleMatch(Domain d) {
33: return Triple.createMatch(S.asNodeMatch(d), P.asNodeMatch(d), O
34: .asNodeMatch(d));
35: }
36:
37: /**
38: Answer true iff this pattern, given the values for variables as found in a given
39: Domain, matches the given triple; update the Domain with any variable bindings.
40:
41: @param d the Domain with the current bound variable values (and slots for the rest)
42: @param t the concrete triple to match
43: @return true iff this pattern matches the triple [and side-effects the domain]
44: */
45: public boolean match(Domain d, Triple t) {
46: return S.match(d, t.getSubject())
47: && P.match(d, t.getPredicate())
48: && O.match(d, t.getObject());
49: }
50:
51: public String toString() {
52: return "<pattern " + S + " @" + P + " " + O + ">";
53: }
54: }
55:
56: /*
57: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
58: All rights reserved.
59:
60: Redistribution and use in source and binary forms, with or without
61: modification, are permitted provided that the following conditions
62: are met:
63:
64: 1. Redistributions of source code must retain the above copyright
65: notice, this list of conditions and the following disclaimer.
66:
67: 2. Redistributions in binary form must reproduce the above copyright
68: notice, this list of conditions and the following disclaimer in the
69: documentation and/or other materials provided with the distribution.
70:
71: 3. The name of the author may not be used to endorse or promote products
72: derived from this software without specific prior written permission.
73:
74: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
75: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
77: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
78: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
79: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
81: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
83: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84: */
|