diff --git a/website/src/lib/wee-bit-fuzzy.test.ts b/website/src/lib/wee-bit-fuzzy.test.ts index 7d29fe9..393cc7b 100644 --- a/website/src/lib/wee-bit-fuzzy.test.ts +++ b/website/src/lib/wee-bit-fuzzy.test.ts @@ -4,9 +4,11 @@ const pMatches = [ ["پیټی", "پېټی"], ["دوستی", "دوستي"], ["پته", "پټه"], + ["تخلیه", "تحلیه"], ]; const fMatches = [ + ["tahliya", "takhliya"], ["sareyy", "saRey"], ["peyTey", "peTey"], ]; @@ -17,12 +19,22 @@ pMatches.forEach((pair) => { const result = pair[1].match(new RegExp(re, "i")); 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) => { - test(`${pair[0]} should match ${pair[1]}`, () => { + test(`${pair[0]} should match ${pair[1]} both ways`, () => { const re = makeAWeeBitFuzzy(pair[0], "f"); const result = pair[1].match(new RegExp(re, "i")); 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(); + }); }); \ No newline at end of file diff --git a/website/src/lib/wee-bit-fuzzy.ts b/website/src/lib/wee-bit-fuzzy.ts index 617907d..318c32b 100644 --- a/website/src/lib/wee-bit-fuzzy.ts +++ b/website/src/lib/wee-bit-fuzzy.ts @@ -35,6 +35,7 @@ const tSounds = "[ت|ط|ټ]"; const dSounds = "[د|ډ]"; const rSounds = "[ر|ړ|ڼ]"; const nSounds = "[ن|ڼ]"; +const hKhSounds = "[خ|ح|ښ|ه]"; const pReplacer = { "ی": fiveYeys, @@ -67,9 +68,15 @@ const pReplacer = { "ن": nSounds, "ڼ": nSounds, + + "خ": hKhSounds, + "ح": hKhSounds, + "ښ": hKhSounds, + "ه": hKhSounds, }; const fiveYeysF = "(?:eyy|ey|ee|e|uy)"; +const hKhF = "(?:kh|h|x)"; const zSoundsF = "(?:z|dz)"; const fReplacer = { @@ -81,11 +88,14 @@ const fReplacer = { "z": zSoundsF, "dz": zSoundsF, + "x": hKhF, + "h": hKhF, + "kh": hKhF, }; 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 { // + s.replace(/ /g, "").split("").join(" *");