Nasty.Lexical.WordNet (Nasty v0.3.0)
View SourceMain API for accessing WordNet lexical database.
Provides high-level functions for querying synsets, lemmas, relations, and semantic similarity. Implements lazy loading to load WordNet data only when first accessed.
Quick Start
# Get synsets for a word
synsets = WordNet.synsets("dog", :noun)
# Get definition
definition = WordNet.definition(synset_id)
# Get synonyms
synonyms = WordNet.synonyms("big")
# Get hypernyms (more general concepts)
hypernyms = WordNet.hypernyms(synset_id)Languages
Currently supports:
:en- English (Open English WordNet):es- Spanish (Open Multilingual WordNet):ca- Catalan (Open Multilingual WordNet)
Data Loading
WordNet data is loaded lazily on first access. To pre-load:
WordNet.ensure_loaded(:en)
WordNet.ensure_loaded(:es)Example
# Find synsets for "dog"
iex> WordNet.synsets("dog", :noun, :en)
[
%Synset{id: "oewn-02084071-n", definition: "a member of the genus Canis", ...},
%Synset{id: "oewn-10144073-n", definition: "informal term for a man", ...}
]
# Get definition
iex> WordNet.definition("oewn-02084071-n", :en)
"a member of the genus Canis"
# Get hypernyms
iex> WordNet.hypernyms("oewn-02084071-n", :en)
["oewn-02083346-n"] # canine
# Get synonyms via synsets
iex> WordNet.synonyms("big", :adj, :en)
["large", "big"]
Summary
Functions
Gets all relations from a synset.
Gets antonyms (opposites) for a synset.
Finds common hypernyms (shared ancestors) between two synsets.
Gets the definition of a synset.
Ensures WordNet data for a language is loaded.
Gets usage examples for a synset.
Finds synsets in target language via Interlingual Index.
Gets holonyms (whole-of relations) for a synset.
Gets hypernyms (more general concepts) for a synset.
Gets hyponyms (more specific concepts) for a synset.
Gets all lemmas (word senses) for a word.
Checks if WordNet data is loaded for a language.
Gets meronyms (part-of relations) for a synset.
Finds the shortest path between two synsets in the hypernym hierarchy.
Gets similar synsets.
Returns statistics about loaded WordNet data.
Gets synonyms for a word by finding all words in same synsets.
Gets a synset by its ID.
Gets all synsets for a word with optional POS filter.
Functions
@spec all_relations(String.t(), atom()) :: [ {Nasty.Lexical.WordNet.Relation.relation_type(), String.t()} ]
Gets all relations from a synset.
Returns list of {relation_type, target_synset_id} tuples.
Gets antonyms (opposites) for a synset.
Examples
iex> WordNet.antonyms("oewn-01386883-a", :en) # hot
["oewn-01387319-a"] # cold
Finds common hypernyms (shared ancestors) between two synsets.
Returns list of synset IDs that are hypernyms of both input synsets.
Gets the definition of a synset.
Examples
iex> WordNet.definition("oewn-02084071-n", :en)
"a member of the genus Canis"
Ensures WordNet data for a language is loaded.
Automatically called by query functions, but can be called explicitly to pre-load data.
Gets usage examples for a synset.
Examples
iex> WordNet.examples("oewn-02084071-n", :en)
["the dog barked all night"]
@spec from_ili(String.t(), atom()) :: [Nasty.Lexical.WordNet.Synset.t()]
Finds synsets in target language via Interlingual Index.
Examples
iex> spanish_dog = WordNet.synsets("perro", :noun, :es) |> hd()
iex> WordNet.from_ili(spanish_dog.ili, :en)
[%Synset{id: "oewn-02084071-n", lemmas: ["dog", ...]}]
Gets holonyms (whole-of relations) for a synset.
Examples
iex> WordNet.holonyms("oewn-03903868-n", :en) # wheel
["oewn-02958343-n", ...] # car, bicycle, ...
Gets hypernyms (more general concepts) for a synset.
Examples
iex> WordNet.hypernyms("oewn-02084071-n", :en) # dog
["oewn-02083346-n"] # canine
Gets hyponyms (more specific concepts) for a synset.
Examples
iex> WordNet.hyponyms("oewn-02083346-n", :en) # canine
["oewn-02084071-n", ...] # dog, wolf, fox, ...
@spec lemmas(String.t(), Nasty.Lexical.WordNet.Synset.pos_tag() | nil, atom()) :: [ Nasty.Lexical.WordNet.Lemma.t() ]
Gets all lemmas (word senses) for a word.
Examples
iex> WordNet.lemmas("dog")
[%Lemma{word: "dog", synset_id: "oewn-02084071-n", ...}, ...]
Checks if WordNet data is loaded for a language.
Gets meronyms (part-of relations) for a synset.
Examples
iex> WordNet.meronyms("oewn-02958343-n", :en) # car
["oewn-03903868-n", ...] # wheel, door, engine, ...
@spec shortest_path(String.t(), String.t(), atom()) :: non_neg_integer() | nil
Finds the shortest path between two synsets in the hypernym hierarchy.
Returns the path length (number of edges), or nil if no path exists.
Gets similar synsets.
Examples
iex> WordNet.similar("oewn-01386883-a", :en) # hot
["oewn-01391351-a", ...] # warm, ...
Returns statistics about loaded WordNet data.
Examples
iex> WordNet.stats(:en)
%{synsets: 120532, lemmas: 155287, relations: 207016}
@spec synonyms(String.t(), Nasty.Lexical.WordNet.Synset.pos_tag() | nil, atom()) :: [ String.t() ]
Gets synonyms for a word by finding all words in same synsets.
Examples
iex> WordNet.synonyms("big")
["large", "big"]
@spec synset(String.t(), atom()) :: Nasty.Lexical.WordNet.Synset.t() | nil
Gets a synset by its ID.
Examples
iex> WordNet.synset("oewn-02084071-n", :en)
%Synset{id: "oewn-02084071-n", ...}
@spec synsets(String.t(), Nasty.Lexical.WordNet.Synset.pos_tag() | nil, atom()) :: [ Nasty.Lexical.WordNet.Synset.t() ]
Gets all synsets for a word with optional POS filter.
Parameters
word- Word to look uppos- Part of speech filter (:noun, :verb, :adj, :adv) or nil for alllanguage- Language code (default: :en)
Examples
iex> WordNet.synsets("dog")
[%Synset{...}, ...]
iex> WordNet.synsets("run", :verb)
[%Synset{...}, ...]