Module:Wikidata statements/doc
The Wikidata statements module provides a number of helper functions to access selected statements from Wikidata. It is intended to be used by other modules; calling these functions directly from Wikitext is not possible.
Usage
local wdStatements = require "Module:Wikidata statements" values = getValueList(entityId, propertyId) items = getItemIdList(entityId, propertyId) value = getOneValue(entityId, propertyId) property = getOnePropertyId(entityId, propertyId) item = getOneItemId(entityId, propertyId)
Parameters
All public functions have the same two parameters:
- entityId
- The ID of the entity whose statements are queried. This can be any valid Wikidata entity ID, either an item ID (like "Q1") or a property ID (like "P373").
- propertyId
- The ID of the property of the statements which are queried. This can be any valid Wikidata property ID (like "P373").
For example, passing the parameters ("Q30", "P36") will query the property capital (P36) of the item United States (Q30).
Functions
All functions will discard the following statements before returning any result:
- All statements with a "deprecated" rank.
- All statements with a "normal" rank if there is at least one statement with a "preferred" rank.
- All statements with qualifiers P580 (start time) and/or P582 (end time) which indicate that the statement's validity has either not yet started or already expired at the time of the query.
- getValueList(itemId, propertyId)
- Return a Lua table of statements filtered according to the rules described above, each of them formatted as Wikitext.
- getItemIdList(itemId, propertyId)
- Return a Lua table of Wikidata item IDs for a property which is expected to actually hold references to other Wikidata items. If the property holds values other than references to other Wikidata items, an error is generated.
- getOneValue(itemId, propertyId)
- Return a single statement formatted as Wikitext. If the queried item has multiple statements for the given property (even after filtering according to the rules described above), an error is generated.
- getOnePropertyId(itemId, propertyId)
- Return a single Wikidata item ID for a property which is expected to actually hold references to Wikidata properties. If the property holds values other than such references, or the queried item has multiple statements for the given property (even after filtering according to the rules described above), an error is generated.
- getOneItemId(itemId, propertyId)
- Return a single Wikidata item ID for a property which is expected to actually hold references to other Wikidata items. If the property holds values other than such references, or the queried item has multiple statements for the given property (even after filtering according to the rules described above), an error is generated.