Skip to content

Commit c56a61b

Browse files
committed
fix(enricher): use the right field names of EntityMention
Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
1 parent b530f4e commit c56a61b

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

docling_agent/agent/enricher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ def _make_entity_mention(
891891
label = str(item["label"]).strip() if item.get("label") else None
892892
needle = original or text
893893
span = self._find_entity_span(source_text=source_text, needle=needle, search_start=search_start)
894-
mention = EntityMention(text=text, original=original, label=label, span=span, created_by=created_by)
894+
mention = EntityMention(text=text, orig=original, label=label, charspan=span, created_by=created_by)
895895
logger.info("_generate_entities: mention=%s", mention)
896896
return mention
897897

tests/test_enricher.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
from pathlib import Path
44

5-
from docling_core.types.doc.document import DoclingDocument
5+
from docling_core.types.doc.document import DoclingDocument, EntityMention
66

77
from docling_agent.agent.editor import DoclingEditingAgent
88
from docling_agent.agent.enricher import DoclingEnrichingAgent
@@ -187,6 +187,43 @@ def _fake_editor_run(self, task: str, document: DoclingDocument | None = None, *
187187
print("=" * 70)
188188

189189

190+
def test_make_entity_mention():
191+
"""Regression test for _make_entity_mention function."""
192+
enricher = DoclingEnrichingAgent(backend=_backend(), tools=[])
193+
source_text = "International Business Machines is a technology company based in Armonk."
194+
195+
# Basic entity mention
196+
item = {"text": "International Business Machines"}
197+
mention = enricher._make_entity_mention(item=item, source_text=source_text)
198+
assert isinstance(mention, EntityMention)
199+
assert mention.text == "International Business Machines"
200+
assert mention.charspan == (0, 31)
201+
202+
# Entity with original and label
203+
item = {"text": "IBM", "original": "International Business Machines", "label": "ORGANIZATION"}
204+
mention = enricher._make_entity_mention(item=item, source_text=source_text)
205+
assert mention.text == "IBM"
206+
assert mention.orig == "International Business Machines"
207+
assert mention.label == "ORGANIZATION"
208+
assert mention.charspan == (0, 31)
209+
210+
# Case-insensitive matching
211+
item = {"text": "international business machines"}
212+
mention = enricher._make_entity_mention(item=item, source_text=source_text)
213+
assert mention.charspan == (0, 31)
214+
215+
# Entity not found
216+
item = {"text": "Red Hat"}
217+
mention = enricher._make_entity_mention(item=item, source_text=source_text)
218+
assert mention.charspan is None
219+
220+
# Original takes precedence in search
221+
source_abbrev = "The CEO of IBM announced products."
222+
item = {"text": "International Business Machines", "original": "IBM"}
223+
mention = enricher._make_entity_mention(item=item, source_text=source_abbrev)
224+
assert mention.charspan == (11, 14)
225+
226+
190227
if __name__ == "__main__":
191228
print("=" * 70)
192229
print("TEST 1: Demonstrating the heading levels problem")

0 commit comments

Comments
 (0)