-
Notifications
You must be signed in to change notification settings - Fork 3
English To Latin
Requires: english (list of English word and their keys)
Requires: wordsDict (Latin dictionary)
Requires: word (English word)
Returns: out (list of possible Latin equivalent words and defs)
First the englishToLatin method is used to find the Latin equivalent words and definitions for a given English word.
The method initializes an empty listOfWords array and an empty out array.
The method then searches through the english list, which likely contains Latin words with their English definitions. It checks if the lowercase form of the orth (orthographic form) property matches the lowercase form of the provided word. If a match is found, the words line is added to the listOfWords.
The listOfWords is then reordered with the weighWords method.
Next, the method removes any duplicate words from the listOfWords using the removeDuplicateWords method.
If the listOfWords contains more than the responseLimit (default is 6), only words above the limit in the list are kept. This helps to filter out less relevant or potentially incorrect translations.
Finally, the method calls the findEnglishWordDefs method to lookup the definitions of the Latin words in the dictionary, which are stored in the out list.
Finally, the out object, containing the Latin equivalent words and definitions, is returned.
Requires: listOfWords (list of words)
Returns: listOfWords (list of words weighed by frequency)
The weighWords method is used to weigh words from the English list based on their frequency.
The method uses the sort function to sort the listOfWords array. It compares two words a and b and calculates their true frequency using the calculateTrueFrequency method.
The method subtracts the frequency of word a from the frequency of word b to determine their relative ranking. Words with higher frequencies will appear before words with lower frequencies in the sorted array.
Finally, the sorted listOfWords array is then returned.
Requires: listOfWords (list of words)
Returns: listOfWords (list of words without duplicates)
The removeDuplicateWords method is used to remove duplicate words from the list of words.
The method creates a Map object named entriesMap, which will store the unique entries based on a unique key.
It iterates over each entry in the listOfWords array.
For each entry, the method generates a unique key by combining the word's identifier (wid) and its true frequency. The true frequency is calculated using the calculateTrueFrequency method.
The method checks if there is already an existing entry in entriesMap with the same key. If no existing entry is found or the current entry has a lower true frequency than the existing entry, the current entry is added or updated in the entriesMap.
Once all entries have been processed, the method returns an array containing the unique values from the entriesMap.
Requires: word (English word data)
Returns: number (true frequency)
The calculateTrueFrequency method, is used to determine the true frequency of a word.
The true frequency is calculated by taking the frequency of the word, adding it to its compound value, between 0 and 15, increasing the more pure the word is, and subtracting the semi value, whether or not, the meaning is set of by a semicolon in the definition.
Finally, the true frequency is returned.
Requires: listOfWords (list of words)
Returns: listOfWords (list of words with definitions)
The findEnglishWordDefs method is used to find the definitions of English words.
The method uses the map function to iterate over each word in the listOfWords array.
For each word, the method searches for a corresponding entry in the wordsDict dictionary It compares the id of each dictionary entry with the word's id (wid) to find a match.
If a matching dictionary entry is found, the method creates an object containing the dictionary entry, foundDictline and an empty stems array. This object represents a word with its associated definition.
If no matching dictionary entry is found, the method returns null for that word.
The map function returns an array of objects representing the words with their definitions.
The method uses the filters out any null values from the resulting array, ensuring that only valid word definitions are included.
Finally, the method returns the listOfWords with their definitions.