Skip to content

Keep TableAnnotation type when a line is split - #570

Open
FedyaBadyilo wants to merge 2 commits into
ispras:developfrom
FedyaBadyilo:fix/select-annotations-keep-tables
Open

FedyaBadyilo wants to merge 2 commits into
ispras:developfrom
FedyaBadyilo:fix/select-annotations-keep-tables

Conversation

@FedyaBadyilo

Copy link
Copy Markdown

Summary

  • _select_annotations now copies table and attachment marks as TableAnnotation / AttachAnnotation instead of a generic Annotation.
  • Several tables on one split line all stay in the tree: AnnotationMerger no longer drops all but the first.

Closes #569

Test plan

  • python -m unittest tests.unit_tests.test_misc_annotations
  • flake8 .

selected = AbstractStructureExtractor._select_annotations(annotations, 0, 9)
table_anns = [ann for ann in selected if ann.name == TableAnnotation.name]
self.assertEqual(2, len(table_anns))
self.assertTrue(all(isinstance(ann, TableAnnotation) for ann in table_anns))

@NastyBoget NastyBoget Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У нас нет обязательного требования к тому, чтобы аннотации были соответствующего класса, важно лишь название, так как AnnotationMerger все равно эту информацию удаляет. Это не очень хорошо, и в будущем мы планируем пересмотреть аннотирование в принципе. Я бы удалила эту строку теста

for annotation in annotations:
if annotation.name in [TableAnnotation.name, AttachAnnotation.name]:
if start == 0:
new_annotation = Annotation(start=start, end=end, value=annotation.value, name=annotation.name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проблема этой строки не в том, что мы теряем информацию о типе класса, а в том, что мы не сохраняем поле annotation.is_mergeable при создании новой аннотации. У Annotation по умолчанию is_mergeable = True, для TableAnnotation и AttachAnnotation is_mergeable = False. Достаточно это исправить, и написанный тест будет проходить


def test_select_annotations_keeps_multiple_tables_after_merge(self) -> None:
"""Two tables on one line must both survive a slice and AnnotationMerger."""
text = "Заголовок и текст"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: переменная не используется

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Из нескольких таблиц на одной строке в дереве остаётся только первая

2 participants