Class: Marc2LinkedData::ParseMarcAuthority

Inherits:
Object
  • Object
show all
Defined in:
lib/marc2linkeddata/parseMarcAuthority.rb

Constant Summary collapse

@@config =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ ParseMarcAuthority

Returns a new instance of ParseMarcAuthority.



16
17
18
19
20
21
22
23
# 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

Instance Attribute Details

#isniObject (readonly)

Returns the value of attribute isni.



13
14
15
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 13

def isni
  @isni
end

#locObject (readonly)

Returns the value of attribute loc.



12
13
14
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 12

def loc
  @loc
end

#viafObject (readonly)

Returns the value of attribute viaf.



14
15
16
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 14

def viaf
  @viaf
end

Class Method Details

.parse_leader(file_handle, leader_bytes = 24) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# 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

Instance Method Details

#conference?Boolean

X11 - Meeting Name

Returns:

  • (Boolean)


396
397
398
399
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 396

def conference?
  # e.g. http://id.loc.gov/authorities/names/n79044866
  field111[:error].nil?
end

#corporation?Boolean

X10 - Corporate Name

Returns:

  • (Boolean)


391
392
393
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 391

def corporation?
  field110[:error].nil?
end

#field100Object



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# 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

#field110Object



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# 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

#field111Object



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# 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

#field130Object



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# 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

#field151Object



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# 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?Boolean

X51 - Jurisdiction / Geographic Name

- http://www.loc.gov/mads/rdf/v1#Geographic

Returns:

  • (Boolean)


408
409
410
411
# 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) ⇒ Object



25
26
27
28
29
# 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_idObject

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



33
34
35
36
37
38
39
40
# 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) ⇒ Object



42
43
44
45
46
47
48
49
# 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_iri4isniObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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_iri4libObject



73
74
75
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 73

def get_iri4lib
  "#{@@config.prefixes['lib_auth']}#{get_id}"
end

#get_iri4locObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 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_iri4oclcObject



116
117
118
119
120
121
122
123
124
125
# 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_iri4viafObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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


581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 581

def get_oclc_links
  oclc_iri = nil
  begin
    # Try to get OCLC using LOC ID.
    oclc_iri = @loc.get_oclc_identity
  rescue
    # Try to get OCLC using 035a field data, but
    # this is not as reliable/accurate as LOC.
    oclc_iri = get_iri4oclc
  end
  unless oclc_iri.nil?
    # Try to get additional data from OCLC, using the RDFa
    # available in the OCLC identities pages.
    oclc_auth = OclcIdentity.new oclc_iri
    graph_insert_sameAs(@loc.rdf_uri, oclc_auth.rdf_uri)
    oclc_auth.creative_works.each do |creative_work_uri|
      # Notes on work-around for OCLC data inconsistency:
      # RDFa for http://www.worldcat.org/identities/lccn-n79044798 contains:
      # <http://worldcat.org/oclc/747413718> a <http://schema.org/CreativeWork> .
      # However, the RDF for <http://worldcat.org/oclc/747413718> contains:
      # <http://www.worldcat.org/oclc/747413718> schema:exampleOfWork <http://worldcat.org/entity/work/id/994448191> .
      # Note how the subject here is 'WWW.worldcat.org' instead of 'worldcat.org'.
      #creative_work_iri = creative_work.to_s.gsub('worldcat.org','www.worldcat.org')
      #creative_work_iri = creative_work_iri.gsub('wwwwww','www') # in case it gets added already by OCLC
      creative_work = OclcCreativeWork.new creative_work_uri
      graph_insert_seeAlso(oclc_auth.rdf_uri, creative_work.rdf_uri)
      if @@config.oclc_auth2works
        # Try to use VIAF to relate auth to work as creator, contributor, editor, etc.
        # Note that this requires additional RDF retrieval for each work (slower processing).
        unless @viaf.nil?
          if creative_work.creator? @viaf.iri
            graph_insert_creator(creative_work.rdf_uri, oclc_auth.rdf_uri)
          elsif creative_work.contributor? @viaf.iri
            graph_insert_contributor(creative_work.rdf_uri, oclc_auth.rdf_uri)
          elsif creative_work.editor? @viaf.iri
            graph_insert_editor(creative_work.rdf_uri, oclc_auth.rdf_uri)
          end
        end
        # TODO: Is auth the subject of the work (as in biography) or both (as in autobiography)?
        # binding.pry if @@config.debug
        # binding.pry if creative_work.iri.to_s == 'http://www.worldcat.org/oclc/006626542'
        # Try to find the generic work entity for this example work.
        creative_work.get_works.each do |oclc_work_uri|
          oclc_work = OclcWork.new oclc_work_uri
          graph_insert_exampleOfWork(creative_work.rdf_uri, oclc_work.rdf_uri)
        end
      end
    end
  end
end

#graphObject



641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# 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) ⇒ Object



671
672
673
# 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) ⇒ Object



686
687
688
# 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) ⇒ Object



683
684
685
# 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) ⇒ Object



689
690
691
# 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) ⇒ Object



680
681
682
# 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) ⇒ Object



705
706
707
708
# 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) ⇒ Object



674
675
676
# 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) ⇒ Object



677
678
679
# 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) ⇒ Object



692
693
694
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 692

def graph_insert_type(uriS, uriO)
  graph_insert(uriS, RDF.type, uriO)
end

#graph_type_agent(uriS) ⇒ Object


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



699
700
701
702
703
# 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) ⇒ Object



710
711
712
713
# 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) ⇒ Object



715
716
717
718
# 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?Boolean

X00 - Name-Title

Returns:

  • (Boolean)


381
382
383
384
385
386
387
388
# 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_008Object

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



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# 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_detailsObject

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



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# 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_nameObject

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



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# 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_rdfObject

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



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# 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_rdfObject



566
567
568
569
570
571
572
573
574
575
576
577
578
579
# 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?Boolean

X00 - Personal Name

Returns:

  • (Boolean)


375
376
377
378
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 375

def person?
  field = field100
  field[:error].nil? && (! field[:name].empty?) && field[:title].empty?
end

#to_ttlObject

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



637
638
639
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 637

def to_ttl
  graph.to_ttl
end

#uniform_title?Boolean

X30 - Uniform Title

Returns:

  • (Boolean)


402
403
404
# File 'lib/marc2linkeddata/parseMarcAuthority.rb', line 402

def uniform_title?
  field130[:error].nil?
end