0

I'm now to Jena and SPARQL and i'm struggling with the queries

I'm trying to get the type from the following ontology.

uspv:R3 a pv:Report.
uspv:R3 pv:atTime uspv:R3t.
uspv:R3t a owltime:Interval;
    owltime:hasDateTimeDescription uspv:R3dtDescription.
uspv:R3dtDescription owltime:unitType owltime:unitYear;
    owltime:year "1871"^^xsd:gYear.
uspv:R3 pv:category pv:riot.
uspv:R3 pv:motivation pv:political.
uspv:R3 pv:motivation pv:race.
uspv:R3 pv:fatalities uspv:R3f.
uspv:R3f a pv:FatalitiesValue;
    pv:unstructuredFatalities "0"^^xsd:string;
    pv:fatalitiesValue "0"^^xsd:integer.
uspv:R3 pv:location uspv:R3l.
uspv:R3l a pv:Location;
    pv:unstructuredLocation "Putnam Co"^^xsd:string.
uspv:R3 pv:source uspv:R3s.
uspv:R3s a pv:Source;
    pv:unstructuredSource "Gilje"^^xsd:string.
uspv:R3 pv:description "Race riot during an election to replace a murdered black official. Trelease, p.319\n"^^xsd:string.

This is just a little chunk of a TTL file that I managed to read and create a model out of it. Now I'm trying the following code to retrieve the type.

private static void query() {
    String queryString = "" +
            "PREFIX da: <http://dacura.cs.tcd.ie/data/politicalviolence/uspv/>" +
            "PREFIX w3: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
            "SELECT ?type" +
            "WHERE { da:R3t  w3:type ?type. }";


com.hp.hpl.jena.query.Query query = QueryFactory.create(queryString);
QueryExecution qExe = QueryExecutionFactory.sparqlService( "http://dbpedia.org/sparql", query );
ResultSet results = qExe.execSelect();
ResultSetFormatter.out(System.out, results, query) ;
}

My output is just:

-------------
| typeWHERE |
=============
-------------

I think I didn't really get the concept of the queries. Please, could someone help me with this example?

Michael
  • 1,030
  • 14
  • 29
  • 2
    Try a adding a space in the string between "?type" and "WHERE" in the query? I.e. "SELECT ?type " – scotthenninger Mar 26 '16 at 17:05
  • I know it's offtopic, but try to use common prefixes, e.g. at least `rdf` instead of `w3`. Makes it easier to understand for people used to Semantic Web. – UninformedUser Mar 26 '16 at 19:03
  • The **where** keyword is optional inquiries. Because you don't have a space, you're selecting a variable called a typeWHERE. Your query doesn't find a value for typeWHERE. – Joshua Taylor Mar 26 '16 at 20:21
  • Also, you can just use `a` instead of rdf:type in Sparql queries, just like in Turtle (TTL). – Joshua Taylor Mar 26 '16 at 21:57
  • Thank you for helping me to find the missing space! I still get no result.. @JoshuaTaylor how do you mean it with using 'a'? – Michael Mar 26 '16 at 22:23
  • See how in the ontology it says ` uspv:R3 a pv:Report.`? That `a` is shorthand for rdf:type (= your w3:type). Your query can be ` da:R3t a ?type.` – Joshua Taylor Mar 26 '16 at 22:50

0 Answers0