Skip to content

Add LAGraph_RegularPathQuerry#10

Open
VanyaGlazunov wants to merge 2 commits intomainfrom
feat-add-LAGraph_RegularPathQuerry
Open

Add LAGraph_RegularPathQuerry#10
VanyaGlazunov wants to merge 2 commits intomainfrom
feat-add-LAGraph_RegularPathQuerry

Conversation

@VanyaGlazunov
Copy link
Collaborator

@VanyaGlazunov VanyaGlazunov commented Mar 22, 2026

This PR introduces a flexible abstraction for evaluating Regular Path Queries (RPQs) over edge-labeled graphs and provides a concrete implementation using LAGraph_RegularPathQuery function. We add RPQ_Evaluator trait and implement it with algo mentioned above. We transformation from parser output PropertyPathExpression which is regexp of WHERE clause to NFA using thomposon's construction algorithm. The NFA constructoin is heavily vibe-coded. Sparql parser is cherry-picked from its branch.

NFA Construction via Thompson's Algorithm

The evaluator converts SPARQL property paths into NFAs using Thompson's construction:

  1. Base case: Each edge label becomes a simple 2-state NFA with a single labeled transition
  2. Sequence (a/b): Connects NFAs by merging the final state of the first with the start state of the second
  3. Alternative (a|b): Creates a new start state with ε-transitions to both sub-NFAs, and a new final state with ε-transitions from both
  4. Kleene star (a*): Adds ε-transitions from start→final (zero iterations) and final→start (repetition)
  5. Plus (a+): Similar to star but without the zero-iteration bypass
  6. Optional (a?): Adds a direct ε-transition from start to final

ε-Elimination

After construction, the NFA contains ε-transitions that must be eliminated before GraphBLAS evaluation:

  • Computes ε-closure for each state (all states reachable via ε-transitions only)
  • Rebuilds the NFA with direct labeled transitions between ε-closure sets
  • Marks states as final if their ε-closure contains any original final state

Matrix Preparation

For each unique label in the NFA:

  • Collects all transitions with that label as COO triples (from_state, to_state, 1)
  • Builds a Boolean LAGraph_Graph representing the NFA's transition structure for that label

@VanyaGlazunov
Copy link
Collaborator Author

Hello @suvorovrain and @georgiy-belyanin can you look at this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant