Improved dictionary processing.
This commit is contained in:
parent
5cc3a428f3
commit
2310352ad6
|
@ -1,11 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
|
|
||||||
|
/*
|
||||||
const inflect = require('inflect');
|
const inflect = require('inflect');
|
||||||
const tensify = require('tensify');
|
const tensify = require('tensify');
|
||||||
|
|
||||||
const dictionary = require('./dictionary.json');
|
|
||||||
|
|
||||||
function getTenses(word) {
|
function getTenses(word) {
|
||||||
try {
|
try {
|
||||||
const { past, past_participle: participle } = tensify(word);
|
const { past, past_participle: participle } = tensify(word);
|
||||||
|
@ -15,21 +15,26 @@ function getTenses(word) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
const dictionary = require('./dictionary.json');
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
|
/*
|
||||||
const formsDictionary = Object.fromEntries(Object.entries(dictionary).flatMap(([word, definition]) => {
|
const formsDictionary = Object.fromEntries(Object.entries(dictionary).flatMap(([word, definition]) => {
|
||||||
const plural = inflect.pluralize(word);
|
const plural = inflect.pluralize(word);
|
||||||
const { past, participle } = getTenses(word);
|
const { past, participle } = getTenses(word);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[word, definition],
|
[word, definition],
|
||||||
...(plural && !dictionary[plural] ? [[plural, `Plural of ${word}`]] : []),
|
...(plural && !dictionary[plural] ? [[plural, definition]] : []),
|
||||||
...(past && !dictionary[past] ? [[past, `Past tense of ${word}`]] : []),
|
...(past && !dictionary[past] ? [[past, definition]] : []),
|
||||||
...(participle && !dictionary[participle] ? [[past, `Past participle of ${word}`]] : []),
|
...(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 sortedWords = validWords.reduce((acc, [rawWord, fullDefinition]) => {
|
||||||
const word = rawWord.toLowerCase();
|
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 normalizedWord = word.normalize('NFD').replace(/\p{Diacritic}/ug, '').toLowerCase().trim();
|
||||||
const definition = dictionary[normalizedWord];
|
const definition = dictionary[normalizedWord];
|
||||||
const singular = normalizedWord.replace(/s$/, '');
|
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);
|
const string = JSON.stringify(definitions, null, 4);
|
||||||
|
|
Loading…
Reference in New Issue