Commit
·
d6100e0
1
Parent(s):
bf5bc24
app
Browse files
app.py
CHANGED
@@ -51,21 +51,20 @@ def prepare_entities_for_highlight(text, results):
|
|
51 |
print("Results:", results)
|
52 |
# it should look like:
|
53 |
# [{'entity': 'org.ent.pressagency.Reuters', 'score': np.float32(98.47), 'index': 78, 'word': 'Reuters', 'start': 440, 'end': 447}]
|
54 |
-
for
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
entities.append(entity)
|
69 |
|
70 |
# Sort entities by their start position
|
71 |
entities = sorted(entities, key=lambda x: x["start"])
|
|
|
51 |
print("Results:", results)
|
52 |
# it should look like:
|
53 |
# [{'entity': 'org.ent.pressagency.Reuters', 'score': np.float32(98.47), 'index': 78, 'word': 'Reuters', 'start': 440, 'end': 447}]
|
54 |
+
for entity in results.items():
|
55 |
+
entity_span = (entity["start"], entity["end"])
|
56 |
+
|
57 |
+
# Only add non-overlapping entities
|
58 |
+
if entity_span not in seen_spans:
|
59 |
+
seen_spans.add(entity_span)
|
60 |
+
entity_text = text[
|
61 |
+
entity["start"] : entity["end"]
|
62 |
+
].strip() # Ensure we're working with the correct portion of the text
|
63 |
+
entity["text"] = entity_text
|
64 |
+
entity.pop("word")
|
65 |
+
print(f"Entity text: {entity}")
|
66 |
+
|
67 |
+
entities.append(entity)
|
|
|
68 |
|
69 |
# Sort entities by their start position
|
70 |
entities = sorted(entities, key=lambda x: x["start"])
|