简体   繁体   English

Python sparql查询“错误的” URI

[英]Python sparql query on “wrong” URI's

I wrote a python script that goes through a list of URI's and runs the following query on each of them: 我写了一个python脚本,它遍历了URI的列表,并在每个URI上运行以下查询:

query = "SELECT ?subject WHERE {<http://dbpedia.org" + uri + "> dct:subject ?subject.}"

This works when the given URI is correct, such as /resource/Android_TV . 当给定的URI正确时,例如/resource/Android_TV

But in my list of URI's I also have other URI's such as /resource/Sheldon_J._Plankton . 但是在我的URI列表中,我还具有其他URI,例如/resource/Sheldon_J._Plankton

When I run this query it doesn't find anything, but if I go to the corresponding DBPedia page http://dbpedia.org/resource/Sheldon_J._Plankton 当我运行此查询时,它什么也找不到,但是如果我转到相应的DBPedia页面http://dbpedia.org/resource/Sheldon_J._Plankton

it changes to 它变成

http://dbpedia.org/page/Plankton_(character) . http://dbpedia.org/page/Plankton_(character)

So apparantly the correct URI for this page would be: 因此,显然该页面的正确URI为:

resource/Plankton_(character) . resource/Plankton_(character)

Is it possible to write the query in such a way that it changes the URI to be correct? 是否可以通过将URI更改为正确的方式来编写查询? This list of URI's is very, very long so I can't manually check and fix them unfortunately. URI的列表非常非常长,因此很遗憾,我无法手动对其进行检查和修复。

You can follow <http://dbpedia.org/ontology/wikiPageRedirects> : 您可以遵循<http://dbpedia.org/ontology/wikiPageRedirects>

<http://dbpedia.org/resource/Sheldon_J._Plankton> dbo:wikiPageRedirects*/dct:subject ?subject .

The * will make the property path match zero or more redirects. *将使属性路径匹配零个或多个重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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