Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion machine/corpora/place_markers_usfm_update_block_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def process_block(self, block: UsfmUpdateBlock) -> UsfmUpdateBlock:
(
e.type in [UsfmUpdateBlockElementType.PARAGRAPH, UsfmUpdateBlockElementType.STYLE]
and not e.marked_for_removal
and len(e.tokens) == 1
)
for e in elements
)
Expand Down Expand Up @@ -114,7 +115,18 @@ def process_block(self, block: UsfmUpdateBlock) -> UsfmUpdateBlock:
adj_trg_tok = self._predict_marker_location(
self._align_info[ref]["alignment"], adj_src_tok, src_toks, trg_toks
)
trg_str_idx = trg_tok_starts[adj_trg_tok] if adj_trg_tok < len(trg_tok_starts) else len(trg_sent)

if (
adj_trg_tok > 0
and element.type == UsfmUpdateBlockElementType.STYLE
and element.tokens[0].marker[-1] == "*"
):
# Insert end tokens directly after the token they follow
trg_str_idx = trg_tok_starts[adj_trg_tok - 1] + len(trg_toks[adj_trg_tok - 1])
elif adj_trg_tok < len(trg_tok_starts):
trg_str_idx = trg_tok_starts[adj_trg_tok]
else:
trg_str_idx = len(trg_sent)

to_insert.append((trg_str_idx, element))
to_insert.sort(key=lambda x: x[0])
Expand Down
8 changes: 3 additions & 5 deletions tests/corpora/test_place_markers_usfm_update_block_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ def test_style_markers() -> None:
)
result = r"""\id MAT
\c 1
\v 1 Esta es la \w primera \w*oración. Este texto está en \w inglés \w*y esta prueba es \w para \w*marcadores de estilo.
\v 1 Esta es la \w primera\w* oración. Este texto está en \w inglés\w* y esta prueba es \w para\w* marcadores de estilo.
"""
# NOTE: the spacing before/after end markers is incorrect,
# but this is an issue with how the is USFM is generated from the tokens
assess(target, result)

target = update_usfm(
Expand Down Expand Up @@ -269,7 +267,7 @@ def test_consecutive_markers() -> None:
usfm = r"""\id MAT
\c 1
\v 1 Old verse 1
\p \qt \+w word \+w* \qt*
\p \qt \+w word\+w*\qt*
"""

align_info = [
Expand All @@ -290,7 +288,7 @@ def test_consecutive_markers() -> None:
result = r"""\id MAT
\c 1
\v 1 New verse 1
\p \qt \+w WORD \+w*\qt*
\p \qt \+w WORD\+w*\qt*
"""
assess(target, result)

Expand Down