feat: get_persons and get_locations common functions
@@ -688,6 +688,38 @@ def get_entities(annotated_utterance, only_named=False, with_labels=False):
return entities if entities is not None else []
+def get_named_persons(annotated_utterance):
+ named_entities = get_entities(annotated_utterance, only_named=True, with_labels=True)
+ all_entities = get_entities(annotated_utterance, only_named=False, with_labels=True)
+
+ named_persons = []
+ for ent in named_entities:
+ if ent["type"] == "PER":
+ named_persons.append(ent["text"])
+ for ent in all_entities:
+ if ent["label"] == "person":
+ named_persons.append(ent["text"])
+ named_persons = list(set(named_persons))
+
+ return named_persons
+
+
+def get_named_locations(annotated_utterance):
+ named_entities = get_entities(annotated_utterance, only_named=True, with_labels=True)
+ all_entities = get_entities(annotated_utterance, only_named=False, with_labels=True)
+
+ named_locations = []
+ for ent in named_entities:
+ if ent["type"] == "LOC":
+ named_locations.append(ent["text"])
+ for ent in all_entities:
+ if ent["label"] == "location":
+ named_locations.append(ent["text"])
+ named_locations = list(set(named_locations))
+
+ return named_locations
+
+
def get_raw_entity_names_from_annotations(annotations):
"""
