wnram

package module
v0.0.0-...-12d124e Latest Latest
Warning

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

Go to latest
Published: May 11, 2017 License: BSD-2-Clause Imports: 13 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

Missing features

  • Morphology - specifically generating a lemma from input text

Example Usage

import (
    "log"

    "github.com/lloyd/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

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

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() (*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

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
	//	AdjectiveSatellite
	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