Skip to content

Задание 6. Преобразование грамматики в ОНФХ и алгоритм Хеллингса - #235

Closed
semrosin wants to merge 22 commits into
FormalLanguageConstrainedPathQuerying:mainfrom
semrosin:wcnf-hellings
Closed

semrosin wants to merge 22 commits into
FormalLanguageConstrainedPathQuerying:mainfrom
semrosin:wcnf-hellings

Conversation

@semrosin

Copy link
Copy Markdown
  • С использованием возможности pyformlang для работы с контекстно-свободными грамматиками реализована функция преобразования контекстно-свободной грамматики в ослабленную нормальную форму Хомского (ОНФХ).
    def cfg_to_weak_normal_form(cfg: pyformlang.cfg.CFG) -> pyformlang.cfg.CFG
  • Реализована функция, основанная на алгоритме Хеллингса, решающая задачу достижимости между всеми парами вершин для заданного графа и заданной КС грамматики (не обязательно в ОНФХ).
    def hellings_based_cfpq(
      cfg: pyformlang.cfg.CFG,
      graph: nx.DiGraph,
      start_nodes: set[int] = None,
      final_nodes: set[int] = None,
    ) -> set[tuple[int, int]]
  • Добавлены собственные тесты:
    • Преобразования в ОНФХ: корректность формы правил, сохранение языка и ε, удаление бесполезных символов.
    • Хеллингса на граничные случаи: пустые графы и грамматики, фильтры вершин, параллельные рёбра, многосимвольные метки и нестандартный стартовый символ.

…е DOT (#1)

* feat: get graph info

* feat: save two cycles graph in dot format

* test: unit tests for getting graph info

* test: unit tests for saving two cycles graph

* test: fix data in two cycles graph test

* feat: return graph statistics as GraphInfo

* test: cover graph library failure scenarios

* test: add DOT graph round-trip coverage

* test: simplify graph library test coverage

* refactor: remove double comparison from tests

* refactor: fix type annotation

* fix format

* test: fix ci failures caused by pydot bug
…ию и НКА по графу (#2)

* feat: add regex to dfa function

* feat: add graph to nfa function

* test: add tests for task 2

* fix: graph to nfa declaration

* docs: add more docs for functions
…осов через разреженные матрицы (#3)

* feat: add sparse adjacency-matrix FA

* feat: add automata intersection

* feat: add tensor-based RPQ

* test: sparse adjacency-matrix FA, automata intersection, and tensor-based RPQ
The frontier is now a (len(starts) * |Q_dfa|) x |V| Boolean matrix with one
row block per start node. Every BFS layer is computed with Boolean matrix
products: the frontier is shifted along the graph edges of a symbol and
advanced inside every block by the block-diagonal DFA transition matrix.
The try block now imports from project.msbfs_rpq instead of the non-existent
project.rpq, so the RPQ autotests run instead of being skipped.
* feat: add multiple-source RPQ solver

* test: add RPQ regression coverage

* test: resolve RPQ test naming collision

* refactor: rename files

* refactor: use blocked Boolean matrix BFS for multiple-source RPQ

The frontier is now a (len(starts) * |Q_dfa|) x |V| Boolean matrix with one
row block per start node. Every BFS layer is computed with Boolean matrix
products: the frontier is shifted along the graph edges of a symbol and
advanced inside every block by the block-diagonal DFA transition matrix.

* test: fix ms_bfs_based_rpq import in RPQ autotest

The try block now imports from project.msbfs_rpq instead of the non-existent
project.rpq, so the RPQ autotests run instead of being skipped.

* refactor: delegate start/final handling to graph_to_nfa in ms_bfs_based_rpq

* test: rename msbfs test to reflect isolated-vertex semantics

* fix: rename autotests file back

* fix: switch from numpy arrays to scupy matrices
fix(task 3): использование разреженных матриц SciPy
@semrosin semrosin closed this Oct 19, 2026
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