wikiglot.Wiktionary#

class wikiglot.Wiktionary(locale: str = 'en')[source]#

Bases: object

A class for interacting with Wiktionary to retrieve linguistic information.

Parameters:

locale – The locale to be used for language-specific operations.

Methods

lemmatize

Lemmatize a given word in a specified language or in the default language if none is specified.

lookup

Look up a word.

__init__(locale: str = 'en')[source]#

Initialize the Wiktionary class with the specified locale.

Parameters:

locale – The locale to be used for language-specific operations.

lemmatize(word: str, language_from: str | None = None, session: Session | None = None) set[str][source]#

Lemmatize a given word in a specified language or in the default language if none is specified.

Parameters:
  • word – The word to be lemmatized.

  • language_from – The language in which the word is to be lemmatized. If not provided, the language of the Wiktionary will be used.

  • session – A requests.Session object to be used for the request. If not provided, a new session will be created.

Returns:

A set of lemmas for the given word.

Return type:

set[str]

Raises:

ValueError – If the specified language is not in the language map.

lookup(word: str, language_from: str | None = None, session: Session | None = None) dict | None[source]#

Look up a word.

Parameters:
  • word – The word to look up.

  • language_from – The language in which to look up the word. If not specified, the language of the Wiktionary is used.

  • session – A requests.Session object to be used for the request. If not provided, a new session will be created each time the function is used.

Returns:

A dictionary containing the word’s information if the word is found, None otherwise.

Return type:

dict or None

Raises:

ValueError – If the specified language is not in the language map.