translations

Loads and sets translations

translations

Type: object

invalid

Indicates, that no decision could be made

invalid

Type: {goal: string, distance: number}

tolerance

Highest tolerated Distance for Levenshtein

tolerance

Type: number

minimalDistance

Searchs through Array, to find the word that is closest to the word given as parameter

minimalDistance(word: string, goals: Array<string>, maxdistance: number): {distance: number, goal: string}
Parameters
word (string) The Word, that was given as an Input
goals (Array<string>) The Words, which word will be compared to
maxdistance (number = tolerance) The maximal levensthein distance that the word may have. Defaults to tolerance
Returns
{distance: number, goal: string}: Returns an Object containing the closest word and its distance. If no word is found, the method returns invalid

IllegalArgumentError

Indicates that an Invalid Argument was given

new IllegalArgumentError(message: any)

Extends Error

Parameters
message (any)

arraySum

Calculates the Sum of an Array

arraySum(array: Array<Number>): number
Parameters
array (Array<Number>) to be reduced
Returns
number: sum

splitSentence

Splits a String in Groups of words

splitSentence(offset: number, string: string, subSize: number): Array<string>
Parameters
offset (number) The offset at which the splitting should start; for example if offset equals one, the first word is put in the Array as an entry, for 2 it's the first two words, and so on. Must be smaller than subSize
string (string) The String to be split
subSize (number) The Number of words to leave together. Defaults to two if undefined, if smaller then one, string will be returned
Returns
Array<string>: Array of split wordgroups

interpretSentence

Divides a Sentence in Parts, each having not more than subSize words, sends these to minimal distance and calculates than, which is most likely to be correct Uses the formula described here

interpretSentence(string: string, goals: (Array<string> | Array<Array<string>>), maxdistance: number): number
Parameters
string (string) The Sentence to be interpreted
goals ((Array<string> | Array<Array<string>>)) An Array containing the words or containing arrays with alternatives in it. One dimensional Array will automatically be put in two Dimensions
maxdistance (number = tolerance) The maximal levensthein distance that the word may have. Defaults to tolerance
Returns
number: Returns Index of the Entry that is most likely

addTranslations

Adds or overrides translations

addTranslations(trans: any)
Parameters
trans (any) An object containing the translations to be added in the same format as in the default lang files

removeGarbage

Removes unnecessary words from string. Unnecessary words are to be defined in the language files as Array named garbage

removeGarbage(string: string, lang: string): string
Parameters
string (string) String to be shortened
lang (string) language the string is in
Returns
string: String with removed Words

yesNoMaybe

Decides, if word is most likely Yes, No or Maybe (including Variations) and uses language

yesNoMaybe(word: string, lang: string): {distance: number, goal: string}
Parameters
word (string) Input of the User
lang (string) The Language the User is using as two-letter-code
Returns
{distance: number, goal: string}: Decides if yes, no or maybe was most likely meant

index

Names MUST be two-letter code, like the examples

index