From 1983f129fa6fe518f2c197ce5b2d151de6555e51 Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Thu, 29 Jan 2026 09:10:03 -0600 Subject: [PATCH] change(web): simplify Spur logic - parentNode always exists --- .../src/main/correction/search-quotient-spur.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/engine/predictive-text/worker-thread/src/main/correction/search-quotient-spur.ts b/web/src/engine/predictive-text/worker-thread/src/main/correction/search-quotient-spur.ts index 6ec3bffbf1..9c963f35a5 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/correction/search-quotient-spur.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/correction/search-quotient-spur.ts @@ -91,9 +91,9 @@ export abstract class SearchQuotientSpur implements SearchQuotientNode { this.parentNode = parentNode; this.inputSource = inputSource as PathInputProperties; - this.lowestPossibleSingleCost = (parentNode?.lowestPossibleSingleCost ?? 0) - Math.log(inputSrc?.bestProbFromSet ?? 1); + this.lowestPossibleSingleCost = parentNode.lowestPossibleSingleCost - Math.log(inputSrc?.bestProbFromSet ?? 1); this.inputs = inputs?.length > 0 ? inputs : null; - this.inputCount = (parentNode?.inputCount ?? 0) + (this.inputs ? 1 : 0); + this.inputCount = parentNode.inputCount + (this.inputs ? 1 : 0); } /** @@ -120,11 +120,11 @@ export abstract class SearchQuotientSpur implements SearchQuotientNode { } public get bestExample(): {text: string, p: number} { - const bestPrefix = this.parentNode?.bestExample ?? { text: '', p: 1 }; + const bestPrefix = this.parentNode.bestExample ?? { text: '', p: 1 }; const bestLocalInput = this.inputs?.reduce((max, curr) => max.p < curr.p ? curr : max) ?? { sample: { insert: '', deleteLeft: 0 }, p: 1}; return { - text: KMWString.substring(bestPrefix.text, 0, (this.parentNode?.codepointLength ?? 0) - bestLocalInput.sample.deleteLeft) + bestLocalInput.sample.insert, + text: KMWString.substring(bestPrefix.text, 0, this.parentNode.codepointLength - bestLocalInput.sample.deleteLeft) + bestLocalInput.sample.insert, p: bestPrefix.p * bestLocalInput.p } }