Retrieving properties of redirected resource

2019-05-31 13:09发布

问题:

How can I retrieve all the properties of http://dbpedia.org/resource/Milano? I tried with this query but I have a few results and I don't understand the reason:

select ?prop ?c 
where {<http://dbpedia.org/resource/Milano> ?prop ?c.}

SPARQL results

回答1:

The question isn't entirely clear, but expect that the problem you're asking about is why you're getting triples about dbpedia:Milano, but not dbpedia:Milan. This query, as you can see in the results, only returns ten rows:

select ?prop ?c
where {
  <http://dbpedia.org/resource/Milano> ?prop ?c.
}

SPARQL results

One of those rows, however, is

prop                                          c
http://dbpedia.org/ontology/wikiPageRedirects http://dbpedia.org/resource/Milan

So, the simple answer is "query for Milan" with a query like this:

select ?prop ?c
where {
  <http://dbpedia.org/resource/Milan> ?prop ?c.  # you can use dbpedia:Milan, too
}

SPARQL results

A more sophisticated answer would return the triples for dbpedia:Milano and any triples of anything that it redirects to (and, I suppose, anything that any of those redirect to, and so on, though I think that Wikipedia limits redirects to be one level deep). You can do this with a property path query in SPARQL:

select ?prop ?c
where {
  dbpedia:Milano dbpedia-owl:wikiPageRedirects* ?subject .
  ?subject ?prop ?c.
}

SPARQL results

In that query ?subject will be anything related by a path of length zero or more (so, given the data that we've seen, ?subject will be bound to at least dbpedia:Milano and dbpedia:Milan. If you want to preserve information about the subject of the various triples that you're using, you might want to add ?subject to the select line, so as to have select ?subject ?prop ?c.

If you don't care about the particular value of ?subject, then you actually don't need to bind ?subject at all, and could use a blank node in the query:

select ?prop ?c
where {
  dbpedia:Milano dbpedia-owl:wikiPageRedirects* [ ?prop ?c ] .
}

SPARQL results

Caveat

Unfortunately, although this last query is legal SPARQL, Virtuoso says it's an error. Fortunately, this last refinement is entirely optional; it's not vital to the solution. If you were querying against a different endpoint, you'd be able to use it. The error that Virtuoso gives is:

Virtuoso 37000 Error SP031: SPARQL compiler: Object of transitive triple pattern should be variable or QName or literal, not blank node

SPARQL query:
define sql:big-data-const 0 
#output-format:text/html
define sql:signal-void-variables 1 define input:default-graph-uri <http://dbpedia.org> select ?prop ?c
where {
  dbpedia:Milano dbpedia-owl:wikiPageRedirects* [ ?prop ?c ] .
}

I contacted the Virtuoso mailing list and they confirmed that it's a Virtuoso bug, and that they'll fix it. I don't know how long it will take for the fix to get to the DBpedia endpoint, though.