class Marc2LinkedData::ParseMarcAuthority

Attributes

isni[R]
loc[R]
viaf[R]

Public Class Methods

new(record) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 16
def initialize(record)
  @@config ||= Marc2LinkedData.configuration
  @record = record
  @graph = RDF::Graph.new
  @loc = nil
  @isni = nil
  @viaf = nil
end
parse_leader(file_handle, leader_bytes=24) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 144
def self.parse_leader(file_handle, leader_bytes=24)
  # example:
  #record.leader
  #=> "00774cz  a2200253n  4500"
  # 00-04: '00774' - record length
  # 05:    'c' - corrected or revised
  # 06:    'z' - always 'z' for authority records
  # 09:    'a' - UCS/Unicode
  # 12-16: '00253' - base address of data, Length of Leader and Directory
  # 17:    'n' - Complete authority record
  # leader_status_codes = {
  #     'a' => 'Increase in encoding level',
  #     'c' => 'Corrected or revised',
  #     'd' => 'Deleted',
  #     'n' => 'New',
  #     'o' => 'Obsolete',
  #     's' => 'Deleted; heading split into two or more headings',
  #     'x' => 'Deleted; heading replaced by another heading'
  # }
  leader = file_handle.read(leader_bytes)
  file_handle.seek(-1 * leader_bytes, IO::SEEK_CUR)
  {
      :length => leader[0..4].to_i,
      :status => leader[5],  # leader_status_codes[ record.leader[5] ]
      :type => leader[6],    # always 'z' for authority records
      :encoding => leader[9],  # translate letter code into ruby encoding string
      :data_address => leader[12..16].to_i,
      :complete => leader[17].include?('n')
  }
end

Public Instance Methods

conference?() click to toggle source

X11 - Meeting Name

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 396
def conference?
  # e.g. http://id.loc.gov/authorities/names/n79044866
  field111[:error].nil?
end
corporation?() click to toggle source

X10 - Corporate Name

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 391
def corporation?
  field110[:error].nil?
end
field100() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 230
def field100
  # http://www.loc.gov/marc/authority/concise/ad100.html
  # [#<MARC::Subfield:0x007f009d6a74e0 @code="a", @value="Abe, Eiichi,">,
  #     #<MARC::Subfield:0x007f009d6a7440 @code="d", @value="1927-">,
  #     #<MARC::Subfield:0x007f009d6a73a0 @code="t", @value="Hoppu dais\xC5\xAB.">,
  #     #<MARC::Subfield:0x007f009d6a7300 @code="l", @value="English">],
  #     @tag="100">
  begin
    # 100 is a personal name or name-title
    return @field100 unless @field100.nil?
    field = get_fields('100').first
    # field = @record.fields.select {|f| f if f.tag == '100' }.first
    name = field.subfields.select {|f| f.code == 'a' }.first.value rescue ''
    date = field.subfields.select {|f| f.code == 'd' }.first.value rescue ''
    title = field.subfields.select {|f| f.code == 't' }.first.value rescue ''
    lang = field.subfields.select {|f| f.code == 'l' }.first.value rescue ''
    @field100 = {
        :name => name.force_encoding('UTF-8'),
        :date => date,
        :title => title.force_encoding('UTF-8'),
        :lang => lang,
        :error => nil
    }
  rescue => e
    @@config.logger.debug "Failed to parse field 100 for #{get_id}: #{e.message}"
    @field100 = {
        :name => nil,
        :date => nil,
        :title => nil,
        :lang => nil,
        :error => 'ERROR_PERSON_NAME' #e.message
    }
  end
end
field110() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 265
def field110
  # http://www.loc.gov/marc/authority/concise/ad110.html
  begin
    # 110 is a corporate name
    return @field110 unless @field110.nil?
    field = get_fields('110').first
    a = field.subfields.collect {|f| f.value if f.code == 'a' }.compact rescue []
    b = field.subfields.collect {|f| f.value if f.code == 'b' }.compact rescue []
    c = field.subfields.collect {|f| f.value if f.code == 'c' }.compact rescue []
    name = [a,b,c].flatten.join(' : ')
    @field110 = {
        :name => name.force_encoding('UTF-8'),
        :error => nil
    }
  rescue => e
    @@config.logger.debug "Failed to parse field 110 for #{get_id}: #{e.message}"
    @field110 = {
        :name => nil,
        :error => 'ERROR_CORPORATE_NAME' #e.message
    }
  end
