From acf7aab588b162ddf238d12c02f8a0569dd2c4e5 Mon Sep 17 00:00:00 2001 From: Eddie Antonio Santos Date: Tue, 28 Apr 2020 15:55:01 -0600 Subject: [PATCH] refactor(common/lmlayer): extract function: spansAreBackToBack --- .../word_breaking/join-word-breaker-decorator.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts b/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts index 21838f564a..3b74fccbdc 100644 --- a/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts +++ b/common/predictive-text/worker/word_breaking/join-word-breaker-decorator.ts @@ -46,12 +46,13 @@ namespace wordBreakers { let current: Span | undefined = results[index]; let window = []; - if (previous && previous.end === current.start) { + if (previous && spansAreBackToBack(previous, current)) { window.push(index - 1); } + window.push(index); - if (next && current.end === next.start) { + if (next && spansAreBackToBack(current, next)) { window.push(index + 1); } @@ -92,6 +93,14 @@ namespace wordBreakers { return contiguousRanges; } + /** + * Returns true when the spans are contiguous. + * Order matters when calling this function! + */ + function spansAreBackToBack(former: Span, latter: Span): boolean { + return former.end === latter.start; + } + /** * Given an array of ranges of indices, and the corresponding spans, * concatenates spans according to the ranges of indices.