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):
parts = list(self._entity_parts(s, trim_re))
if not parts:
return ''
for _ in range(name_shifts):
parts.insert(0, parts.pop())
if parts[-1].lower() in self.NAME_PREFIXES:
parts.insert(0, parts.pop())
if name_shifts > 0:
pivot = -name_shifts - 1
try:
while parts[pivot].lower() in self.NAME_PREFIXES:
pivot -= 1
except IndexError:
pass
else:
pivot += 1
parts = parts[pivot:] + parts[:pivot]
return '-'.join(parts)
def _name2entity(self, name, name_shifts):