dahlia / wikidata

Wikidata client library for Python
https://pypi.org/project/Wikidata/
GNU General Public License v3.0
337 stars 31 forks source link

Not an Issue : regarding documentation on using Wikidata #14

Open sobalgi opened 5 years ago

sobalgi commented 5 years ago

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.

bfontaine commented 5 years ago

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.

danmichaelo commented 4 years ago

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
    ...