def _text_matches_main_name(self, entity, text): """ Check if the entity name is a perfect match on the text. :param entity: :param text: :return: """ text = normalize_entity_name(text) text = remove_prefixes_from_name(text) name = remove_suffixes_from_name(entity.name) name = normalize_entity_name(name) name = remove_prefixes_from_name(name) if name == text: return True return False
def get_entities_for_surface(self, surface): """Return all entities for the surface form. :param surface: :return: """ surface = normalize_entity_name(surface) try: bytestr = self.surface_index[surface] ids_array = array.array('d') ids_array.fromstring(bytestr) result = [] i = 0 while i < len(ids_array) - 1: offset = ids_array[i] surface_score = ids_array[i + 1] entity = self._read_entity_from_offset(int(offset)) # Check if the main name of the entity exactly matches the text. result.append((entity, surface_score)) i += 2 return result except KeyError: return []