SPARQL Federated Query Not Returning All Solutions

不打扰是莪最后的温柔 提交于 2019-12-11 10:30:31

问题


This is an evolution of this question.

Basically I am having trouble getting all the solutions to a SPARQL query from a remote endpoint. I have read through section 2.4 here because it seems to describe a situation almost identical to mine.

The idea is that I want to filter my results from DBPedia based on information in my local RDF graph. The query is here:

PREFIX ns1:             
<http://www.semanticweb.org/caeleanb/ontologies/twittermap#>
PREFIX dbo: <http://dbpedia.org/ontology/>

SELECT *
WHERE {
  ?p ns1:displayName ?name .
  SERVICE <http://dbpedia.org/sparql> {
    ?s rdfs:label ?name .
    ?s rdf:type foaf:Person .
  }
}

And the only result I get is dbpedia:John_McCain (for ?s). I think this is because John McCain is the only match in the first 'x' results, but I can't figure out how to get the query to return all matches. For example, if I add a filter like:

SERVICE <http://dbpedia.org/sparql> {
  ?s rdfs:label ?name .
  ?s rdf:type foaf:Person .
  FILTER(?name = "John McCain"@en || ?name = "Jamie Oliver"@en)
}

Then it correctly returns BOTH dbpedia:Jamie_Oliver and dbpedia:John_McCain. There are dozens of other matches like Jamie Oliver that do not come through unless I specifically add it to a Filter like this.

Can someone explain a way to extract the rest of the matches? Thanks.


回答1:


It looks like the cause of this issue is that the SERVICE block is attempting to pull all foaf:Persons from DBPedia, and then filter them based on my local Stardog db. Since there is a 10,000 result limit when querying DBPedia, only matches which occur in that set of 10,000 arbitrary Persons will be found. To fix this, I wrote a script to put together a FILTER block containing every string name in my Stardog db and attached it to the SERVICE block to filter remotely and thereby avoid hitting the 10,000 result limit. It looks something like this:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX ns1: <http://www.semanticweb.org/caeleanb/ontologies/twittermap#>

CONSTRUCT{
  ?s rdf:type ns1:Person ;
    ns1:Politician .
}
WHERE {
    ?s rdfs:label ?name .
    ?s rdf:type dbo:Politician .
    FILTER(?name IN ("John McCain"@en, ...)
}


来源:https://stackoverflow.com/questions/46862589/sparql-federated-query-not-returning-all-solutions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!