On 04/09/12 09:54, Yoga Indra Pamungkas wrote:
String queryString =
"PREFIX ont:
<http://www.semanticweb.org/ontologies/2012/7/OntologySkripsiKomputasi.owl#>"
+ "PREFIX dl: <http://www.digilib.stis.ac.id/skripsi/>"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ "PREFIX dc: <http://purl.org/dc/elements/1.1/>"
+ "SELECT ?type \n"
+ "WHERE {" + "?type rdf:type ont:mechanicalTurk"
+"}";
Andy, is there any way to create dynamic query in sparql? like I want to make
dynamic rdf:type ont:mechanicalTurk generate by user?
so I try to create
String type = "mechanicalTurk";
String queryString =
"PREFIX ont:
<http://www.semanticweb.org/ontologies/2012/7/OntologySkripsiKomputasi.owl#>"
+ "PREFIX dl: <http://www.digilib.stis.ac.id/skripsi/>"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ "PREFIX dc: <http://purl.org/dc/elements/1.1/>"
+ "SELECT ?type \n"
+ "WHERE {" + "?type rdf:type ont:type"
+"}";
com.hp.hpl.jena.query.ParameterizedSparqlString
http://jena.apache.org/documentation/javadoc/arq/com/hp/hpl/jena/query/ParameterizedSparqlString.html
Andy
________________________________
Dari: Andy Seaborne <[email protected]>
Kepada: [email protected]
Dikirim: Selasa, 4 September 2012 0:42
Judul: Re: Sparql from Database
On 03/09/12 16:36, Yoga Indra Pamungkas wrote:
I have store rdf statement to database from inference ontology such as example
below :
(http://www.digilib.stis.ac.id/skripsi/78 rdf:type
http://www.semanticweb.org/ontologies/2012/7/OntologySkripsiKomputasi.owl#pengembanganWebService)
- (http://www.digilib.stis.ac.id/skripsi/78 rdf:type
http://www.semanticweb.org/ontologies/2012/7/OntologySkripsiKomputasi.owl#aplikasiWeb)
- (http://www.digilib.stis.ac.id/skripsi/78 rdf:type
http://www.semanticweb.org/ontologies/2012/7/OntologySkripsiKomputasi.owl#pengembanganSistem)
- (http://www.digilib.stis.ac.id/skripsi/78 rdf:type
http://www.semanticweb.org/ontologies/2012/7/OntologySkripsiKomputasi.owl#skripsiKS)
- (http://www.digilib.stis.ac.id/skripsi/78 owl:sameAs
http://www.digilib.stis.ac.id/skripsi/78)
- (http://www.digilib.stis.ac.id/skripsi/69
http://www.semanticweb.org/ontoloies/2012/7/OntologySkripsiKomputasi.owl#anotasiOleh
'Indra')
- (http://www.digilib.stis.ac.id/skripsi/69
http://purl.org/dc/elements/1.1/creator '07.5371')
- (http://www.digilib.stis.ac.id/skripsi/69 rdf:type
'semantic.OntologyKomputasi.metodelogiPenelitian')
rdf:type does not take a literal string object.
- (http://www.digilib.stis.ac.id/skripsi/200491 rdf:type
'semantic.OntologyKomputasi.mechanicalTurk')
- (http://www.digilib.stis.ac.id/skripsi/200491 rdf:type
http://www.semanticweb.org/ontologies/2012/7/OntologySkripsiKomputasi.owl#mechanicalTurk)
- (http://www.digilib.stis.ac.id/skripsi/200491 rdf:type
http://www.semanticweb.org/ontologies/2012/7/OntologySkripsiKomputasi.owl#aplikasiWeb)
I assume from many example that I've been read, sparql query cannot directly to
the database, but we have to create a model and call it from database and then
query it.
So I try this :
m = maker.getModel(DOCUMENT_NAME);
String queryString =
"PREFIX ont:
<http://www.semanticweb.org/ontologies/2012/7/OntologySkripsiKomputasi.owl#>"
+ "PREFIX dl: <http://www.digilib.stis.ac.id/skripsi/>"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ "PREFIX dc: <http://purl.org/dc/elements/1.1/>"
+ "SELECT DISTINCT ?type ?title ?creator"
+ "WHERE {" + "?type rdf:type dl:aplikasiWeb"
ont:aplikasiWeb, not dl:....
+ "?title dc:title "
+ "?creator dc:creator "
+"}";
That is not valid syntax. (and putting newlines in helps)
Query query = QueryFactory.create(queryString);
This will give you an exception.
QueryExecution qeExec = QueryExecutionFactory.create(query, m);
printStatements(m, null, null, null);
//output
ResultSet result = qeExec.execSelect();
ResultSetFormatter.out(System.out, result, query);
qeExec.close();
To get resource http://www.digilib.stis.ac.id/skripsi/78 and the thesis creator
& title. But it doesn't work.
Something like:
PREFIX dl: <http://www.digilib.stis.ac.id/skripsi/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?x ?title ?creator
{
?x rdf:type dl:pengembanganWebService ;
dc:title ?title ;
dc:creator ?creator .
}
Andy
My Question :
1. Is there something direct query over database, so I don't have to call the
model and sparql it?
2. If there's no way to do that, and I should call the model and do like my
code above, is there any way to store it like SQL code below?
while (rs.next()) {
Thesis thesis= new Thesis();
thesis.setIdThesis(rs.getString("thesis_code"));
thesis.setTitle(rs.getString("thesis_title"));
}
Thanks for your help.