-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
find page from Wikidata title #145
Comments
Thanks for trying wptools @lm913! The wikidata item you want (Q29486521) can be got with
as shown in our Usage wiki page. However, you'll notice that the wikidata item in question (https://www.wikidata.org/wiki/Q29486521) has no Wikipedia entries. Does that make sense? |
Thank you for your quick response! Let me describe my use case more. I have around 6000 words that I want to get the Q-IDs for and wanted to use a script to query on the word, not the Q-ID, since I only have the word as a starting point. I suppose I could flag all the words that return a Wikipedia disambiguation page and look into them further but wanted to know if there was a way, using a word query, to identify when there are multiple results and step-through them programmatically. I'm not sure what the presence of a Wikipedia entry indicates. Does the search favour Wikidata results that have a Wikipedia entry? |
One way I can think of is you can check the if page.data['claims']['P31'] == [u'Q4167410']:
for p in page.data['links']: # [u'Handbag', u'Messenger bag', u'Satchel (bag)']
# do something with the each link here But this way I don't think it can get to the actual item |
Thanks @lisongx I looked into that earlier but unfortunately doesn't show the 'shoulder bag' specifically which does exist in Wikidata |
@lm913 Maybe you could try directly search wikimedia api for wiikidata, and then doing other stuff with the wikdiata id you get from there, For example, if you request this URL,
this would return all the entity with that label you want "search": [
{
"repository": "",
"id": "Q29486521",
"concepturi": "http://www.wikidata.org/entity/Q29486521",
"title": "Q29486521",
"pageid": 31133085,
"url": "//www.wikidata.org/wiki/Q29486521",
"label": "shoulder bag",
"description": "bag with one or two long straps, designed to be suspended from one shoulder or across the chest",
"match": {
"type": "label",
"language": "en",
"text": "shoulder bag"
}
},
{
"repository": "",
"id": "Q7502696",
"concepturi": "http://www.wikidata.org/entity/Q7502696",
"title": "Q7502696",
"pageid": 7415866,
"url": "//www.wikidata.org/wiki/Q7502696",
"label": "Shoulder bag",
"description": "Wikipedia disambiguation page",
"match": {
"type": "label",
"language": "en",
"text": "Shoulder bag"
}
}] |
This is a great solution @lisongx ! Thank you so much :) |
Side issue: shoulder bag (desired Q-ID): Q29486521 Query code:
Output:
the |
But from the above, I think the claims are correct, right? In [9]: page.data['claims']
Out[9]:
{u'P1014': [u'300216945'],
u'P18': [u'Tumi mens shoulder bag valentine.jpg'],
u'P2670': [u'Q1973949'],
u'P279': [u'Q1323314'],
u'P373': [u'Shoulder bags'],
u'P3832': [u'10141']} Would you be able to use this data from wikidata to accomplish your task? |
Thanks for your help Sean @lisongx ! It's true, we do not currently support Wikidata's @lm913 I believe this result is still self-consistent. Note the
This is telling us that we got redirected from our original query. The full result may be misleading because the final wikibase item (Q) is different than the input, but that is because of the redirect. The
So, we did a
Our Wiki—it's small—page https://github.com/siznax/wptools/wiki/Request-actions explains our request actions and https://github.com/siznax/wptools/wiki/Wikidata explains how we get Wikidata. tl;dr: you should be able to get what you need by chaining together the right |
@lm913 After reading your use case again (#145 (comment)) I realize now what the confusion is: you want Wikidata items from Wikidata titles, but wptools does not search Wikidata, it only fetches Wikidata with an item id (Q). Searching Wikidata for the right Q item can be done directly from the Wikidata API: https://www.wikidata.org/w/api.php?action=wbsearchentities&language=en&search=shoulder%20bag I don't think wptools can add any value by simply showing you that result. However, once you find the Wikidata item (Q) you want, then you can use wptools to get the Wikidata you want into a python object. |
On the other hand, it may be useful to show search results for a title from both Wikipedia and Wikidata. What would a useful search command look like? Maybe...
Wikidata result: Wikipedia result: We'd probably want to transform the results so they are consistent and minimal. Maybe...
@lm913 would that help solve your problem? |
@siznax @lisongx @lm913 I just discovered wptools and was looking for the same functionality. I'd like to easily search wikidata for some text substring, i.e. I would suggest adding some optional parameters to
Not sure about how to deal with multiple languages. Maybe there should be also a parameter for that. Regards |
Example: shoulder bag
When I use
page = wptools.page('shoulder bag')
wptools returns the Wikipedia disambiguation page, however, when searching directly in Wikidata there are multiple entries for 'shoulder bag'The results I am looking for is the first in the list "shoulder bag bag with one or two long straps, designed to be suspende..."
I can't seem to find a way to get wptools to return the result I'm looking for. Does anyone have additional insight in this?
The text was updated successfully, but these errors were encountered: