Extension:WikibaseLexeme/Lua

WikibaseLexeme provides a Lua Scribunto interface that implements functions to access data from the Wikibase repository, if the Wikibase Client configuration enables  and. Lua modules and wiki templates can invoke these functions.

This is not a stable interface yet, though we hope to declare it stable soon.

Most aspects of the data are accessed as methods on a loaded entity. For Forms and Senses, you can either load the Form or Sense directly by its ID from , or load the surrounding Lexeme and then get the Form or Sense from it via  or.


 * Accessing data of Lexemes is expensive.

Loading entities doesn't count as expensive if the same entity is loaded twice during a module run. However, due to restrictions in the caching, if more than 14 other entities are loaded inbetween, the entity must be fetched again, which then counts as expensive.

mw.wikibase.lexeme
has some general Lua functionality for working with Wikibase Lexeme data.

mw.wikibase.lexeme.splitLexemeId
Split a Lexeme, Sense or Form ID into the Lexeme ID part and (if present) Sense or Form ID part. Returns two strings for Sense or Form IDs, one string for Lexeme IDs and nil otherwise.

An example call might look like this:

mw.wikibase.lexeme.entity.lexeme
has methods for accessing data of a loaded Lexeme entity. It is typically not used directly –  returns a table on which you can call the following methods, as well as the methods from mw.wikibase.entity.

mw.wikibase.lexeme.entity.lexeme:getLemmas
Gets the lemma(s) of this Lexeme, as a list of tables where each table has the lemma text as the first element and the lemma language as the second.

An example call might look like this:

mw.wikibase.lexeme.entity.lexeme:getLemma
Gets the lemma of this Lexeme in the given language, or in the content language if no language is given. Returns the lemma and its language as two strings if the lexeme has a lemma in this language, or nil otherwise. (Language fallbacks are not applied.)

An example call might look like this:

mw.wikibase.lexeme.entity.lexeme:getLanguage
Gets the Item ID of the language of this Lexeme.

An example call might look like this:

mw.wikibase.lexeme.entity.lexeme:getLexicalCategory
Gets the Item ID of the lexical category of this Lexeme.

An example call might look like this:

mw.wikibase.lexeme.entity.lexeme:getForms
Get the Forms of this Lexeme, as a list of Form entities.

An example call might look like this:

mw.wikibase.lexeme.entity.lexeme:getSenses
Get the Senses of this Lexeme, as a list of Sense entities.

An example call might look like this:

mw.wikibase.lexeme.entity.form
has methods for accessing data of a loaded Form entity. It is typically not used directly – returns a table on which you can call the following methods, as well as the methods from mw.wikibase.entity. while lexeme:getForms returns a list of such tables.

mw.wikibase.lexeme.entity.form:getRepresentations
Gets the representation(s) of this Form, as a list of tables where each table has the representation text as the first element and the representation language as the second.

An example call might look like this:

mw.wikibase.lexeme.entity.form:getRepresentation
Gets the representation of this Form in the given language, or in the content language if no language is given. Returns the representation and its language as two strings if the Form has a representation in this language, or nil otherwise. (Language fallbacks are not applied.)

An example call might look like this:

mw.wikibase.lexeme.entity.form:getGrammaticalFeatures
Gets the grammatical features of this Form as a list of item IDs.

An example call might look like this:

mw.wikibase.lexeme.entity.form:hasGrammaticalFeature
Tests whether this Form has the given grammatical feature or not.

An example call might look like this:

mw.wikibase.lexeme.entity.sense
has methods for accessing data of a loaded Sense entity. It is typically not used directly – returns a table on which you can call the following methods, as well as the methods from mw.wikibase.entity. while lexeme:getSenses returns a list of such tables.

mw.wikibase.lexeme.entity.sense:getGlosses
Gets the gloss(es) of this Sense, as a list of tables where each table has the gloss text as the first element and the gloss language as the second.

An example call might look like this:

mw.wikibase.lexeme.entity.sense:getGloss
Gets the gloss of this Sense in the given language, or in the content language if no language is given. Returns the gloss and its language as two strings if the Sense has a gloss in this language, or nil otherwise. (Language fallbacks are not applied.)

An example call might look like this: