autosuggestion
Version:
  Generates suggestions for text completion.  
65 lines (64 loc) • 2.38 kB
TypeScript
import { Word, NextNodes, NodeStack, SuggestedPattern, Value } from './types';
import { Suggestion } from './suggestion';
/**
* **NOTE:** a valid [[Match]] with a `remainder` can **only** occur if the partial match
* occurs at a word boundary (i.e., the [[Node | node]] contained in the [[Match| match]]
* has `end === true`). This is due to the fact that the API for defining a [[Pattern | pattern]]
* does not support concatenating a lookup result and char sequences into a single word. E.g.,
* a pattern such as `<some_lookup_context>s` to make a lookup result plural is not supported.
*/
export interface Match {
nodes: NodeStack;
remainder: Word[];
}
export declare class Node {
readonly value: Value;
end: boolean;
next: NextNodes;
constructor(value: Value);
isLeaf(): boolean;
/**
* Given an input sequence of words, a starting [[Node | node]], and
* a [[Dictionary | dictionary]], finds all valid matching paths that
* the input satisfies.
*
* #### Simple Example
* If we have a starting node which yields the following
* sub-trie,
* ```
* t - r - i - e
* \
* e - e
* ```
* and input *"tr"*, the returned node will be *"r"*.
*
* #### Advanced Example
* With a more complex starting trie,
* ```
* null - a - b - c - - d (1)
* \
* <X> - - d (2)
*
* <X>: null - a - b - c
* \
* <Y>
*
* <Y>: null - a - b - c - - d (3)
* ```
* given **"abc d"**, it wll return the **"d"** [[Node | nodes]] labeled
* _(1)_, _(2)_, _(3)_
*
* Since patterns can span multiple levels of nested contexts, we need to return
* not only the matched words (partially matched on completed words), but also the
* remainder of the match. This way, we can check for matches in parent contexts in
* case a pattern satisfies a match over an arbitrary number of contextual levels.
*/
matchPattern(tokens: Word[]): Match[];
matchWord(tokens: Word[]): Match[];
/**
* Given an word, returns the final node which matches the complete word. null otherwise.
*/
matchChars(word: Word): Node | null;
completePattern(tokens: SuggestedPattern): Suggestion[];
completeWord(tokens: SuggestedPattern): Suggestion[];
}