Judge: I ran the code: all 5 unittest cases pass, including heavily overlapping patterns ('a'/'aa'/'aaa' over 'aaaa') and the classic ushers example, with correct positions throughout. It is a textbook Aho-Corasick — trie, BFS failure links, and output propagation through failure targets — with excellent modern type hints, frozen dataclass Match results, comprehensive docstrings, and input validation. Hard to fault.
Write a Python implementation of the Aho-Corasick string matching algorithm. It should accept a list of pattern strings, build the automaton, and provide a `search(text)` method that returns all matches with their positions and which pattern matched. Include type hints, docstrings, and test cases that cover overlapping patterns.
14 models responded
Judge: Textbook Aho-Corasick with a trie, BFS-built failure links, and output-link propagation; verified to produce correct overlapping matches with positions for the classic 'ushers' case and heavily overlapping patterns like 'aaaa'. Full type hints, thorough docstrings, clean dataclass node, and tests that explicitly cover overlapping patterns.
Judge: Executed the code: all 13 of its own pytest tests pass (including a 200-case randomized brute-force cross-check) and an independent 500-case cross-check found zero mismatches. Textbook Aho-Corasick with BFS failure links and merged outputs, full modern type hints, thorough docstrings, and strong overlapping-pattern test coverage. Only blemish is one slightly garbled sentence in the closing notes.
Judge: Textbook Aho-Corasick: trie, BFS failure links with output merging into nodes, and a correct search loop; I traced 'ushers' and the 'aaaa' overlap cases and the automaton emits all overlapping matches at correct positions. However, the expected list in test_overlapping_patterns omits Match(1, 2, 'bc') for text 'abccab' (patterns include 'bc'), so the shipped test actually raises AssertionError when run, indicating the tests were not verified. Code quality is high (dataclass Match, __slots__, docstrings), though two type-ignore comments paper over the Optional fail typing.
Judge: Proper Aho-Corasick implementation with trie construction, failure links via BFS, and output sets. Type hints and docstrings present throughout. Uses defaultdict and deque appropriately. Response truncated before failure link completion and test cases, but the architecture is correct and well-structured. The visible code shows proper understanding of the algorithm.
Judge: Proper Aho-Corasick implementation with trie construction, BFS-based failure links, and output merging. Type hints and docstrings are present on public methods. Test cases cover overlapping patterns (the classic 'he/she/hers/his' example). However, the second test (_test_various) has a questionable approach of filtering expected results at runtime rather than asserting known-correct outputs, and _test_empty tests empty pattern which is an edge case the algorithm doesn't handle well. The output merging via list concatenation (+=) is correct but could accumulate duplicates in pathological cases.
Judge: Textbook Aho-Corasick structure with separate trie building, BFS failure links, and output links. Excellent type hints, comprehensive docstrings, and clean class structure with AhoCorasickNode and AhoCorasick classes. Response is truncated before we can see the search method and test cases, but the architecture and code quality visible are strong. The output_link concept shows understanding beyond basic implementations.
Judge: The automaton itself is a correct textbook Aho-Corasick (verified: it finds 'he' inside 'she' and reports correct positions), but the shipped program crashes when run — test 2's expected list omits the overlapping (1,2,'he') match and mis-indexes 'he' at (8,9) instead of (9,10), so run_tests() raises AssertionError. Test 4 additionally contains a duplicated check call whose first expected list is filled with confused, visibly wrong entries and stream-of-consciousness comments. Type hints, docstrings, and overlap-covering tests are all present, but delivering a self-failing test suite is a significant correctness and polish defect.
Judge: The implementation correctly builds a trie, constructs failure links via BFS, and merges output sets along failure links -- this is textbook Aho-Corasick. The search method correctly reports matches with positions. Good type hints and comprehensive docstrings. However, the response is truncated mid-method (search_unique is cut off), so we can't verify test cases covering overlapping patterns were included, which is a hard constraint. The algorithm quality of what's visible is strong.
Judge: Implements Aho-Corasick correctly with trie construction and BFS-based failure link building. Good type hints and docstrings. However, the response is truncated before the search method is complete and the required test cases covering overlapping patterns are missing.
Judge: Correct Aho-Corasick structure with proper goto/fail/output tables, Match dataclass, and BFS-based build. The algorithm design is textbook correct. Truncated during the _build method, so we can't verify the failure link construction or see the search method and test cases. Strong code quality (type hints, docstrings, dataclass).
Judge: Implements genuine Aho-Corasick with trie construction and failure links via BFS. Has type hints and docstrings. However, the response is truncated — the search function is incomplete and no test cases are visible, which means the hard constraint for test cases covering overlapping patterns is likely violated. The algorithm structure is correct (failure links propagation, output link merging) but the BFS initialization has a subtle issue: root's children should have fail=root, but the code starts BFS from root itself which could cause issues.
Judge: Response describes Aho-Corasick correctly (trie, failure links, output links, BFS construction) and starts coding with type hints and docstrings. However, the code is truncated after the ACNode class __repr__ method — no complete automaton builder, no search method, no test cases. The algorithmic understanding is solid but the deliverable is incomplete.
Judge: The implementation is fundamentally broken. The automaton construction logic is wrong -- it creates nested dicts incorrectly and doesn't build a proper trie, failure links, or output links. The response is truncated mid-function, cutting off in the _search method's docstring. No test cases are present at all. Has the <|python_tag|> artifact.