Class: Traject::UMichFormat::BibTypes

Inherits:
Object
  • Object
show all
Defined in:
lib/traject/umich_format/bib_types.rb

Overview

Determine the "types" of material represented by the bib record. The comments below come from the Ex Libris Aleph system and represent the logic used within it to determine types. This file is based on the logic use at the University of Michigan

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bib_format, record) ⇒ BibTypes

Returns a new instance of BibTypes


14
15
16
17
18
19
20
21
22
# File 'lib/traject/umich_format/bib_types.rb', line 14

def initialize(bib_format, record)
  @bib_format = bib_format
  @record = record
  # Memoize values, since many of them are used several times
  @spec_vals  = Hash.new { |h, spec_string| h[spec_string] = Traject::MarcExtractor.new(spec_string).extract(@record) }

  # Need these a lot -- the sub x and v from any 6XX field
  @xv6XX      = Traject::UMichFormat::XV6XX.new(@record)
end

Class Attribute Details

.pp_regexpObject

Returns the value of attribute pp_regexp


514
515
516
# File 'lib/traject/umich_format/bib_types.rb', line 514

def pp_regexp
  @pp_regexp
end

Instance Attribute Details

#bib_formatObject (readonly)

Returns the value of attribute bib_format


12
13
14
# File 'lib/traject/umich_format/bib_types.rb', line 12

def bib_format
  @bib_format
end

#recordObject (readonly)

Returns the value of attribute record


12
13
14
# File 'lib/traject/umich_format/bib_types.rb', line 12

def record
  @record
end

Instance Method Details

#[](spec_string) ⇒ Array<String>

Provide memoized values for on-the-fly created MarcExtractor objects

Parameters:

  • spec_string (String)

    A Traject::MarcExtractor-compatible spec string

Returns:

  • (Array<String>)

    The strings in the specified subfields/byterange/whatever


55
56
57
# File 'lib/traject/umich_format/bib_types.rb', line 55

def [](spec_string)
  @spec_vals[spec_string]
end

#audio_typesObject

Audio/music ! Recording: Compact disc TYP RC Audio CD LDR F06-01 EQUAL [i,j] FMT F00-02 EQUAL MU 007 F01-01 EQUAL d 007 F12-01 EQUAL e TYP RC Audio CD 8524 j MATCH CD* 8524 b EQUAL MUSIC ! ! Recording: LP record TYP RL Audio LP LDR F06-01 EQUAL [i,j] FMT F00-02 EQUAL MU 007 F01-01 EQUAL d 300 a MATCH SOUND DISC 300 b MATCH 33 1/3 RPM

TYP RL Audio LP 8524 j MATCH LP* 8524 c EQUAL MUSI TYP RL Audio LP 8524 j MATCH LP* 8524 b EQUAL MUSIC ! ! Recording: Music TYP RM Audio (music) LDR F06-01 EQUAL j FMT F00-02 EQUAL MU ! ! Recording: Spoken word TYP RS Audio (spoken word) LDR F06-01 EQUAL i FMT F00-02 EQUAL MU ! ! Recording: Undefined TYP RU Audio LDR F06-01 EQUAL [i,j] FMT F00-02 EQUAL MU


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
174
175
176
177
178
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
# File 'lib/traject/umich_format/bib_types.rb', line 148

def audio_types
  ldr6 = record.leader[6]

  types = []

  # Get the 8524* fields
  f8524 = record.fields('852').select{|f| f.indicator1 == '4'}

  # RC
  if %w[i j].include?(ldr6) && (bib_format == 'MU') 
    @record.fields('007').map{|f| f.value}.each do |f|
      if f[1] == 'd' && f[12] == 'e'
        types << 'RC'
        break
      end
    end
  end

  f8524.each do |f|
    if (f['b'].upcase == 'MUSIC') && (f['j'] =~ /\ACD/i)
      types << 'RC'
      break
    end
  end

  # RL

  if  (bib_format == 'MU') && %w[i j].include?(ldr6) && self['007[1]'].include?('d')
    record.fields('300').each do |f|
      str = f.subfields.collect {|s| s.value}.join(' ')
      if (str =~ /DISC/i) && str =~ /33 1\/3 RPM/i
        types << 'RL'
        break
      end
    end
  end


  f8524.each do |f|
    if  (f['j'] =~ /\ALP/i) &&
        ((f['b'].upcase == 'MUSIC') || (f['c'].upcase == 'MUSI'))
      types << 'RL'
      break
    end
  end

  # RM
  types << 'RM' if (ldr6 == 'j') && (bib_format == 'MU')

  # RS
  types << 'RS' if (ldr6 == 'i') && (bib_format == 'MU')

  # RU
  types << 'RU' if %w[i j].include?(ldr6) && (bib_format == 'MU')

  types.uniq!
  return types
end

#biography_typesObject

TYP BI Biography 6#### xv MATCH biography TYP BI Biography 6#### xv MATCH diaries TYP BI Biography 008 F34-01 EQUAL [a,b,c] TYP BI Biography 006 F17-01 EQUAL [a,b,c]


489
490
491
492
493
494
495
496
497
# File 'lib/traject/umich_format/bib_types.rb', line 489

def biography_types
  return ['BI'] if record['008'] && %w[a b c].include?(record['008'].value[34])
  return ['BI'] if (%w[a b c ] & self['006[17]']).size > 0

  return ['BI'] if @xv6XX.match? /(?:biography|diaries)/i

  # Nope
  return []
end

#codesObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/traject/umich_format/bib_types.rb', line 25

def codes
  codes = []
  codes.concat self.video_types
  codes.concat self.audio_types
  codes.concat self.microform_types
  codes.concat self.musical_score_types
  codes.concat self.map_types
  codes.concat self.serial_types
  codes.concat self.mixed_types
  codes.concat self.software_types
  codes.concat self.statistics_types
  codes.concat self.conference_types
  codes.concat self.biography_types
  codes.concat self.reference_types
  codes.concat self.pp_types
  codes.concat self.videogame_types

  codes.uniq!
  codes.compact!
  
  codes
end

#conference_typesObject

! X (no icon) - Conference TYP XC Conference 008 F29-01 EQUAL 1 TYP XC Conference 111## EXIST TYP XC Conference 711## EXIST TYP XC Conference 811## EXIST TYP XC Conference FMT F00-02 EQUAL CF 006 F00-01 EQUAL [a,s] 006 F12-01 EQUAL 1 TYP XC Conference FMT F00-02 EQUAL MU 008 F30-01 EQUAL c TYP XC Conference FMT F00-02 EQUAL MU 008 F31-01 EQUAL c ! additional types defined for vufind extract TYP XC Conference 6#### xv MATCH congresses


387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/traject/umich_format/bib_types.rb', line 387

def conference_types
  # Get the easy stuff done first

  return ['XC'] if  (record['008'] && (record['008'].value[29] == '1')) || record.fields(['111', '711', '811']).size > 0

  if  (bib_format == 'CF')
    @record.fields('006').map{|f| f.value}.each do |f|
      return ['XC'] if  %w[a s].include?(f[0]) && (f[12] == '1')
    end
  end

  if  (bib_format == 'MU') && record['008'] &&
      (record['008'].value[30..31] =~ /c/)
    return ['XC']
  end

  return ['XC'] if @xv6XX.match? /congresses/i

  # Nope.
  return []
end

#journal_typesObject


304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/traject/umich_format/bib_types.rb', line 304

def journal_types

  types = []
  # gotta be SE and have a 008
  return types unless (bib_format == 'SE') && record['008']


  # We need lots of chars from the 008
  f8 = record['008'].value

  if  (f8[21] == 'p') &&
      [' ','a','b','c','d','f','g','h','i','s','x','z','|'].include?(f8[22]) &&
      ['0', '|'].include?(f8[29])
    types << 'AJ'
  end

  if  [' ','d','l','m','p','w','|'].include?(f8[21]) &&
      [' ','a','b','c','d','f','g','h','i','s','x','z','|'].include?(f8[22]) &&
      ['a','b','g','m','n','o','p','s','w','x','y',' '].include?(f8[24]) &&
      ['0', '|'].include?(f8[29])
    types << 'AJ'
  end

  types.uniq!
  return types
end

#map_typesObject


262
263
264
265
266
267
268
# File 'lib/traject/umich_format/bib_types.rb', line 262

def map_types
  types = []
  if (bib_format == 'MP') || %w[e f].include?(record.leader[6]) ||  self['007[0]'].include?('a')
    types << 'MN'
  end
  return types
end

#microform_typesObject

TYP WM Microform FMT F00-02 EQUAL MP 008 F29-01 EQUAL [a,b,c] TYP WM Microform FMT F00-02 EQUAL VM 008 F29-01 EQUAL [a,b,c]


226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/traject/umich_format/bib_types.rb', line 226

def microform_types
  return [] unless record['008']
  types = ['WM']
  f8_23 = record['008'].value[23]
  return types if %w[BK MU SE MX].include?(bib_format) && %w[a b c].include?(f8_23)

  f8_29 = record['008'].value[29]
  return types if %w[MP VM].include?(bib_format) &&  %w[a b c].include?(f8_29)

  return types if record['245'] && (record['245']['h'] =~ /micro/i)

  # Nope. Not microform
  return []
end

#mixed_typesObject

! Mixed material: archi-V-e TYP MV Archive FMT F00-02 EQUAL MX TYP MV Archive LDR F08-01 EQUAL a ! ! Mixed material: manuscript TYP MW Manuscript LDR F06-01 EQUAL [d,f,p,t]


346
347
348
349
350
351
# File 'lib/traject/umich_format/bib_types.rb', line 346

def mixed_types
  types = []
  types << 'MV' if (bib_format == 'MX') || (record.leader[8] == 'a')
  types << 'MW' if %w[d f p t].include?(record.leader[6])
  return types
end

#musical_score_typesObject

! Musical Score TYP MS Musical Score LDR F06-01 EQUAL [c,d]


245
246
247
248
249
# File 'lib/traject/umich_format/bib_types.rb', line 245

def musical_score_types
  types = []
  types << 'MS' if %w[c d].include?(record.leader[6])
  return types
end

#newspaper_typesObject


331
332
333
334
335
336
# File 'lib/traject/umich_format/bib_types.rb', line 331

def newspaper_types
  types = []
  types << 'AN' if (bib_format == 'SE') && record['008'] &&
      ((record['008'].value[21] == 'n') || (record['008'].value[22] == 'e'))
  return types
end

#pp_typesObject


531
532
533
534
535
536
537
# File 'lib/traject/umich_format/bib_types.rb', line 531

def pp_types
  if @xv6XX.match? self.class.pp_regexp
    return ['PP']
  else
    return []
  end
end

#reference_typesObject

TYP EN Encyclopedias 6#### xv MATCH encyclopedias TYP EN Encyclopedias 008 F24-01 EQUAL e TYP EN Encyclopedias 006 F07-01 EQUAL e

TYP DI Dictionaries 6#### xv MATCH dictionaries TYP DI Dictionaries 008 F24-01 EQUAL d TYP DI Dictionaries 006 F07-01 EQUAL d

TYP DR Directories 6#### xv MATCH directories TYP DR Directories 008 F24-01 EQUAL r TYP DR Directories 006 F07-01 EQUAL d


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
# File 'lib/traject/umich_format/bib_types.rb', line 449

def reference_types
  types = []

  # Will need the 008[24] and 006[7]
  f8_24 =  self['008[24]']
  f6_7 = self['006[7]']



  if (f8_24.include? 'e') || (f6_7.include? 'e')
    types << 'EN'
  end

  if f6_7.include? 'd'
    types << 'DI'
    types << 'DR'
  end

  if f8_24.include? 'd'
    types << 'DI'
  end

  if f8_24.include? 'r'
    types << 'DR'
  end

  types << 'EN' if @xv6XX.match? /encyclopedias/i
  types << 'DI' if @xv6XX.match? /dictionaries/i
  types << 'DR' if @xv6XX.match? /directories/i

  types.uniq!
  return types
