Options
All
  • Public
  • Public/Protected
  • All
Menu

A Scope is the top-level node of a Phrase Trie -- a trie of (trie)s which allows not only matching next characters, but also next words. This class exposes methods for adding, removing, and suggesting patterns.

As a technical note, a Scope's value is null, thus all patterns within a scope are accessible through the Scope.next.word or Scope.next.lookup.

Hierarchy

Index

Constructors

constructor

  • Constructs a Scope.

    Parameters

    • dictionary: Dictionary

      typically a reference to the dictionary this scope is contained within.

    • patterns: Pattern[] = ...

      an array of patterns to initially add to this scope.

    Returns Scope

Properties

Readonly dictionary

dictionary: Dictionary

end

end: boolean

next

next: NextNodes

Readonly value

value: Value

Methods

Private _add

  • _add(node: Node, pattern: Pattern, isLastWord?: boolean): void

Private _addChars

  • _addChars(node: Node, word: string, isLastWord?: boolean): Node
  • Parameters

    • node: Node
    • word: string
    • isLastWord: boolean = true

    Returns Node

Private _addFirstCharOfNextWord

Private _addLookup

  • _addLookup(node: Node, lookup: Lookup, isLastWord?: boolean): Node[]

Private _unwind

  • _unwind(stack: Node[], input: string[], lookahead?: number): Suggestion[]

add

completePattern

completeWord

isLeaf

  • isLeaf(): boolean

matchChars

  • matchChars(word: string): null | Node
  • Given an word, returns the final node which matches the complete word. null otherwise.

    Parameters

    • word: string

    Returns null | Node

matchPattern

  • matchPattern(tokens: string[]): Match[]
  • Given an input sequence of words, a starting node, and a 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" 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.

    Parameters

    • tokens: string[]

    Returns Match[]

matchWord

  • matchWord(tokens: string[]): Match[]

remove

suggest

  • suggest(input: string | string[], lookahead?: number): Suggestion[]
  • Given a sequence of input tokens, returns an array of suggested completions.

    Parameters

    • input: string | string[]

      a sequence of input tokens.

    • lookahead: number = 0

      how many tokens to resolve in lookups which occur immediately after input. See lookahead.

    Returns Suggestion[]

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Private property
  • Private method
  • Property

Generated using TypeDoc