Module:Wikidata/doc

From DiSSCo Modelling Framework
< Module:Wikidata
Revision as of 20:47, 6 January 2022 by Admin (talk | contribs) (1 revision imported: Import of useful Templates and Modules from Wikidata)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is the documentation page for Module:Wikidata

Module permitting basic data retrieval from items. It is mostly useful for other modules or for {{Data}}

A copy is available on test Wikidata

Functions callable from Lua

p.getClaims returns claims in a particular item that match a particular query

  • item (required): its Qid
  • property (required) property that the claims should have
  • qualifier = qualifiers that the statement should have
  • withrank = rank of the statement ; 'preferred', 'normal', 'deprecated' or 'valid' (ie. normal and preferred). By default = preferred.
  • sourceproperty = this property should be used in the source
  • withsource = the source that should be provided in the statement (if sourceproperty is not provided, the property used is P248 (P248))
  • excludespecial = set to true if you do not want to get "novalue" and "somevalue".
  • numval = if you want to set a maximum number of values to be returned
  • sorttype = set to "chronological" to get the statements in chronological order using the P580 (P580), P582 (P582) and P585 (P585) qualifiers. Set to "inverted" for chronological order. From a Lua module, you can also define your own sorting criteria.
  • showsource = set to "true" if you want the source of the statement to be displayed.

p.formatStatements(args): returns a string containing the statements given in the table args. Same keys as getClaims, plus formatting arguments:

  • lang (required) for the desired language
  • displayformat = the format in which the args should be returned. For example, for a string-type property displayformat = "weblink" returns a formatted weblink.
  • conj = the conjunction separating the statements. For example, conj = '<br />' will make a new line between each statement.
  • showqualifiers = the qualifiers that should be shown along with the mainsnak value

p.getLabel get the label of an entity

  • entity = entity ID with its Q or P
  • lang

Functions callable from wikitext

  • p.formatStatementsE same as p.formatStatements, except that "lang" is not required. It is most conveniently used from {{Data}} that takes exactly the same arguments.
  • p.getLabel get the label of an entity

Examples

Code Render Comment
{{#invoke:Wikidata|getLabel|entity=Q42}} Media URL Media URL (Q42)
{{#invoke:Wikidata|getLabel|entity=Q42|link=wikipedia}} Media URL
{{#invoke:Wikidata|getLabel|entity=Q42|link=-}} Media URL
{{#invoke:Wikidata|getLabel|entity=Q42|link=wikipedia|lang=ja}} Media URL
{{#invoke:Wikidata|getLabel|entity=Q42|link=wikidata}} Media URL
{{#invoke:Wikidata|getLabel|entity=Q42|link=wikidata|lang=ja}} Media URL
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p31}} Media URL (Q42) modified (P31)
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p31|lang=ja}}
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p569}} Media URL (Q42) P569 (P569)
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p569|lang=ja}}
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p569|displayformat=raw}}
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186}} (Q12418) P186 (P186)
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|displayformat=raw}}
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|lang=ja}}
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|rank=valid}} rank = "valid" accepts both "preferred" and "normal" values
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|numval=1}} returns the number of values numval (priority to those with "rank= preferred", if there are not enough of them, also accepts "rank = normal")
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|qualifier=p518}} (Q12418) P186 (P186) P518 (P518) should only display values that have a p518 qualifier
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|showqualifiers=p518}} shows the value of the p518 qualifier (if any) in addition to the main value
{{#invoke:Wikidata|formatStatementsE|item=Q83259|property=p669|showqualifiers=p670|delimiter=&#32;}} (Q83259) P669 (P669) P670 (P670) shows the value of the P670 qualifier (if any) in addition to the main value separated by a space
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=P276|sourceproperty=P854}} (Q12418) P276 (P276) P854 (P854)
{{#invoke:Wikidata|formatStatementsE|item=Q11879536|property=P460|withsource=Q1645493}} (Q11879536) P460 (P460) (Q1645493)
{{#invoke:Wikidata|formatStatementsE|item=Q11879536|property=P460|withsource=Q1645493|showsource=true}}
{{#invoke:Wikidata|formatStatementsE|item=Q153|property=P231|showsource=true}} (Q153) P231 (P231)
{{#invoke:Wikidata|formatStatementsE|item=Q205309|property=P793|sorttype=inverted}} (Q205309) P793 (P793)

See also