1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package examples;
19
20 import org.openrdf.query.MalformedQueryException;
21
22 import com.ontotext.ordi.wsmo4rdf.QueryResultListener;
23 import com.ontotext.ordi.wsmo4rdf.WsmoConnection;
24 import com.ontotext.ordi.wsmo4rdf.WsmoSource;
25
26 /**
27 * This class demonstrates how to evaluate a SPARQL query against default
28 * WsmoRepository implementation.
29 */
30 class EvaluateSPARQLQuery {
31
32 public static void main(String[] args) {
33 if (args.length == 0) {
34 System.out.println("Specify a SPARQL query to be evaluated!");
35 System.exit(1);
36 }
37
38
39
40
41 WsmoSource wsmoSource = com.ontotext.ordi.Factory.create(
42 WsmoSource.class, null);
43 WsmoConnection repository = wsmoSource.getConnection();
44
45
46 QueryResultListener resultDispatcher = new QueryResultListener() {
47 public void nextBindingSet() {
48 System.out.println();
49 }
50
51 public void nextBinding(String name, Object value) {
52 System.out.println(String.format("Binding: %s\t\tValue:%s",
53 name, value.toString()));
54 }
55 };
56
57
58 try {
59 repository.evaluate(args[0], resultDispatcher);
60 } catch (MalformedQueryException e) {
61 throw new RuntimeException("Invalid SPARQL query!", e);
62 } finally {
63 wsmoSource.shutdown();
64 }
65 }
66 }