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()
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
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
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])
def squash_name_parts(self, name): name_parts = get_list(name, 'mods:namePart') return ' '.join([force_text(n) for n in name_parts])
def get_part(title_info, part_name, delimiter=''): part = force_text(title_info.get(part_name, ''), ' ').strip() return delimiter + part if part else ''
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])