pyaiml21.graphmaster.pattern.Pattern

class pyaiml21.graphmaster.pattern.Pattern(priority: float, is_star: bool, parse: Callable[[Node, Logger], bool], recognises: Callable[[Node], bool], advance: Callable[['GMNode', Node], 'GMNode'], match: MatchFn)[source][source]

A collection of data and functions representing a <pattern> node.

Each Pattern has assigned:
  • priority: defines the order of pattern matching (the higher priority, the sooner it is matched)

  • is_star: whether this node represents a node from which the result can be obtained by <star> tag

  • parse: function that takes a node and validates its syntax structure; it is guaranteed that recognises returns True

  • recognises: function to check whether the node has type that can be matched with this pattern

  • advance: a function that given current node returns the next node to store in the graphmaster; it is guaranteed the recognises returns True

  • match: function used to match against this pattern node

Methods

Attributes

priority

priority of matching, the higher the better

is_star

is this a star match?

parse

is current node an instance of this pattern - during parsing

recognises

is current node an instance of this pattern - condition for advance

advance

after input is recognised, store it and return next node

match

Match the next word(s).

advance: Callable[['GMNode', Node], 'GMNode'][source]

after input is recognised, store it and return next node

is_star: bool[source]

is this a star match?

match: MatchFn[source]

Match the next word(s).

Input: words, position of current word, current node, graphmaster Output: iterable of next nodes and number of matched words Preconditions: the position never points outside the sequence

This function is used by the Pattern nodes to gradually match the sequence of Input Path words. Each returned tuple represents the next node to continue matching and the number of words we have matched from the sequence.

parse: Callable[[Node, Logger], bool][source]

is current node an instance of this pattern - during parsing

priority: float[source]

priority of matching, the higher the better

recognises: Callable[[Node], bool][source]

is current node an instance of this pattern - condition for advance