@@ -5,8 +5,7 @@ import { LexicalModelTypes } from '@keymanapp/common-types';
55
66import { ClassicalDistanceCalculation } from './classical-calculation.js' ;
77import { ExecutionTimer , STANDARD_TIME_BETWEEN_DEFERS } from './execution-timer.js' ;
8- import { QUEUE_NODE_COMPARATOR , SearchQuotientSpur } from './search-quotient-spur.js' ;
9- import { PathResult } from './search-quotient-node.js' ;
8+ import { PathResult , SearchQuotientNode } from './search-quotient-node.js' ;
109import { subsetByChar , subsetByInterval , mergeSubset , TransformSubset } from '../transform-subsets.js' ;
1110import TransformUtils from '../transformUtils.js' ;
1211
@@ -571,22 +570,22 @@ export class SearchNode {
571570}
572571
573572export class SearchResult {
574- private resultNode : SearchNode ;
573+ readonly node : SearchNode ;
575574
576575 constructor ( node : SearchNode ) {
577- this . resultNode = node ;
576+ this . node = node ;
578577 }
579578
580579 get inputSequence ( ) : ProbabilityMass < Transform > [ ] {
581- return this . resultNode . priorInput ;
580+ return this . node . priorInput ;
582581 }
583582
584583 get matchSequence ( ) : TraversableToken < string > [ ] {
585- return this . resultNode . calculation . matchSequence . map ( ( char , i ) => ( { key : char , traversal : this . resultNode . matchedTraversals [ i + 1 ] } ) ) ;
584+ return this . node . calculation . matchSequence . map ( ( char , i ) => ( { key : char , traversal : this . node . matchedTraversals [ i + 1 ] } ) ) ;
586585 } ;
587586
588587 get matchString ( ) : string {
589- return this . resultNode . resultKey ;
588+ return this . node . resultKey ;
590589 }
591590
592591 /**
@@ -597,15 +596,15 @@ export class SearchResult {
597596 * `totalCost`.)
598597 */
599598 get knownCost ( ) : number {
600- return this . resultNode . editCount ;
599+ return this . node . editCount ;
601600 }
602601
603602 /**
604603 * Gets the "input sampling cost" of the edge, which should be considered as the
605604 * negative log-likelihood of the input path taken to reach the node.
606605 */
607606 get inputSamplingCost ( ) : number {
608- return this . resultNode . inputSamplingCost ;
607+ return this . node . inputSamplingCost ;
609608 }
610609
611610 /**
@@ -615,41 +614,34 @@ export class SearchResult {
615614 * to the resulting output.
616615 */
617616 get totalCost ( ) : number {
618- return this . resultNode . currentCost ;
617+ return this . node . currentCost ;
619618 }
620619
621620 get finalTraversal ( ) : LexiconTraversal {
622- return this . resultNode . currentTraversal ;
621+ return this . node . currentTraversal ;
623622 }
624623
625624 get spaceId ( ) : number {
626- return this . resultNode . spaceId ;
625+ return this . node . spaceId ;
627626 }
628627}
629628
630629// Current best guesstimate of how compositor will retrieve ideal corrections.
631- export async function * getBestMatches ( searchSpace : SearchQuotientSpur , timer : ExecutionTimer ) : AsyncGenerator < SearchResult > {
630+ export async function * getBestMatches ( searchSpace : SearchQuotientNode , timer : ExecutionTimer ) : AsyncGenerator < SearchResult > {
632631 let currentReturns : { [ resultKey : string ] : SearchNode } = { } ;
633632
634633 // Stage 1 - if we already have extracted results, build a queue just for them and iterate over it first.
635- const returnedValues = Object . values ( searchSpace . returnedValues ) ;
634+ const returnedValues = Object . values ( searchSpace . previousResults ) ;
636635 if ( returnedValues . length > 0 ) {
637- let preprocessedQueue = new PriorityQueue < SearchNode > ( QUEUE_NODE_COMPARATOR , returnedValues ) ;
636+ let preprocessedQueue = new PriorityQueue < SearchResult > ( ( a , b ) => a . totalCost - b . totalCost , returnedValues ) ;
638637
639638 while ( preprocessedQueue . count > 0 ) {
640639 const entryFromCache = timer . time ( ( ) => {
641640 let entry = preprocessedQueue . dequeue ( ) ;
642641
643- // Is the entry a reasonable result?
644- if ( entry . isFullReplacement ) {
645- // If the entry's 'match' fully replaces the input string, we consider it
646- // unreasonable and ignore it.
647- return null ;
648- }
649-
650- currentReturns [ entry . resultKey ] = entry ;
642+ currentReturns [ entry . node . resultKey ] = entry . node ;
651643 // Do not track yielded time.
652- return new SearchResult ( entry ) ;
644+ return entry ;
653645 } , TimedTaskTypes . CACHED_RESULT ) ;
654646
655647 if ( entryFromCache ) {
0 commit comments