Normalize for resolveTerm

This commit is contained in:
Jared Miller 2025-12-25 10:30:12 -05:00
parent e3b8f7188f
commit 82c66ba3f0
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -142,46 +142,46 @@ const specialCaseMap = {
};
const resolveTerm = (term) => {
const normalized = term.replace(//g, "'");
const normalized = term.replace(/'/g, "'");
const special = specialCaseMap[normalized];
if (special && entryMap.has(special)) {
return special;
}
if (entryMap.has(term)) {
return term;
if (entryMap.has(normalized)) {
return normalized;
}
const lower = term.toLowerCase();
const lower = normalized.toLowerCase();
const candidates = [];
// Singularize
if (lower.endsWith("ies")) {
candidates.push(term.slice(0, -3) + "Y");
candidates.push(normalized.slice(0, -3) + "Y");
}
if (lower.endsWith("ves")) {
candidates.push(term.slice(0, -3) + "F");
candidates.push(term.slice(0, -3) + "FE");
candidates.push(normalized.slice(0, -3) + "F");
candidates.push(normalized.slice(0, -3) + "FE");
}
if (lower.endsWith("es")) {
candidates.push(term.slice(0, -2));
candidates.push(normalized.slice(0, -2));
}
if (lower.endsWith("s")) {
candidates.push(term.slice(0, -1));
candidates.push(normalized.slice(0, -1));
}
// Pluralize
if (lower.endsWith("y") && !/[aeiou]y$/.test(lower)) {
candidates.push(term.slice(0, -1) + "IES");
candidates.push(normalized.slice(0, -1) + "IES");
}
if (lower.endsWith("f")) {
candidates.push(term.slice(0, -1) + "VES");
candidates.push(normalized.slice(0, -1) + "VES");
}
if (lower.endsWith("fe")) {
candidates.push(term.slice(0, -2) + "VES");
candidates.push(normalized.slice(0, -2) + "VES");
}
candidates.push(`${term}S`);
candidates.push(`${normalized}S`);
if (/(s|x|z|ch|sh)$/i.test(lower)) {
candidates.push(`${term}ES`);
candidates.push(`${normalized}ES`);
}
return candidates.find((candidate) => entryMap.has(candidate)) || null;