wnram

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2025 License: BSD-2-Clause Imports: 11 Imported by: 1

README

An in-memory Go Library for WordNet

This is a go language library for accessing Princeton's wordnet.

Implementation Overview

This library is a native golang parser for wordnet which stores the entire thing in RAM. This approach was taken for faster access times because the wordnet database sits in only about 80MB of ram, which is not a lot these days. Parsing the full data files takes around two seconds on a modest laptop.

Supported features

  • Lookup by term
  • Synonyms
  • All relation types (Antonyms, Hyponyms, Hypernyms, etc)
  • Iteration of the database
  • Lemmatization
  • Morphology - specifically generating a lemma from input text

Example Usage

import (
    "log"

    "github.com/coreruleset/wnram"
)

func main() {
    wn := wnram.New("./path")
    // lookup "yummy"
    if found, err := wn.Lookup(Criteria{Matching: "yummy", POS: []PartOfSpeech{Adjective}}); err != nil {
       log.Fatal("%s", err)
    } else {
       // dump details about each matching term to console
       for _, f := range found {
           f.Dump()
       }
	}
}

License

BSD 2 Clause, see LICENSE.

Documentation

Index

Constants

View Source
const Pertainym = DerivedFromAdjective

Variables

This section is empty.

Functions

This section is empty.

Types

type Criteria

type Criteria struct {
	Matching string
	POS      PartOfSpeechList
}

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

An initialized read-only, in-ram instance of the wordnet database. May safely be shared by multiple threads of execution

func New

func New(dir string) (*Handle, error)

Initialize a new in-ram WordNet databases reading files from the specified directory.

func (*Handle) Iterate

func (h *Handle) Iterate(pos PartOfSpeechList, cb func(Lookup) error) error

func (*Handle) Lookup

func (h *Handle) Lookup(crit Criteria) ([]Lookup, error)

look up word clusters based on given criteria

func (*Handle) MorphWord

func (h *Handle) MorphWord(word string, pos PartOfSpeech) string

Try to find all possible baseforms (lemmas) of individual word in POS.

type Lookup

type Lookup struct {
	// contains filtered or unexported fields
}

The results of a search against the wordnet database

func (*Lookup) Dump

func (w *Lookup) Dump()

func (*Lookup) DumpStr

func (w *Lookup) DumpStr() string

func (*Lookup) Gloss

func (w *Lookup) Gloss() string

A description of this meaning

func (*Lookup) Lemma

func (w *Lookup) Lemma() string

A canonical synonym for this word

func (*Lookup) POS

func (w *Lookup) POS() PartOfSpeech

func (*Lookup) Related

func (w *Lookup) Related(r Relation) (relationships []Lookup)

Get words related to this word. r is a bitfield of relation types to include

func (*Lookup) String

func (w *Lookup) String() string

func (*Lookup) Synonyms

func (w *Lookup) Synonyms() (synonyms []string)

func (*Lookup) Word

func (w *Lookup) Word() string

The specific word that was found

type PartOfSpeech

type PartOfSpeech uint8

Parts of speech

const (
	Noun PartOfSpeech = iota
	Verb
	Adjective
	Adverb
)

func (PartOfSpeech) String

func (pos PartOfSpeech) String() string

type PartOfSpeechList

type PartOfSpeechList []PartOfSpeech

A set of multiple parts of speech

func (PartOfSpeechList) Contains

func (l PartOfSpeechList) Contains(want PartOfSpeech) bool

func (PartOfSpeechList) Empty

func (l PartOfSpeechList) Empty() bool

type Relation

type Relation uint32

The ways in which synonym clusters may be related to others.

const (
	AlsoSee Relation = 1 << iota
	// A word with an opposite meaning
	Antonym
	// A noun for which adjectives express values.
	// The noun weight is an attribute, for which the adjectives light and heavy express values.
	Attribute
	Cause
	// Terms in different syntactic categories that have the same root form and are semantically related.
	DerivationallyRelatedForm
	// Adverbs are often derived from adjectives, and sometimes have antonyms; therefore the synset for an adverb usually contains a lexical pointer to the adjective from which it is derived.
	DerivedFromAdjective
	// A topical classification to which a synset has been linked with a REGION
	InDomainRegion
	InDomainTopic
	InDomainUsage
	ContainsDomainRegion
	ContainsDomainTopic
	ContainsDomainUsage
	Entailment
	// The generic term used to designate a whole class of specific instances.
	// Y is a hypernym of X if X is a (kind of) Y .
	Hypernym
	InstanceHypernym
	InstanceHyponym
	// The specific term used to designate a member of a class. X is a hyponym of Y if X is a (kind of) Y .
	Hyponym
	MemberMeronym
	PartMeronym
	SubstanceMeronym
	MemberHolonym
	PartHolonym
	SubstanceHolonym
	ParticipleOfVerb
	RelatedForm
	SimilarTo
	VerbGroup
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL