Improved dictionary processing.
This commit is contained in:
parent
5cc3a428f3
commit
2310352ad6
|
@ -1,11 +1,11 @@
|
|||
'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);
|
||||
|
@ -15,21 +15,26 @@ function getTenses(word) {
|
|||
return {};
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
const dictionary = require('./dictionary.json');
|
||||
|
||||
async function init() {
|
||||
/*
|
||||
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}`]] : []),
|
||||
...(plural && !dictionary[plural] ? [[plural, definition]] : []),
|
||||
...(past && !dictionary[past] ? [[past, definition]] : []),
|
||||
...(participle && !dictionary[participle] ? [[past, definition]] : []),
|
||||
];
|
||||
}));
|
||||
*/
|
||||
|
||||
const validWords = Object.entries(formsDictionary).filter(([word]) => /^[a-zA-Z]+$/.test(word));
|
||||
const validWords = Object.entries(dictionary).filter(([word]) => /^[a-zA-Z]+$/.test(word));
|
||||
|
||||
const sortedWords = validWords.reduce((acc, [rawWord, fullDefinition]) => {
|
||||
const word = rawWord.toLowerCase();
|
||||
|
|
30192
assets/dictionary.json
30192
assets/dictionary.json
File diff suppressed because one or more lines are too long
|
@ -10,9 +10,9 @@ async function init() {
|
|||
const normalizedWord = word.normalize('NFD').replace(/\p{Diacritic}/ug, '').toLowerCase().trim();
|
||||
const definition = dictionary[normalizedWord];
|
||||
const singular = normalizedWord.replace(/s$/, '');
|
||||
const singularDefinition = dictionary[singular] ? `Plural of ${singular}: ${dictionary[singular]}` : null;
|
||||
const singularDefinition = dictionary[singular];
|
||||
|
||||
return [normalizedWord, definition || singularDefinition];
|
||||
return [normalizedWord, definition || singularDefinition || null];
|
||||
}));
|
||||
|
||||
const string = JSON.stringify(definitions, null, 4);
|
||||
|
|
Loading…
Reference in New Issue