end
field111() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 288
def field111
  # http://www.loc.gov/marc/authority/concise/ad111.html
  # #<MARC::Subfield:0x007f43a50fd1e8 @code="a", @value="Joseph Priestley Symposium">,
  # #<MARC::Subfield:0x007f43a50fd148 @code="d", @value="(1974 :">,
  # #<MARC::Subfield:0x007f43a50fd0a8 @code="c", @value="Wilkes-Barre, Pa.)">],
  # @tag="111">,
  begin
    # 111 is a meeting name
    return @field111 unless @field111.nil?
    field = get_fields('111').first
    name = field.subfields.select {|f| f.code == 'a' }.first.value rescue ''
    date = field.subfields.select {|f| f.code == 'd' }.first.value rescue ''
    city = field.subfields.select {|f| f.code == 'c' }.first.value rescue ''
    @field111 = {
        :name => name.force_encoding('UTF-8'),
        :date => date,
        :city => city.force_encoding('UTF-8'),
        :error => nil
    }
  rescue => e
    @@config.logger.debug "Failed to parse field 111 for #{get_id}: #{e.message}"
    @field111 = {
        :name => nil,
        :date => nil,
        :city => nil,
        :error => 'ERROR_MEETING_NAME'
    }
  end
end
field130() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 318
def field130
  # http://www.loc.gov/marc/authority/concise/ad151.html
  # e.g. http://id.loc.gov/authorities/names/n79119331
  # #<MARC::DataField:0x007f7f6bffe708
  # @indicator1=" ",
  # @indicator2="0",
  # @subfields=[#<MARC::Subfield:0x007f7f6bffe208 @code="a", @value="Fair maid of the Exchange">],
  # @tag="130">,
  # plus a lot of 400 fields
  begin
    # 130 is a uniform title
    return @field130 unless @field130.nil?
    field = get_fields('130').first
    title = field.subfields.collect {|f| f.value if f.code == 'a'}.first rescue ''
    @field130 = {
        :title => title.force_encoding('UTF-8'),
        :error => nil
    }
  rescue => e
    @@config.logger.debug "Failed to parse field 130 for #{get_id}: #{e.message}"
    @field130 = {
        :title => nil,
        :error => 'ERROR_UNIFORM_TITLE'
    }
  end
end
field151() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 345
def field151
  # http://www.loc.gov/marc/authority/concise/ad151.html
  # e.g. http://id.loc.gov/authorities/names/n79045127
  begin
    # 151 is a geographic name
    return @field151 unless @field151.nil?
    field = get_fields('151').first
    name = field.subfields.collect {|f| f.value if f.code == 'a' }.first rescue ''
    @field151 = {
        :name => name.force_encoding('UTF-8'),
        :error => nil
    }
  rescue => e
    @@config.logger.debug "Failed to parse field 151 for #{get_id}: #{e.message}"
    @field151 = {
        :name => nil,
        :error => 'ERROR_PLACE_NAME'
    }
  end
end
geographic?() click to toggle source

X51 - Jurisdiction / Geographic Name

- http://www.loc.gov/mads/rdf/v1#Geographic
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 408
def geographic?
  # e.g. http://id.loc.gov/authorities/names/n79046135.html
  field151[:error].nil?
end
get_fields(field_num) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 25
def get_fields(field_num)
  fields = @record.fields.select {|f| f if f.tag == field_num }
  raise "Invalid data in field #{field_num}" if fields.length < 1
  fields
end
get_id() click to toggle source

Try to use the SUL catkey and/or the OCLC control numbers, maybe SUL catkey in the record IRI

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 33
def get_id
  # extract ID from control numbers, see
  # http://www.loc.gov/marc/authority/ad001.html
  #field001 = record.fields.select {|f| f if f.tag == '001' }.first.value
  #field003 = record.fields.select {|f| f if f.tag == '003' }.first.value
  #"#{field003}-#{field001}"
  get_fields(@@config.field_auth_id).first.value
end
get_iri(field, iri_pattern) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 42
def get_iri(field, iri_pattern)
  begin
    iris = field.subfields.collect {|f| f.value if f.value.include? iri_pattern }
    iris.first || nil
  rescue
    nil
  end
end
get_iri4isni() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 51
def get_iri4isni
  isni_iri = nil
  begin
    # e.g. http://www.isni.org/0000000109311081
    field = get_fields(@@config.field_auth_isni).first
    isni_iri = get_iri(field, 'isni.org')
    # If ISNI is not already in the MARC record, try to get it from VIAF.
    if isni_iri.nil? && @@config.get_isni
      isni_iri = @viaf.get_isni rescue nil
      @@config.logger.debug 'Failed to resolve ISNI URI' if isni_iri.nil?
      # binding.pry if @viaf.iri.to_s.include? '67737121' #@@config.debug
    end
    unless isni_iri.nil?
      # Ensure the ISNI IRI has this prefix: http://www.isni.org/isni/
      isni_iri.gsub('www.isni.org', 'www.isni.org/isni') unless isni_iri =~ /www\.isni\.org\/isni\//
    end
    return isni_iri
  rescue
    nil
  end
end
get_iri4lib() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 73
def get_iri4lib
  "#{@@config.prefixes['lib_auth']}#{get_id}"
end
get_iri4loc() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 77
def get_iri4loc
  loc_iri = nil
  begin
    # e.g. http://id.loc.gov/authorities/names/n42000906
    field = get_fields(@@config.field_auth_loc).first
    loc_iri = get_iri(field, 'id.loc.gov')
  rescue
  end
  begin
    if loc_iri.nil?
      # If the LOC is not in the marc record, try to determine the LOC IRI from the ID.
      loc_id = get_id
      if loc_id =~ /^n/i
        loc_iri = "#{@@config.prefixes['loc_names']}#{loc_id.downcase}"
      end
      if loc_id =~ /^sh/i
        loc_iri = "#{@@config.prefixes['loc_subjects']}#{loc_id.downcase}"
      end
      unless loc_iri.nil?
        # Verify the URL (used HEAD so it's as fast as possible)
        @@config.logger.debug "Trying to validate LOC IRI: #{loc_iri}"
        loc_iri = Marc2LinkedData.http_head_request(loc_iri + '.rdf')
      end
      if loc_iri.nil?
        # If it gets here, it's a problem.
        binding.pry if @@config.debug
        @@config.logger.error 'FAILURE to resolve LOC IRI'
      else
        @@config.logger.debug "DISCOVERED LOC IRI: #{loc_iri}"
      end
    else
      @@config.logger.debug "MARC contains LOC IRI: #{loc_iri}"
    end
    return loc_iri
  rescue
    nil
  end
end
get_iri4oclc() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 116
def get_iri4oclc
  begin
    field = get_fields(@@config.field_auth_oclc).first
    oclc_cn = field.subfields.collect {|f| f.value if f.code == 'a'}.first
    oclc_id = /\d+$/.match(oclc_cn).to_s
    oclc_id.empty? ? nil : "http://www.worldcat.org/oclc/#{oclc_id}"
  rescue
    nil
  end
end
get_iri4viaf() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 127
def get_iri4viaf
  begin
    # e.g. http://viaf.org/viaf/181829329
    # VIAF RSS feed for changes, e.g. http://viaf.org/viaf/181829329.rss
    field = get_fields(@@config.field_auth_viaf).first
    viaf_iri = get_iri(field, 'viaf.org')
    # If VIAF is not already in the MARC record, try to get it from LOC.
    if viaf_iri.nil? && @@config.get_viaf
      viaf_iri = @loc.get_viaf rescue nil
      @@config.logger.debug 'Failed to resolve VIAF URI' if viaf_iri.nil?
    end
    return viaf_iri
  rescue
    nil
  end
end
graph() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 641
def graph
  # TODO: figure out how to specify all the graph prefixes.
  return @graph unless @graph.empty?
  @lib = LibAuth.new get_iri4lib
  # Try to find LOC, VIAF, and ISNI IRIs in the MARC record
  @loc = Loc.new get_iri4loc rescue nil
  # Try to identify problems in getting an LOC IRI.
  if @loc.nil?
    binding.pry if @@config.debug
    raise 'Failed to get authority at LOC'
  end
  # might require LOC to get ISNI.
  @viaf = Viaf.new get_iri4viaf rescue nil
  # might require VIAF to get ISNI.
  @isni = Isni.new get_iri4isni rescue nil

  # TODO: ORCID? VIVO? VITRO? Stanford CAP?

  # Get LOC control number and add catalog permalink? e.g.
  # http://lccn.loc.gov/n79046291
  graph_insert_sameAs(@lib.rdf_uri, @loc.rdf_uri)
  graph_insert_sameAs(@lib.rdf_uri, @viaf.rdf_uri) unless @viaf.nil?
  graph_insert_sameAs(@lib.rdf_uri, @isni.rdf_uri) unless @isni.nil?
  parse_auth_details
  # Optional elaboration of authority data with OCLC identity and works.
  get_oclc_links if @@config.get_oclc
  # @@config.logger.info "Extracted #{@loc.id}"
  @graph
