Skip to content
 
 

Latest commit

 

History

61 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wikidata-CLI

Command-line tools to make working with wikidata zuper easy.
For most, those tools are just wikidata-sdk functions wrapped for the command-line needs.

Summary


Dependencies

  • NodeJs (recommended way to install it: use the awesome NVM)

Installation

npm install -g wikidata-cli

Installing globally allows to make those commands accessible from your shell $PATH


Commands

qlabel

Working with Wikidata, we often end up with obscure ids. We can always look-up those ids labels on the website but that means loading pages and pages, when a small API call and parsing could return just what we need: a label

qlabel Q1103345
# => The Cluetrain Manifesto

By default, the result uses your environment local language (process.env.LANG), but we can pass a 2-letters language code as second argument

qlabel Q1103345 de
# => Cluetrain-Manifest

qclaims

A quick way to access the claims of an entity

# all Q2001's claims
qclaims Q2001
# or just his place of birth
qclaims Q2001 P19
# or by specifying another language than your local language
qclaims Q2001 fr
qclaims Q2001 P19 fr

qdata

A quick way to access an entities data

qdata Q1496

This simply outputs the result of https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&ids=Q1496, parsed to keep only what is relevant to the requested entity (here Q1496). The output is valid json, so it lets you the possibility to pipe it to a JSON parser such as jsondepth:

qdata Q1496 | jd labels.pt
# => { language: 'pt', value: 'Fernão de Magalhães' }

wikiqid

This one is kind of the inverse of qlabel: pass it the title of a Wikipedia article and it will return the corresponding Wikidata id

wikiqid Cantabria
# => Q3946
wikiqid New Delhi
# => Q987

By default, it will look at the Wikipedia corresponding to your environment local language (process.env.LANG), but you can specify another language by passing a 2-letters language code as last argument

wikiqid science politique fr
# => Q36442

You can also pass it full Wikipedia urls

wikiqid https://en.wikipedia.org/wiki/Friedrich_Nietzsche
# => Q9358

wdprops

A command to access the list of all Wikidata properties in a given language (by default the environment local language)

  • Get the list of all Wikidata properties in your environment local language:
wdprops

Output an JSON object of the kind:

[...]
  "P2897": "identifiant Eldoblaje Movie",
  "P2898": null,
  "P2899": "âge minimal",
[...]

NB: properties without a label in the requested language are set to null, as you can see above for P2898 in French

  • Get the list of all Wikidata properties in another language
# here swedish
wdprops sv

This command first tries to find the list in the props folder (created at wikidata-cli root), and request them to query.wikidata.org if missing.

wdsparl reset

This means that after a while, your local version will miss new and updated properties: this can be solved by running wdprops reset

wdsparl

A command to run a SPARQL query and get its JSON output

From this SPARQL query file: ./path/to/query.rq

SELECT ?work WHERE {
  ?work wdt:P50 wd:Q42 .
}

get its output from your terminal like so:

wdsparql ./path/to/query.rq > ./results.json

Options

wdsparql -s ./path/to/query.rq > ./simplified_results.json

wdsparqlsimplify

A command to apply wikidata-sdk simplifySparqlResults function function to a query results file. Kind of the isolated second step of the wdsparql --simplify command:

wdsparql ./path/to/query.rq > ./results.json
wdsparqlsimplify ./results.json > ./simplified_results.json

See Also

Commands that got their own modules:

a command-line tool to filter a Wikidata dump by claim

a small server to edit Wikidata from the terminal: curl -X POST http://localhost:4115/claim -d 'entity=Q4115189&property=P2002&value=Zorg'


License

MIT

About

read and edit a Wikibase instance from the command line

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages