Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Latin To English

Maksim Straus edited this page Jun 7, 2023 · 1 revision

Latin To English

Requires: wordsDict (Latin dictionary)
Requires: uniques (list of unique Latin words, that cant be found normally)
Requires: addons (prefixes, suffixes and enclitic type fragments used in latin word formation)
Requires: stems (list of possible word stems)
Requires: inflects (list of possible word inflection)
Requires: tricks (class with a collection of helper methods)

Latin To English (public)

Requires: word (Latin word to translate)
Returns: out (list of possible English translations)

The latinToEnglish method is used to find the definition and word formation from a given Latin word. It follows a series of steps to discover the translation.

The method starts by initializing two variables: isUnique, which determines if the word is in the unique list, and an empty object called out, which stores the output.

It then checks if the base word is present in the unique list using the parseUniques method. The output of parseUniques is stored in uniqueOut, and its values are assigned to out and isUnique respectively.

If isUnique is false, indicating that the word is not in the unique list, the findForms method is called with the word, and its output is assigned to out.

If out is still empty, and the switchFirstIOrJ trick does not return the original word, the word is processed using switchFirstIOrJ to find a modified word. The findForms method is then called with the modified word, and its output is assigned to out.

If out is still empty at this point, enclitics are removed from the word using the splitEnclitics method.

The modified word is then checked against the unique list using parseUniques. The output is assigned to uniqueOut, and its values are assigned to out and isUnique.

If isUnique is false, indicating that the modified word is not in the unique list, the findForms method is called with the modified word, and its output is assigned to out.

If out is still empty, and the switchFirstIOrJ trick does not return the original word, the word is processed using switchFirstIOrJ to find a further modified word. The findForms method is then called with the further modified word, and its output is assigned to out.

The method also checks if the word consists of only Roman numerals using the onlyRomanDigits trick. If it does, the evaluateRomanNumerals trick is used to convert the Roman numerals to Arabic numerals. If a valid conversion is obtained, the translated number is added to out along with some metadata.

Finally, the out object, containing the list of possible English translations, is returned.

Parse Uniques (private)

Requires: word (word that should be found)
Returns: out (matching unique data)
Returns: isUnique (true if word is unique)

The parseUniques method, searches through a list of words that cant be found through normal searching methods.

First the method initializes an empty array called out, which will store the output, and a variable called isUnique, initially set to false.

It iterates over the uniques list, which contains unique Latin words and their definitions.

For each unique word in the list, it compares the lowercase form of the orth property (representing the Latin word) with the lowercase form of the word parameter.

If there is a match, indicating that the Latin word corresponds to the English definition, the matching unique object is added to the out array along with an empty stems array. The isUnique variable is set to true, indicating that the word is found, and the loop is exited.

Finally, the method returns an array containing out and isUnique.

Find Forms (private)

Requires: word (Latin word)
Requires: reduced (true if word has been reduced before)
Returns: out (list of results)

The findForms method is used to find word forms based on a given Latin word.

The method initializes two variables, infls to store the found inflections and out to store the results.

The method checks the word against a list of inflections (inflects). It iterates through each inflection and checks if the word ends with the inflection's ending. If a match is found, the inflection is added to the infls array.

The method then calls the checkStems method, passing the word, infls, and true as parameters. This method checks the stems against the inflections and returns a list of possible stems.

If no stems were found in the previous step, the method calls checkStems again, but this time with the last parameter set to false. This allows for words that end with certain patterns, such as "erunt."

The method then calls the lookupStems method, passing the stems and out as parameters. This method looks up the stems in the dictionary and retrieves their definitions.

If the out is still empty and reduced is false, the method calls the reduce method with the word as a parameter. This reduces the word to its base form and returns any additional data.

Finally, the method returns the out object containing the list of results.

Reduce (private)

Requires: word (Latin word)
Returns: out (list of results or false)

The reduce method is used to reduce a Latin word by removing prefixes and suffixes in order to find its base form.

The method initializes two variables, out to store the results and foundNewMatch to track whether any new matches were found during the reduction process.

The method iterates through each prefix in the prefixes property of addons and checks if the word starts with the prefix. If a match is found, the prefix is removed from the word, and the prefix is added to the out array along with an empty list of stems. The process breaks after the first matching prefix is found.

Next, the method iterates through each suffix in suffixes property of addons and checks if the word ends with the suffix. If a match is found, the suffix is removed from the word, and the suffix is added to the out array along with an empty list of stems. The process breaks after the first matching suffix is found.

The method calls the findForms method, passing the reduced word and true as parameters. This step attempts to find forms based on the reduced word.

The method checks if any new matches were found during the reduction process. It iterates through each word in out and checks if its stems list has a length greater than zero. If a match is found, foundNewMatch is set to true.

