简体   繁体   中英

How to make, in one SPARQL query, three independent queries on three different SPARQL endpoints?

is there a way that I can do three independent queries on on three different SPARQL endpoints, in one SPARQL query? For example, I have three SPARQL endpoints (ie, url1, url2 and url3) and three independent queries I want to make, ie, query1 on url1, query2 on url2 and query3 on url3. Is it possible that I can conduct the three queries once in one SPARQL query?

I tried the pattern like

SELECT * WHERE {

 SERVICE <url1> {query1} 

 SERVICE <url2> {query2} 

 SERVICE <url3> {query3} 
}

It seems that the query tries to connect results from three queries, because the three queries are independent, the final result is empty. If I do three times query one endpoint by one endpoint, each query has returned results.

Thank you very much for your help!

You can use UNION to make 3 separate calls: it is roughly the same as making 3 queries.

SELECT * WHERE {
 { SERVICE <url1> {query1} }
 UNION
 { SERVICE <url2> {query2} }
  UNION
 { SERVICE <url3> {query3} }
}

The app may need to know which rows come from which call, so labelling the results can be useful:

SELECT * WHERE {
 { SERVICE <url1> { query1 } BIND (<url1> AS ?serviceLabel) }
 UNION
 { SERVICE <url2> { query2 } BIND (<url2> AS ?serviceLabel) }
  UNION
 { SERVICE <url3> { query3 } BIND (<url2> AS ?serviceLabel) }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM