improve wee-bit-fuzzy
This commit is contained in:
parent
c898dd6950
commit
cd628f28ab
|
@ -4,9 +4,11 @@ const pMatches = [
|
||||||
["پیټی", "پېټی"],
|
["پیټی", "پېټی"],
|
||||||
["دوستی", "دوستي"],
|
["دوستی", "دوستي"],
|
||||||
["پته", "پټه"],
|
["پته", "پټه"],
|
||||||
|
["تخلیه", "تحلیه"],
|
||||||
];
|
];
|
||||||
|
|
||||||
const fMatches = [
|
const fMatches = [
|
||||||
|
["tahliya", "takhliya"],
|
||||||
["sareyy", "saRey"],
|
["sareyy", "saRey"],
|
||||||
["peyTey", "peTey"],
|
["peyTey", "peTey"],
|
||||||
];
|
];
|
||||||
|
@ -17,12 +19,22 @@ pMatches.forEach((pair) => {
|
||||||
const result = pair[1].match(new RegExp(re, "i"));
|
const result = pair[1].match(new RegExp(re, "i"));
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
test(`${pair[1]} should match ${pair[0]}`, () => {
|
||||||
|
const re = makeAWeeBitFuzzy(pair[1], "p");
|
||||||
|
const result = pair[0].match(new RegExp(re, "i"));
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
fMatches.forEach((pair) => {
|
fMatches.forEach((pair) => {
|
||||||
test(`${pair[0]} should match ${pair[1]}`, () => {
|
test(`${pair[0]} should match ${pair[1]} both ways`, () => {
|
||||||
const re = makeAWeeBitFuzzy(pair[0], "f");
|
const re = makeAWeeBitFuzzy(pair[0], "f");
|
||||||
const result = pair[1].match(new RegExp(re, "i"));
|
const result = pair[1].match(new RegExp(re, "i"));
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
test(`${pair[1]} should match ${pair[0]} both ways`, () => {
|
||||||
|
const re = makeAWeeBitFuzzy(pair[1], "f");
|
||||||
|
const result = pair[0].match(new RegExp(re, "i"));
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
|
@ -35,6 +35,7 @@ const tSounds = "[ت|ط|ټ]";
|
||||||
const dSounds = "[د|ډ]";
|
const dSounds = "[د|ډ]";
|
||||||
const rSounds = "[ر|ړ|ڼ]";
|
const rSounds = "[ر|ړ|ڼ]";
|
||||||
const nSounds = "[ن|ڼ]";
|
const nSounds = "[ن|ڼ]";
|
||||||
|
const hKhSounds = "[خ|ح|ښ|ه]";
|
||||||
|
|
||||||
const pReplacer = {
|
const pReplacer = {
|
||||||
"ی": fiveYeys,
|
"ی": fiveYeys,
|
||||||
|
@ -67,9 +68,15 @@ const pReplacer = {
|
||||||
|
|
||||||
"ن": nSounds,
|
"ن": nSounds,
|
||||||
"ڼ": nSounds,
|
"ڼ": nSounds,
|
||||||
|
|
||||||
|
"خ": hKhSounds,
|
||||||
|
"ح": hKhSounds,
|
||||||
|
"ښ": hKhSounds,
|
||||||
|
"ه": hKhSounds,
|
||||||
};
|
};
|
||||||
|
|
||||||
const fiveYeysF = "(?:eyy|ey|ee|e|uy)";
|
const fiveYeysF = "(?:eyy|ey|ee|e|uy)";
|
||||||
|
const hKhF = "(?:kh|h|x)";
|
||||||
const zSoundsF = "(?:z|dz)";
|
const zSoundsF = "(?:z|dz)";
|
||||||
|
|
||||||
const fReplacer = {
|
const fReplacer = {
|
||||||
|
@ -81,11 +88,14 @@ const fReplacer = {
|
||||||
|
|
||||||
"z": zSoundsF,
|
"z": zSoundsF,
|
||||||
"dz": zSoundsF,
|
"dz": zSoundsF,
|
||||||
|
"x": hKhF,
|
||||||
|
"h": hKhF,
|
||||||
|
"kh": hKhF,
|
||||||
};
|
};
|
||||||
|
|
||||||
const pRepRegex = new RegExp(Object.keys(pReplacer).join("|"), "g");
|
const pRepRegex = new RegExp(Object.keys(pReplacer).join("|"), "g");
|
||||||
|
|
||||||
const fRepRegex = /eyy|ey|uy|ee|e|z|dz/g;
|
const fRepRegex = /eyy|ey|uy|ee|e|z|dz|x|kh|h/g;
|
||||||
|
|
||||||
function makePAWeeBitFuzzy(s: string): string {
|
function makePAWeeBitFuzzy(s: string): string {
|
||||||
// + s.replace(/ /g, "").split("").join(" *");
|
// + s.replace(/ /g, "").split("").join(" *");
|
||||||
|
|
Loading…
Reference in New Issue