LexemeEntity#

class wikibaseintegrator.entities.lexeme.LexemeEntity(lemmas=None, lexical_category=None, language=None, forms=None, senses=None, **kwargs)[source]#

Bases: BaseEntity

add_claims(claims, action_if_exists=ActionIfExists.APPEND_OR_REPLACE)#
Parameters:
  • claims (Claim | list[Claim] | Claims) – A Claim, list of Claim or just a Claims object to add to the claims of this entity.

  • action_if_exists (ActionIfExists, default: ActionIfExists.APPEND_OR_REPLACE) – What to do when the property already has claims. Two claims are equal when they have the same property, value and qualifiers (the rank and the references are not compared). Defaults to APPEND_OR_REPLACE. APPEND_OR_REPLACE: Add the new claim if no equal claim exists. Otherwise, update the equal claim in place (same statement) instead of adding a duplicate: it takes the rank of the new claim if set (not normal), and its references if it has some (they replace the existing references). The other claims of the property are kept. MERGE_REFS_OR_APPEND: Add the new claim if no equal claim exists. Otherwise, add the references of the new claim missing from the equal claim. The other claims of the property are kept. FORCE_APPEND: Always add the new claim, even if an equal claim exists (duplicate statement). KEEP: Add the new claim only if the property has no claim yet, otherwise do nothing. REPLACE_ALL: Remove the claims of the property that are not equal to one of the new claims, then add the new claims not already present. The equal claims are kept as they are.

Return type:

Self

Returns:

Return the updated entity object.

clear(**kwargs)#

Use the clear parameter of wbeditentity API call to clear the content of the entity. The entity will be updated with an empty dictionary.

Parameters:

kwargs (Any) – More arguments for _write() and Python requests

Return type:

dict[str, Any]

Returns:

A dictionary representation of the edited Entity

delete(login=None, allow_anonymous=False, is_bot=None, **kwargs)#

Delete the current entity. Use the pageid first if available and fallback to the page title.

Parameters:
  • login (_Login | None, default: None) – A wbi_login.Login instance

  • allow_anonymous (bool, default: False) – Allow an unidentified edit to the MediaWiki API (default False)

  • is_bot (bool | None, default: None) – Flag the edit as a bot

  • reason – Reason for the deletion. If not set, an automatically generated reason will be used.

  • deletetalk – Delete the talk page, if it exists.

  • kwargs (Any) – Any additional keyword arguments to pass to mediawiki_api_call_helper and requests.request

Return type:

dict

Returns:

The data returned by the API as a dictionary

download_entity_ttl(**kwargs)#
Return type:

str

from_json(json_data)[source]#

Import a dictionary into BaseEntity attributes.

Parameters:

json_data (dict[str, Any]) – A specific dictionary from MediaWiki API

Return type:

Self

Returns:

get(entity_id=None, **kwargs)[source]#

Request the MediaWiki API to get data for the entity specified in argument.

Parameters:
  • entity_id (str | int | None, default: None) – The ID of the entity to load, starting with ‘L’. By default, the ID of this entity, to reload it.

  • kwargs (Any)

Return type:

LexemeEntity

Returns:

a LexemeEntity instance

get_claims(property, login=None, allow_anonymous=True, is_bot=None, **kwargs)#

Load the claims of a property from the Wikibase instance. They replace the claims of this property already loaded, unsaved changes included, so calling it again refreshes them instead of duplicating them.

Parameters:
  • property (str) – The property number, e.g. ‘P31’

  • login (_Login | None, default: None) – A login instance

  • allow_anonymous (bool, default: True) – Allow an anonymous request

  • is_bot (bool | None, default: None) – Add the bot flag to the query

  • kwargs (Any) – More arguments for Python requests

Return type:

Self

Returns:

This entity

get_entity_url(wikibase_url=None)#
Return type:

str

get_json()[source]#

To get the dict equivalent of the JSON representation of the entity.

Return type:

dict[str, str | dict]

Returns:

new(**kwargs)[source]#
Return type:

LexemeEntity

write(**kwargs)[source]#

Write the LexemeEntity data to the Wikibase instance and return the LexemeEntity object returned by the instance.

Parameters:
  • data – The serialized object that is used as the data source. A newly created entity will be assigned an ‘id’.

  • summary – A summary of the edit

  • login – A login instance

  • allow_anonymous – Force a check if the query can be anonymous or not

  • clear – Clear the existing entity before updating

  • is_bot – Add the bot flag to the query

  • kwargs (Any) – More arguments for Python requests

Return type:

LexemeEntity

Returns:

an LexemeEntity of the response from the instance

write_form(form, login=None, allow_anonymous=False, is_bot=None, **kwargs)[source]#

Add a single Form to the Lexeme with the wbladdform action.

Contrary to write(), only the Form is sent to the Wikibase instance, the rest of the Lexeme is left untouched.

Parameters:
  • form (Form) – The Form to add. It must be a new Form, without an id.

  • login (_Login | None, default: None) – A login instance

  • allow_anonymous (bool, default: False) – Force a check if the query can be anonymous or not

  • is_bot (bool | None, default: None) – Add the bot flag to the query

  • kwargs (Any) – More arguments for lexeme_add_form and Python requests

Return type:

str

Returns:

The id of the newly created Form, e.g. L10-F2

write_forms(**kwargs)[source]#

Add all the new Forms of the Lexeme, one wbladdform action per Form. The Forms already existing on the Wikibase instance are skipped.

Parameters:

kwargs (Any) – Arguments passed to write_form()

Return type:

list[str]

Returns:

The ids of the newly created Forms

write_required(base_filter, action_if_exists=ActionIfExists.REPLACE_ALL, **kwargs)#
Return type:

bool

write_sense(sense, login=None, allow_anonymous=False, is_bot=None, **kwargs)[source]#

Add a single Sense to the Lexeme with the wbladdsense action.

Contrary to write(), only the Sense is sent to the Wikibase instance, the rest of the Lexeme is left untouched.

Parameters:
  • sense (Sense) – The Sense to add. It must be a new Sense, without an id.

  • login (_Login | None, default: None) – A login instance

  • allow_anonymous (bool, default: False) – Force a check if the query can be anonymous or not

  • is_bot (bool | None, default: None) – Add the bot flag to the query

  • kwargs (Any) – More arguments for lexeme_add_sense and Python requests

Return type:

str

Returns:

The id of the newly created Sense, e.g. L10-S2

write_senses(**kwargs)[source]#

Add all the new Senses of the Lexeme, one wbladdsense action per Sense. The Senses already existing on the Wikibase instance and the Senses marked as removed are skipped.

Parameters:

kwargs (Any) – Arguments passed to write_sense()

Return type:

list[str]

Returns:

The ids of the newly created Senses

ETYPE = 'lexeme'#
property api: WikibaseIntegrator#
property claims: Claims#
Setter accepts:

Claim | Claims

property forms: Forms#
property id: str | None#
Setter accepts:

None | str | int

property language: str#
property lastrevid: int | None#
property lemmas: Lemmas#
property lexical_category: str | None#
property pageid: str | int | None#
property senses: Senses#
property title: str | None#
property type: str#