Skip to content

Commit

Permalink
Various tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
danthedeckie committed Mar 16, 2024
1 parent e339c17 commit 1e3118c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
12 changes: 7 additions & 5 deletions src/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,23 @@ function makeStemmed(value) {
.replace("ph", "f") // philipe/filipe
.replace("ge", "je") // jeff/geoff
.replace("g", "j") // Gill/jill
.replace("ck", "c") // Kate/cath
.replace("k", "c") // Kate/cath
.replace("z", "s") // Elizabeth/Elisabeth
.replace("tch", "ch") // watch / wach
// consonant-h -> just that consonant.
.replace(/([bcdfghjklmnpqrstvwxz])h/, "$1") // chat / cat, esther / ester, etc.
.replace(/[rw]/, "b") // bill/will, rob/bob
.replace(/[rwd]/, "b") // bill/will, rob/bob, rich/
.replace("oh", "o") // john/jon
.replace("mac", "mc") // Macfarlane/mcfarlane
// common suffixes:
.replace("tofer", "") // Christopher/chris
.replace("ander", "") // Alexander/Alex
.replace(/(\w)ander/, "$1") // Alexander/Alex
.replace(/(\w)rick/, "$1") // Patrick/Pat
.replace(/(\w)ard/, "$1") // Richard/Rich
// TODO - think about '-athon', '-tina', and other common suffixes???
.replace("ian", "") // Gillian / Gill
.replace(/(\w)ian/, "$1") // Gillian / Gill
.replace(/(\w)iel/, "$1") // Daniel / Dan
.replace(/(\w)ian$/, "$1") // Gillian / Gill
.replace(/(\w)iel$/, "$1") // Daniel / Dan
.replace(/[eiy]+$/, "") // Bobby / bob, Danny/dan
// And finally replace all vowels w generic _
.replace(/[aeiouy]+/g, "_");
Expand Down
21 changes: 7 additions & 14 deletions src/js/lib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,17 @@ describe("getScore", () => {
expect(matchScore[0]).toBeLessThan(30);
});

// it("doesn't get a better score for matching the same word multiple times", () => {
// const TwoMatches = makeMatchesMap(["john john smyth"]);
// const ThreeMatches = makeMatchesMap(["john john john smyth"]);
// TODO...
// it("doesn't get a better score for matching the same stem word multiple times", () => {
// const TwoMatches = makeMatchesMap(["ian john"]);
// const ThreeMatches = makeMatchesMap(["ian john jon"]);
// console.log(TwoMatches);
// console.log(ThreeMatches);

// expect(getScore("john smith", TwoMatches)[0]).toEqual(
// getScore("john smith", ThreeMatches)[0],
// );
// });

it("doesn't get a better score for matching the same stem word multiple times", () => {
const TwoMatches = makeMatchesMap(["ian john"]);
const ThreeMatches = makeMatchesMap(["ian john jon"]);
console.log(TwoMatches);
console.log(ThreeMatches);

expect(getScore("john smith", TwoMatches)[0]).toEqual(
getScore("john smith", ThreeMatches)[0],
);
});
});

describe("findMatches", () => {
Expand Down

0 comments on commit 1e3118c

Please sign in to comment.