2021-03-06 10:40:31 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const fetch = require("node-fetch");
|
2021-03-16 10:02:53 +00:00
|
|
|
const { readDictionary } = require("@lingdocs/pashto-inflector");
|
2021-03-06 10:40:31 +00:00
|
|
|
const path = require("path");
|
|
|
|
const verbsPath = path.join(".", "src", "words");
|
|
|
|
const verbCollectionPath = path.join(verbsPath, "verb-categories");
|
|
|
|
const nounAdjCollectionPath = path.join(verbsPath, "noun-adj-categories");
|
|
|
|
const verbTsFiles = fs.readdirSync(verbCollectionPath);
|
|
|
|
const nounAdjTsFiles = fs.readdirSync(nounAdjCollectionPath);
|
|
|
|
|
|
|
|
const allVerbTsS = [...new Set(verbTsFiles.reduce((arr, fileName) => {
|
|
|
|
const TsS = require(path.join("..", verbCollectionPath, fileName));
|
|
|
|
return [...arr, ...TsS];
|
|
|
|
}, []))];
|
|
|
|
|
|
|
|
const allNounAdjTsS = [...new Set(nounAdjTsFiles.reduce((arr, fileName) => {
|
|
|
|
const TsS = require(path.join("..", nounAdjCollectionPath, fileName));
|
|
|
|
return [...arr, ...TsS.map(x => ({ ...x, category: path.parse(fileName).name }))];
|
|
|
|
}, []))];
|
|
|
|
|
|
|
|
console.log("getting words from dictionary...");
|
|
|
|
|
2021-03-16 10:02:53 +00:00
|
|
|
fetch(process.env.LINGDOCS_DICTIONARY_URL).then(res => res.arrayBuffer()).then(buffer => {
|
|
|
|
const dictionary = readDictionary(buffer);
|
|
|
|
const entries = dictionary.entries;
|
2021-03-06 10:40:31 +00:00
|
|
|
// MAKE VERBS FILE
|
|
|
|
const allVerbs = getVerbsFromTsS(entries);
|
|
|
|
const content = `const verbs = ${JSON.stringify(allVerbs)};
|
|
|
|
export default verbs;`;
|
|
|
|
fs.writeFileSync(path.join(verbsPath, "verbs.js"), content);
|
|
|
|
|
|
|
|
// MAKE NOUN-ADJ FILE
|
|
|
|
const allNounsAdjs = getNounsAdjsFromTsS(entries);
|
2021-08-31 16:33:44 +00:00
|
|
|
const content1 = `import { Types as T } from "@lingdocs/pashto-inflector";
|
|
|
|
const nounsAdjs: { entry: T.DictionaryEntry, def: string, category: string }[] = ${JSON.stringify(allNounsAdjs)};
|
2021-03-06 10:40:31 +00:00
|
|
|
export default nounsAdjs;`;
|
2021-08-31 16:33:44 +00:00
|
|
|
fs.writeFileSync(path.join(verbsPath, "nouns-adjs.ts"), content1);
|
2021-03-06 10:40:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function getVerbsFromTsS(entries) {
|
2021-07-08 14:11:06 +00:00
|
|
|
const missingEc = [];
|
|
|
|
const toReturn = allVerbTsS.map(item => {
|
2021-03-06 10:40:31 +00:00
|
|
|
const entry = entries.find(x => item.ts === x.ts);
|
|
|
|
if (!entry) {
|
|
|
|
console.log("couldn't find ts", ts);
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-07-08 14:11:06 +00:00
|
|
|
if (!entry.ec) {
|
|
|
|
missingEc.push(entry.ts);
|
|
|
|
}
|
2021-03-06 10:40:31 +00:00
|
|
|
if (entry.c && entry.c.includes("comp.")) {
|
|
|
|
const complement = entries.find(x => entry.l === x.ts);
|
|
|
|
return {
|
|
|
|
entry,
|
|
|
|
complement,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return { entry, def: item.e };
|
|
|
|
}).filter(x => x);
|
2021-07-08 14:11:06 +00:00
|
|
|
if (missingEc.length !== 0) {
|
|
|
|
console.log("Verbs missing ec:", missingEc);
|
|
|
|
}
|
|
|
|
return toReturn;
|
2021-03-06 10:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getNounsAdjsFromTsS(entries) {
|
2021-10-05 01:15:31 +00:00
|
|
|
const b = allNounAdjTsS.map(item => {
|
2021-03-06 10:40:31 +00:00
|
|
|
const entry = entries.find(x => item.ts === x.ts);
|
|
|
|
if (!entry) {
|
2021-08-31 16:33:44 +00:00
|
|
|
console.log("couldn't find ts", item);
|
2021-03-06 10:40:31 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2021-10-10 01:45:42 +00:00
|
|
|
// const firstWord = entry.e.split(",")[0].split(";")[0].split("(")[0].trim();
|
|
|
|
// console.log(firstWord, entry.f, entry.ts);
|
2021-10-05 01:15:31 +00:00
|
|
|
// if (firstWord.contains(" ")) console.log("SPACE PRESENT");
|
2021-03-06 10:40:31 +00:00
|
|
|
return { entry, def: item.e, category: item.category };
|
|
|
|
}).filter(x => x);
|
2021-10-05 01:15:31 +00:00
|
|
|
return b;
|
|
|
|
// console.log(b.length, "number of nouns/adjs");
|
2021-03-06 10:40:31 +00:00
|
|
|
}
|