70 lines
2.5 KiB
JavaScript
70 lines
2.5 KiB
JavaScript
// Generates the present-tense conjugation for every -er verb in verbs.db
|
|
// and stores it in a `conjugations` table. Run: node conjugate.js
|
|
//
|
|
// Regular -er endings are computed; spelling-change verbs are overridden
|
|
// so the data stays accurate.
|
|
|
|
const { execFileSync } = require("child_process");
|
|
const path = require("path");
|
|
|
|
const DB = path.join(__dirname, "verbs.db");
|
|
|
|
// Verbs whose present tense is NOT the plain regular pattern.
|
|
const OVERRIDES = {
|
|
manger: ["mange", "manges", "mange", "mangeons", "mangez", "mangent"],
|
|
voyager: ["voyage", "voyages", "voyage", "voyageons", "voyagez", "voyagent"],
|
|
changer: ["change", "changes", "change", "changeons", "changez", "changent"],
|
|
commencer: ["commence", "commences", "commence", "commençons", "commencez", "commencent"],
|
|
acheter: ["achète", "achètes", "achète", "achetons", "achetez", "achètent"],
|
|
appeler: ["appelle", "appelles", "appelle", "appelons", "appelez", "appellent"],
|
|
payer: ["paie", "paies", "paie", "payons", "payez", "paient"],
|
|
nettoyer: ["nettoie", "nettoies", "nettoie", "nettoyons", "nettoyez", "nettoient"],
|
|
répéter: ["répète", "répètes", "répète", "répétons", "répétez", "répètent"],
|
|
};
|
|
|
|
function regular(inf) {
|
|
const stem = inf.slice(0, -2); // drop "er"
|
|
const nousStem = inf.endsWith("ger")
|
|
? stem + "e"
|
|
: inf.endsWith("cer")
|
|
? stem.slice(0, -1) + "ç"
|
|
: stem;
|
|
return [stem + "e", stem + "es", stem + "e", nousStem + "ons", stem + "ez", stem + "ent"];
|
|
}
|
|
|
|
function present(inf) {
|
|
return OVERRIDES[inf] || regular(inf);
|
|
}
|
|
|
|
function getInfinitives() {
|
|
const out = execFileSync("sqlite3", [DB, "SELECT infinitif FROM verbs ORDER BY infinitif;"], {
|
|
encoding: "utf8",
|
|
});
|
|
return out.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
}
|
|
|
|
function esc(s) {
|
|
return s.replace(/'/g, "''");
|
|
}
|
|
|
|
function build() {
|
|
const verbs = getInfinitives();
|
|
let sql = `
|
|
DROP TABLE IF EXISTS conjugations;
|
|
CREATE TABLE conjugations (
|
|
infinitif TEXT NOT NULL,
|
|
tense TEXT NOT NULL,
|
|
p1 TEXT, p2 TEXT, p3 TEXT, p4 TEXT, p5 TEXT, p6 TEXT,
|
|
PRIMARY KEY (infinitif, tense)
|
|
);
|
|
`;
|
|
for (const inf of verbs) {
|
|
const f = present(inf).map(esc);
|
|
sql += `INSERT INTO conjugations VALUES ('${esc(inf)}','présent','${f[0]}','${f[1]}','${f[2]}','${f[3]}','${f[4]}','${f[5]}');\n`;
|
|
}
|
|
execFileSync("sqlite3", [DB], { input: sql });
|
|
const n = execFileSync("sqlite3", [DB, "SELECT COUNT(*) FROM conjugations;"], { encoding: "utf8" }).trim();
|
|
console.log(`conjugations written: ${n} rows`);
|
|
}
|
|
|
|
build();
|