Syntax for Sparql query for pages with specific infobox

一笑奈何 提交于 2019-12-13 04:39:28

问题


I'm trying Sparql for the first time (on dbpedia) and can't get any queries to work. Everything I try returns a syntax error or an empty dataset.

For example, I tried the queries on this page. They didn't work, so I made the following changes:
- I read that wikiPageUsesTemplate has changed to http://dbpedia.org/ontology/wikiPageUsesTemplate,
- I add 'WHERE' to select statement, though I guess that must be optional,
- I reduced the whole thing to a minimum: just the infobox clause.

But it still doesn't work! Here is what I came up with:

PREFIX dbo: <http://dbpedia.org/ontology/>

SELECT * WHERE {
    ?page dbo:wikiPageUsesTemplate
        <http://dbpedia.org/resource/Template:Infobox_artist>
}
LIMIT 100

I have been trying my queries here.


回答1:


I'm not sure why you're using dbpedia-owl:wikiPageUsesTemplate. According to http://wiki.dbpedia.org/Datasets39/Properties (emphasis added):

http://xx.dbpedia.org/property/wikiPageUsesTemplate (may be changed to http://dbpedia.org/ontology/wikiPageUsesTemplate in future releases)

I'm not whether the current data in DBpedia is a future release (in terms of that document), but it sounds like you should still be on the old property. It's easy enough to test this, though. Since you have a query language and a webservice, it's quite easy to try a more general result as a sort of sanity check. In particular, something like the following very strongly suggests that it's not the property you want.

SELECT *  WHERE {
  ?s <http://dbpedia.org/ontology/wikiPageUsesTemplate> ?o         
}
LIMIT 100

SPARQL results (0 results)

Similarly, since you've got an interactive endpoint, why not try seeing what properties do relate things to <http://dbpedia.org/resource/Template:Infobox_artist>, and by what properties?

SELECT distinct ?p  WHERE {
  ?s ?p <http://dbpedia.org/resource/Template:Infobox_artist>      
}
limit 500

SPARQL results (2 results)

The two results are

http://www.w3.org/2002/07/owl#sameAs
http://dbpedia.org/ontology/wikiPageRedirects

More queries can show us what redirects to it. It turns out that it's just

http://dbpedia.org/resource/Template:Infobox_Artist

As it turns out, though, nothing is related to that either.

SELECT * WHERE {
   ?s ?p <http://dbpedia.org/resource/Template:Infobox_Artist>
}
limit 500

SPARQL results (0 results)

It doesn't look like DBpedia is actually recording the information that you're looking for.



来源:https://stackoverflow.com/questions/23812489/syntax-for-sparql-query-for-pages-with-specific-infobox

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