kwg

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: GPL-3.0 Imports: 10 Imported by: 10

README

kwg - a library to interface with Andy Kurnia's KWG (Kurnia Word Graph). For more information about KWG, see https://github.com/andy-k/wolges

Documentation

Index

Constants

View Source
const (
	// BackHooks are letters that hook on to the back of a word to make a new word
	BackHooks = iota
	// FrontHooks are letters that hook on to the front of a word to make a new word
	FrontHooks
	// A BackInnerHook is a boolean indicating whether the word would still be valid
	// if the last letter of it was removed.
	BackInnerHook
	// A FrontInnerHook is a boolean indicating whether the word would still be valid
	// if the first letter of it was removed.
	FrontInnerHook
)
View Source
const (
	CacheKeyPrefix = "kwg:"
)

Variables

View Source
var DaPool = sync.Pool{
	New: func() interface{} {
		return &KWGAnagrammer{}
	},
}

Functions

func CacheLoadFunc

func CacheLoadFunc(cfg map[string]any, key string) (interface{}, error)

CacheLoadFunc is the function that loads an object into the global cache.

func FindHooks added in v0.1.4

func FindHooks(kwg *KWG, word []tilemapping.MachineLetter, hooktype int) []tilemapping.MachineLetter

func FindInnerHook added in v0.1.4

func FindInnerHook(kwg *KWG, word []tilemapping.MachineLetter, hooktype int) bool

func FindMachineWord

func FindMachineWord(d *KWG, word tilemapping.MachineWord) bool

FindMachineWord finds a word in a KWG

func FindWord

func FindWord(d *KWG, word string) bool

FindWord finds a word in a KWG

Types

type KWG

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

A KWG is a Kurnia Word Graph. More information is available here: https://github.com/andy-k/wolges/blob/main/details.txt Thanks to Andy Kurnia.

func Get

func Get(cfg map[string]any, name string) (*KWG, error)

Get loads a named KWG from the cache or from a file

func LoadKWG

func LoadKWG(cfg map[string]any, filename string) (*KWG, error)

func ScanKWG

func ScanKWG(data io.Reader, filesize int) (*KWG, error)

func (*KWG) Accepts

func (k *KWG) Accepts(nodeIdx uint32) bool

func (*KWG) ArcIndex

func (k *KWG) ArcIndex(nodeIdx uint32) uint32

func (*KWG) CountWords

func (k *KWG) CountWords()

func (KWG) GetAlphabet

func (k KWG) GetAlphabet() *tilemapping.TileMapping

func (*KWG) GetLetterSet

func (k *KWG) GetLetterSet(nodeIdx uint32) tilemapping.LetterSet

func (*KWG) GetRootNodeIndex

func (k *KWG) GetRootNodeIndex() uint32

func (*KWG) GetWordIndexOf

func (k *KWG) GetWordIndexOf(nodeIdx uint32, letters tilemapping.MachineWord) int32

func (*KWG) InLetterSet

func (k *KWG) InLetterSet(letter tilemapping.MachineLetter, nodeIdx uint32) bool

func (*KWG) IsEnd

func (k *KWG) IsEnd(nodeIdx uint32) bool

func (*KWG) LexiconName

func (k *KWG) LexiconName() string

func (*KWG) NextNodeIdx

func (k *KWG) NextNodeIdx(nodeIdx uint32, letter tilemapping.MachineLetter) uint32

func (*KWG) Tile

func (k *KWG) Tile(nodeIdx uint32) uint8

type KWGAnagrammer

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

zero value works. not threadsafe.

func (*KWGAnagrammer) Anagram

func (da *KWGAnagrammer) Anagram(dawg *KWG, f func(tilemapping.MachineWord) error) error

func (*KWGAnagrammer) InitForMachineWord

func (da *KWGAnagrammer) InitForMachineWord(kwg *KWG, machineTiles tilemapping.MachineWord) error

func (*KWGAnagrammer) InitForString

func (da *KWGAnagrammer) InitForString(kwg *KWG, tiles string) error

func (*KWGAnagrammer) IsValidJumble

func (da *KWGAnagrammer) IsValidJumble(dawg *KWG, word tilemapping.MachineWord) (bool, error)

checks if a word with no blanks has any valid anagrams.

func (*KWGAnagrammer) Subanagram

func (da *KWGAnagrammer) Subanagram(dawg *KWG, f func(tilemapping.MachineWord) error) error

func (*KWGAnagrammer) Superanagram

func (da *KWGAnagrammer) Superanagram(dawg *KWG, f func(tilemapping.MachineWord) error) error

type Lexicon

type Lexicon struct {
	KWG
}

func (Lexicon) HasAnagram

func (l Lexicon) HasAnagram(word tilemapping.MachineWord) bool

func (Lexicon) HasWord

func (l Lexicon) HasWord(word tilemapping.MachineWord) bool

func (Lexicon) Name

func (l Lexicon) Name() string

Jump to

Keyboard shortcuts

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