0

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")
}
Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
  • Use SPARQL 1.1 `SERVICE` feature. And you'll need an `INSERT WHERE` query if you want to add that data to your local repo. Also, there might a limit of the returned resultset size depending on the SPARQL endpoint - the reason for this is quite obvious, it's a shared service and too many/too expensive queries could block the whole service – UninformedUser Aug 28 '20 at 16:36
  • Thanks for the answer! Could you send an example? – João Aug 29 '20 at 02:02
  • I mean, its should be more or less as I said: `INSERT { ?subj wdt:P31 wd:Q744913 . ?subj wdt:P625 ?coord . ?subj rdfs:label ?label . } WHERE { SERVICE { ?subj wdt:P31 wd:Q744913 ; wdt:P625 ?coord ; rdfs:label ?label FILTER ( lang(?label) = "en" ) } }` – UninformedUser Aug 29 '20 at 07:51
  • Hi Stanislav! Thank you very much for sharing the knowledge. From the Brazilian friend. John. – João Sep 02 '20 at 17:09

2 Answers2

1

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")
    }
}
Richard-Degenne
  • 2,892
  • 2
  • 26
  • 43
1

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)

Vladimir Alexiev
  • 2,477
  • 1
  • 20
  • 31
  • Hi! Thanks for the answers. However, I didn't understand the benefit of the second query. – João Sep 19 '20 at 15:09
  • `wdt:P625 ?coord` returns a string. `p:P625/psv:P625` unpacks that into lat & long, i.e. extracts structured data. It also translates to more understandable (`rdf:type a :AirAccident`) and more widely used (`wgs:lat; wgs:long`) ontology terms. – Vladimir Alexiev Sep 23 '20 at 08:38