Skip to content
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

Speed of looking up properties #7

Open
az0 opened this issue Oct 5, 2017 · 5 comments
Open

Speed of looking up properties #7

az0 opened this issue Oct 5, 2017 · 5 comments

Comments

@az0
Copy link

az0 commented Oct 5, 2017

I am looping through entities and looking up multiple properties for each (7 in my real project, 3 in the attached toy example). Each property slows it down, so it will take hours to go through all the entities. Is there a way to speed this up please?

from wikidata.client import Client

client = Client()  # doctest: +SKIP

p_givenname = client.get('P735')
p_surname = client.get('P734')
p_dob = client.get('P569')


def get_entity(wikidata_id):
    entity = client.get(wikidata_id, load=True)

    givenname = entity[p_givenname].label
    surname = entity[p_surname].label
    dob = entity[p_dob]
    print ('%s %s %s' % (givenname, surname, dob))

w_ids = ['Q498805',
         'Q482745',
         'Q186',
         'Q1363428',
         'Q299700',
         'Q196223',
         'Q488828',
         'Q490120']


import datetime as dt
n0 = dt.datetime.now()
for w_id in w_ids:
    get_entity(w_id)
n1 = dt.datetime.now()
print ('elapsed time: ', n1 - n0)
print ('record count: ', len(w_ids))
@az0
Copy link
Author

az0 commented Apr 5, 2018

Am I incorrectly using the library, or is there an issue in the library? I left my program running for days, and it did not finish.

@k----n
Copy link
Contributor

k----n commented Apr 6, 2018

I would probably use a SPARQL query instead (https://query.wikidata.org/).

@az0
Copy link
Author

az0 commented Apr 7, 2018

I used SPARQL to get the IDs such as Q498805 to feed into Wikidata, but I could not figure out how to get all the metadata out of SPARQL.

@k----n
Copy link
Contributor

k----n commented Apr 7, 2018

Use the "wdt" prefix in the predicate.

SELECT * WHERE
{
     wd:Q498805 wdt:P569 ?o .
     SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

@az0
Copy link
Author

az0 commented Apr 7, 2018

@k----n I expanded on that, and it helps. I will continue working with it to add the labels and filters I was trying. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants