Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

How do you get the value of an "instance" property? #38

Closed
michaelmendoza42 opened this issue Aug 31, 2021 · 1 comment
Closed

How do you get the value of an "instance" property? #38

michaelmendoza42 opened this issue Aug 31, 2021 · 1 comment

Comments

@michaelmendoza42
Copy link

Hi, I'm new to wikidata in general.

I can't figure out how to get the start/end dates of someone who held office.
For example, president George Washington (Q23), there is a property P39 (offices held) and within that I can get that he was a president (Q11696). But that item itself has no start/end date property (P580, P582). However, on the wikidata page there is definitely those properties for each office held.

In my code I'm doing something like:

p39 = client.get('P39')
george = client.get('Q23')
george.get(p39)

which returns <wikidata.entity.Entity Q11696 'President of the United States'>
which is my dead end. this is the same object you'd get if i just did
client.get('Q11696') because the item has no relation to the original item Q23.

Even the SPARQL to figure out the dates for a held office is kinda crazy. You have to do something like:

?pres p:P39 ?position_held_statement .
?position_held_statement ps:P39 wd:Q11696 .
?position_held_statement pq:P580 ?start .

any help is appreciated. thanks.

@aGGre55or
Copy link

Follow the algorithm: first the entity, then the property, and not vice versa.

client = Client()
entity = client.get('Q23', load=True)
p39 = client.get('P39')
print(entity[p39].label)

Repository owner locked and limited conversation to collaborators Jan 10, 2024
@dahlia dahlia converted this issue into discussion #56 Jan 10, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants