fwew_lib

package module
v6.0.0-...-9df223c Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: GPL-2.0 Imports: 17 Imported by: 0

README

fwew Library

Build Status

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 two 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 main contains all the things. version.go handles program version.

Package main 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{
	6, 0, 0,
	"next",
	"Nawma Nalutsa",
	"",
}

Version is a printable version struct containing program version information

Functions

func ArrCount

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

ArrCount returns the number of occurrences of q in s

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 CacheDict

func CacheDict() error

This will cache the whole dictionary. 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 GetDictSize

func GetDictSize() (amount int, err error)

func GetLenitionTable

func GetLenitionTable() [][2]string

func GetOtherThats

func GetOtherThats() [][3]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 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 NumberToNavi

func NumberToNavi(input int) (string, error)

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

func Reverse

func Reverse(s string) string

Reverse returns the reversed version of s

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 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 UncacheDict

func UncacheDict()

func UpdateDict

func UpdateDict() error

Update the dictionary.txt. Be careful to not do anything with the dict-file, while update is in progress

Types

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
	ET             string
	FR             string
	HU             string
	NL             string
	PL             string
	RU             string
	SV             string
	TR             string
	Affixes        affix
}

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

func GetFullDict

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

func List

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

Filter 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) (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 TranslateFromNavi

func TranslateFromNavi(searchNaviWord string) (results []Word, err error)

Translate some navi text. !! Only one word is allowed, if spaces are found, they will be treated like part of the word !! This will return an array of Words, that fit the input text One Navi-Word can have multiple meanings and words (e.g. synonyms)

func TranslateToNavi

func TranslateToNavi(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 int, withMarkdown, showIPA, showInfixes, showDashed, showInfDots, showSource 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