end
graph_insert(uriS, uriP, uriO) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 671
def graph_insert(uriS, uriP, uriO)
  @graph.insert RDF::Statement(uriS, uriP, uriO)
end
graph_insert_contributor(uriS, uriO) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 686
def graph_insert_contributor(uriS, uriO)
  graph_insert(uriS, RDF::SCHEMA.contributor, uriO)
end
graph_insert_creator(uriS, uriO) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 683
def graph_insert_creator(uriS, uriO)
  graph_insert(uriS, RDF::SCHEMA.creator, uriO)
end
graph_insert_editor(uriS, uriO) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 689
def graph_insert_editor(uriS, uriO)
  graph_insert(uriS, RDF::SCHEMA.editor, uriO)
end
graph_insert_exampleOfWork(uriS, uriO) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 680
def graph_insert_exampleOfWork(uriS, uriO)
  graph_insert(uriS, RDF::SCHEMA.exampleOfWork, uriO)
end
graph_insert_name(uriS, name) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 705
def graph_insert_name(uriS, name)
  graph_insert(uriS, RDF::FOAF.name, name) if @@config.use_foaf
  graph_insert(uriS, RDF::SCHEMA.name, name) if @@config.use_schema
end
graph_insert_sameAs(uriS, uriO) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 674
def graph_insert_sameAs(uriS, uriO)
  graph_insert(uriS, RDF::OWL.sameAs, uriO)
end
graph_insert_seeAlso(uriS, uriO) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 677
def graph_insert_seeAlso(uriS, uriO)
  graph_insert(uriS, RDF::RDFS.seeAlso, uriO)
end
graph_insert_type(uriS, uriO) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 692
def graph_insert_type(uriS, uriO)
  graph_insert(uriS, RDF.type, uriO)
end
graph_type_agent(uriS) click to toggle source

Methods that can use FOAF or SCHEMA or both (or neither?)

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 699
def graph_type_agent(uriS)
  # Note: schema.org has no immediate parent for Person or Organization
  graph_insert_type(uriS, RDF::FOAF.Agent) if @@config.use_foaf
  graph_insert_type(uriS, RDF::SCHEMA.Thing) if @@config.use_schema
end
graph_type_organization(uriS) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 710
def graph_type_organization(uriS)
  graph_insert_type(uriS, RDF::FOAF.Organization) if @@config.use_foaf
  graph_insert_type(uriS, RDF::SCHEMA.Organization) if @@config.use_schema
end
graph_type_person(uriS) click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 715
def graph_type_person(uriS)
  graph_insert_type(uriS, RDF::FOAF.Person) if @@config.use_foaf
  graph_insert_type(uriS, RDF::SCHEMA.Person) if @@config.use_schema
end
name_title?() click to toggle source

X00 - Name-Title

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 381
def name_title?
  # e.g. http://id.loc.gov/authorities/names/n79044934
  # if get_id == 'n79044934'.upcase
  #   binding.pry if @@config.debug
  # end
  field = field100
  field[:error].nil? && (! field[:name].empty?) && (! field[:title].empty?)
end
parse_008() click to toggle source

BLOCK —————————————————- Parse fields

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 179
def parse_008
  # http://www.loc.gov/marc/authority/concise/ad008.html
  field = get_fields('008').first
  field008 = field.value
  languages = []
  languages.append('English') if ['b','e'].include? field008[8]
  languages.append('French') if ['b','f'].include? field008[8]
  rules = ''
  rules = 'EARLIER' if field008[10] == 'a'
  rules = 'AACR1' if field008[10] == 'b'
  rules = 'AACR2' if field008[10] == 'c'
  rules = 'AACR2 compatible' if field008[10] == 'd'
  rules = 'OTHER' if field008[10] == 'z'
  rules = 'N/A' if field008[10] == 'n'
  # 32 - Undifferentiated personal name
  # Whether the personal name in a name or name/title heading contained in field 100 in an established heading record or a reference record is used by one person or by two or more persons.
  # a - Differentiated personal name
  #     Personal name in field 100 is a unique name.
  # b - Undifferentiated personal name
  #     Personal name in field 100 is used by two or more persons.
  # n - Not applicable
  #     1XX heading is not a personal name or the personal name is a family name.
  # | - No attempt to code
  {
      :date => Date.strptime(field008[0..5], "%y%m%d"),
      :geographic_subdivision => field008[6], # '#', d, i, n, or '|'
      :romanization_scheme => field008[7], # a..g, n, or '|'
      :languages => languages,
      :kind => field008[9], # a..g, or '|'
      :rules => rules,
      :heading_system => field008[11],
      :series_type => field008[12],
      :series_numbered => field008[13],
      :use_1XX_for_7XX => field008[14] == 'a',
      :use_1XX_for_6XX => field008[15] == 'a',
      :use_1XX_for_4XX => field008[16] == 'a',
      :use_1XX_for_8XX => field008[16] == 'a',
      :type_subject_subdivision => field008[17],
      # 18-27 - Undefined character positions
      :type_government_agency => field008[28],
      :reference_evaluation => field008[29],
      # 30 - Undefined character position
      :record_available => field008[31] == 'a',
      # TODO: 32
      # TODO: 33
      # 34-37 - Undefined character positions
      # TODO: 38
      # TODO: 39
  }
