Overview
Synsets are the core building blocks of WordNet - sets of cognitive synonyms that represent a single concept. Each synset contains lemmas (word forms), definitions (glosses), examples, and relationships to other synsets.WordNetSynset Type
Methods
synset
Looks up a synset by its unique identifier.id: string- Synset identifier in formatword.pos.number
WordNetSynset | null- Synset object if found, null otherwise
- Performs O(1) lookup using internal Map
- Case-sensitive ID matching
- Does not normalize or validate the ID format
synsets
Finds all synsets containing a given word, optionally filtered by part of speech.word: string- Word to look up (can be inflected)pos?: WordNetPos- Optional part of speech filter: “n”, “v”, “a”, or “r”
WordNetSynset[]- Array of matching synsets (empty if none found)
- Automatically applies morphological analysis via
morphy()(see Morphy) - Normalizes word to lowercase and replaces spaces with underscores
- Without POS filter, returns synsets across all parts of speech
- Returns empty array if word not found or has no synsets for specified POS
- Performs O(1) lemma lookup after normalization
lemmas
Returns all lemmas (word forms) in the database, optionally filtered by part of speech.pos?: WordNetPos- Optional part of speech filter: “n”, “v”, “a”, or “r”
string[]- Alphabetically sorted array of lemmas
- Returns normalized forms (lowercase, underscores for spaces)
- Without POS filter, includes all lemmas across all parts of speech
- Results are automatically sorted alphabetically
- A lemma may appear once but have multiple synsets
- Performance: O(n) where n is the number of unique lemmas
WordNet Class
TheWordNet class maintains two internal indexes for efficient lookups:
byId- Maps synset IDs to synset objects (forsynset()method)lemmaIndex- Maps normalized lemmas to arrays of synsets (forsynsets()method)
- Converted to lowercase
- Spaces replaced with underscores
- Example: “New York” → “new_york”