genthesaurus

package
v0.0.0-...-8d0fdad Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

genthesaurus

A simple thesaurus generator for Go using the ea-thesaurus json found here:

https://github.com/dariusk/ea-thesaurus

TODO

  • Find words by tag
  • Traverse associations (and filter them by tag)
  • Improve UX

Usage

package main

import (
    "fmt"

    "github.com/Flokey82/go_gens/genthesaurus"
)

func main() {
    // Load thesaurus
    thesaurus := genthesaurus.New()
    
    // Add a new word association.
    thesaurus.AddAssociation("good", "evil", 1, "antonym")

    // Add some tags.
    thesaurus.Add("good", "positive")
    thesaurus.Add("evil", "negative")

    thesaurus.Log()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertEAJSON

func ConvertEAJSON(path string) error

ConvertEAJSON converts the original ea-thesaurus.json file to a more convenient format.

The original uses a map[string][]map[string]string structure, where every map in the slice only has one key-value pair.

See: https://github.com/dariusk/ea-thesaurus

Types

type Association

type Association struct {
	*Entry        // Reference to the associated entry.
	Count    int  // Number of times the association was found.
	Relation Tags // Relation type of the association (e.g. "antonym", "synonym")
}

Association is a single word association in the thesaurus.

type Entry

type Entry struct {
	Word         string         // The word.
	Associations []*Association // Associated words.
	Tags         Tags           // Tags (e.g. "noun", "verb", "color", "animal")
}

Entry is a single entry in the thesaurus.

func (*Entry) AddAssociation

func (e *Entry) AddAssociation(word *Entry, count int, relTags ...string)

AddAssociation adds an association to the entry (if it doesn't exist). If it does exist, the count is increased.

'word' is the associated word to add. 'count' is the number of times the association was found / the strength of the association. 'relTags' are tags that describe the relationship between the word and the association.

func (*Entry) SortAssociations

func (e *Entry) SortAssociations()

SortAssociations sorts the associations by count.

type Tags

type Tags []string

Tags is a list of tags.

func (*Tags) Add

func (t *Tags) Add(tag string)

Add adds a tag to the list (if it doesn't exist).

func (*Tags) Append

func (t *Tags) Append(tags ...string)

Append adds a list of tags to the list (if they don't exist).

func (*Tags) Has

func (t *Tags) Has(tag string) bool

Has returns true if the list of tags contains the tag.

func (*Tags) Sort

func (t *Tags) Sort()

Sort sorts the list of tags.

type Thesaurus

type Thesaurus struct {
	Entries []*Entry          // All entries.
	ByWord  map[string]*Entry // Entries by word.
}

Thesaurus is a thesaurus.

func New

func New() *Thesaurus

New returns a new thesaurus.

func NewFromJSON

func NewFromJSON(path string) (*Thesaurus, error)

NewFromJSON returns a new thesaurus from a json file.

func (*Thesaurus) Add

func (t *Thesaurus) Add(word string, tags ...string) *Entry

Add adds a word to the thesaurus. If the word exists, the supplied tags are appended.

func (*Thesaurus) AddAssociation

func (t *Thesaurus) AddAssociation(word, association string, count int, relTags ...string)

AddAssociation adds an association to the thesaurus.

'word' is the word to add the association to. 'association' is the associated word to add. 'count' is the number of times the association was found / the strength of the association. 'relTags' are tags that describe the relationship between the word and the association.

func (*Thesaurus) Log

func (t *Thesaurus) Log()

Log logs the thesaurus.

func (*Thesaurus) Sort

func (t *Thesaurus) Sort()

Sort sorts the thesaurus by word and the associations by count.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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