hooks.add_entity: Maintain sequences of name prefixes.
This commit is contained in:
		
							parent
							
								
									07d22418d4
								
							
						
					
					
						commit
						56cba1456f
					
				
					 1 changed files with 10 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue