NAME
wdq - command line access to Wikidata Query Service
USAGE
Access Wikidata Query Service via command line. In query
mode (default), a SPARQL query is read from STDIN or option --query
. Default namespaces are and SELECT
clause are added if missing. In lookup
mode, Wikidata entity ids, URLs, or Wikimedia project URLs are read from STDIN or as command line arguments to look up label and description.
EXAMPLES
# get all parts of the solar system
wdq -q '?c wdt:P361 wd:Q544'
wdq -q '{ ?c wdt:P361 wd:Q544 }' # equivalent
wdq -q 'SELECT * WHERE { ?c wdt:P361 wd:Q544 }' # equivalent
# look up label and description
wdq Q1
wdq lookup Q1 # equivalent
echo Q1 | wdq lookup # equivalent
OPTIONS
- --query|-q QUERY
-
Query or query file (
-
for STDIN as default) - --format|-f FORMAT
-
Output format. Supported formats include
json
,xml
,tsv
, andcsv
SPARQL result format,simple
for flat JSON without language tags (default), andldjson
for line delimited flat json. For more flexible output options pipe to another tool such as jq, miller, and catmandu. If Catmandu is installed, its exporters can directly be used with optionexport
. - --limit INTEGER
-
Add or override a LIMIT clause to limitate the number of results. Single-digit options such as
-1
can also be used to also set a limit. - --no-header|-H
-
Exclude header in CSV output or other exporter.
- --export EXPORTER
-
Use a Catmandu exporter as output format, for instance
XLS
(Excel) and Markdown tables (Table
). The following produce same output:wdq --export Foo wdq --format ldjson | catmandu convert to Foo
Use Catmandu config file (
catmandu.yml
) to further configure export. - --ids|-i
-
Abbreviate Wikidata identifier URIs as strings (except output format
xml
). - --language|-g
-
Language to query labels and descriptions in. Set to the locale by default. This option is currentl only used on lookup mode.
- --ignore
-
Ignore empty results instead of issuing warning and exit code.
- --color|-C
-
By default output is colored if writing to a terminal. Disable this with
--no-color
or force color with--color
or-C
. - --api URL
-
SPARQL endpoint. Default value:
https://query.wikidata.org/bigdata/namespace/wdq/sparql
- --no-mediawiki|-m
-
Don't query MediaWiki API to map URLs to Wikidata items.
- --no-execute|-n
-
Don't execute SPARQL queries but show them in expanded form. Useful to validate and pretty-print queries. MediaWiki API requests may be
- -N
-
Don't execute any queries. Same as
--no-mediawiki --no-execute
. - --help|-h|-?
-
Show usage help
- --ontology
-
Show information about the Wikidata Ontology
- --prefixes
-
Show the default prefixes
- --no-default-prefixes
-
Don't add default namespace prefixes to the SPARQL query
- --man
-
Show detailled manual
- --version|-V
-
Show version if this script
WIKIDATA ONTOLOGY
Entity (item/property)
wd:Q_ <-- owl:sameAs --> wd:Q_
--> rdfs:label, skos:altLabel, schema:description "_"@_
--> schema:dateModified, schema:version
--> wdt:P_ "_", URI, _:blank
--> p:P_ Statement
Item
wd:Q_ <-- schema:about <http://_.wikipedia.org/wiki/_>
--> schema:inLanguage, wikibase:badge
Property
wd:P_ --> wikibase:propertyType PropertyType
--> wkibase:directClaim wdt:P_
--> wikibase:claim p:P_
--> wikibase:statementProperty ps:P_
--> wikibase:statementValue psv:P_
--> wikibase:qualifier pq:P_
--> wikibase:qualifierValue pqv:P_
--> wikibase:reference pr:P_
--> wikibase:referenceValue prv:P_
--> wikibase:novalue wdno:P_
PropertyType
wikibase: String, Url, WikibaseItem, WikibaseProperty, CommonsMedia,
Monolingualtext, GlobeCoordinate, Quantity, Time
Statement
wds:_ --> wikibase:rank Rank
--> a wdno:P_
--> ps:P_ "_", URI, _:blank
--> psv:P_ Value
--> pq:P_ "_", URI, _:blank
--> pqv:P_ Value
--> prov:wasDerivedFrom Reference
Reference
wdref:_ --> pr:P_ "_", URI
--> prv:P_ Value
Rank
wikibase: NormalRank, PreferredRank, DeprecatedRank, BestRank
Value (GlobecoordinateValue/QuantityValue/TimeValue)
wdv:_ --> wikibase: geoLatitude, geoLongitude, geoPrecision, geoGlobe URI
--> wikibase: timeValue, timePrecision, timeTimezone, timeCalendarModel
--> wikibase: quantityAmount, quantityUpperBound, quantityLowerBound,
quantityUnit URI
COPYRIGHT AND LICENSE
Copyright by Jakob Voss voss@gbv.de
Based on a PHP script by Marius Hoch hoo@online.de
at https://github.com/mariushoch/asparagus.
Licensed under GPL 2.0+