wikidata icon indicating copy to clipboard operation
wikidata copied to clipboard

Not an Issue : regarding documentation on using Wikidata

Open sobalgi opened this issue 5 years ago • 2 comments

Hello, Firstly this is not an issue with the code. Sorry for posting this under issues.

I wanted to get some additional documentation on using the module.

Suppose I want get a list of all the entities with a certain property. The current documentation Wikidata client library for Python only shows how to get a property given an entity. I'm trying to find if I can get a list of entities with the mentioned property.

e.g. get a list of countries (entities) given the property for country 'P17'.

I'm not sure if this already exists. Please let me know if it exists. I would appreciate if the module had an improved documentation Issue #10 .

Thanks, @sobalgi.

sobalgi avatar Nov 18 '18 04:11 sobalgi

You can do that with SPARQL queries. You can play with your query on https://query.wikidata.org then use pywikibot to run it in Python.

from pywikibot.data.sparql import SparqlQuery

q = SparqlQuery("SELECT ...")
for item in q:
    # do something
    ...

I don’t know if the wikidata module allows you to do that.

bfontaine avatar Mar 06 '19 22:03 bfontaine

You can do that with SPARQL queries. You can play with your query on https://query.wikidata.org then use pywikibot to run it in Python.

from pywikibot.data.sparql import SparqlQuery

q = SparqlQuery("SELECT ...")
for item in q:
    # do something
    ...

I don’t know if the wikidata module allows you to do that.

Updated pywikibot syntax for the anyone googling this:

from pywikibot.data.sparql import SparqlQuery

query = SparqlQuery()
for item in query.select("SELECT ..."):
    # do something
    ...

danmichaelo avatar Jul 03 '20 14:07 danmichaelo