estnltk.wordnet.wn module

class estnltk.wordnet.wn.Lemma(key, literal)[source]

Represents a lemma.

Attributes

synset_literal (str) Literal part of the synset’s key (literal.pos.sense).
synset_pos (str) Pos part of the synset’s key (literal.pos.sense).
synset_sense (str) Sense part of the synset’s key (literal.pos.sense).
name (str) Literal/Name of the lemma.

Methods

antonyms() Just for comformance with the NLTK WordNet API.
derivationally_related_forms() Just for comformance with the NLTK WordNet API.
pertainyms() Just for comformance with the NLTK WordNet API.
synset() Returns synset into which the given lemma belongs to.
antonyms()[source]

Just for comformance with the NLTK WordNet API. No relations between lemmas in Estonian WordNet.

Just for comformance with the NLTK WordNet API. No relations between lemmas in Estonian WordNet.

pertainyms()[source]

Just for comformance with the NLTK WordNet API. No relations between lemmas in Estonian WordNet.

synset()[source]

Returns synset into which the given lemma belongs to.

Returns:

Synset

Synset into which the given lemma belongs to.

class estnltk.wordnet.wn.Synset(raw_synset)[source]

Represents a WordNet synset.

Attributes

name (str) Synset string identifier in the form lemma.pos.sense_id.
id (int) Synset integer identifier.
pos (str) Synset’s part-of-speech.
_raw_synset: eurown.Synset Underlying Synset object. Not intended to access directly.

Methods

closure(relation[, depth]) Finds all the ancestors of the synset using provided relation.
definition() Returns the definition of the synset.
examples() Returns the examples of the synset.
get_related_synsets(relation) Retrieves all the synsets which are related by given relation.
get_variants() Returns variants/lemmas of the synset.
holonyms() Retrieves all the holonyms.
hypernyms() Retrieves all the hypernyms.
hyponyms() Retrieves all the hyponyms.
lch_similarity(synset) Calculates Leacock and Chodorow’s similarity between the two synsets.
lemmas() Returns the synset’s lemmas/variants’ literal represantions.
lowest_common_hypernyms(target_synset) Returns the common hypernyms of the synset and the target synset, which are furthest from the closest roots.
member_holonyms() Retrieves all the member holoynms.
meronyms() Retrieves all the meronyms.
path_similarity(target_synset) Calculates path similarity between the two synsets.
root_hypernyms() Retrieves all the root hypernyms.
wup_similarity(target_synset) Calculates Wu and Palmer’s similarity between the two synsets.
closure(relation, depth=inf)[source]

Finds all the ancestors of the synset using provided relation.

Parameters:

relation : str

Name of the relation which is recursively used to fetch the ancestors.

Returns:

list of Synsets

Returns the ancestors of the synset via given relations.

definition()[source]

Returns the definition of the synset.

Returns:

str

Definition of the synset as a new-line separated concatenated string from all its variants’ definitions.

examples()[source]

Returns the examples of the synset.

Returns:

list of str

List of its variants’ examples.

Retrieves all the synsets which are related by given relation.

Parameters:

relation : str

Name of the relation via which the sought synsets are linked.

Returns:

list of Synsets

Synsets which are related via relation.

get_variants()[source]

Returns variants/lemmas of the synset.

Returns:

list of eurown.Variants

Lemmas/variants of the synset.

holonyms()[source]

Retrieves all the holonyms.

Returns:

list of Synsets

Synsets which are linked via holonymy relation.

hypernyms()[source]

Retrieves all the hypernyms.

Returns:

list of Synsets

Synsets which are linked via hypernymy relation.

hyponyms()[source]

Retrieves all the hyponyms.

Returns:

list of Synsets

Synsets which are linked via hyponymy relation.

lch_similarity(synset)[source]

Calculates Leacock and Chodorow’s similarity between the two synsets.

Parameters:

synset : Synset

Synset from which the similarity is calculated.

Returns:

float

Leacock and Chodorow’s from synset.

None, if synsets are not connected via hypernymy/hyponymy relations. Obvious, if part-of-speeches don’t match.

Notes

Similarity is calculated using the formula -log( (dist(synset1,synset2)+1) / (2*maximum taxonomy depth) ).

lemmas()[source]

Returns the synset’s lemmas/variants’ literal represantions.

Returns:

list of Lemmas

List of its variations’ literals as Lemma objects.

lowest_common_hypernyms(target_synset)[source]

Returns the common hypernyms of the synset and the target synset, which are furthest from the closest roots.

Parameters:

target_synset : Synset

Synset with which the common hypernyms are sought.

Returns:

list of Synsets

Common synsets which are the furthest from the closest roots.

member_holonyms()[source]

Retrieves all the member holoynms.

Returns:

list of Synsets

Synsets which are “wholes” of what the synset represents.

meronyms()[source]

Retrieves all the meronyms.

Returns:

list of Synsets

Synsets which are linked via meronymy relation.

path_similarity(target_synset)[source]

Calculates path similarity between the two synsets.

Parameters:

target_synset : Synset

Synset from which the distance is calculated.

Returns:

float

Path similarity from target_synset. Similarity with the synset itself is 1,

similarity with ureachable synset is None, 1/(shortest_path_distance + 1) otherwise.

root_hypernyms()[source]

Retrieves all the root hypernyms.

Returns:

list of Synsets

Roots via hypernymy relation.

wup_similarity(target_synset)[source]

Calculates Wu and Palmer’s similarity between the two synsets.

Parameters:

synset : Synset

Synset from which the similarity is calculated.

Returns:

float

Wu and Palmer’s similarity from synset.

Notes

Similarity is calculated using the formula ( 2*depth(least_common_subsumer(synset1,synset2)) ) / ( depth(synset1) + depth(synset2) )

estnltk.wordnet.wn.all_synsets(pos=None)[source]

Return all the synsets which have the provided pos.

Parameters:

pos : str

Part-of-speech of the sought synsets. Sensible alternatives are wn.ADJ, wn.ADV, wn.VERB, wn.NOUN and *. If pos == *, all the synsets are retrieved and initialized for fast retrieval the next time.

Returns:

list of Synsets

Lists the Synsets which have pos as part-of-speech. Empty list, if pos not in [wn.ADJ, wn.ADV, wn.VERB, wn.NOUN, *].

Notes

Returns thousands or tens of thousands of synsets - first time will take significant time. Useful for initializing synsets as each returned synset is also stored in a global dictionary for fast retrieval the next time.

estnltk.wordnet.wn.lemma(lemma_key)[source]

Returns the Lemma object with the given key.

Parameters:

lemma_key : str

Key of the returned lemma.

Returns:

Lemma

Lemma matching the lemma_key.

estnltk.wordnet.wn.lemma_from_key(lemma_key)[source]

Just for comformance with the NLTK WordNet API. No necessary lexical information.

estnltk.wordnet.wn.lemmas(lemma, pos=None)[source]

Returns all the Lemma objects of which name is lemma and which have pos as part of speech.

Parameters:

lemma : str

Literal of the sought Lemma objects.

pos : str, optional

Part of speech of the sought Lemma objects. If None, matches any part of speech. Defaults to None

Returns:

list of Lemmas

Lists all the matched Lemmas.

estnltk.wordnet.wn.morphy(word)[source]

Performs morphological analysis on the word.

Parameters:

word : str

Word to be lemmatized.

Returns:

str

Lemma of the word.

estnltk.wordnet.wn.synset(synset_key)[source]

Returns synset object with the provided key.

Parameters:

synset_key : string

Unique synset identifier in the form of lemma.pos.sense_no.

Returns:

Synset

Synset with key synset_key. None, if no match was found.

Notes

Uses lazy initialization - synsets will be fetched from a dictionary after the first request.

estnltk.wordnet.wn.synsets(lemma, pos=None)[source]

Returns all synset objects which have lemma as one of the variant literals and fixed pos, if provided.

Parameters:

lemma : str

Lemma of the synset.

pos : str, optional

Part-of-speech specification of the searched synsets, defaults to None.

Returns:

list of Synsets

Synsets which contain lemma and of which part-of-speech is pos, if specified. Empty list, if no match was found.

Notes

Uses lazy initialization - parses only those synsets which are not yet initialized, others are fetched from a dictionary.

class estnltk.wordnet.wn.Lemma(key, literal)[source]

Represents a lemma.

Attributes

synset_literal (str) Literal part of the synset’s key (literal.pos.sense).
synset_pos (str) Pos part of the synset’s key (literal.pos.sense).
synset_sense (str) Sense part of the synset’s key (literal.pos.sense).
name (str) Literal/Name of the lemma.

Methods

antonyms() Just for comformance with the NLTK WordNet API.
derivationally_related_forms() Just for comformance with the NLTK WordNet API.
pertainyms() Just for comformance with the NLTK WordNet API.
synset() Returns synset into which the given lemma belongs to.
antonyms()[source]

Just for comformance with the NLTK WordNet API. No relations between lemmas in Estonian WordNet.

derivationally_related_forms()[source]

Just for comformance with the NLTK WordNet API. No relations between lemmas in Estonian WordNet.

pertainyms()[source]

Just for comformance with the NLTK WordNet API. No relations between lemmas in Estonian WordNet.

synset()[source]

Returns synset into which the given lemma belongs to.

Returns:

Synset

