2024-06-09 16:07:52 +00:00
'use strict' ;
const fs = require ( 'fs' ) . promises ;
const words = require ( './words.json' ) ;
2024-07-04 20:55:54 +00:00
const wordsBlacklist = require ( './words_blacklist.json' ) ;
const dictionary = require ( './dictionary.json' ) ;
// mainly lowercase names
const blacklist = new Set ( wordsBlacklist ) ;
2024-06-09 16:07:52 +00:00
async function init ( ) {
2024-07-04 20:55:54 +00:00
const notNameWords = words . filter ( ( word ) => word . charAt ( 0 ) === word . charAt ( 0 ) . toLowerCase ( ) && ! blacklist . has ( word ) ) ; // don't include names for places, products, people, etc.
2024-06-18 22:23:21 +00:00
2024-06-18 19:40:38 +00:00
const definitions = Object . fromEntries ( notNameWords . map ( ( word ) => {
2024-06-09 16:07:52 +00:00
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 ( ) ;