2

So I know that in order to run SPARQL statements against a local ttl file I use rdflib. In order to run SPARQL statements against dbpedia I run Sparqlwrapper. But how do I do both? i.e. suppose I have a local ttl file and I want to leverage some of the online resources available.

So ... suppose I have the following local ttl

 @prefix foaf: <http://xmlns.com/foaf/0.1/> . 

<http://www.learningsparql.com/ns/demo#i93234>
        foaf:nick "Dick" ;  
        foaf:givenname "Richard" ; 
        foaf:mbox "richard49@hotmail.com" ;
        foaf:surname "Mutt" ;
        foaf:workplaceHomepage <http://www.philamuseum.org/> ;
        foaf:aimChatID "bridesbachelor" . 

Then I create the following python program to execute a SPARQL query and print out more human readable versions of the properties

filename = "C:/DataStuff/SemanticOntology/LearningSPARQLExamples/ex050.ttl"  interesting
import rdflib
g = rdflib.Graph()

result = g.parse(filename, format='ttl')
print(result)
query = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?propertyLabel ?value 
WHERE
{
  ?s ?property ?value . 
  ?property rdfs:label ?propertyLabel . 
}

"""

results=g.query(query)
print('Results!')
for row in results:
    print(row)

Which will return nothing because it isn't accessing dbpedia, and therefore doesn't know what rdfs:label is. I get that. But how do I tell it to?

Dano13
  • 149
  • 9
  • 1
    not sure if I understand the question correctly, but for me it sound like you need some federated query support. And then call the DBpedia endpoint via `service `. According to https://github.com/RDFLib/rdflib/issues/769 , this feature has not been implemented yet, so I doubt what you want will be possible. But maybe I"m wrong and smarter people here have a better answer – UninformedUser Sep 17 '19 at 19:17

0 Answers0