finiteautomata commited on
Commit
3b3110b
·
1 Parent(s): 36086d9
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -17,6 +17,13 @@ def display_text(example):
17
  # Sort entities by start
18
  entities = sorted(example["entities"], key=lambda x: x["start"])
19
 
 
 
 
 
 
 
 
20
  # Chunk text
21
 
22
  if len(entities) == 0:
@@ -36,6 +43,9 @@ def display_text(example):
36
 
37
  last_index = end
38
 
 
 
 
39
  # description = entity["kg_result"]["detailedDescription"]["articleBody"]
40
  chunks = [(c, t) if t is not None else c for c, t in chunks]
41
  annotated_text(*chunks)
@@ -48,13 +58,10 @@ ds["train"] = ds["train"].select(elements)
48
 
49
  for ex in ds["train"]:
50
  st.write("=" * 80)
51
- # display_text(ex)
52
- st.write(ex["text"])
53
-
54
- for ent in ex["entities"]:
55
- entity_name = ent["text"]
56
- entity_type = ent["type"]
57
- entity_description = ent["kg_result"]["detailedDescription"]["articleBody"]
58
- annotated_text(
59
- (entity_name, "entity"), (f"({entity_type})", "type"), entity_description
60
- )
 
17
  # Sort entities by start
18
  entities = sorted(example["entities"], key=lambda x: x["start"])
19
 
20
+ for entity in entities:
21
+ entity_text = entity["text"]
22
+ # find in text
23
+ start = text.find(entity_text)
24
+ end = start + len(entity_text)
25
+ entity["start"] = start
26
+ entity["end"] = end
27
  # Chunk text
28
 
29
  if len(entities) == 0:
 
43
 
44
  last_index = end
45
 
46
+ if last_index < len(text):
47
+ chunks.append((text[last_index:], None))
48
+
49
  # description = entity["kg_result"]["detailedDescription"]["articleBody"]
50
  chunks = [(c, t) if t is not None else c for c, t in chunks]
51
  annotated_text(*chunks)
 
58
 
59
  for ex in ds["train"]:
60
  st.write("=" * 80)
61
+ display_text(ex)
62
+ with st.expander("Show entities"):
63
+ for ent in ex["entities"]:
64
+ entity_name = ent["text"]
65
+ entity_type = ent["type"]
66
+ entity_description = ent["kg_result"]["detailedDescription"]["articleBody"]
67
+ st.write(f"{entity_name} ({entity_type}): {entity_description}")