end
parse_auth_details() click to toggle source

BLOCK —————————————————- Parse authority record

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 416
def parse_auth_details
  if @loc.iri.to_s =~ /name/
    if @@config.get_loc
      # Retrieve and use LOC RDF
      parse_auth_name_rdf
    else
      # Use only the MARC record, without RDF retrieval
      parse_auth_name
    end
  elsif @loc.iri.to_s =~ /subjects/
    # TODO: what to do with subjects?
    binding.pry if @@config.debug
    # parse_auth_subject_rdf
  else
    # What is this?
    binding.pry if @@config.debug
  end
end
parse_auth_name() click to toggle source

BLOCK —————————————————- Parse authority record without RDF

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 439
def parse_auth_name
  #
  # Create triples for various kinds of LOC authority.
  #
  name = ''
  if person?
    name = field100[:name]
    graph_type_person(@lib.rdf_uri)

    # TODO: find another way to get first and last names without VIAF
    # # VIAF extracts first and last name, try to use them. Note
    # # that VIAF uses schema:name, schema:givenName, and schema:familyName.
    # if @@config.get_viaf && ! @viaf.nil?
    #   @viaf.family_names.each do |n|
    #     # ln = URI.encode(n)
    #     # TODO: try to get a language type, if VIAF provide it.
    #     # name = RDF::Literal.new(n, :language => :en)
    #     ln = RDF::Literal.new(n)
    #     @graph.insert RDF::Statement(@lib.rdf_uri, RDF::FOAF.familyName, ln) if @@config.use_foaf
    #     @graph.insert RDF::Statement(@lib.rdf_uri, RDF::SCHEMA.familyName, ln) if @@config.use_schema
    #   end
    #   @viaf.given_names.each do |n|
    #     # fn = URI.encode(n)
    #     # TODO: try to get a language type, if VIAF provide it.
    #     # name = RDF::Literal.new(n, :language => :en)
    #     fn = RDF::Literal.new(n)
    #     @graph.insert RDF::Statement(@lib.rdf_uri, RDF::FOAF.firstName, fn) if @@config.use_foaf
    #     @graph.insert RDF::Statement(@lib.rdf_uri, RDF::SCHEMA.givenName, fn) if @@config.use_schema
    #   end
    # end
  elsif name_title?
    # e.g. http://id.loc.gov/authorities/names/n79044934
    # http://viaf.org/viaf/182251325/rdf.xml
    name = field100[:name]
    graph_insert_type(@lib.rdf_uri, RDF::URI.new('http://www.loc.gov/mads/rdf/v1#NameTitle'))
  elsif corporation?
    name = field110[:name]
    graph_type_organization(@lib.rdf_uri)
  elsif conference?
    # e.g. http://id.loc.gov/authorities/names/n79044866
    name = [field111[:name],field111[:date],field111[:city]].join('')
    graph_insert_type(@lib.rdf_uri, RDF::SCHEMA.event)
  elsif uniform_title?
    name = field130[:title]  # use 'name' for code below, although it's a title
    graph_insert_type(@lib.rdf_uri, RDF::URI.new('http://www.loc.gov/mads/rdf/v1#Title'))
    graph_insert_type(@lib.rdf_uri, RDF::SCHEMA.title)
  elsif geographic?
    name = field151[:name]  # use 'name' for code below, although it's a place
    graph_insert_type(@lib.rdf_uri, RDF::SCHEMA.Place)
  else
    # TODO: find out what type this is.
    binding.pry if @@config.debug
    name = ''
    graph_type_agent(@lib.rdf_uri)
  end
  if name != ''
    name = RDF::Literal.new(name)
    graph_insert_name(@lib.rdf_uri, name)
  end
