lib/authority_control/record_update.rb
### Look up term in MySQL database, add URI if valid
Look up term in MySQL database, add URI if valid
Look up term in MySQL database add URI if valid
def add_lcgft_uri(record:, conn:)
  changed_rec = false
  bad_rec = false
  heading_subfields = %w[a]
  rec = duplicate_record(record)
  rec.fields('655').each do |field|
    next unless field['0'].nil?
    next unless field.indicator2 == '7' && field['2'] == 'lcgft'
    field_index = rec.fields.index(field)
    heading_string = get_heading_from_field(field, heading_subfields)
    search_string = normalize_heading_for_local_search(heading: heading_string)
    target_lccn = get_lccn_from_local_db(conn: conn,
                                       heading: search_string,
                                       query: authorized_lcgft_lccn_query)
    if target_lccn.nil?
      target_lccn = get_lccn_from_local_db(conn: conn,
                                         heading: search_string,
                                         query: variant_lcgft_lccn_query)
    end
    next unless target_lccn
    target_uri = "http://id.loc.gov/authorities/genreForms/#{target_lccn}"
    changed_rec = true
    authorized_form = get_pref_lcgft_from_local_db(conn: conn,
                                                   uri: target_uri,
                                                   query: lcgft_heading_string_query)
    next unless authorized_form
    unless authorized_form.gsub(/[[:punct:][:space:]]/, '') == field['a'].gsub(/[[:punct:][:space:]]/, '')
      bad_rec = true
    end
    new_field = MARC::DataField.new('655', ' ', '7')
    new_field.append(MARC::Subfield.new('a', authorized_form))
    unless new_field.subfields[-1].value =~ heading_final_punct_regex
      new_field.subfields[-1].value << '.'
    end
    new_field = add_non_heading_subfields_to_subject_field(field, new_field)
    new_field.append(MARC::Subfield.new('2', 'lcgft'))
    new_field.append(MARC::Subfield.new('0', target_uri))
    rec.fields[field_index] = new_field
  end
  { record: rec, changed_rec: changed_rec, bad_rec: bad_rec }
end
def add_lcgft_uri ( record : , conn : ) changed_rec = false bad_rec = false heading_subfields = %w[ a ] rec = duplicate_record ( record ) rec . fields ( '655' ) . each do | field | next unless field [ '0' ] . nil? next unless field . indicator2 == '7' && field [ '2' ] == 'lcgft' field_index = rec . fields . index ( field ) heading_string = get_heading_from_field ( field , heading_subfields ) search_string = normalize_heading_for_local_search ( heading : heading_string ) target_lccn = get_lccn_from_local_db ( conn : conn , heading : search_string , query : authorized_lcgft_lccn_query ) if target_lccn . nil? target_lccn = get_lccn_from_local_db ( conn : conn , heading : search_string , query : variant_lcgft_lccn_query ) end next unless target_lccn target_uri = "http://id.loc.gov/authorities/genreForms/#{target_lccn}" changed_rec = true authorized_form = get_pref_lcgft_from_local_db ( conn : conn , uri : target_uri , query : lcgft_heading_string_query ) next unless authorized_form unless authorized_form . gsub ( / [[:punct:][:space:]] / , '' ) == field [ 'a' ] . gsub ( / [[:punct:][:space:]] / , '' ) bad_rec = true end new_field = MARC :: DataField . new ( '655' , ' ' , '7' ) new_field . append ( MARC :: Subfield . new ( 'a' , authorized_form ) ) unless new_field . subfields [ - 1 ] . value =~ heading_final_punct_regex new_field . subfields [ - 1 ] . value << '.' end new_field = add_non_heading_subfields_to_subject_field ( field , new_field ) new_field . append ( MARC :: Subfield . new ( '2' , 'lcgft' ) ) new_field . append ( MARC :: Subfield . new ( '0' , target_uri ) ) rec . fields [ field_index ] = new_field end { record : rec , changed_rec : changed_rec , bad_rec : bad_rec } end
Look up term in MySQL database, add URI if valid
Look up term in MySQL database add URI if valid
record
conn