Added plurals and tenses to source, Mash and Letters dictionaries.
This commit is contained in:
@@ -1,11 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs').promises;
|
||||
const inflect = require('inflect');
|
||||
const tensify = require('tensify');
|
||||
|
||||
const dictionary = require('./dictionary.json');
|
||||
|
||||
function getTenses(word) {
|
||||
try {
|
||||
const { past, past_participle: participle } = tensify(word);
|
||||
|
||||
return { past, participle };
|
||||
} catch (error) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function init() {
|
||||
const validWords = Object.entries(dictionary).filter(([word]) => /^[a-zA-Z]+$/.test(word));
|
||||
const formsDictionary = Object.fromEntries(Object.entries(dictionary).flatMap(([word, definition]) => {
|
||||
const plural = inflect.pluralize(word);
|
||||
const { past, participle } = getTenses(word);
|
||||
|
||||
return [
|
||||
[word, definition],
|
||||
...(plural && !dictionary[plural] ? [[plural, `Plural of ${word}`]] : []),
|
||||
...(past && !dictionary[past] ? [[past, `Past tense of ${word}`]] : []),
|
||||
...(participle && !dictionary[participle] ? [[past, `Past participle of ${word}`]] : []),
|
||||
];
|
||||
}));
|
||||
|
||||
const validWords = Object.entries(formsDictionary).filter(([word]) => /^[a-zA-Z]+$/.test(word));
|
||||
|
||||
const sortedWords = validWords.reduce((acc, [rawWord, fullDefinition]) => {
|
||||
const word = rawWord.toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user