sparqlrdffusekiapache-jena

How to pass a variable to a SERVICE expression in SPARQL?


I have built an ontology for live concerts, Concert_Ontology.ttl. This contains definitions for concerts, artists, repertoires, and songs. I want to match the artists in my ontology and the artists in the dbpedia Person ontology based on the attributes c:artistName and dbp:name. I have written the following query to access the dbpedia endpoint and retrieve additional information about the artists.

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>  
PREFIX dbo: <http://dbpedia.org/ontology/>  
PREFIX dbp: <http://dbpedia.org/property/>  
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  
PREFIX c: <http://localhost:8080/Concert_Ontology.ttl#>  

SELECT ?performer ?artistname ?dob  
WHERE {  
    ?performer a c:Artist ;  
               c:artistName ?artistname .  
    SERVICE <http://dbpedia.org/sparql> {  
        ?person a dbo:Person ;  
              dbo:birthDate ?dob ;  
              dbp:name ?n .  
        FILTER (str(?n) = ?artistname)  
    }  
}  

However, I do not seem to be able to access the ?artistname variable from within the SERVICE expression. If I put the FILTER method outside the SERVICE expression the query works, but since dbpedia has a return cap of 10000 results, I am not able to retrieve and match all the artists.

Could someone guide me in finding a solution to this problem?


Solution

  • I found a solution to my problem. The filter function will not work with a local variable on the remote endpoint. However, if I omit the filter function and simply use the same variable name for the local and remote variable, it will return the correct results. Like this:

    SELECT ?performer ?artistname ?dob
    WHERE {
        ?performer a :Performer ;
                   :artistName ?artistname .
        SERVICE <http://dbpedia.org/sparql> {
            ?person a dbo:Person ;
                    dbo:birthDate ?dob ;
                    dbp:name ?artistname .
        }
    }