def test_build_string_list_from_fields(): """Test build_string_list_from_fields.""" record = Record() record.add_field( Field(tag='200', indicators=['0', '1'], subfields=[ 'a', 'Cerasi', 'b', 'Claudio et Elena', 'x', "Collections d'art" ])) data = build_string_list_from_fields(record=record, tag='200', subfields={ 'a': ', ', 'b': ', ', 'c': ', ', 'd': ', ', 'f': ', ', 'x': ' - ' }) assert data == ["Cerasi, Claudio et Elena - Collections d'art"] record = Record() record.add_field( Field(tag='210', indicators=['0', '1'], subfields=[ 'a', 'Place of public./distr.', 'b', 'Address/publisher/dist.', 'c', 'Name of publisher/dist.', 'd', 'Date', 'e', 'Place', 'f', 'Address' ])) data = build_string_list_from_fields(record=record, tag='210', subfields={ 'a': ', ', 'b': '. ', 'c': ', ', 'd': '; ', 'e': '; ', 'f': '; ' }, tag_grouping=[{ 'subtags': 'c', 'start': ' ( ', 'end': ' )', 'delimiter': '', 'subdelimiter': ', ' }, { 'subtags': 'def', 'start': ' ( ', 'end': ' )', 'delimiter': '', 'subdelimiter': '; ' }]) assert data == [ 'Place of public./distr.' '. Address/publisher/dist.' ' ( Name of publisher/dist. )' ' ( Date; Place; Address )' ]
def trans_gnd_parallel_access_point(self): """Transformation parallel_access_point 700/710/711.""" tag = '700' subfields = {'a': ', ', 'b': ', ', 'c': ', ', 'd': ', ', 'x': ' - - '} if self.marc.get_fields('710') or self.marc.get_fields('711'): subfields = { 'a': ', ', 'b': '. ', 'n': ', ', 'd': ', ', 'c': ', ', 'e': '. ', 'g': '. ', 'k': '. ', 't': '. ', 'x': ' - - ' } if self.marc.get_fields('710'): tag = '710' if self.marc.get_fields('711'): tag = '711' if self.logger and self.verbose: self.logger.info('Call Function', 'trans_gnd_parallel_access_point') parallel_access_point = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields) if parallel_access_point: self.json_dict['parallel_access_point'] = parallel_access_point
def trans_idref_parallel_access_point(self): """Transformation parallel_access_point 700/710.""" tag = '700' subfields = {'a': ', ', 'b': ', ', 'c': ', ', 'd': ', ', 'f': ', ', 'x': ' - - '} tag_grouping = [] if self.marc.get_fields('710'): tag = '710' subfields = {'a': ', ', 'b': '. ', 'c': ', ', 'd': ' ; ', 'e': ' ; ', 'f': ' ; ', 'x': ' - - '} tag_grouping = [ { 'subtags': 'c', 'start': ' ( ', 'end': ' )', 'delimiter': '', 'subdelimiter': ', ' }, { 'subtags': 'def', 'start': ' ( ', 'end': ' )', 'delimiter': '', 'subdelimiter': ' ; ' } ] parallel_access_point = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields, tag_grouping=tag_grouping ) if parallel_access_point: self.json_dict['parallel_access_point'] = parallel_access_point
def trans_rero_variant_name(self): """Transformation variant_name 400/410/411.""" if self.logger and self.verbose: self.logger.info('Call Function', 'trans_rero_variant_name') tag = '400' punctuation = '' spaced_punctuation = '' subfields = {'a': ' ', 'b': ' ', 'c': ' '} # TODO: This code is not working for mixed tags! # Does 400, 410, 411 mixes exist? if self.marc.get_fields('410') or self.marc.get_fields('411'): subfields = {'a': ' ', 'b': ' ', 'd': ' '} if self.marc.get_fields('410'): tag = '410' if self.marc.get_fields('411'): tag = '411' variant_names = self.json_dict.get('variant_name', []) variant_name = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields, punctuation=punctuation, spaced_punctuation=spaced_punctuation ) if variant_name: variant_names += variant_name if variant_names: self.json_dict['variant_name'] = variant_names
def trans_rero_variant_access_point(self): """Transformation variant_access_point 400/410/411.""" if self.logger and self.verbose: self.logger.info( 'Call Function', 'trans_rero_variant_access_point') tag = '400' subfields = {'a': ' ', 'b': ' ', 'c': ' ', 'd': ' ', 'q': ' ', 'x': ' '} punctuation = '' spaced_punctuation = '' if self.marc.get_fields('410') or self.marc.get_fields('411'): subfields = {'a': ' ', 'b': ' ', 'n': ' ', 'd': ' ', 'c': ' ', 'e': ' ', 'g': ' ', 'k': ' ', 't': ' ', 'x': ' '} if self.marc.get_fields('410'): tag = '410' if self.marc.get_fields('411'): tag = '411' variant_access_points = self.json_dict.get('variant_access_point', []) variant_access_point = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields, punctuation=punctuation, spaced_punctuation=spaced_punctuation ) if variant_access_point: variant_access_points += variant_access_point if variant_access_points: self.json_dict['variant_access_point'] = variant_access_points
def trans_idref_variant_name(self): """Transformation variant_name 400/410.""" if self.logger and self.verbose: self.logger.info('Call Function', 'trans_idref_variant_name') tag = '400' subfields = {'a': ', ', 'b': ', ', 'c': ', '} tag_grouping = [] if self.marc.get_fields('410'): tag = '410' subfields = {'a': ', ', 'b': '. ', 'c': ', '} tag_grouping = [{ 'subtags': 'c', 'start': ' ( ', 'end': ' )', 'delimiter': '', 'subdelimiter': ', ' }] variant_names = self.json_dict.get('variant_name', []) variant_name = build_string_list_from_fields(record=self.marc, tag=tag, subfields=subfields, tag_grouping=tag_grouping) if variant_name: variant_names += variant_name if variant_names: self.json_dict['variant_name'] = variant_names
def trans_rero_parallel_access_point(self): """Transformation parallel_access_point 700/710/710.""" if self.logger and self.verbose: self.logger.info( 'Call Function', 'trans_rero_parallel_access_point') tag = '700' subfields = {'a': ' ', 'b': ' ', 'c': ' ', 'd': ' ', 'q': ' ', 'x': ' '} punctuation = '' spaced_punctuation = '' if self.marc.get_fields('710') or self.marc.get_fields('711'): subfields = {'a': ' ', 'b': ' ', 'n': ' ', 'd': ' ', 'c': ' ', 'e': ' ', 'g': ' ', 'k': ' ', 't': ' ', 'x': ' '} if self.marc.get_fields('710'): tag = '710' if self.marc.get_fields('711'): tag = '711' parallel_access_point = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields, punctuation=punctuation, spaced_punctuation=spaced_punctuation ) if parallel_access_point: self.json_dict['parallel_access_point'] = parallel_access_point
def trans_rero_preferred_name(self): """Transformation preferred_name 100/110/111.""" tag = '100' punctuation = '' spaced_punctuation = '' subfields = {'a': ' ', 'b': ' ', 'c': ' '} if self.marc.get_fields('110') or self.marc.get_fields('111'): subfields = {'a': ' ', 'b': ' ', 'd': ' '} if self.marc.get_fields('110'): tag = '110' if self.marc.get_fields('111'): tag = '111' if self.logger and self.verbose: self.logger.info('Call Function', 'trans_rero_preferred_name') variant_names = self.json_dict.get('variant_name', []) preferred_names = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields, punctuation=punctuation, spaced_punctuation=spaced_punctuation ) for preferred_name in preferred_names: if self.json_dict.get('preferred_name'): variant_names.append(preferred_name) else: self.json_dict['preferred_name'] = preferred_name if variant_names: self.json_dict['variant_name'] = variant_names
def trans_gnd_preferred_name(self): """Transformation preferred_name 100/110/111.""" tags = ['100'] subfields = {'a': ', ', 'b': ', ', 'c': ', '} if self.marc.get_fields('110') or self.marc.get_fields('111'): tags = [] subfields = {'a': ', ', 'b': '. ', 'n': ', '} if self.marc.get_fields('110'): tags.append('110') if self.marc.get_fields('111'): tags.append('111') if self.logger and self.verbose: self.logger.info('Call Function', 'trans_gnd_preferred_name') variant_names = self.json_dict.get('variant_name', []) for tag in tags: preferred_names = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields ) for idx, preferred_name in enumerate(preferred_names): if idx == 0: self.json_dict['preferred_name'] = preferred_name else: variant_names.append(preferred_name) if variant_names: self.json_dict['variant_name'] = variant_names
def trans_rero_qualifier(self): """Transformation qualifier 100 $c.""" if self.logger and self.verbose: self.logger.info('Call Function', 'trans_rero_qualifier') subfields = {'c': ' '} qualifier = build_string_list_from_fields(self.marc, '100', subfields) if qualifier and qualifier[0]: self.json_dict['qualifier'] = qualifier[0]
def trans_rero_numeration(self): """Transformation numeration 100 $b.""" if self.logger and self.verbose: self.logger.info('Call Function', 'trans_rero_numeration') subfields = {'b': ' '} numeration = build_string_list_from_fields(self.marc, '100', subfields) if numeration and numeration[0]: self.json_dict['numeration'] = numeration[0]
def trans_rero_authorized_access_point(self): """Trans authorized_access_point 100/110/111.""" tag = '100' agent = 'bf:Person' subfields = { 'a': ' ', 'b': ' ', 'c': ' ', 'd': ' ', 'q': ' ', 'x': ' ' } punctuation = '' spaced_punctuation = '' if self.marc.get_fields('110') or self.marc.get_fields('111'): subfields = { 'a': ' ', 'b': ' ', 'n': ' ', 'd': ' ', 'c': ' ', 'e': ' ', 'g': ' ', 'k': ' ', 't': ' ', 'x': ' ' } if self.marc.get_fields('110'): tag = '110' agent = 'bf:Organisation' self.json_dict['conference'] = False if self.marc.get_fields('111'): tag = '111' agent = 'bf:Organisation' self.json_dict['conference'] = True if self.logger and self.verbose: self.logger.info('Call Function', 'trans_rero_authorized_access_point') self.json_dict['bf:Agent'] = agent authorized_access_points = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields, punctuation=punctuation, spaced_punctuation=spaced_punctuation) variant_access_points = self.json_dict.get('variant_access_point', []) for authorized_access_point in authorized_access_points: if self.json_dict.get('authorized_access_point'): variant_access_points.append(authorized_access_point) else: self.json_dict['authorized_access_point'] = \ authorized_access_point if variant_access_points: self.json_dict['variant_access_point'] = variant_access_points
def trans_rero_biographical_information(self): """Transformation biographical_information 680 $a.""" if self.logger and self.verbose: self.logger.info( 'Call Function', 'trans_rero_biographical_information') biographical_information = [] subfields = {'a': ', '} for tag in [680]: biographical_information += \ build_string_list_from_fields(self.marc, str(tag), subfields) if biographical_information: self.json_dict['biographical_information'] = \ biographical_information
def trans_gnd_biographical_information(self): """Transformation biographical_information 678 $abu.""" if self.logger and self.verbose: self.logger.info('Call Function', 'trans_gnd_biographical_information') biographical_information = [] for tag in [678]: subfields = {'a': ', ', 'b': ', ', 'u': ', '} biographical_information += \ build_string_list_from_fields(self.marc, str(tag), subfields) if biographical_information: self.json_dict['biographical_information'] = \ biographical_information
def trans_rero_variant_access_point(self): """Transformation variant_access_point from field 450 455.""" if self.logger and self.verbose: self.logger.info('Call Function', 'trans_rero_variant_access_point') tag = '450' if self.marc['455']: tag = '455' subfields = {'a': ', ', 'x': ' - '} variant_access_points = build_string_list_from_fields( self.marc, tag, subfields) if variant_access_points: self.json_dict['variant_access_point'] = variant_access_points
def trans_idref_biographical_information(self): """Transformation biographical_information 300 $a 34x $a.""" if self.logger and self.verbose: self.logger.info('Call Function', 'trans_idref_biographical_information') tag_list = [300] + list(range(340, 349 + 1)) # 300, 340:349 biographical_information = [] subfields = {'a': ', '} for tag in tag_list: biographical_information += \ build_string_list_from_fields(self.marc, str(tag), subfields) if biographical_information: self.json_dict['biographical_information'] = \ biographical_information
def trans_idref_variant_access_point(self): """Transformation variant_access_point 400/410.""" if self.logger and self.verbose: self.logger.info('Call Function', 'trans_idref_variant_access_point') tag = '400' subfields = { 'a': ', ', 'b': ', ', 'c': ', ', 'd': ', ', 'f': ', ', 'x': ' - - ' } tag_grouping = [] if self.marc.get_fields('410'): tag = '410' subfields = { 'a': ', ', 'b': '. ', 'c': ', ', 'd': ' ; ', 'e': ' ; ', 'f': ' ; ', 'x': ' - - ' } tag_grouping = [{ 'subtags': 'c', 'start': ' ( ', 'end': ' )', 'delimiter': '', 'subdelimiter': ', ' }, { 'subtags': 'def', 'start': ' ( ', 'end': ' )', 'delimiter': '', 'subdelimiter': ' ; ' }] variant_access_point = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields, tag_grouping=tag_grouping) if variant_access_point: self.json_dict['variant_access_point'] = variant_access_point
def trans_gnd_variant_name(self): """Transformation variant_name 400/410/411.""" if self.logger and self.verbose: self.logger.info('Call Function', 'trans_gnd_variant_name') tag = '400' subfields = {'a': ', ', 'b': ', ', 'c': ', '} if self.marc.get_fields('410') or self.marc.get_fields('411'): subfields = {'a': ', ', 'b': '. ', 'n': ', '} if self.marc.get_fields('410'): tag = '410' if self.marc.get_fields('411'): tag = '411' variant_names = self.json_dict.get('variant_name', []) variant_name = build_string_list_from_fields(record=self.marc, tag=tag, subfields=subfields) if variant_name: variant_names += variant_name if variant_names: self.json_dict['variant_name'] = variant_names
def trans_gnd_authorized_access_point(self): """Transformation authorized_access_point 100/110/111.""" tags = ['100'] agent = 'bf:Person' subfields = {'a': ', ', 'b': ', ', 'c': ', ', 'd': ', ', 'x': ' - - '} if self.marc.get_fields('110') or self.marc.get_fields('111'): tags = [] subfields = { 'a': ', ', 'b': '. ', 'n': ', ', 'd': ', ', 'c': ', ', 'e': '. ', 'g': '. ', 'k': '. ', 't': '. ', 'x': ' - - ' } if self.marc.get_fields('110'): tags.append('110') if self.marc.get_fields('111'): tags.append('111') agent = 'bf:Organisation' if self.logger and self.verbose: self.logger.info('Call Function', 'trans_gnd_authorized_access_point') variant_access_points = self.json_dict.get('variant_access_point', []) for tag in tags: authorized_access_points = build_string_list_from_fields( record=self.marc, tag=tag, subfields=subfields) for authorized_access_point in authorized_access_points: self.json_dict['bf:Agent'] = agent if self.json_dict.get('authorized_access_point'): variant_access_points.append(authorized_access_point) else: self.json_dict['authorized_access_point'] = \ authorized_access_point if variant_access_points: self.json_dict['variant_access_point'] = variant_access_points