Nasty.Lexical.WordNet.Synset (Nasty v0.3.0)

View Source

Represents a WordNet synset (synonym set) - a group of words that share the same meaning.

A synset is the fundamental unit of WordNet, grouping together words (lemmas) that are synonymous and interchangeable in some context. Each synset has a unique ID, part of speech, definition, usage examples, and links to other synsets through semantic relations.

Fields

  • id - Unique synset identifier (e.g., "oewn-02084071-n")
  • pos - Part of speech (:noun, :verb, :adj, :adv)
  • definition - Textual definition/gloss of the synset meaning
  • examples - List of example sentences demonstrating usage
  • lemmas - List of word forms (strings) in this synset
  • language - ISO 639-1 language code (:en, :es, :ca, etc.)
  • ili - Interlingual Index ID for cross-lingual linking (optional)

Example

%Synset{
  id: "oewn-02084071-n",
  pos: :noun,
  definition: "a member of the genus Canis",
  examples: ["the dog barked all night"],
  lemmas: ["dog", "domestic dog", "Canis familiaris"],
  language: :en,
  ili: "i2084071"
}

Summary

Functions

Converts Universal Dependencies POS tag to WordNet POS tag.

Creates a new synset struct with validation.

Returns the primary lemma (first lemma in the synset).

Checks if a part-of-speech tag is valid.

Types

language_code()

@type language_code() :: atom()

pos_tag()

@type pos_tag() :: :noun | :verb | :adj | :adv

t()

@type t() :: %Nasty.Lexical.WordNet.Synset{
  definition: String.t(),
  examples: [String.t()],
  id: String.t(),
  ili: String.t() | nil,
  language: language_code(),
  lemmas: [String.t()],
  pos: pos_tag()
}

Functions

from_ud_pos(ud_pos)

@spec from_ud_pos(atom()) :: pos_tag() | nil

Converts Universal Dependencies POS tag to WordNet POS tag.

Examples

iex> Synset.from_ud_pos(:propn)
:noun

iex> Synset.from_ud_pos(:aux)
:verb

new(id, pos, definition, language, opts \\ [])

@spec new(String.t(), pos_tag(), String.t(), language_code(), keyword()) ::
  {:ok, t()} | {:error, term()}

Creates a new synset struct with validation.

Examples

iex> Synset.new("oewn-02084071-n", :noun, "a member of the genus Canis", :en)
{:ok, %Synset{id: "oewn-02084071-n", pos: :noun, ...}}

iex> Synset.new("invalid", :invalid, "definition", :en)
{:error, :invalid_pos}

primary_lemma(synset)

@spec primary_lemma(t()) :: String.t() | nil

Returns the primary lemma (first lemma in the synset).

Examples

iex> synset = %Synset{lemmas: ["dog", "domestic dog"]}
iex> Synset.primary_lemma(synset)
"dog"

valid_pos?(pos)

@spec valid_pos?(atom()) :: boolean()

Checks if a part-of-speech tag is valid.