开发者

Search for a Wikipedia page based on its NRHP refnum

开发者 https://www.devze.com 2023-04-07 16:58 出处:网络
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

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

(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

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?


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"]

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:

http://wikidata.org/w/api.php?action=wbgetentities&format=json&ids=Q1065206&props=sitelinks%2Furls&sitefilter=enwiki

Which returns: {"entities":{"Q1065206":{"id":"Q1065206","type":"item","sitelinks":{"enwiki":{"site":"enwiki","title":"New York City Hall","url":"//en.wikipedia.org/wiki/New_York_City_Hall","badges":[]}}}},"success":1}

..


There doesn't seem to be a way to find an article based on the refnum.

What you can do is to use the API to get all articles in Category:National Register of Historic Places and for each of them parse the first section to get the renum.

Or you could try asking at Wikipedia:WikiProject National Register of Historic Places.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号