Skip to content

Lexemes

client.lexemes reads lexemes through the WikibaseLexeme REST API at /w/rest.php/wikibaselexeme/v0. A lexeme bundles the forms of a word and the senses of those forms. The examples on this page use the client from the first block; later blocks reuse it.

import asyncio

from bibliofabric.wikidata import WikidataClient

client = WikidataClient()

Get a lexeme

lexeme = await client.lexemes.get("L2")
print("lemmas:", lexeme.lemmas)
print("lexical_category:", lexeme.lexical_category)
print("language:", lexeme.language)
print("forms:", [form.representations.get("en") for form in lexeme.forms])
print("grammatical_features:", lexeme.forms[0].grammatical_features)
print("glosses:", lexeme.senses[0].glosses)
lemmas: {'en': 'first'}
lexical_category: Q1084
language: Q1860
forms: ['firsts', 'first', '1st']
grammatical_features: ['Q146786']
glosses: {'en': 'Element in an ordered list which comes before all others according to the ordering', 'de': 'einer Ordnung folgend das Element vor allen anderen', 'es': 'primero; elemento que se ubica antes que todos los demás en una lista ordenada.', ...}

The output above trims the glosses dict, which carries senses in eleven languages. get() returns a RestLexeme with lemmas, lexical_category, language, statements, forms, and senses. Here lexical_category and language are bare item ids (Q1084 noun, Q1860 English); the wbgetentities lexeme payload nests them as objects instead. Each form carries representations (language to string), grammatical_features (a list of item ids such as Q146786 plural), and statements. Each sense carries glosses and statements.

Forms and senses come inside the lexeme

There are no per-form or per-sense routes. /entities/forms/{id} and /entities/senses/{id} answer rest-no-match, so forms and senses always arrive inside the lexeme payload. The same prefix rule applies to the lexeme route itself. The path exists only under wikibaselexeme/v0, and the same path under wikibase/v1 answers 404.

The methods accept L ids only; a Q, P, or M id raises ConfigurationError before any request.

Lexemes through wbgetentities

client.entities reads lexemes too, with the Action API payload shape, where lexical_category and language arrive as nested claim objects and forms and senses appear as claims.

entity = await client.entities.get("L2", select=["claims", "labels"])
print(entity.id, len(entity.claims), "claims")
L2 15 claims

Use client.lexemes when you want the REST shape with its separated forms and senses, and client.entities when you already work with Action API claims for other entity kinds.