Skip to content

Commit

Permalink
Bail-out earlier on the score summation loop to improve performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
amitmarkel committed Dec 19, 2023
1 parent 228e297 commit 9305a53
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions javascript/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ export class Parser {
score += this.model.get('UW1')?.get(sentence.substring(i - 3, i - 2)) || 0;
score += this.model.get('UW2')?.get(sentence.substring(i - 2, i - 1)) || 0;
score += this.model.get('UW3')?.get(sentence.substring(i - 1, i)) || 0;
if (score > 0) { result.push(i); continue; }
score += this.model.get('UW4')?.get(sentence.substring(i, i + 1)) || 0;
score += this.model.get('UW5')?.get(sentence.substring(i + 1, i + 2)) || 0;
score += this.model.get('UW6')?.get(sentence.substring(i + 2, i + 3)) || 0;
if (score > 0) { result.push(i); continue; }
score += this.model.get('BW1')?.get(sentence.substring(i - 2, i)) || 0;
score += this.model.get('BW2')?.get(sentence.substring(i - 1, i + 1)) || 0;
score += this.model.get('BW3')?.get(sentence.substring(i, i + 2)) || 0;
if (score > 0) { result.push(i); continue; }
score += this.model.get('TW1')?.get(sentence.substring(i - 3, i)) || 0;
score += this.model.get('TW2')?.get(sentence.substring(i - 2, i + 1)) || 0;
score += this.model.get('TW3')?.get(sentence.substring(i - 1, i + 2)) || 0;
Expand Down

0 comments on commit 9305a53

Please sign in to comment.