Repository navigation
Fix repeated-mention alignment with monotonic occurrence DP - #485
Merged
Merged
Conversation
WordAligner's exact phase relied on difflib's greedy longest-block seeding, which prefers the earliest source occurrence. One early seed could lock out exact matches for extractions ordered before it, and repeated mentions fell through to fuzzy alignment, which pins every duplicate to its first occurrence. Add a DP exact phase that selects one occurrence per extraction, order-preserving and non-overlapping, maximizing total matched tokens so longer extractions keep priority in contested regions. Unmatched extractions fall through to the existing difflib (lesser-match) and fuzzy phases unchanged. Legacy behavior remains available via exact_alignment_algorithm='difflib'.
aksg87
force-pushed
the
fix/aligner-monotonic-dp
branch
from
July 2, 2026 07:51
3ab951f to
3feccd0
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WordAlignerso repeated mentions align to their successive occurrences instead of all collapsing to the first: the difflib exact phase greedily prefers the earliest source occurrence, and one greedy seed can also force preceding extractions into first-occurrence fuzzy matches.exact_alignment_algorithm("dp" default; "difflib" restores legacy behavior) toalign_extractions,resolver_params, andAlignmentPolicy, mirroring thefuzzy_alignment_algorithmpattern.MATCH_FUZZY→MATCH_EXACT, and exact spans of different extractions may now overlap (duplicates of a single mention share its span).Tests
tests/resolver_test.pycovering successive occurrences, greedy-seed lockout, the legacy escape hatch, chunk offsets, and invalid-value errorsMATCH_EXACTresults than legacy across 300 random corpora.venv/bin/python -m pytest tests -ra -m "not live_api".venv/bin/python -m tox -e format.venv/bin/python -m tox -e lint-src.venv/bin/python -m tox -e lint-tests