Normalize for resolveTerm
This commit is contained in:
parent
1909dbf0bb
commit
243f957037
1 changed files with 14 additions and 14 deletions
28
script.js
28
script.js
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue