forked from mark-watson/Java-AI-Book-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSparqlQueries2.java
More file actions
executable file
·39 lines (34 loc) · 1.35 KB
/
SparqlQueries2.java
File metadata and controls
executable file
·39 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package semanticweb;
import java.io.IOException;
import java.util.List;
import org.openrdf.query.MalformedQueryException;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.repository.RepositoryException;
import org.openrdf.rio.RDFParseException;
/**
*
* <p/>
* Copyright 2002-2008 by Mark Watson. All rights reserved.
* <p/>
* This software is not public domain. It can be legally
* used under either of the following licenses:
* <p/>
* 1. LGPL
* 2. Apache 2
*/
public class SparqlQueries2 implements ISparqlProcessResults {
public static void main (String [] args) throws RepositoryException, IOException, RDFParseException, MalformedQueryException, QueryEvaluationException {
new SparqlQueries2();
}
public SparqlQueries2() throws RepositoryException, IOException, RDFParseException, MalformedQueryException, QueryEvaluationException {
TripleStoreSesameManager ts = new TripleStoreSesameManager();
ts.loadRDF("rdf_files/news.nt");
String sparql_query = "SELECT ?subject ?object WHERE { ?subject <http:://knowledgebooks.com/ontology#containsCountry> ?object . }";
ts.doSparqlQuery(sparql_query, this);
}
public void processResult(List<String> data) {
System.out.print("next result: ");
for (String s : data) System.out.print("|"+s+"|" + "\t ");
System.out.println(" . ");
}
}