If no new matches were found, the out variable is set to false.

Finally, the method returns the out object containing the list of results. If no new matches were found, it returns false.

Check Stems (private)

Requires: word (Latin word)
Requires: infls (list of inflections)
Requires: ensureInfls (ensure the forms match)
Returns: matchStems (list of stems)

The checkStems method is used to check the stems of a Latin word against a list of inflections.

The method initializes an empty array called matchStems to store the matched stems.

For each inflection in the infls list that is a match, the method removes the inflection from the end of the word.

The method then iterates through each stem in the stems list and checks if the stripped wordStem matches the stem's orth (orthographic form).

If a match is found, the method checks if the inflection and stem identify as the same pos (part of speech). If they do not match, it checks for specific exceptions where VPAR (verb participle) and V (verb) can be considered as matching pos.

If the ensureInfls parameter is set to true and the inflections do not apply to the correct stem declension, conjugation, etc., the iteration continues to the next stem.

If the stem is already in the matchStems list, the method checks if the inflection is already in the inflections list of that stem. If it is not, the inflection is added to the stem's inflections list.

If the stem is not already in the matchStems list, the method adds the stem along with the current inflection to the matchStems list.

Finally, the method returns the matchStems list containing the matched stems and their corresponding inflections.

Lookup Stems (private)

Requires: matchedStems (list of matched stems)
Requires: out (list of results)
Returns: out (list of results)

The lookupStems method is used to look up the stems of the matched Latin words and add them to the output list.

For each matched stem in the matchedStems list, the method searches for the corresponding word in the wordsDict list using the wid property.

If a matching word is found in the wordsDict, the method checks if the word is already in the out list. It does this by comparing the word's orth property (orthographic form).

If the word is already in the out list, the method retrieves the matching word from the out list and adds the matched stem to its stems.

If the word is not in the out list, the method creates a temporary stem, tempStem based on the matched stem. If the word's part of speech is V (verb), it determines whether to remove extra inflections based on the orth of the fourth part of the word. The removeExtraInfls method is called to remove any unnecessary inflections.

The method then adds a new entry to the out list, containing a copy of the dictWord (matching word) and the tempStem as its stems.

Finally, the method returns the updated out list.

Add Stem To Word (private)

Requires: stem (string of the stem to add)
Requires: word (Latin word and its data)

The addStemToWord method, adds a stem to a Latin word.

First the method checks if the stem is not already present in the stems property of the word object. This is done by iterating over each stem (st) in the stems array of the word object.

If the stem is found in the stems array, the variable wordIsInOutWordStems is set to true, indicating that the stem is already present, and the loop is then exited.

If the stem is not found in the stems array, indicating that it is not already present in the word, it is added to the stems array of the word object.

There is no explicit return statement in the method, as the word object is modified in place.

Split Enclitic (private)

Requires: word (latin word)
Returns: word (without enclitic)
Returns: out(enclitic data)

The splitEnclitic method is used to split enclitics from the ends of a Latin word. It serves the purpose of separating enclitics from the word forms that are not included in the dictionaries, but their root forms are.

The method initializes an empty array called out, which will store the enclitic data, and a variable called tackon, initially undefined.

It iterates over the list of tackons within the addons object. These tackons represent enclitics that are directly attached to the end of the word.

For each enclitic in the list, it checks if the word ends with the orth property of the enclitic. If there is a match, indicating that the word ends with an enclitic, the tackon variable is set to the matching enclitic, and the loop is exited.

If a tackon is found, it is assigned to the form property of the tackon object. An exception is made for the word "est", where the enclitic is not added to the out list.

The enclitic is then removed from the word by slicing the string from the beginning to the length of the enclitic.

If no tackon is found, it determines whether to use the packons or notPackons list from the addons object based on whether the word starts with "qu". These packons and notPackons represent enclitics that can occur at the end of the word after a specific condition.

It iterates over the selected list of packons or notPackons and checks if the word ends with the orth property of each enclitic. If there is a match, indicating that the word ends with an enclitic, the matching enclitic is added to the out list, and the enclitic is removed from the word as described earlier.

Finally, the method returns an array containing the modified word and the out array

Remove Extra Inflections (private)

Requires: stems (list of stems)
Requires: removeType (the type of POS to remove, VPAR default)
Returns: filteredStems (copy of stems, with the infls of removeType removed)

The removeExtraInfls method is sued to create to remove inflections that dont match the passed in part of speach in the removeType.

The method creates a new array called filteredInfls then filters the infls property of the stem object. The filter function checks each inflection (infl) and only keeps those that have a pos property different from the specified removeType.

The method then returns a new object that is a shallow copy of the stem object, with the infls property replaced by the filteredInfls array. This ensures that the original stem object is not modified.

Clone this wiki locally