问题描述
我有一个应用程序,它维护在国家历史名胜登记处注册的地方表.鉴于其 NRHP refnum
,我想在维基百科中可靠地搜索这些地方之一.
I have an application which maintains a table of places registered in the National Registry of Historic places. I'd like to reliably search for one of these places in Wikipedia, given its NRHP refnum
.
我目前使用的搜索如下所示:
The search I am currently using now looks like this:
http://en.wikipedia.org/w/index.php?title=Special:Search&search=refnum+66000539
(我使用 Python 作为我的语言,但我不认为这在这里特别相关.我构造了 url,执行了 urlfetch
,然后看看会返回什么.)
(I use Python as my language, but I don't think this is especially relevant here. I construct the url, do a urlfetch
, and see what comes back.)
但是这个例子和许多其他例子都没有结果.但是,当我访问纽约市政厅的维基百科页面时:
But this example, and many others, turn up no results. However, when I go to the Wikipedia page for New York City Hall:
http://en.wikipedia.org/wiki/New_York_City_Hall
它在页面上清楚地给出了这个确切的refnum
.如何使用我已知的 refnum
构建搜索,以便可靠地找到此页面?
It clearly gives this exact refnum
on the page. How can I construct a search, using the refnum
, which I already know, so that I can reliably find this page?
推荐答案
您可以为此使用维基数据.NRHP 的属性是 P649.由于尚未实现查询,请在 wmflabs 上使用 工具.为了得到你想要的,这有效:
You can use Wikidata for this. The property for NRHP is P649. Since queries are not implemented yet, use a tool on wmflabs. To get what you want, this works:
http://wdq.wmflabs.org/api?q=STRING[649:"66000539"]
返回:{"status":{"error":"OK","items":1,"querytime":"6.354ms","parsed_query":"STRING[649:'66000539']"},"items":[1065206]}
这里的基本部分是"items",它是维基数据中对象的ID.使用它来获取维基百科的链接.如果你想要英文版本,这有效:
Which returns: {"status":{"error":"OK","items":1,"querytime":"6.354ms","parsed_query":"STRING[649:'66000539']"},"items":[1065206]}
The essential part here is "items" which is the ID of the object in Wikidata. Use that to get the link to Wikipedia. If you want the English language version, this works:
返回:{"entities":{"Q1065206":{"id":"Q1065206","type":"item","sitelinks":{"enwiki":{"site":"enwiki","title":"纽约市政厅","url":"//en.wikipedia.org/wiki/New_York_City_Hall","badges":[]}}}},"success":1}
...
这篇关于根据其 NRHP 引用句柄搜索维基百科页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!