Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.
Maksim Straus edited this page Jun 8, 2023 · 3 revisions

Parser

WordsDict, LatinAddons, Stems, Uniques, Inflects and English, are all imported here. Stems and Inflects endings, are both sorted by length, for parsing purposes.

Parse Line (public)

Requires: line (string of text to be translated)
Requires: direction (lte for Latin to English, etl for English to Latin)
Requires: formatted (boolean for whether of not output is formatted)
Returns: out (list of definitions)

The parseLine method is used to parse a line of text.

First method initializes an empty array called out to store the translations.

Then the method sanitizes the line using the sanatize method from the formatter class.

Next the line is split into an array of words using the space character as the delimiter.

For each word in the words array, the parse method is called to translate the word. The translations for each word are pushed to the out array.

Once all words have been translated, the method returns the out array containing the translations.

Parse (private)

Requires: word (a single word to be translated)
Requires: direction (lte for Latin to English, etl for English to Latin)
Requires: formatted (boolean for whether of not output is formatted)
Returns: out (list of definitions)

The parse method is used to manage and perform lookups of a single word in the dictionary.

The method first initializes an empty array called out to store the definitions.

Based on the specified direction, the method calls the respective translation method (latinToEnglish for lte or englishToLatin for etl) to perform the translation of the word. The result is assigned to the out variable.

If the formatted option is true, the method calls the formatOutput method from the formatter class to format the output.

The method returns an object containing the word and the out array of definitions.

Clone this wiki locally