如何使用QID URL从Wikidata中获取数据

时间:2020-09-02 21:25:53

标签: python wikidata

我想知道如何使用QID URL获取数据。我有一些名称,我使用falcon 2.0实体链接器curl命令(将其更改为python脚本)以获取其QID信息。现在,我想使用该QID访问有关性别(男性或女性)或别名的信息或其他信息。有人可以提出应该如何处理的想法。下面给出了获取QID URL的代码。猎鹰2.0的链接为https://github.com/SDM-TIB/Falcon2.0

import requests 
import json

response_list=[] 
person_names=[]

if __name__ == '__main__':


   limit=100
   with open(filename, 'r') as in_file:
       in_reader = in_file.readlines()
       for data in in_reader:
           if limit > 0:
               person_names.append(data.rstrip()) 
               limit -=1
           else :
               break
               
               
   """
   Url of post request and header of type json create linking against each line of text.
   """
   
   
   url="https://labs.tib.eu/falcon/falcon2/api?mode=long"
   headers = {'Content-type': 'application/json'}
   for name in person_names:
       data = {"text":name }
       data_json = json.dumps(data)
       response = requests.post(url, data=data_json, headers=headers)
       print(response.content)

该实体的输出为http://www.wikidata.org/entity/Q42493

1 个答案:

答案 0 :(得分:0)

您可以将http://www.wikidata.org/entity/Q42493格式的URL转换为https://www.wikidata.org/wiki/Special:EntityData/Q42493.json,以获取包含所需信息的JSON负载,但是首先应确保实体解析算法可为您提供准确的结果,这样您具有正确的QID开头。