end
parse_auth_name_rdf() click to toggle source

Create triples for various kinds of LOC authority. This method relies on RDF data retrieval.

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 506
def parse_auth_name_rdf
  @@config.logger.warn "#{@loc.iri} DEPRECATED" if @loc.deprecated?
  name = ''
  if @loc.person?
    name = @loc.label || field100[:name]
    graph_type_person(@lib.rdf_uri)
    # VIAF extracts first and last name, try to use them. Note
    # that VIAF uses schema:name, schema:givenName, and schema:familyName.
    if @@config.get_viaf && ! @viaf.nil?
      @viaf.family_names.each do |n|
        # ln = URI.encode(n)
        # TODO: try to get a language type, if VIAF provide it.
        # name = RDF::Literal.new(n, :language => :en)
        ln = RDF::Literal.new(n)
        @graph.insert RDF::Statement(@lib.rdf_uri, RDF::FOAF.familyName, ln) if @@config.use_foaf
        @graph.insert RDF::Statement(@lib.rdf_uri, RDF::SCHEMA.familyName, ln) if @@config.use_schema
      end
      @viaf.given_names.each do |n|
        # fn = URI.encode(n)
        # TODO: try to get a language type, if VIAF provide it.
        # name = RDF::Literal.new(n, :language => :en)
        fn = RDF::Literal.new(n)
        @graph.insert RDF::Statement(@lib.rdf_uri, RDF::FOAF.firstName, fn) if @@config.use_foaf
        @graph.insert RDF::Statement(@lib.rdf_uri, RDF::SCHEMA.givenName, fn) if @@config.use_schema
      end
    end
  elsif @loc.name_title?
    # e.g. http://id.loc.gov/authorities/names/n79044934
    # http://viaf.org/viaf/182251325/rdf.xml
    name = @loc.label || field100[:name]
    graph_insert_type(@lib.rdf_uri, RDF::URI.new('http://www.loc.gov/mads/rdf/v1#NameTitle'))
  elsif @loc.corporation?
    name = @loc.label || field110[:name]
    graph_type_organization(@lib.rdf_uri)
  elsif @loc.conference?
    # e.g. http://id.loc.gov/authorities/names/n79044866
    name = @loc.label || [field111[:name],field111[:date],field111[:city]].join('')
    graph_insert_type(@lib.rdf_uri, RDF::SCHEMA.event)
  elsif @loc.geographic?
    # e.g. http://id.loc.gov/authorities/names/n79045127
    name = @loc.label || field151[:name]
    graph_insert_type(@lib.rdf_uri, RDF::SCHEMA.Place)
  elsif @loc.uniform_title?
    name = field130[:title]  # use 'name' for code below, although it's a title
    graph_insert_type(@lib.rdf_uri, RDF::URI.new('http://www.loc.gov/mads/rdf/v1#Title'))
    graph_insert_type(@lib.rdf_uri, RDF::SCHEMA.title)
  else
    # TODO: find out what type this is.
    binding.pry if @@config.debug
    name = @loc.label || ''
    graph_type_agent(@lib.rdf_uri)
  end
  if name != ''
    name = RDF::Literal.new(name)
    graph_insert_name(@lib.rdf_uri, name)
  end
end
parse_auth_subject_rdf() click to toggle source
# File lib/marc2linkeddata/parseMarcAuthority.rb, line 566
def parse_auth_subject_rdf
  # The term 'subject' refers to:
  #  X30 - Uniform Titles
  #  X48 - Chronological Terms
  #  X50 - Topical Terms
  #  X51 - Geographic Names
  #  X55 - Genre/Form Terms
  #
  # The term 'subject subdivision' refers to:
  # X80 - general subdivision terms
  # X81 - geographic subdivision names
  # X82 - chronological subdivision terms
  # X85 - form subdivision terms
end
person?() click to toggle source

X00 - Personal Name

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 375
def person?
  field = field100
  field[:error].nil? && (! field[:name].empty?) && field[:title].empty?
end
to_ttl() click to toggle source

BLOCK —————————————————- Graph methods

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 637
def to_ttl
  graph.to_ttl
end
uniform_title?() click to toggle source

X30 - Uniform Title

# File lib/marc2linkeddata/parseMarcAuthority.rb, line 402
def uniform_title?
  field130[:error].nil?
end