lib/authority_control/mysql_populate.rb
def populate_lcgft_database(conn:, filename:)
  create_lcgft_tables(conn)
  reader = MARC::Reader.new(filename)
  reader.each do |record|
    lccn = record['001'].value.strip
    uri = "http://id.loc.gov/authorities/genreForms/#{lccn}"
    heading_string = record['155']['a']
    f682 = record.fields('682')
    deprecated = false
    f682.each do |field|
      deprecated = true if field['i'] && field['i'] =~ /deleted/
    end
    next if deprecated
    string_values = { uri: uri, heading_string: heading_string }
    insert_value_into_heading_string_table(conn: conn, table_name: lcgft_heading_string_table_name, values: string_values)
    label = normalize_heading_for_local_search(heading: heading_string)
    alt_terms = record.fields('455')
    alt_terms.each do |alt_term|
      text = alt_term['a']
      text = normalize_heading_for_local_search(heading: text)
      insert_value_into_heading_table(conn: conn, table_name: lcgft_variant_table_name, values: { heading: text, lccn: lccn })
    end
    auth_values = { heading: label, lccn: lccn }
    insert_value_into_heading_table(conn: conn, table_name: lcgft_heading_table_name, values: auth_values)
    lccn_uri_values = { lccn: lccn, uri: uri }
    insert_value_into_lccn_uri_table(conn: conn, values: lccn_uri_values)
  end
end
### Populate tables for LCGFT from MARC records
Populate tables for LCGFT from MARC records
Populate tables for LCGFT from MARC records
def populate_lcgft_database(conn:, filename:)
  create_lcgft_tables(conn)
  reader = MARC::Reader.new(filename)
  reader.each do |record|
    lccn = record['001'].value.strip
    uri = "http://id.loc.gov/authorities/genreForms/#{lccn}"
    heading_string = record['155']['a']
    f682 = record.fields('682')
    deprecated = false
    f682.each do |field|
      deprecated = true if field['i'] && field['i'] =~ /deleted/
    end
    next if deprecated
    string_values = { uri: uri, heading_string: heading_string }
    insert_value_into_heading_string_table(conn: conn, table_name: lcgft_heading_string_table_name, values: string_values)
    label = normalize_heading_for_local_search(heading: heading_string)
    alt_terms = record.fields('455')
    alt_terms.each do |alt_term|
      text = alt_term['a']
      text = normalize_heading_for_local_search(heading: text)
      insert_value_into_heading_table(conn: conn, table_name: lcgft_variant_table_name, values: { heading: text, lccn: lccn })
    end
    auth_values = { heading: label, lccn: lccn }
    insert_value_into_heading_table(conn: conn, table_name: lcgft_heading_table_name, values: auth_values)
    lccn_uri_values = { lccn: lccn, uri: uri }
    insert_value_into_lccn_uri_table(conn: conn, values: lccn_uri_values)
  end
end
def populate_lcgft_database ( conn : , filename : ) create_lcgft_tables ( conn ) reader = MARC :: Reader . new ( filename ) reader . each do | record | lccn = record [ '001' ] . value . strip uri = "http://id.loc.gov/authorities/genreForms/#{lccn}" heading_string = record [ '155' ] [ 'a' ] f682 = record . fields ( '682' ) deprecated = false f682 . each do | field | deprecated = true if field [ 'i' ] && field [ 'i' ] =~ / deleted / end next if deprecated string_values = { uri : uri , heading_string : heading_string } insert_value_into_heading_string_table ( conn : conn , table_name : lcgft_heading_string_table_name , values : string_values ) label = normalize_heading_for_local_search ( heading : heading_string ) alt_terms = record . fields ( '455' ) alt_terms . each do | alt_term | text = alt_term [ 'a' ] text = normalize_heading_for_local_search ( heading : text ) insert_value_into_heading_table ( conn : conn , table_name : lcgft_variant_table_name , values : { heading : text , lccn : lccn } ) end auth_values = { heading : label , lccn : lccn } insert_value_into_heading_table ( conn : conn , table_name : lcgft_heading_table_name , values : auth_values ) lccn_uri_values = { lccn : lccn , uri : uri } insert_value_into_lccn_uri_table ( conn : conn , values : lccn_uri_values ) end end
Populate tables for LCGFT from MARC records
Populate tables for LCGFT from MARC records
conn
filename