GraphDB - Federated Query

449 views Asked by At

I would like to know how to perform a federated search on GraphDB. For example, to insert the code below in GraphDB, how should I do it? The idea is to add the content below to my local GraphDB.

#Locations of air accidents in wikidata - https://query.wikidata.org/
SELECT ?label ?coord ?place
WHERE
{
   ?subj wdt:P31 wd:Q744913  .
   ?subj wdt:P625 ?coord .
   ?subj rdfs:label ?label
   filter (lang(?label) = "en")
}
2

There are 2 answers

1
Richard-Degenne On

Posting @UninformedUser's comment as an answer for better readability.

SPARQL 1.1 offers the SERVICE feature, described here. You can use it to perform federated queries against Wikidata directly inside of GraphDB.

SELECT * WHERE {
    SERVICE <https://query.wikidata.org/sparql> {
        ?subj wdt:P31 wd:Q744913 ;
            wdt:P625 ?coord ;
            rdfs:label ?label
        FILTER (lang(?label) = "en")
    }
}
2
Vladimir Alexiev On

To insert the data to your local GraphDB, use something like this:

INSERT {
        ?subj wdt:P31 wd:Q744913 ;
            wdt:P625 ?coord ;
            rdfs:label ?label
} WHERE {
    SERVICE <https://query.wikidata.org/sparql> {
        ?subj wdt:P31 wd:Q744913 ;
            wdt:P625 ?coord ;
            rdfs:label ?label
        FILTER (lang(?label) = "en")
    }
}

However, you'd probably want to unpack the coordinates and use some ontology that's easier to understand, eg:

PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#> # see http://prefix.cc/wgs.sparql
INSERT {
        ?subj a :AirAccident;
            wgs:lat ?lat; wgs:long ?long; 
            rdfs:label ?label
} WHERE {
    SERVICE <https://query.wikidata.org/sparql> {
      ?subj wdt:P31 wd:Q744913 ;
            p:P625/psv:P625  [wikibase:geoLatitude ?lat; wikibase:geoLongitude ?long];
            rdfs:label ?label
        FILTER (lang(?label) = "en")
    }
}

For the p:P625, psv:P625, wikibase:geoLatitude stuff, see https://github.com/nichtich/wdq#wikidata-ontology (and if you install it, wdq help ontology gives this color-coded)