01: /*
02: * (c) Copyright 2007, 2008 Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: * [See end of file]
05: */
06:
07: package arq.examples;
08:
09: import com.hp.hpl.jena.sparql.algebra.Algebra;
10: import com.hp.hpl.jena.sparql.algebra.Op;
11: import com.hp.hpl.jena.sparql.engine.QueryIterator;
12: import com.hp.hpl.jena.sparql.engine.binding.Binding;
13:
14: import com.hp.hpl.jena.query.Query;
15: import com.hp.hpl.jena.query.QueryFactory;
16:
17: /** Simple example to show parsing a query and producing the
18: * SPARQL agebra expression for the query.
19: * @author Andy Seaborne
20: */
21: public class AlgebraEx {
22: public static void main(String[] args) {
23: String s = "SELECT DISTINCT ?s { ?s ?p ?o }";
24:
25: // Parse
26: Query query = QueryFactory.create(s);
27: System.out.println(query);
28:
29: // Generate algebra
30: Op op = Algebra.compile(query);
31: System.out.println(op);
32:
33: // Execute it.
34: QueryIterator qIter = Algebra.exec(op, Ex1.createModel());
35:
36: // Results
37: for (; qIter.hasNext();) {
38: Binding b = qIter.nextBinding();
39: System.out.println(b);
40: }
41: qIter.close();
42: }
43: }
44:
45: /*
46: * (c) Copyright 2007, 2008 Hewlett-Packard Development Company, LP
47: * All rights reserved.
48: *
49: * Redistribution and use in source and binary forms, with or without
50: * modification, are permitted provided that the following conditions
51: * are met:
52: * 1. Redistributions of source code must retain the above copyright
53: * notice, this list of conditions and the following disclaimer.
54: * 2. Redistributions in binary form must reproduce the above copyright
55: * notice, this list of conditions and the following disclaimer in the
56: * documentation and/or other materials provided with the distribution.
57: * 3. The name of the author may not be used to endorse or promote products
58: * derived from this software without specific prior written permission.
59: *
60: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
61: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
62: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
64: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
65: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
66: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
67: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
68: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
69: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70: */
|