schat2-clive/assets/words-to-dictionary.js

26 lines
762 B
JavaScript
Raw Normal View History

2024-06-09 16:07:52 +00:00
'use strict';
const fs = require('fs').promises;
const words = require('./words.json');
const dictionary = require('./dictionary_old.json');
async function init() {
const definitions = Object.fromEntries(words.map((word) => {
const normalizedWord = word.normalize('NFD').replace(/\p{Diacritic}/ug, '').toLowerCase().trim();
const definition = dictionary[normalizedWord];
const singular = normalizedWord.replace(/s$/, '');
2024-06-09 21:37:17 +00:00
const singularDefinition = dictionary[singular];
2024-06-09 16:07:52 +00:00
2024-06-09 21:37:17 +00:00
return [normalizedWord, definition || singularDefinition || null];
2024-06-09 16:07:52 +00:00
}));
const string = JSON.stringify(definitions, null, 4);
await fs.writeFile('./dictionary.json', string);
console.log(`Wrote ${Object.keys(definitions).length} words to ./dictionary.json`);
}
init();