I'm trying to create a Sparql-Query to get all messages, that are related to a lecture. I'm new at the whole 'semantic web'-story so be patient if the usage namespace is completely wrong.
The query I try to execute is:
PREFIX siocNS: <http://rdfs.org/sioc/ns#>
PREFIX rdfPred: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX purlPred: <http://purl.org/dc/terms/>
PREFIX purlPredLecture: <http://purl.org/<CENSORED>/lecture/>
select ?post ?title ?content ?time ?creator where
{
?post rdfPred:type siocNS:Post.
?post purlPred:title ?title.
?post purlPred:content ?content.
?post purlPred:created ?time.
?post purlPred:creator ?creator.
?post purlPred:context purlPredLecture:1337-7331.
}
where 1337-7331
is an ID.
On Sesame-Workbench the query seems working fine (because I get my 2 expected rows). On Java ,using Jena, it seems that my QueryExecuion
isn't correct.
Here my code:
String prefix = "PREFIX siocNS: <http://rdfs.org/sioc/ns#>\n"
+ "PREFIX rdfPred: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX purlPred: <http://purl.org/dc/terms/>\n"
+ "PREFIX purlPredLecture: <http://purl.org/<CENSORED>/lecture/>\n";
String queryString = "select ?post ?title ?content ?time ?creator where\n"
+ "{\n"
+ "?post rdfPred:type siocNS:Post.\n"
+ "?post purlPred:title ?title. \n"
+ "?post purlPred:content ?content. \n"
+ "?post purlPred:created ?time. \n"
+ "?post purlPred:creator ?creator.\n"
+ "?post purlPred:context purlPredLecture:"
+ lectureID + ".\n" + "}";
logger.info("Created Query:" + prefix + queryString);
Query query = QueryFactory.create(prefix
+ queryString, Syntax.syntaxSPARQL);
query.addResultVar("?post");
query.addResultVar("?title");
query.addResultVar("?content");
query.addResultVar("?time");
query.addResultVar("?creator");
Model model = ModelFactory.createDefaultModel();
QueryExecution execution = QueryExecutionFactory
.create(query, model);
ResultSet execSelect = execution.execSelect();
while (execSelect.hasNext()) {
...
DO SOME STUFF
...
}
The query shown above was copied from the java-debugger. Did I missed something on preparation of the Query(Execution)
and does Sesame-Workbench complete missing things?
Thx for your help!
dpa