You're querying two different endpoints with possible default limits per
query request ... always keep this in mind. Might not be a problem here,
but Wikidata has a hard-coded 60s limit, other endpoints like public
DBpedia limit to 10000 "rows".
I also doubt that ?creatorURI and ?creatorID will be pushed into the
SERVICE queries, but I might be wrong. Andy will correct me.
I'm also not sure if FROM <> will load the data, I don't think so. It
worked before in Jena, but it's mainly used for graphs in the loaded
dataset.
What you can do:
|// create a model and load the data||
|
|Model model = ModelFactory.createDefaultModel();||
||model.read("http://www.worldcat.org/oclc/470488115");|
|// run the query|
|Query query = QueryFactory.create(queryStr);||
||
||try(QueryExecution qef = QueryExecutionFactory.create(query, model)) {||
|| ResultSet rs = qef.execSelect();||
|| ResultSetFormatter.out(rs);||
||}|
You should also fix your second SERVICE clause because
|?bl_creator ?creatorURI.|
is not a triple pattern, the predicate is missing. The relation here
should be owl:sameAs
Fixed query:
|PREFIX schema: <http://schema.org/>||
||PREFIX library: <http://purl.org/library/>||
||PREFIX dct: <http://purl.org/dc/terms/>||
||PREFIX owl: <http://www.w3.org/2002/07/owl#>||
||PREFIX wdt: <http://www.wikidata.org/prop/direct/>||
||
||SELECT ?work ?workLabel||
||WHERE||
|| { <http://www.worldcat.org/oclc/470488115>||
|| schema:author ?creatorURI||
|| BIND(replace(str(?creatorURI), "^(.*[\\/])*", "") AS ?creatorID)||
|| { SERVICE <https://query.wikidata.org/sparql>||
|| { ?author wdt:P214 ?creatorID .||
|| ?work wdt:P50 ?author ;||
|| wdt:P1476 ?workLabel||
|| }||
|| }||
|| UNION||
|| { SERVICE <http://bnb.data.bl.uk/sparql>||
|| { ?bl_creator owl:sameAs ?creatorURI .||
|| ?work dct:creator ?bl_creator ;||
|| dct:title ?workLabel||
|| }||
|| }||
|| }|
Just with Wikidata the query works and is quite fast, with the British
National Bibliography it fails because if illegal data returned and
takes quite long. Others here might inspect what's going one.
On 27.11.19 17:23, Hyrundo Publishing Association wrote:
> Hello Sirs at Jena,
>
> I am following the examples of federated queries given at this URL:
> https://www.oclc.org/developer/news/2016/federated-queries-with-sparql.en.html
>
> <https://www.oclc.org/developer/news/2016/federated-queries-with-sparql.en.html>
>
> and then I’m trying to replicate the results bringing those SPARQL examples
> into a Jena/Java Main class in NetBeans…
> with no results…
>
>
> For example, the given SPARQL code:
>
> PREFIX schema: <http://schema.org/>
> PREFIX library: <http://purl.org/library/>
> PREFIX wdt: <http://www.wikidata.org/prop/direct/>
> PREFIX dct: <http://purl.org/dc/terms/>
>
> SELECT ?work ?workLabel
> FROM <http://www.worldcat.org/oclc/470488115>
> WHERE {
> <http://www.worldcat.org/oclc/470488115> schema:author ?creatorURI.
> BIND(replace(STR(?creatorURI), "^(.*[\\/])*", "") AS ?creatorID)
>
> {SERVICE <https://query.wikidata.org/sparql> { //endpoint n.1
> ?author wdt:P214 ?creatorID.
> ?work wdt:P50 ?author .
> ? work wdt:P1476 ?workLabel
> }
> }
> UNION
> {
> SERVICE <http://bnb.data.bl.uk/sparql> { //endpoint n.2
> ?bl_creator ?creatorURI.
> ?work dct:creator ?bl_creator.
> ?work dct:title ?workLabel
> }
> }
> }
> When having two different endpoints to query, how to set the query execution
> in Jena?
> Query query = QueryFactory.create(queryStr);
> QueryExecution qexec =
> QueryExecutionFactory.sparqlService(“http://URL_of_the_SPARQL_endpoint",
> query) ?
>
> Any hint?
> Thank you in advance.
>
>
>
> Hyrundo
>
>