def _parse(self, text, scope=None):
     entities = self._parser.parse(text.lower(), scope=scope)
     result = []
     for entity in entities:
         ent = parsed_entity(entity_kind=entity["entity_kind"],
                             entity_value=entity["value"],
                             entity_resolved_value=entity["entity"],
                             entity_range=entity["range"])
         result.append(ent)
     return result
Пример #2
0
    def _parse(self, text, scope=None):
        tokens = tokenize(text, self.language)
        shifts = _compute_char_shifts(tokens)
        cleaned_text = " ".join(token.value for token in tokens)

        entities = self._parser.parse(cleaned_text, scope)
        result = []
        for entity in entities:
            start = entity["range"]["start"]
            start -= shifts[start]
            end = entity["range"]["end"]
            end -= shifts[end - 1]
            entity_range = {START: start, END: end}
            ent = parsed_entity(entity_kind=entity["entity_identifier"],
                                entity_value=entity["value"],
                                entity_resolved_value=entity["resolved_value"],
                                entity_range=entity_range)
            result.append(ent)
        return result