WolframModel.Matcher (WolframModel v1.3.0)

Copy Markdown View Source

Deterministic pattern matcher for WolframModel.

Exposes a general match/2 that handles rules with any number of pattern hyperedges (1, 2, or N) via recursive backtracking. Patterns are matched positionally: the element at position i in the pattern binds to the element at position i in the matched hyperedge. Shared variables across patterns must map to the same vertex in every matched hyperedge.

Hyperedges are ordered lists. Each pattern variable can be any term; atoms and integers are treated as variable names to bind.

Summary

Functions

Builds a merged mapping from two (pattern, hyperedge) pairs. Kept for backward compatibility.

Finds all ways to match patterns against hyperedges with consistent variable bindings. Supports patterns of any length (1, 2, or N hyperedges).

Types

match_result()

@type match_result() :: %{
  mapping: map(),
  matched_hyperedges: [Hypergraph.hyperedge()]
}

Functions

build_mapping_for_two(p1, p2, he1, he2)

@spec build_mapping_for_two([term()], [term()], [term()], [term()]) :: map()

Builds a merged mapping from two (pattern, hyperedge) pairs. Kept for backward compatibility.

match(hyperedges, patterns)

Finds all ways to match patterns against hyperedges with consistent variable bindings. Supports patterns of any length (1, 2, or N hyperedges).

Returns a list of %{mapping: map(), matched_hyperedges: [hyperedge()]}. Each matched_hyperedges list has the same length as patterns and is in the same order. Each distinct hyperedge in the graph may only be used once per match (no self-overlap).