2024-08-06 20:12:32 +00:00
|
|
|
import * as T from "./src/types";
|
|
|
|
import { inflectWord } from "./src/lib/src/pashto-inflector";
|
2024-08-06 20:30:59 +00:00
|
|
|
import * as tp from "./src/lib/src/type-predicates";
|
2024-08-06 20:37:41 +00:00
|
|
|
import { conjugateVerb } from "./src/lib/src/verb-conjugation";
|
2024-08-06 21:42:53 +00:00
|
|
|
import fetch from "node-fetch";
|
2024-08-06 20:12:32 +00:00
|
|
|
|
|
|
|
// Script to try inflecting all the words in the dictionary and make sure that
|
|
|
|
// no errors are thrown in the process
|
|
|
|
|
|
|
|
type InflectionError = {
|
|
|
|
ts: number;
|
|
|
|
p: string;
|
|
|
|
f: string;
|
|
|
|
err: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
async function checkAll() {
|
|
|
|
const res = await fetch(process.env.LINGDOCS_DICTIONARY_URL);
|
2024-08-06 21:42:53 +00:00
|
|
|
// @ts-ignore
|
2024-08-06 20:12:32 +00:00
|
|
|
const { entries }: T.Dictionary = await res.json();
|
|
|
|
const errors: InflectionError[] = [];
|
|
|
|
|
|
|
|
entries.forEach((entry) => {
|
|
|
|
try {
|
|
|
|
inflectWord(entry);
|
|
|
|
} catch (e) {
|
|
|
|
errors.push({
|
|
|
|
ts: entry.ts,
|
|
|
|
p: entry.p,
|
|
|
|
f: entry.f,
|
|
|
|
err: e.toString(),
|
|
|
|
});
|
|
|
|
}
|
2024-08-06 21:26:06 +00:00
|
|
|
if (tp.isVerbDictionaryEntry(entry)) {
|
2024-08-06 20:30:59 +00:00
|
|
|
const complement = entry.l
|
|
|
|
? entries.find((e) => e.ts === entry.l)
|
|
|
|
: undefined;
|
|
|
|
if (entry.l && !complement) {
|
|
|
|
errors.push({
|
|
|
|
ts: entry.ts,
|
|
|
|
p: entry.p,
|
|
|
|
f: entry.f,
|
|
|
|
err: "verb complement missing",
|
|
|
|
});
|
2024-08-06 20:37:41 +00:00
|
|
|
} else {
|
2024-08-06 21:26:06 +00:00
|
|
|
try {
|
|
|
|
conjugateVerb(entry, complement);
|
|
|
|
} catch (e) {
|
|
|
|
errors.push({
|
|
|
|
ts: entry.ts,
|
|
|
|
p: entry.p,
|
|
|
|
f: entry.f,
|
|
|
|
err: e,
|
|
|
|
});
|
|
|
|
}
|
2024-08-06 20:30:59 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-06 20:12:32 +00:00
|
|
|
});
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkAll().then((errors) => {
|
|
|
|
if (errors.length) {
|
|
|
|
console.log(
|
|
|
|
"The following errors occured while inflecting all dictionary words"
|
|
|
|
);
|
|
|
|
console.log(errors);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
console.log("No errors occured while inflecting all dictionary words");
|
|
|
|
});
|