Skip to content

Commit

Permalink
Merge pull request #128 from not-my-profile/trim-before-levenshtein
Browse files Browse the repository at this point in the history
fix: trim before calculating levenshtein for fuzzyMatch
  • Loading branch information
daniel-sc authored Feb 18, 2025
2 parents d67b0f4 + a1cc282 commit 77f52fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/merger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('merger', () => {
], 'en');
const translationTargetFile = new TranslationFile([
{id: '1.1', source: 'aaaaaaaaaa11', target: 'aaa1', state: 'translated', locations: []},
{id: '1.2', source: 'aaaaaaaaaa22', target: 'aaa2', state: 'translated', locations: []},
{id: '1.2', source: 'aaaaaaaaaa22 ', target: 'aaa2', state: 'translated', locations: []},
{id: '2', source: 'bbbbbb1', target: 'bbb1', state: 'translated', locations: []},
{id: '3', source: 'ccccccc', target: 'ccc1', state: 'translated', locations: []},
], 'en', 'de');
Expand Down
4 changes: 2 additions & 2 deletions src/merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ function findCloseMatches(originUnit: TranslationUnit, destUnits: TranslationUni
elem: TranslationUnit,
score: number
}[] {
const originText = originUnit.source;
const originText = originUnit.source.trim();
return destUnits
.map(n => ({
elem: n,
score: levenshtein(originText, n.source) / originText.length
score: levenshtein(originText, n.source.trim()) / originText.length
}))
.filter(x => x.score < FUZZY_THRESHOLD)
.sort((a, b) => a.score - b.score);
Expand Down

0 comments on commit 77f52fc

Please sign in to comment.