Synset into which the given lemma belongs to.

class estnltk.wordnet.wn.Synset(raw_synset)[source]

Represents a WordNet synset.

Attributes

name (str) Synset string identifier in the form lemma.pos.sense_id.
id (int) Synset integer identifier.
pos (str) Synset’s part-of-speech.
_raw_synset: eurown.Synset Underlying Synset object. Not intended to access directly.

Methods

closure(relation[, depth]) Finds all the ancestors of the synset using provided relation.
definition() Returns the definition of the synset.
examples() Returns the examples of the synset.
get_related_synsets(relation) Retrieves all the synsets which are related by given relation.
get_variants() Returns variants/lemmas of the synset.
holonyms() Retrieves all the holonyms.
hypernyms() Retrieves all the hypernyms.
hyponyms() Retrieves all the hyponyms.
lch_similarity(synset) Calculates Leacock and Chodorow’s similarity between the two synsets.
lemmas() Returns the synset’s lemmas/variants’ literal represantions.
lowest_common_hypernyms(target_synset) Returns the common hypernyms of the synset and the target synset, which are furthest from the closest roots.
member_holonyms() Retrieves all the member holoynms.
meronyms() Retrieves all the meronyms.
path_similarity(target_synset) Calculates path similarity between the two synsets.
root_hypernyms() Retrieves all the root hypernyms.
wup_similarity(target_synset) Calculates Wu and Palmer’s similarity between the two synsets.
closure(relation, depth=inf)[source]

Finds all the ancestors of the synset using provided relation.

Parameters:

relation : str

Name of the relation which is recursively used to fetch the ancestors.

Returns:

list of Synsets

Returns the ancestors of the synset via given relations.

definition()[source]

Returns the definition of the synset.

Returns:

str

Definition of the synset as a new-line separated concatenated string from all its variants’ definitions.

examples()[source]

Returns the examples of the synset.

Returns:

list of str

List of its variants’ examples.

get_related_synsets(relation)[source]

Retrieves all the synsets which are related by given relation.

Parameters:

relation : str

Name of the relation via which the sought synsets are linked.

Returns:

list of Synsets

Synsets which are related via relation.

get_variants()[source]

Returns variants/lemmas of the synset.

Returns:

list of eurown.Variants

Lemmas/variants of the synset.

holonyms()[source]

Retrieves all the holonyms.

Returns:

list of Synsets

Synsets which are linked via holonymy relation.

hypernyms()[source]

Retrieves all the hypernyms.

Returns:

list of Synsets

Synsets which are linked via hypernymy relation.

hyponyms()[source]

Retrieves all the hyponyms.

Returns:

list of Synsets

Synsets which are linked via hyponymy relation.

lch_similarity(synset)[source]

Calculates Leacock and Chodorow’s similarity between the two synsets.

Parameters:

synset : Synset

Synset from which the similarity is calculated.

Returns:

float

Leacock and Chodorow’s from synset.

None, if synsets are not connected via hypernymy/hyponymy relations. Obvious, if part-of-speeches don’t match.

Notes

Similarity is calculated using the formula -log( (dist(synset1,synset2)+1) / (2*maximum taxonomy depth) ).

lemmas()[source]

Returns the synset’s lemmas/variants’ literal represantions.

Returns:

list of Lemmas

List of its variations’ literals as Lemma objects.

lowest_common_hypernyms(target_synset)[source]

Returns the common hypernyms of the synset and the target synset, which are furthest from the closest roots.

Parameters:

target_synset : Synset

Synset with which the common hypernyms are sought.

Returns:

list of Synsets

Common synsets which are the furthest from the closest roots.

member_holonyms()[source]

Retrieves all the member holoynms.

Returns:

list of Synsets

Synsets which are “wholes” of what the synset represents.

meronyms()[source]

Retrieves all the meronyms.

Returns:

list of Synsets

Synsets which are linked via meronymy relation.

path_similarity(target_synset)[source]

Calculates path similarity between the two synsets.

Parameters:

target_synset : Synset

Synset from which the distance is calculated.

Returns:

float

Path similarity from target_synset. Similarity with the synset itself is 1,

similarity with ureachable synset is None, 1/(shortest_path_distance + 1) otherwise.

root_hypernyms()[source]

Retrieves all the root hypernyms.

Returns:

list of Synsets

Roots via hypernymy relation.

wup_similarity(target_synset)[source]

Calculates Wu and Palmer’s similarity between the two synsets.

Parameters:

synset : Synset

Synset from which the similarity is calculated.

Returns:

float

Wu and Palmer’s similarity from synset.

Notes

Similarity is calculated using the formula ( 2*depth(least_common_subsumer(synset1,synset2)) ) / ( depth(synset1) + depth(synset2) )