Skip to content

Marker placement does not occur in verse ranges #370

Description

@benjaminking

Verse ranges are represented as multiple rows in a UsfmUpdateBlock, only the first of which is non-empty. The marker placement algorithm uses only one alignment matrix, defaulting to the last, which is empty in the case of a verse range. This results in markers not being placed for verse ranges.

Here is a failing test for this case:

source = "This is the first part. This is the second part."
    pretranslation = "Esta es la primera parte. Esta es la segunda parte."
    align_info = PlaceMarkersAlignmentInfo(
        source_tokens=[t for t in TOKENIZER.tokenize(source)],
        translation_tokens=[t for t in TOKENIZER.tokenize(pretranslation)],
        alignment=to_word_alignment_matrix("0-0 1-1 2-2 3-3 4-4 5-5 6-6 7-7 8-8 9-9 10-10 11-11"),
        paragraph_behavior=UpdateUsfmMarkerBehavior.PRESERVE,
        style_behavior=UpdateUsfmMarkerBehavior.STRIP,
    )
    empty_align_info = PlaceMarkersAlignmentInfo(
        source_tokens=[],
        translation_tokens=[],
        alignment=to_word_alignment_matrix(""),
        paragraph_behavior=UpdateUsfmMarkerBehavior.PRESERVE,
        style_behavior=UpdateUsfmMarkerBehavior.STRIP,
    )
    usfm = r"""\id MAT
\c 1
\v 1-2 This is the first part.
\p This is the second part.
"""
    result = r"""\id MAT
\c 1
\v 1-2 Esta es la primera parte.
\p Esta es la segunda parte.
"""

    rows = [
        UpdateUsfmRow(scr_ref("MAT 1:1"), str(pretranslation), metadata={"alignment_info": align_info}),
        UpdateUsfmRow(scr_ref("MAT 1:2"), "", metadata={"alignment_info": empty_align_info}),
    ]
    target = update_usfm(rows, usfm, update_block_handlers=[PlaceMarkersUsfmUpdateBlockHandler()])
    assert_usfm_equals(target, result)

Activity

  1. self-assigned this
    on Sep 15, 2026
  2. added theissue type on Sep 15, 2026
  3. moved this from 🆕 New to 👀 In review in Servalon Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

invalidThis doesn't seem right

Type

Projects

  • Status
    👀 In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions