Lexeme¶
-
class
LexData.
Lexeme
(repo: LexData.wikidatasession.WikidataSession, idLex: str)¶ Bases:
LexData.entity.Entity
Wrapper around a dict to represent a Lexeme
This is the main class of LexData. It represents an existing lexeme on Wikidata. In Wikidata all entities are stored in JSON format. Since JSON can be mapped naturally to python dictionaries a lexeme can be represented by a dictionary. All changes to a lexeme are changes to values in this dictionary. To allow access to all parts of lexemes while at the same time making common operations such as adding claims or forms as easily as possible, lexemes and other entities are handled by classes that inherit from dict. You can access arbitrary parts of the lexeme with the usual dictionary syntax lexeme[key] or with the function
dict.get()
.If you modify the content of the dictionary you have to upload the new version of the lexeme to Wikidata. If you use the functions of the class Lexeme the data is uploaded automatically.
-
createClaims
(claims: Dict[str, List[str]])¶ Add claims to the Lexeme.
Note
createClaim() is deprecated and might be removed in future versions. Use Entity.addClaims() instead.
- Parameters
claims – The set of claims to be added
-
createForm
(form: str, infosGram: List[str], language: Optional[LexData.language.Language] = None, claims: Optional[List[LexData.claim.Claim]] = None) → str¶ Create a new form for the lexeme. Optionally claims can be added to the new form.
- Example
>>> L123.createForm("Form", ["Q100"])
- Parameters
form (str) – the new form to add
infosGram (List[str]) – grammatical features
language (Optional[Language]) – the language of the form. This normally is the same as the language of the lexeme – this is also the default value.
claims – claims to add to the new form
- Returns
The id of the form
- Return type
str
-
createSense
(glosses: Dict[str, str], claims: Optional[List[LexData.claim.Claim]] = None) → str¶ Create a new sense for the lexeme. Optionally claims can be added to the new sense.
- Example
>>> L123.createSense({"en": "English gloss"}, claims={"P7": ["Q100"]})
- Parameters
glosses (Dict[str, str]) – glosses for the sense
claims – claims to add to the new form
- Return type
str
-
getLex
(idLex: str)¶ This function retrieves the content of the lexeme and synchronizes the local object. This function can be called when the lexeme has be changed by a different program or user.
- Parameters
idLex (str) – Lexeme identifier (example: “L2”)
-
property
language
¶ The language code of the lexeme as string (Example: “en”)
- Return type
str
-
property
lemma
¶ The lemma of the lexeme as string
Note: A lexeme can have multiple lemmas (for example for different writing systems), this function only returns the first.
- Return type
str
-
update_from_json
(data: str, overwrite=False)¶ Update the lexeme from an json-string.
This is a lower level function usable to save arbitrary modifications on a lexeme. The data has to be supplied in the right format by the user.
- Parameters
data – Data update: See the API documentation about the format.
overwrite – If set the whole entity is replaced by the supplied data
-