1

I want to retrieve the name of the city associated to a person in a triplestore which links a person to a geonames entry. I am using a local server (Apache Jena Fuseki) on this minimal triplestore (in turtle):

@prefix ex: <http://www.example.audio/ex> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix gn: <http://www.geonames.org/ontology#> .

ex:Cristina     rdf:type            foaf:Person ;
                foaf:firstName      "Cristina" ;
                foaf:based_near     <https://sws.geonames.org/3164527/> .

https://sws.geonames.org/3164527/ is the URI of the city of Verona

This is the query I am trying to perform:

SELECT ?person
WHERE {
?person foaf:based_near ?city .
?city gn:name "Verona" .
}

As you can see, what I wish to do is using the gn:name predicate. How can I achieve this? Obviously I am doing something wrong.

L_T
  • 161
  • 2
  • 7
  • there is no RDF triple ` gn:name "Verona" .` loaded in your triple store, so how do you want to query it? If there is no remote SPARQL endpoint hosting the geonames dataset, it will not work.If there is such a SPARQL endpoint, SPARQL 1.1 `SERVICE` keyword is the way to go – UninformedUser Feb 17 '22 at 16:45
  • Just to make clear, you can only query for what is loaded into your triple store - there is no magic behind SPARQL. Anything beyond has to be done by formulating the query such that it in your case considers data in a public SPARQL protocol accessible service. Just having URI from the web is not enough, like `https://sws.geonames.org/3164527/` - this has also to be hosted in another triple store and you still have to query such a remote store via triple patterns – UninformedUser Feb 17 '22 at 16:53
  • you could try to use Wikidata for the federated query, at least it contains geonames IDs - but clearly not for all Geonames entities. Your Verona example has a different ID in Wikidata because of a different level of ADM. Nevertheless, this would be the service clause to use: – UninformedUser Feb 17 '22 at 18:54
  • `SERVICE { wd:P1566 wdt:P1921 ?formatter_uri . ?s wdt:P1566 ?gn_id ; rdfs:label "Verona"@en ; BIND(REPLACE(?gn_id, "^(.*)$", ?formatter_uri) AS ?gn_uri) }}` - here `gn_uri` will be the Geonames URI gotten from Wikidata, you just have to use this instead of `?city`. Moreover, you Geonames URI has a small issue, the protocol should be `http:` – UninformedUser Feb 17 '22 at 18:57
  • oh thanks, I see the point. – L_T Feb 17 '22 at 21:44
  • 1
    Maybe you can just use Wikidata if you don't have all the data locally - but it takes some time to figure out the Wikidata schema and write the federated query part. Let me know if you have questions regarding your current issue – UninformedUser Feb 18 '22 at 07:41

0 Answers0