hooks.add_entity: Maintain sequences of name prefixes.

This commit is contained in:
Brett Smith 2017-12-27 11:50:12 -05:00
parent 07d22418d4
commit 56cba1456f

View file

@ -43,12 +43,16 @@ class AddEntityHook:
def _str2entity(self, s, trim_re, name_shifts): def _str2entity(self, s, trim_re, name_shifts):
parts = list(self._entity_parts(s, trim_re)) parts = list(self._entity_parts(s, trim_re))
if not parts: if name_shifts > 0:
return '' pivot = -name_shifts - 1
for _ in range(name_shifts): try:
parts.insert(0, parts.pop()) while parts[pivot].lower() in self.NAME_PREFIXES:
if parts[-1].lower() in self.NAME_PREFIXES: pivot -= 1
parts.insert(0, parts.pop()) except IndexError:
pass
else:
pivot += 1
parts = parts[pivot:] + parts[:pivot]
return '-'.join(parts) return '-'.join(parts)
def _name2entity(self, name, name_shifts): def _name2entity(self, name, name_shifts):