cleaner get-words
This commit is contained in:
parent
f249555eac
commit
35a984a2b2
|
@ -1,5 +1,7 @@
|
||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
/src/words/raw-words.ts
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
/node_modules
|
/node_modules
|
||||||
/.pnp
|
/.pnp
|
||||||
|
|
|
@ -24,60 +24,29 @@ const allAdverbTsS = adverbTsFiles.flatMap(fileName => [
|
||||||
...require(path.join("..", adverbCollectionPath, fileName))
|
...require(path.join("..", adverbCollectionPath, fileName))
|
||||||
]).filter((v, i, a) => a.findIndex(x => x === v) === i);
|
]).filter((v, i, a) => a.findIndex(x => x === v) === i);
|
||||||
|
|
||||||
|
const allTs = [...allVerbTsS, ...allAdverbTsS, ...allNounAdjTsS];
|
||||||
console.log("getting words from dictionary...");
|
console.log("getting words from dictionary...");
|
||||||
|
|
||||||
fetch(process.env.LINGDOCS_DICTIONARY_URL + ".json").then(res => res.json()).then(data => {
|
fetch("https://account.lingdocs.com/dictionary/entries", {
|
||||||
const { entries } = data;
|
method: "POST",
|
||||||
// MAKE VERBS FILE
|
headers: {
|
||||||
const allWords = [
|
"Content-Type": "application/json",
|
||||||
...getVerbsFromTsS(entries),
|
},
|
||||||
...getNounsAdjsFromTsS(entries),
|
body: JSON.stringify({ ids: allTs }),
|
||||||
];
|
}).then(res => res.json()).then(data => {
|
||||||
const content = `
|
const content = `
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const words: Word[] = ${JSON.stringify(allWords)};
|
const words: Word[] = ${JSON.stringify(data.results)};
|
||||||
export default words;`;
|
export default words;`;
|
||||||
fs.writeFileSync(path.join(wordsPath, wordsFile), content);
|
fs.writeFileSync(path.join(wordsPath, wordsFile), content);
|
||||||
|
const missingEc = data.results.filter(x => "entry" in x && !x.entry.ec);
|
||||||
|
if (missingEc.length) {
|
||||||
|
console.log("verbs missing ec");
|
||||||
|
console.log(missingEc);
|
||||||
|
}
|
||||||
|
if (data.notFound.length) {
|
||||||
|
console.log("entries not found:");
|
||||||
|
console.log(data.notFound);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function getVerbsFromTsS(entries) {
|
|
||||||
const missingEc = [];
|
|
||||||
const toReturn = allVerbTsS.map(ts => {
|
|
||||||
const entry = entries.find(x => ts === x.ts);
|
|
||||||
if (!entry) {
|
|
||||||
console.log("couldn't find ts", ts);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (!entry.ec) {
|
|
||||||
missingEc.push(entry.ts);
|
|
||||||
}
|
|
||||||
if (entry.c && entry.c.includes("comp.")) {
|
|
||||||
const complement = entries.find(x => entry.l === x.ts);
|
|
||||||
return {
|
|
||||||
entry,
|
|
||||||
complement,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return { entry };
|
|
||||||
}).filter(x => x);
|
|
||||||
if (missingEc.length !== 0) {
|
|
||||||
console.log("Verbs missing ec:", missingEc);
|
|
||||||
}
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNounsAdjsFromTsS(entries) {
|
|
||||||
const b = [...allNounAdjTsS, ...allAdverbTsS].map(ts => {
|
|
||||||
const entry = entries.find(x => ts === x.ts);
|
|
||||||
if (!entry) {
|
|
||||||
console.log("couldn't find ts", ts);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
// const firstWord = entry.e.split(",")[0].split(";")[0].split("(")[0].trim();
|
|
||||||
// console.log(firstWord, entry.f, entry.ts);
|
|
||||||
// if (firstWord.contains(" ")) console.log("SPACE PRESENT");
|
|
||||||
return entry;
|
|
||||||
}).filter(x => x);
|
|
||||||
return b;
|
|
||||||
// console.log(b.length, "number of nouns/adjs");
|
|
||||||
}
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue