1

I want to get all entities that the text contains the keyword "tweet about", this is my python code:`import wikidata import requests

API_ENDPOINT="https://www.wikidata.org/w/api.php"
query="tweet about"
params={
    'action':'wbsearchentities',
    'format':'json',
    'language':'en',
    'search':query
}
r=requests.get(API_ENDPOINT,params=params)
print(r.json())

and the print content is :

[{'repository': '', 'id': 'Q58571598', 'concepturi': 'http://www.wikidata.org/entity/Q58571598', 'title': 'Q58571598', 'pageid': 58483717, 'url': '//www.wikidata.org/wiki/Q58571598', 'label': 'Tweet about Skin or a Digital Homage to Skin', 'match': {'type': 'label', 'language': 'en', 'text': 'Tweet about Skin or a Digital Homage to Skin'}}]

But when I do search in wikidata, there are lots of results:

enter image description here

enter image description here

can anyone help me? thank you very much!

Alvin Nguyen
  • 250
  • 4
  • 10
chloe
  • 31
  • 7

1 Answers1

0

Looks like both search systems use a different API.

You should probably play around with something like this :

import requests

API_ENDPOINT = "https://www.wikidata.org/w/api.php"
query = "tweet about"
params = {
    'action': 'query',
    'list':'search',
    'format': 'json',
    'srsearch': query,
    'srprop' : 'titlesnippet|snippet',
    'srlimit':100
}

r = requests.get(API_ENDPOINT, params=params)
print(r.json())

Documentation.

Ettore Rizza
  • 2,800
  • 2
  • 11
  • 23
  • Thank you! But I only got 10 results, it's not enough for me to construct a corpus include "tweet about".. – chloe Mar 07 '19 at 11:49
  • Edited my post to correct the limit parameter (which is srlimit and NOT simply limit). – Ettore Rizza Mar 07 '19 at 11:51
  • It works! thank you! It seems the amount of wikidata entities which contain "tweet about" is not big enough, do you know any other solution to collect grammar-correct sentence including a specific keyword? thank you! – chloe Mar 07 '19 at 12:39
  • Not sure to understand what you mean. But it looks like a totally different question. ;) – Ettore Rizza Mar 07 '19 at 13:02