end

#serial_typesObject

Wrap it all up in serial_types


294
295
296
297
298
299
300
301
# File 'lib/traject/umich_format/bib_types.rb', line 294

def serial_types
  types = []
  types << 'SX' if %w[b s].include?(record.leader[7])
  types.concat journal_types
  types.concat newspaper_types
  types.uniq!
  return types
end

#software_typesObject

TYP CR CDROM 852## j MATCH cd-rom* TYP CR CDROM 852## j MATCH cdrom* TYP CR CDROM 852## j MATCH cd-rom* TYP CS Software 852## j MATCH software*


358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/traject/umich_format/bib_types.rb', line 358

def software_types
  types = []
  self['852j'].each do |j|
    if j =~ /\Acd-?rom/i
      types << 'CR'
    end
    if j =~ /\Asoftware/i
      types << 'CS'
    end
  end
  types.uniq!
  return types
end

#statistics_typesObject


423
424
425
426
427
428
429
430
431
432
433
# File 'lib/traject/umich_format/bib_types.rb', line 423

def statistics_types

  if bib_format == 'BK'
    return ['XS'] if record['008'] && record['008'].value[24..27] =~ /s/
  end

  return ['XS'] if @xv6XX.match? /\AStatistic/i

  # Nope
  return []
end

#video_typesObject

TYP VB Video (Blu-ray) 538## a MATCH Blu-ray TYP VB Video (Blu-ray) 007 F00-05 MATCH v???s TYP VB Video (Blu-ray) 250## a MATCH Blu-ray TYP VB Video (Blu-ray) 852## j MATCH video-b* TYP VB Video (Blu-ray) 852## j MATCH bd-rom*

TYP VD Video (DVD) 538## a MATCH DVD* TYP VD Video (DVD) 007 F04-01 EQUAL v 007 F00-01 EQUAL v TYP VD Video (DVD) 007 F04-01 EQUAL v 008 F33-01 EQUAL v ! ! Visual material: vHs TYP VH Video (VHS) 538## a MATCH VHS* TYP VH Video (VHS) 007 F04-01 EQUAL b 007 F00-01 EQUAL v TYP VH Video (VHS) 007 F04-01 EQUAL b 008 F33-01 EQUAL v ! ! Visual materials: fiLm/video TYP VL Motion Picture 007 F00-01 EQUAL m TYP VL Motion Picture FMT F00-02 EQUAL VM 008 F33-01 EQUAL m


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
# File 'lib/traject/umich_format/bib_types.rb', line 86

def video_types
  types = []

  types << 'VB' if self['538a:250a'].grep(/blu-ray/i).size > 0
  types << 'VB' if self['007[0-5]'].grep(/v...s/i).size > 0
  types << 'VB' if self['852j'].grep(/\A(?:bd-rom|video-b)/i).size > 0

  @record.fields('007').map{|f| f.value}.each do |f|
    if (f[0] == 'v') || self['008[33]'].include?('v')
      types << 'VD' if f[4] == 'v'
      types << 'VH' if f[4] == 'b'
    end
  end


  types << 'VD' if self['538a'].grep(/\Advd(?!\-rom)/i).size > 0

  types << 'VH' if self['538a'].grep(/\AVHS/i).size > 0


  types << 'VL' if self['007[0]'].include?('m')
  types << 'VL' if (self.bib_format == 'VM') && self['008[33]'].include?('m')

  types.uniq!
  return types
end

#videogame_typesObject

TYP VG Video Games FMT F00-02 EQUAL CF 008 F26-01 EQUAL g


544
545
546
547
548
549
550
# File 'lib/traject/umich_format/bib_types.rb', line 544

def videogame_types
  if (bib_format == 'CF') && (self['008[26]'].include? 'g')
    return ['VG']
  else
    return []
  end
end