sparqlrdfsemantic-webontologyapache-jena

Can anyone tell me whats wrong with this SPARQL QUERY?


I am using Eclipse and Jena. I have already made some queries that worked, and I cant find the mistake in this one. This is my code:

// Create a SPARQL query from the given string.
String queryString = //"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  "+
//"PREFIX owl: <http://www.w3.org/2002/07/owl#>" +
//"PREFIX ab: <http://learningsparql.com/ns/addressbook#> " +
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> "+
"PREFIX dc: <http://purl.org/dc/elements/1.1/> " +
"SELECT ?name " +
"where { "+
"?person foaf:weblog \""+"http://ldodds.com/blog/"+"\" . "+
"?person foaf:name ?name . "+
"?person rdf:type ?Person . "+
//"\"<http://ldodds.com/blog/>\""+" dc:title ?title ."+
"} \n ";

Query only:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  
PREFIX owl: <http://www.w3.org/2002/07/owl#>" 
PREFIX ab: <http://learningsparql.com/ns/addressbook#> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
PREFIX dc: <http://purl.org/dc/elements/1.1/> 

SELECT ?name 
where { 
    ?person foaf:weblog "http://ldodds.com/blog/"
    ?person foaf:name ?name
    ?person rdf:type ?Person
    "<http://ldodds.com/blog/>" dc:title ?title
    }

This is the link for ontology that I am using and this is the query that I am trying to answer:

Write a SPARQL query which retrieves a name of a person which is a type of Person and whose weblog address is http://ldodds.com/blog and also retrieves a title of his/her weblog.


Solution

  • Look at your data. The property foaf:weblog uses a resource represented in RDF by an URI as object and not a string literal:

    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>   
    SELECT ?name WHERE { 
       ?person foaf:weblog <http://ldodds.com/blog/> . 
       ?person foaf:name ?name . 
       ?person rdf:type ?Person . 
    }