Example #1
0
 def execute(self, obj):
     # TODO smarter guessing
     obj_text = force_text(obj)
     if self.INSTITUTION_RE.search(obj_text):
         return 'institution'
     if self.ORGANIZATION_RE.search(obj_text):
         return 'organization'
     return (self._default or 'person').lower()
Example #2
0
 def execute(self, obj):
     # TODO smarter guessing
     obj_text = force_text(obj)
     if self.INSTITUTION_RE.search(obj_text):
         return 'institution'
     if self.ORGANIZATION_RE.search(obj_text):
         return 'organization'
     return (self._default or 'person').lower()
Example #3
0
 def filter_names(self, obj, *roles, invert=False):
     names = get_list(obj, 'mods:name')
     filtered = [*names] if invert else []
     for name in names:
         name_roles = get_list(name, 'mods:role')
         for role in name_roles:
             role_terms = get_list(role, 'mods:roleTerm')
             name_roles = {force_text(r).lower() for r in role_terms}
             name_roles.update({self.role_map[r] for r in name_roles if r in self.role_map})
             if name_roles.intersection(roles):
                 if invert:
                     filtered.remove(name)
                 else:
                     filtered.append(name)
     return filtered
Example #4
0
 def filter_names(self, obj, *roles, invert=False):
     names = get_list(obj, 'mods:name')
     filtered = [*names] if invert else []
     for name in names:
         name_roles = get_list(name, 'mods:role')
         for role in name_roles:
             role_terms = get_list(role, 'mods:roleTerm')
             name_roles = {force_text(r).lower() for r in role_terms}
             name_roles.update({self.role_map[r] for r in name_roles if r in self.role_map})
             if name_roles.intersection(roles):
                 if invert:
                     filtered.remove(name)
                 else:
                     filtered.append(name)
     return filtered
Example #5
0
def test_force_text_joined(input_text, list_sep, output_text):
    assert force_text(input_text, list_sep) == output_text
Example #6
0
def test_force_text(input_text, output_text):
    assert force_text(input_text) == output_text
Example #7
0
 def get_name_part(self, obj, type):
     name_parts = get_list(obj, 'mods:namePart')
     return ' '.join(
         [force_text(n) for n in name_parts if n.get('@type') == type])
Example #8
0
 def squash_name_parts(self, name):
     name_parts = get_list(name, 'mods:namePart')
     return ' '.join([force_text(n) for n in name_parts])
Example #9
0
 def get_part(title_info, part_name, delimiter=''):
     part = force_text(title_info.get(part_name, ''), ' ').strip()
     return delimiter + part if part else ''
def test_force_text_joined(input_text, list_sep, output_text):
    assert force_text(input_text, list_sep) == output_text
def test_force_text(input_text, output_text):
    assert force_text(input_text) == output_text
Example #12
0
 def squash_name_parts(self, name):
     name_parts = get_list(name, 'mods:namePart')
     return ' '.join([force_text(n) for n in name_parts])
Example #13
0
 def get_part(title_info, part_name, delimiter=''):
     part = force_text(title_info.get(part_name, ''), ' ').strip()
     return delimiter + part if part else ''
Example #14
0
 def get_name_part(self, obj, type):
     name_parts = get_list(obj, 'mods:namePart')
     return ' '.join([force_text(n) for n in name_parts if n.get('@type') == type])