fwew_lib

package module
v5.22.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: GPL-2.0 Imports: 22 Imported by: 4

README

fwew Library

The Best Na'vi Dictionary library

Development

This option is mostly for Contributors and Developers. Or people who like to compile stuff themselves. You will need the GO Programming Language and Git installed.

Setup

We are using go modules so no GOPATH setup is needed.

To compile and run tests:

cd ~/wherever/you/want
git clone https://github.com/fwew/fwew-lib
cd fwew-lib
go test ./...

Now make changes to the code and have fun. Please also add tests for the new code, so we get a high code coverage.

Usage

We have already three programs, that are using this library:

Translate

Translating is possible from Na'vi or any other supported language. As result, you will get an array of the Word struct, that can be used to create the output you desire.

require (
    fwew "github.com/fwew/fwew-lib"
)

// Translate from a native language
navi = fwew.TranslateToNavi("search", "de")
fmt.Println(word.ToOutputLine(0, true, false, false, false, false, false))

// Translate a Na'vi word into the native language
navi = fwew.TranslateFromNavi("mllte")
fmt.Println(word.ToOutputLine(0, true, false, false, false, false, false, "de"))
Numbers

Numbers also can be translated in both directions. The Na'vi number system is base 8 (Oktal) and therefore the Integers are base 8. Number have to be in the range, that Na'vi is possible of saying 0o0 to 0o77777.

require (
    fwew "github.com/fwew/fwew-lib"
)

// Translate an octal number to the Na'vi word
navi, err := fwew.NumberToNavi(0o56)
if err != nil {
    panic(err)
}
fmt.Println(navi)

// Translate the Na'vi word into the octal integer
number, err := fwew.NaviToNumber("mrrvomrr")
if err != nil {
    panic(err)
}
fmt.Println(number)
List

List() is a powerful search feature of fwew that allows you to list all the words that satisfy a set of given conditions. Every word has to be in the string array given to List(). Simply explode the given string at the space.

The syntax is as follows (cond is short for condition, spec is short for specification):

what cond spec [and what cond spec...]

what can be any one of the following:

pos          part of speech of na'vi word
word         na'vi word
syllables    number of syllables in the na'vi word
words        selection of na'vi words
stress       number representing which syllable is stressed in the na'vi word

cond depends on the what. Here are the conditions that apply to each what: pos:

has    part of speech has the following character sequence anywhere
is     part of speech is exactly the following character sequence
like   part of speech is like (matches) the following wildcard pattern

word:

starts    word starts with the following character sequence
ends      word ends with the following character sequence
has       word has the following character sequence anywhere
like      word is like (matches) the following wildcard pattern

syllables and stress:

<     less than the following number
<=    less than or equal to the following number
=     exactly equal to the following number
>=    greater than or equal to the following number
>     greater than the following number

words:

first    the first consecutive words in the datafile (chronologically oldest words)
last     the last consecutive words in the datafile (chronologically newest words)

spec depends on the cond. Here are the specifications that apply to each cond:

has, is, starts, and ends all expect a character sequence to come next.

<, <=, =, >=, >, first, and last all expect a number to come next.

like expects a character sequence, usually containing at least one wildcard asterisk, to come next.

Examples of List()

List all modal verbs:

fwew.List([]string{"pos", "has", "v", "and", "pos", "has", "m.",})

List all stative verbs:

fwew.List([]string{"pos", "has", "svin.",})

List all nouns that start with tì:

fwew.List([]string{"word", "starts", "tì", "and", "pos", "is", "n.",})

List all 3 syllable transitive verbs:

fwew.List([]string{"syllables", "=", "3", "and", "pos", "has", "vtr.",})

List the newest 25 words in the language:

fwew.List([]string{"words", "last", "25",})
Random

Random() is a random entry generator that generates the given number (or random number!) of random entries. It also features optional clause in which the what cond spec syntax from List() is supported to narrow down what kinds of random entries you get.

Examples of Random

List 10 random entries

fwew.Random(10, nil)

List 5 random transitive verbs

fwew.Random(5, []string{"pos", "has", "vtr",})

List a random number of random words

fwew.Random(0, nil)

List a random number of nouns

fwew.Random(0, []string{"pos", "is", "n.",})
Update dictionary

fwew.Update() will update the dictionary file to the newest version, downloaded from https://tirea.learnnavi.org/dictionarydata/dictionary.txt.
It will NOT update this library. To update the library you need to adjust the go mod of your project.

Assure dictionary

If you don't want to setup the dictionary manually, this will assure it is found of by the program. By default, it is saved next to the executable. If you want to download it to a different directory, you have to handle that yourself. For this purpose DownloadDict() and FindDictionaryFile() are exposed.

Word-struct

In most cases (all except number translation) the result is a Word struct. This word-struct has every information about a word in it. All public definitions are in the word.go file.

ToOutputLine() generates a basic lines, that our projects directly use as output. This Line has options to adjust what is printed.

Documentation

Overview

Package main contains all the things. affixes.go handles affix parsing of input.

Package main contains all the things

Package main contains all the things. lib.go handles common functions.

Package fwew_lib contains all the things. numbers.go contains all the stuff for the number parsing

Package main contains all the things. txt.go handles program strings.

Package fwew_lib contains all the things. version.go handles program version.

Package fwew_lib contains all the things. word.go is home to the Word struct.

Index

Constants

View Source
const (
	// cache
	DictionaryNotFound = constError("no dictionary found")
	// numbers
	NegativeNumber     = constError("negative numbers not allowed")
	NumberTooBig       = constError("number too big")
	NoTranslationFound = constError("no translation found")
	// list
	InvalidNumber = constError("invalidNumericError")
	NoResults     = constError("noResultsError")
)

Errors raised by package x.

View Source
const GLOB = "%"

GLOB https://github.com/ryanuber/go-glob The character which is treated like a glob

Variables

View Source
var Version = version{
	5, 22, 2,
	"",
	"Kanua Kenten",
	"",
}

Version is a printable version struct containing program version information

Functions

func AlphabetizeHelper

func AlphabetizeHelper(a string, b string) bool

func ArrCount

func ArrCount(s []string, q string) int

ArrCount returns the number of occurrences of q in s

func AssignWord

func AssignWord(wordmap map[string][]string, natlangWords string, naviWord string) (result map[string][]string)

Helper function for CacheDictHash2

func AssureDict

func AssureDict() error

AssureDict will assure, that the dictionary exists. If no dictionary is found, it will be downloaded next of the executable.

func BidirectionalSearch

func BidirectionalSearch(searchNaviWords string, checkFixes bool, langCode string) (results [][]Word, err error)

Translate some text. The language context is with Eywa now :ipu: !! Multiple words are supported !! This will return a 2D array of Words, that fit the input text One Word can have multiple meanings and words (e.g. synonyms)

func CacheDict added in v5.16.0

func CacheDict() error

func CacheDictHash

func CacheDictHash() error

func CacheDictHash2

func CacheDictHash2() error

Natural languages to Na'vi

func CacheDictHash2Orig added in v5.16.0

func CacheDictHash2Orig(mysql bool) error

func CacheDictHashOrig added in v5.16.0

func CacheDictHashOrig(mysql bool) error

This will cache the whole dictionary (Na'vi to natural language). Please call this, if you want to translate multiple words or running infinitely (e.g. CLI-go-prompt, discord-bot)

func Contains

func Contains(s []string, q []string) bool

Contains returns true if anything in q is also in s

func ContainsStr

func ContainsStr(s []string, q string) bool

ContainsStr returns true if q is in s

func DeleteElement

func DeleteElement(s []string, q string) []string

DeleteElement "deletes" all occurrences of q in s actually returns a new string slice containing the original minus all q

func DeleteEmpty

func DeleteEmpty(s []string) []string

DeleteEmpty "deletes" all empty string entries in s actually returns a new string slice containing all non-empty strings in s

func DownloadDict

func DownloadDict(filepath string) error

DownloadDict downloads the latest released version of the dictionary file and saves it to the given filepath. You can give an empty string as filepath param, to update the found dictionary file.

func FindDictionaryFile

func FindDictionaryFile() string

the dictionary file can be places into: - <workingDir>/dictionary.txt - <workingDir>/.fwew/dictionary.txt - <homeDir>/.fwew/dictionary.txt

func FullNames

func FullNames(ending string, name_count int, dialect int, syllable_count [3]int, two_thousand_limit bool) (output string)

func GetDictSize

func GetDictSize(lang string) (count string, err error)

Return a complete sentence

func GetDictSizeSimple added in v5.18.0

func GetDictSizeSimple() (count int)

Just a number

func GetHomonyms

func GetHomonyms() (results [][]Word, err error)

Get all words with multiple definitions

func GetLenitionTable

func GetLenitionTable() [][2]string

func GetMultiIPA added in v5.11.7

func GetMultiIPA() (results [][]Word, err error)

Get all words with multiple definitions

func GetMultiwordWords

func GetMultiwordWords() map[string][][]string

Get all words with spaces

func GetOddballs added in v5.13.0

func GetOddballs() (results [][]Word, err error)

Get all words with non-standard phonotactics

func GetOtherThats

func GetOtherThats() [][3]string

func GetPhonemeDistrosMap

func GetPhonemeDistrosMap(lang string) (allDistros [][][]string)

func GetShortLenitionTable

func GetShortLenitionTable() [][2]string

func GetThatTable

func GetThatTable() [][5]string

func Glob

func Glob(pattern, subj string) bool

Glob will test a string pattern, potentially containing globs, against a subject string. The result is a simple true/false, determining whether or not the glob pattern matched the subject text.

func HasPrefixStrArr

func HasPrefixStrArr(s string, q []string) bool

ContainsStrArr returns true if anything in q is in s

func Index

func Index(s []string, q string) int

Index return the index of q in s

func IndexStr

func IndexStr(s string, q rune) int

IndexStr return the index of q in s

func IsLetter

func IsLetter(s string) bool

IsLetter returns true if s is an alphabet character or apostrophe

func IsValidNavi added in v5.13.0

func IsValidNavi(word string, lang string, two_thousand_limit bool) string

func IsValidNaviHelper added in v5.13.0

func IsValidNaviHelper(word string, lang string) string

See if a word is phonotactically valid in Na'vi

func MakeSyllableBreakdown added in v5.18.0

func MakeSyllableBreakdown(syllables []string) string

func NameAlu

func NameAlu(name_count int, dialect int, syllable_count int, noun_mode int, adj_mode int) (output string)
func NaviToNumber(input string) (int, error)

Translate a Na'vi number word to the actual integer. Na'vi numbers are octal values, so the integer is defined as octal number, and can easily be displayed as decimal number. If no translation is found, `NoTranslationFound` is returned as error!

func NoDoubleDiphthongs added in v5.18.0

func NoDoubleDiphthongs(syllable_breakdown string) string

Turns things like maw-ey into ma-wey, so the checker knows mawll is valid as ma-wll and not mistaken for maw-ll (invalid)

func NumberToNavi

func NumberToNavi(input int) (string, error)

Translate an octal-integer into the Na'vi number word.

func PhonemeDistros

func PhonemeDistros()

Called on startup to feed and compile dictionary information into the name generator

func ReefMe

func ReefMe(ipa string, inter bool) []string

func Reverse

func Reverse(s string) string

Reverse returns the reversed version of s

func RomanizeSecondIPA added in v5.11.7

func RomanizeSecondIPA(IPA string) string

Helper function to get phonetic transcriptions of secondary pronunciations Only multiple IPA words will call this function

func RunOnDict

func RunOnDict(f func(word Word) error) (err error)

This will run the function `f` inside the cache or the file directly. Use this to get words out of the dictionary function `f` is called on every single line in the dictionary!

func SHA1Hash

func SHA1Hash(filename string) string

SHA1Hash gets hash of dictionary file

func SearchTerms added in v5.11.3

func SearchTerms(input string) []string

Turn a definition into its searchable terms

func SingleNames

func SingleNames(name_count int, dialect int, syllable_count int) (output string)

* Name generators

func SortedWords

func SortedWords() (nouns []Word, adjectives []Word, verbs []Word, transitiveVerbs []Word)

Helper function for name-alu

func StartEverything

func StartEverything() string

func StripChars

func StripChars(str, chr string) string

StripChars strips all the characters in chr out of str

func Text

func Text(s string) string

Text function is the accessor for []string texts

func TranslateFromNaviHash

func TranslateFromNaviHash(searchNaviWords string, checkFixes bool) (results [][]Word, err error)

Translate some navi text. !! Multiple words are supported !! This will return a 2D array of Words that fit the input text The first word will only contain the query put into the translate command One Navi-Word can have multiple meanings and words (e.g. synonyms)

func TranslateFromNaviHashHelper

func TranslateFromNaviHashHelper(start int, allWords []string, checkFixes bool) (steps int, results [][]Word, err error)

func TranslateToNaviHash

func TranslateToNaviHash(searchWord string, langCode string) (results [][]Word)

func UncacheDict added in v5.16.0

func UncacheDict()

func UncacheHashDict

func UncacheHashDict()

func UncacheHashDict2

func UncacheHashDict2()

func UpdateDict

func UpdateDict() error

Update the dictionary.txt. universalLock will hopefully prevent anything from accessing the dict while updating

Types

type ConjugationCandidate

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

type MetaDict

type MetaDict struct {
	EN map[string][]string
	DE map[string][]string
	ES map[string][]string
	ET map[string][]string
	FR map[string][]string
	HU map[string][]string
	KO map[string][]string
	NL map[string][]string
	PL map[string][]string
	PT map[string][]string
	RU map[string][]string
	SV map[string][]string
	TR map[string][]string
	UK map[string][]string
}

type PhonemeTuple added in v5.15.0

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

type Tuples added in v5.15.0

type Tuples []PhonemeTuple

func (Tuples) Len added in v5.15.0

func (s Tuples) Len() int

func (Tuples) Less added in v5.15.0

func (s Tuples) Less(i, j int) bool

func (Tuples) Swap added in v5.15.0

func (s Tuples) Swap(i, j int)

type Word

type Word struct {
	ID             string
	Navi           string
	IPA            string
	InfixLocations string
	PartOfSpeech   string
	Source         string
	Stressed       string
	Syllables      string
	InfixDots      string
	DE             string
	EN             string
	ES             string
	ET             string
	FR             string
	HU             string
	KO             string
	NL             string
	PL             string
	PT             string
	RU             string
	SV             string
	TR             string
	UK             string
	Affixes        affix
}

Word is a struct that contains all the data about a given word

func AppendAndAlphabetize

func AppendAndAlphabetize(words []Word, word Word) []Word

func AppendToFront

func AppendToFront(words []Word, input Word) []Word

Helper for TranslateFromNaviHashHelper

func EnglishIfNull added in v5.11.2

func EnglishIfNull(word Word) Word

If a definition is not available in a certain language, default to English

func GetFullDict

func GetFullDict() (allWords []Word, err error)

func IsVerb

func IsVerb(input string, comparator string) (result bool, affixes Word)

Helper for TranslateFromNaviHashHelper

func List

func List(args []string, checkDigraphs uint8) (results []Word, err error)

List filters the dictionary based on the args. args can be empty, if so, the whole Dict will be returned (This also happens if < 3 args are given) It will try to always get 3 args and an `and` in between. If less than 3 exist, than it will wil return the previous results.

func Random

func Random(amount int, args []string, checkDigraphs uint8) (results []Word, err error)

Get random words out of the dictionary. If args are applied, the dict will be filtered for args before random words are chosen. args will be put into the `List()` algorithm.

func SearchNatlangWord

func SearchNatlangWord(wordmap map[string][]string, searchWord string) (results []Word)

func TestDeconjugations

func TestDeconjugations(searchNaviWord string) (results []Word)

func TranslateToNaviHashHelper

func TranslateToNaviHashHelper(searchWord string, langCode string) (results []Word)

func (*Word) CloneWordStruct

func (w *Word) CloneWordStruct() Word

CloneWordStruct is basically a copy constructor for Word struct Basically not needed, cause go copies things by itself. Only string arrays in Affixes are pointers and therefore need manual copy.

func (*Word) Equals

func (w *Word) Equals(other Word) bool

func (Word) String

func (w Word) String() string

func (*Word) SyllableCount

func (w *Word) SyllableCount() int

func (*Word) ToOutputLine

func (w *Word) ToOutputLine(
	i string,
	withMarkdown, showIPA, showInfixes, showDashed, showInfDots, showSource, reef bool,
	langCode string,
) (output string, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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