hooks.add_entity: Don't try to rearrange non-Latin names.
This commit is contained in:
parent
ba81dc9847
commit
e758db31ad
1 changed files with 12 additions and 8 deletions
|
@ -41,20 +41,24 @@ class AddEntityHook:
|
|||
if word:
|
||||
yield word
|
||||
|
||||
def _str2entity(self, s, trim_re):
|
||||
def _str2entity(self, s, trim_re, name_shifts):
|
||||
parts = list(self._entity_parts(s, trim_re))
|
||||
if not parts:
|
||||
return ''
|
||||
parts.insert(0, parts.pop())
|
||||
for _ in range(name_shifts):
|
||||
parts.insert(0, parts.pop())
|
||||
if parts[-1].lower() in self.NAME_PREFIXES:
|
||||
parts.insert(0, parts.pop())
|
||||
return '-'.join(parts)
|
||||
|
||||
def _name2entity(self, name, name_shifts):
|
||||
name = self._remove_parens(name)
|
||||
name = self._destroke(name)
|
||||
entity = self._str2entity(name, self.NONASCII_RE, name_shifts)
|
||||
if not entity:
|
||||
entity = self._str2entity(name, self.NONALNUM_RE, 0)
|
||||
return entity
|
||||
|
||||
def run(self, data):
|
||||
if ('payee' in data) and ('entity' not in data):
|
||||
payee = self._remove_parens(data['payee'])
|
||||
payee = self._destroke(payee)
|
||||
entity = self._str2entity(payee, self.NONASCII_RE)
|
||||
if not entity:
|
||||
entity = self._str2entity(payee, self.NONALNUM_RE)
|
||||
data['entity'] = entity
|
||||
data['entity'] = self._name2entity(data['payee'], 1)
|
||||
|
|
Loading…
Reference in a new issue