Class: Stanford::Mods::Record

Inherits:
Mods::Record
  • Object
show all
Defined in:
lib/stanford-mods.rb,
lib/stanford-mods/searchworks.rb

Instance Method Summary collapse

Instance Method Details

#additional_authors_w_datesObject

all names, in display form, except the main_author

names will be the display_value_w_date form
see Mods::Record.name  in nom_terminology for details on the display_value algorithm


39
40
41
42
43
44
45
46
# File 'lib/stanford-mods.rb', line 39

def additional_authors_w_dates
  results = []
  @mods_ng_xml.plain_name.each { |n|  
    results << n.display_value_w_date
  }
  results.delete(main_author_w_date)
  results
end

#catkeyString

Returns value with the numeric catkey in it, or nil if none exists.

Returns:

  • (String)

    value with the numeric catkey in it, or nil if none exists



664
665
666
667
668
669
670
# File 'lib/stanford-mods/searchworks.rb', line 664

def catkey
  catkey=self.term_values([:record_info,:recordIdentifier])
  if catkey and catkey.length>0
    return catkey.first.gsub('a','') #need to ensure catkey is numeric only
  end
  nil
end

#druidObject



674
675
676
# File 'lib/stanford-mods/searchworks.rb', line 674

def druid
  @druid ? @druid : 'Unknown item'
end

#druid=(new_druid) ⇒ Object



671
672
673
# File 'lib/stanford-mods/searchworks.rb', line 671

def druid= new_druid
  @druid=new_druid
end

#era_facetArray<String>

subject/temporal values with trailing comma, semicolon, and backslash (and any preceding spaces) removed

Returns:

  • (Array<String>)

    values for the era_facet Solr field for this document or nil if none



303
304
305
# File 'lib/stanford-mods/searchworks.rb', line 303

def era_facet
  subject_temporal.map { |val| val.sub(/[\\,;]$/, '').strip } unless !subject_temporal
end

#formatArray[String]

Deprecated.
  • kept for backwards compatibility but not part of SW UI redesign work Summer 2014

select one or more format values from the controlled vocabulary here:

http://searchworks-solr-lb.stanford.edu:8983/solr/select?facet.field=format&rows=0&facet.sort=index

Returns:

  • (Array[String])

    value in the SearchWorks controlled vocabulary



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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/stanford-mods/searchworks.rb', line 532

def format
  val = []
  types = self.term_values(:typeOfResource)
  if types
    genres = self.term_values(:genre)
    issuance = self.term_values([:origin_info,:issuance])
    types.each do |type|
      case type
        when 'cartographic'
          val << 'Map/Globe'
        when 'mixed material'
          val << 'Manuscript/Archive'
        when 'moving image'
          val << 'Video'
        when 'notated music'
          val << 'Music - Score'
        when 'software, multimedia'
          val << 'Computer File'
        when 'sound recording-musical'
          val << 'Music - Recording'
        when 'sound recording-nonmusical', 'sound recording'
          val << 'Sound Recording'
        when 'still image'
          val << 'Image'
        when 'text'
          val << 'Book' if issuance and issuance.include? 'monographic'
          book_genres = ['book chapter', 'Book chapter', 'Book Chapter',
            'issue brief', 'Issue brief', 'Issue Brief', 
            'librettos', 'Librettos', 
            'project report', 'Project report', 'Project Report',
            'technical report', 'Technical report', 'Technical Report',
            'working paper', 'Working paper', 'Working Paper']
          val << 'Book' if genres and !(genres & book_genres).empty?
          conf_pub = ['conference publication', 'Conference publication', 'Conference Publication']
          val << 'Conference Proceedings' if genres and !(genres & conf_pub).empty?
          val << 'Journal/Periodical' if issuance and issuance.include? 'continuing'
          article = ['article', 'Article']
          val << 'Journal/Periodical' if genres and !(genres & article).empty?
          stu_proj_rpt = ['student project report', 'Student project report', 'Student Project report', 'Student Project Report']
          val << 'Other' if genres and !(genres & stu_proj_rpt).empty?
          thesis = ['thesis', 'Thesis']
          val << 'Thesis' if genres and !(genres & thesis).empty?
        when 'three dimensional object'
          val << 'Other'
      end
    end
  end
  val.uniq
end

#format_mainArray[String]

select one or more format values from the controlled vocabulary per JVine Summer 2014

http://searchworks-solr-lb.stanford.edu:8983/solr/select?facet.field=format_main_ssim&rows=0&facet.sort=index

Returns:

  • (Array[String])

    value in the SearchWorks controlled vocabulary



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
631
632
633
634
635
636
637
# File 'lib/stanford-mods/searchworks.rb', line 585

def format_main
  val = []
  types = self.term_values(:typeOfResource)
  if types
    genres = self.term_values(:genre)
    issuance = self.term_values([:origin_info,:issuance])
    types.each do |type|
      case type
        when 'cartographic'
          val << 'Map'
        when 'mixed material'
          val << 'Archive/Manuscript'
        when 'moving image'
          val << 'Video'
        when 'notated music'
          val << 'Music score'
        when 'software, multimedia'
          if genres and (genres.include?('dataset') || genres.include?('Dataset'))
            val << 'Dataset'
          else
            val << 'Software/Multimedia'
          end
        when 'sound recording-musical'
          val << 'Music recording'
        when 'sound recording-nonmusical', 'sound recording'
          val << 'Sound recording'
        when 'still image'
          val << 'Image'
        when 'text'
          article_genres = ['article', 'Article',
            'book chapter', 'Book chapter', 'Book Chapter',
            'issue brief', 'Issue brief', 'Issue Brief',
            'project report', 'Project report', 'Project Report',
            'student project report', 'Student project report', 'Student Project report', 'Student Project Report',
            'technical report', 'Technical report', 'Technical Report',
            'working paper', 'Working paper', 'Working Paper'
            ]
          val << 'Book' if genres and !(genres & article_genres).empty?
          val << 'Book' if issuance and issuance.include? 'monographic'
          book_genres = ['conference publication', 'Conference publication', 'Conference Publication',
            'instruction', 'Instruction',
            'librettos', 'Librettos',
            'thesis', 'Thesis'
            ]
          val << 'Book' if genres and !(genres & book_genres).empty?
          val << 'Journal/Periodical' if issuance and issuance.include? 'continuing'
        when 'three dimensional object'
          val << 'Object'
      end
    end
  end
  val.uniq
end

#geographic_facetArray<String>

geographic_search values with trailing comma, semicolon, and backslash (and any preceding spaces) removed

Returns:

  • (Array<String>)

    values for the geographic_facet Solr field for this document or nil if none



297
298
299
# File 'lib/stanford-mods/searchworks.rb', line 297

def geographic_facet
  geographic_search.map { |val| val.sub(/[\\,;]$/, '').strip } unless !geographic_search
end

#geographic_searchArray<String>

Values are the contents of:

subject/geographic
subject/hierarchicalGeographic
subject/geographicCode  (only include the translated value if it isn't already present from other mods geo fields)

Returns:

  • (Array<String>)

    values for the geographic_search Solr field for this document or nil if none



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/stanford-mods/searchworks.rb', line 312

def geographic_search
  @geographic_search ||= begin
    result = self.sw_geographic_search

    # TODO:  this should go into stanford-mods ... but then we have to set that gem up with a Logger
    # print a message for any unrecognized encodings
    xvals = self.subject.geographicCode.translated_value
    codes = self.term_values([:subject, :geographicCode]) 
    if codes && codes.size > xvals.size
      self.subject.geographicCode.each { |n|
        if n.authority != 'marcgac' && n.authority != 'marccountry'
          sw_logger.info("#{druid} has subject geographicCode element with untranslated encoding (#{n.authority}): #{n.to_xml}")
        end
      }
    end

    # FIXME:  stanford-mods should be returning [], not nil ... 
    return nil if !result || result.empty?
    result
  end
end

#get_bc_year(dates) ⇒ Object

get the 3 digit BC year, return it as a negative, so -700 for 300 BC. Other methods will translate it to proper display, this is good for sorting.



783
784
785
786
787
788
789
790
791
792
# File 'lib/stanford-mods/searchworks.rb', line 783

def get_bc_year dates
  dates.each do |f_date|
    matches=f_date.scan(/\d{3} B.C./)
    if matches.length > 0   
      bc_year=matches.first[0..2]
      return (bc_year.to_i-1000).to_s
    end
  end
  return nil
end

#get_double_digit_century(dates) ⇒ Object

get a double digit century like ‘12th century’ from the date array



749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
# File 'lib/stanford-mods/searchworks.rb', line 749

def get_double_digit_century dates
  dates.each do |f_date|
    matches=f_date.scan(/\d{2}th/)
    if matches.length == 1
      @pub_year=((matches.first[0,2].to_i)-1).to_s+'--'
      return @pub_year
    end
    #if there are multiples, check for ones with CE after them
    if matches.length > 0
      matches.each do |match|
        pos = f_date.index(Regexp.new(match+'...CE'))
        pos = pos ? pos.to_i : f_date.index(Regexp.new(match+' century CE'))
        pos = pos ? pos.to_i : 0
        if f_date.include?(match+' CE') or pos > 0
          @pub_year=((match[0,2].to_i) - 1).to_s+'--'
          return @pub_year
        end 
      end
    end
  end
  return nil
end

#get_plain_four_digit_year(dates) ⇒ Object

get a 4 digit year like 1865 from the date array



706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
# File 'lib/stanford-mods/searchworks.rb', line 706

def get_plain_four_digit_year dates
  dates.each do |f_date|
    matches=f_date.scan(/\d{4}/)
    if matches.length == 1
      @pub_year=matches.first 
      return matches.first
    else
      #if there are multiples, check for ones with CE after them
      matches.each do |match|
        #look for things like '1865-6 CE'
        pos = f_date.index(Regexp.new(match+'...CE'))
        pos = pos ? pos.to_i : 0
        if f_date.include?(match+' CE') or pos > 0
          @pub_year=match
          return match  
        end 
      end
      return matches.first
    end
  end
  return nil
end

#get_single_digit_century(dates) ⇒ Object

get a single digit century like ‘9th century’ from the date array



795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
# File 'lib/stanford-mods/searchworks.rb', line 795

def get_single_digit_century dates
  dates.each do |f_date|
    matches=f_date.scan(/\d{1}th/)
    if matches.length == 1
      @pub_year=((matches.first[0,2].to_i)-1).to_s+'--'
      return @pub_year
    end
    #if there are multiples, check for ones with CE after them
    if matches.length > 0
      matches.each do |match|
        pos = f_date.index(Regexp.new(match+'...CE'))
        pos = pos ? pos.to_i : f_date.index(Regexp.new(match+' century CE'))
        pos = pos ? pos.to_i : 0
        if f_date.include?(match+' CE') or pos > 0
          @pub_year=((match[0,1].to_i) - 1).to_s+'--'
          return @pub_year
        end 
      end
    end
  end 
  return nil
end

#get_three_digit_year(dates) ⇒ Object

get a 3 digit year like 965 from the date array



773
774
775
776
777
778
779
780
781
# File 'lib/stanford-mods/searchworks.rb', line 773

def get_three_digit_year dates
  dates.each do |f_date|
    matches=f_date.scan(/\d{3}/)
    if matches.length > 0
      return matches.first
    end
  end
  return nil
end

#get_u_year(dates) ⇒ Object

If a year has a “u” in it, replace instances of u with 0

Parameters:

  • dates (String)

Returns:

  • String



732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
# File 'lib/stanford-mods/searchworks.rb', line 732

def get_u_year dates
  dates.each do |f_date|
    # Single digit u notation
    matches = f_date.scan(/\d{3}u/)
    if matches.length == 1
      return matches.first.gsub('u','0')
    end
    # Double digit u notation
    matches = f_date.scan(/\d{2}u{2}/)
    if matches.length == 1
      return matches.first.gsub('u','-')
    end
  end
  return nil
end

#is_date?(object) ⇒ Boolean

Returns:

  • (Boolean)


437
438
439
# File 'lib/stanford-mods/searchworks.rb', line 437

def is_date?(object)
  true if Date.parse(object) rescue false
end

#is_number?(object) ⇒ Boolean

Returns:

  • (Boolean)


434
435
436
# File 'lib/stanford-mods/searchworks.rb', line 434

def is_number?(object)
  true if Integer(object) rescue false
end

#main_author_w_dateString

the first encountered <mods><name> element with marcrelator flavor role of ‘Creator’ or ‘Author’. if no marcrelator ‘Creator’ or ‘Author’, the first name without a role. if no name without a role, then nil see Mods::Record.name in nom_terminology for details on the display_value algorithm

Returns:

  • (String)

    a name in the display_value_w_date form



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stanford-mods.rb', line 16

def main_author_w_date
  result = nil
  first_wo_role = nil
  @mods_ng_xml.plain_name.each { |n|
    if n.role.size == 0
      first_wo_role ||= n
    end
    n.role.each { |r|
      if r.authority.include?('marcrelator') && 
            (r.value.include?('Creator') || r.value.include?('Author'))
        result ||= n.display_value_w_date
      end          
    }
  }
  if !result && first_wo_role
    result = first_wo_role.display_value_w_date
  end
  result
end

#main_author_w_date_testObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/stanford-mods/searchworks.rb', line 97

def main_author_w_date_test
  result = nil
  first_wo_role = nil
  self.plain_name.each { |n|
    if n.role.size == 0
      first_wo_role ||= n
    end
    n.role.each { |r|
      if r.authority.include?('marcrelator') && 
        (r.value.include?('Creator') || r.value.include?('Author'))
        result ||= n.display_value_w_date
      end          
    }
  }
  if !result && first_wo_role
    result = first_wo_role.display_value_w_date
  end
  result
end

#placeObject

—- PUBLICATION (place, year) —-



381
382
383
384
# File 'lib/stanford-mods/searchworks.rb', line 381

def place
  vals = self.term_values([:origin_info,:place,:placeTerm])
  vals
end

#pub_dateString

The year the object was published, , filtered based on max_pub_date and min_pub_date from the config file

Returns:

  • (String)

    4 character year or nil



494
495
496
497
498
499
500
# File 'lib/stanford-mods/searchworks.rb', line 494

def pub_date
  val=pub_year
  if val
    return val
  end
  nil
end

#pub_date_displayObject



386
387
388
389
390
391
392
# File 'lib/stanford-mods/searchworks.rb', line 386

def pub_date_display
  if pub_dates
    pub_dates.first
  else
    nil
  end
end

#pub_date_facetArray[String]

Values for the pub date facet. This is less strict than the 4 year date requirements for pub_date

Returns:

  • (Array[String])

    with values for the pub date facet



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/stanford-mods/searchworks.rb', line 504

def pub_date_facet
  if pub_date
    if pub_date.start_with?('-')
      return (pub_date.to_i + 1000).to_s + ' B.C.'
    end
    if pub_date.include? '--'
      cent=pub_date[0,2].to_i
      cent+=1
      cent=cent.to_s+'th century'
      return cent
    else
      return pub_date
    end
  else
    nil
  end
end

#pub_date_groups(year) ⇒ Array<String>

Deprecated.

Returns values for the pub_date_group_facet.

Returns:

  • (Array<String>)

    values for the pub_date_group_facet



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/stanford-mods/searchworks.rb', line 396

def pub_date_groups year
  if not year
    return nil
  end
  year=year.to_i
  current_year=Time.new.year.to_i
  result = []
  if year >= current_year - 1
    result << "This year"
  else
    if year >= current_year - 3
      result << "Last 3 years"
    else
      if year >= current_year - 10
        result << "Last 10 years"
      else
        if year >= current_year - 50
          result << "Last 50 years"
        else
          result << "More than 50 years ago"
        end
      end
    end
  end
end

#pub_date_sortObject

creates a date suitable for sorting. Guarnteed to be 4 digits or nil



479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/stanford-mods/searchworks.rb', line 479

def pub_date_sort
  pd=nil
  if pub_date
    pd=pub_date
    if pd.length == 3
      pd='0'+pd
    end
    pd=pd.gsub('--','00')
  end
  raise "pub_date_sort was about to return a non 4 digit value #{pd}!" if pd and pd.length !=4 
  pd
end

#pub_datesArray<String>

get the dates from dateIssued, and dateCreated merged into 1 array.

Returns:

  • (Array<String>)

    values for the issue_date_display Solr field for this document or nil if none



424
425
426
427
428
429
430
431
432
# File 'lib/stanford-mods/searchworks.rb', line 424

def pub_dates
  vals = self.term_values([:origin_info,:dateIssued])
  if vals
    vals = vals.concat self.term_values([:origin_info,:dateCreated]) unless not self.term_values([:origin_info,:dateCreated])
  else
    vals = self.term_values([:origin_info,:dateCreated])
  end
  vals and vals.empty? ? nil : vals
end

#pub_yearString

Get the publish year from mods

Returns:

  • (String)

    4 character year or nil if no valid date was found



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
# File 'lib/stanford-mods/searchworks.rb', line 443

def pub_year
  #use the cached year if there is one
  if @pub_year
    if @pub_year == ''
      return nil
    end
    return @pub_year
  end
  dates = pub_dates
  if dates
    year = []
    pruned_dates = []
    dates.each do |f_date|
      #remove ? and [] 
      pruned_dates << f_date.gsub('?','').gsub('[','').gsub(']','')
    end
    #try to find a date starting with the most normal date formats and progressing to more wonky ones
    @pub_year = get_plain_four_digit_year pruned_dates
    return @pub_year if @pub_year
    # Check for years in u notation, e.g., 198u
    @pub_year = get_u_year pruned_dates
    return @pub_year if @pub_year
    @pub_year = get_double_digit_century pruned_dates
    return @pub_year if @pub_year
    @pub_year = get_bc_year pruned_dates
    return @pub_year if @pub_year
    @pub_year = get_three_digit_year pruned_dates
    return @pub_year if @pub_year
    @pub_year = get_single_digit_century pruned_dates
    return @pub_year if @pub_year
  end
  @pub_year=''
  return nil
end

#subject_all_searchArray<String>

Values are the contents of:

all subject subelements except subject/cartographic plus  genre top level element

Returns:

  • (Array<String>)

    values for the subject_all_search Solr field for this document or nil if none



370
371
372
373
374
375
376
# File 'lib/stanford-mods/searchworks.rb', line 370

def subject_all_search
  vals = topic_search ? Array.new(topic_search) : []
  vals.concat(geographic_search) if geographic_search
  vals.concat(subject_other_search) if subject_other_search
  vals.concat(subject_other_subvy_search) if subject_other_subvy_search
  vals.empty? ? nil : vals
end

#subject_namesObject

convenience method for subject/name/namePart values (to avoid parsing the mods for the same thing multiple times)



681
682
683
# File 'lib/stanford-mods/searchworks.rb', line 681

def subject_names
  @subject_names ||= self.sw_subject_names
end

#subject_occupationsObject

convenience method for subject/occupation values (to avoid parsing the mods for the same thing multiple times)



686
687
688
# File 'lib/stanford-mods/searchworks.rb', line 686

def subject_occupations
  @subject_occupations ||= self.term_values([:subject, :occupation])
end

#subject_other_searchArray<String>

Values are the contents of:

subject/name
subject/occupation  - no subelements
subject/titleInfo

Returns:

  • (Array<String>)

    values for the subject_other_search Solr field for this document or nil if none



339
340
341
342
343
344
345
346
# File 'lib/stanford-mods/searchworks.rb', line 339

def subject_other_search
  @subject_other_search ||= begin
    vals = subject_occupations ? Array.new(subject_occupations) : []
    vals.concat(subject_names) if subject_names
    vals.concat(subject_titles) if subject_titles
    vals.empty? ? nil : vals
  end
end

#subject_other_subvy_searchArray<String>

Values are the contents of:

subject/temporal
subject/genre

Returns:

  • (Array<String>)

    values for the subject_other_subvy_search Solr field for this document or nil if none



352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/stanford-mods/searchworks.rb', line 352

def subject_other_subvy_search
  @subject_other_subvy_search ||= begin
    vals = subject_temporal ? Array.new(subject_temporal) : []
    gvals = self.term_values([:subject, :genre])
    vals.concat(gvals) if gvals

    # print a message for any temporal encodings
    self.subject.temporal.each { |n| 
      sw_logger.info("#{druid} has subject temporal element with untranslated encoding: #{n.to_xml}") if !n.encoding.empty?
    }

    vals.empty? ? nil : vals
  end
end

#subject_temporalObject

convenience method for subject/temporal values (to avoid parsing the mods for the same thing multiple times)



691
692
693
# File 'lib/stanford-mods/searchworks.rb', line 691

def subject_temporal
  @subject_temporal ||= self.term_values([:subject, :temporal])
end

#subject_titlesObject

convenience method for subject/titleInfo values (to avoid parsing the mods for the same thing multiple times)



696
697
698
# File 'lib/stanford-mods/searchworks.rb', line 696

def subject_titles
  @subject_titles ||= self.sw_subject_titles
end

#subject_topicsObject

convenience method for subject/topic values (to avoid parsing the mods for the same thing multiple times)



701
702
703
# File 'lib/stanford-mods/searchworks.rb', line 701

def subject_topics
  @subject_topics ||= self.term_values([:subject, :topic])
end

#sw_addl_authorsArray<String>

Returns values for author_7xx_search field.

Returns:

  • (Array<String>)

    values for author_7xx_search field



61
62
63
# File 'lib/stanford-mods/searchworks.rb', line 61

def sw_addl_authors
  additional_authors_w_dates
end

#sw_addl_titlesArray<String>

this includes all titles except

Returns:

  • (Array<String>)

    values for title_variant_search



177
178
179
# File 'lib/stanford-mods/searchworks.rb', line 177

def sw_addl_titles
  full_titles.select { |s| s !~ Regexp.new(Regexp.escape(sw_short_title)) }
end

#sw_corporate_authorsArray<String>

Returns values for author_corp_display.

Returns:

  • (Array<String>)

    values for author_corp_display



77
78
79
80
# File 'lib/stanford-mods/searchworks.rb', line 77

def sw_corporate_authors
  val = @mods_ng_xml.plain_name.select {|n| n.type_at == 'corporate'}.map { |n| n.display_value_w_date }
  val
end

#sw_full_titleString

Returns value for title_245_search, title_full_display.

Returns:

  • (String)

    value for title_245_search, title_full_display



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/stanford-mods/searchworks.rb', line 127

def sw_full_title
  outer_nodes = @mods_ng_xml.title_info
  outer_node = outer_nodes ? outer_nodes.first : nil
  if outer_node
    nonSort = outer_node.nonSort.text.strip.empty? ? nil : outer_node.nonSort.text.strip
    title = outer_node.title.text.strip.empty? ? nil: outer_node.title.text.strip
    preSubTitle = nonSort ? [nonSort, title].compact.join(" ") : title
    preSubTitle.sub!(/:$/, '') if preSubTitle # remove trailing colon

    subTitle = outer_node.subTitle.text.strip
    preParts = subTitle.empty? ? preSubTitle : preSubTitle + " : " + subTitle
    preParts.sub!(/\.$/, '') if preParts # remove trailing period
    
    partName = outer_node.partName.text.strip unless outer_node.partName.text.strip.empty?
    partNumber = outer_node.partNumber.text.strip unless outer_node.partNumber.text.strip.empty?
    partNumber.sub!(/,$/, '') if partNumber # remove trailing comma
    if partNumber && partName
      parts = partNumber + ", " + partName
    elsif partNumber
      parts = partNumber
    elsif partName
      parts = partName
    end
    parts.sub!(/\.$/, '') if parts

    result = parts ? preParts + ". " + parts : preParts
    result += "." if !result.match(/[[:punct:]]$/)
    result.strip!
    result = nil if result.empty?
    result
  else
    nil
  end
end

#sw_full_title_without_commasObject

Deprecated.

in favor of sw_title_display

remove trailing commas



199
200
201
202
203
# File 'lib/stanford-mods/searchworks.rb', line 199

def sw_full_title_without_commas
  result = self.sw_full_title
  result.sub!(/,$/, '') if result
  result
end

#sw_genreArray[String]

return values for the genre facet in SearchWorks

Returns:

  • (Array[String])


641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/stanford-mods/searchworks.rb', line 641

def sw_genre
  val = []
  genres = self.term_values(:genre)
  if genres
    val << genres.map(&:capitalize)
    val.flatten! if !val.empty?
    if genres.include?('thesis') || genres.include?('Thesis')
      val << 'Thesis/Dissertation'
      val.delete 'Thesis'
    end
    conf_pub = ['conference publication', 'Conference publication', 'Conference Publication']
    if !(genres & conf_pub).empty?
      types = self.term_values(:typeOfResource)
      if types && types.include?('text')
        val << 'Conference proceedings'
        val.delete 'Conference publication'
      end
    end
  end
  val.uniq
end

#sw_geographic_search(sep = ' ') ⇒ Array<String>

Values are the contents of:

subject/geographic
subject/hierarchicalGeographic
subject/geographicCode  (only include the translated value if it isn't already present from other mods geo fields)

Parameters:

  • sep (String) (defaults to: ' ')
    • the separator string for joining hierarchicalGeographic sub elements

Returns:

  • (Array<String>)

    values for geographic_search Solr field for this document or [] if none



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/stanford-mods/searchworks.rb', line 215

def sw_geographic_search(sep = ' ')
  result = term_values([:subject, :geographic]) || []
  
  # hierarchicalGeographic has sub elements
  @mods_ng_xml.subject.hierarchicalGeographic.each { |hg_node|  
    hg_vals = []
    hg_node.element_children.each { |e| 
      hg_vals << e.text unless e.text.empty?
    }
    result << hg_vals.join(sep) unless hg_vals.empty?
  }

  trans_code_vals = @mods_ng_xml.subject.geographicCode.translated_value
  if trans_code_vals
    trans_code_vals.each { |val|  
      result << val if !result.include?(val)
    }
  end

  result    
end

#sw_impersonal_authorsArray<String>

return the display_value_w_date for all <mods><name> elements that do not have type=‘personal’

Returns:

  • (Array<String>)

    values for author_other_facet



72
73
74
# File 'lib/stanford-mods/searchworks.rb', line 72

def sw_impersonal_authors
  @mods_ng_xml.plain_name.select {|n| n.type_at != 'personal'}.map { |n| n.display_value_w_date }
end

#sw_language_facetObject

include langagues known to SearchWorks; try to error correct when possible (e.g. when ISO-639 disagrees with MARC standard)



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/stanford-mods/searchworks.rb', line 11

def sw_language_facet
  result = []
  @mods_ng_xml.language.each { |n| 
    # get languageTerm codes and add their translations to the result
    n.code_term.each { |ct| 
      if ct.authority.match(/^iso639/)
        begin
          vals = ct.text.split(/[,|\ ]/).reject {|x| x.strip.length == 0 } 
          vals.each do |v|
            iso639_val = ISO_639.find(v.strip).english_name
            if SEARCHWORKS_LANGUAGES.has_value?(iso639_val)
              result << iso639_val
            else
              result << SEARCHWORKS_LANGUAGES[v.strip]
            end
          end
        rescue => e
          # TODO:  this should be written to a logger
          p "Couldn't find english name for #{ct.text}"
        end
      else
        vals = ct.text.split(/[,|\ ]/).reject {|x| x.strip.length == 0 } 
        vals.each do |v|
          result << SEARCHWORKS_LANGUAGES[v.strip]
        end
      end
    }
    # add languageTerm text values
    n.text_term.each { |tt| 
      val = tt.text.strip
      result << val if val.length > 0 && SEARCHWORKS_LANGUAGES.has_value?(val)
    }

    # add language values that aren't in languageTerm subelement
    if n.languageTerm.size == 0
      result << n.text if SEARCHWORKS_LANGUAGES.has_value?(n.text)
    end
  }
  result.uniq
end

#sw_loggerObject

—- end PUBLICATION (place, year) —-



524
525
526
# File 'lib/stanford-mods/searchworks.rb', line 524

def sw_logger
  @logger ||= Logger.new(STDOUT)
end

#sw_main_authorString

Returns value for author_1xx_search field.

Returns:

  • (String)

    value for author_1xx_search field



56
57
58
# File 'lib/stanford-mods/searchworks.rb', line 56

def sw_main_author
  main_author_w_date
end

#sw_meeting_authorsArray<String>

Returns values for author_meeting_display.

Returns:

  • (Array<String>)

    values for author_meeting_display



83
84
85
# File 'lib/stanford-mods/searchworks.rb', line 83

def sw_meeting_authors
  @mods_ng_xml.plain_name.select {|n| n.type_at == 'conference'}.map { |n| n.display_value_w_date }
end

#sw_person_authorsArray<String>

Returns values for author_person_facet, author_person_display.

Returns:

  • (Array<String>)

    values for author_person_facet, author_person_display



66
67
68
# File 'lib/stanford-mods/searchworks.rb', line 66

def sw_person_authors
  personal_names_w_dates
end

#sw_short_titleString

Returns value for title_245a_search field.

Returns:

  • (String)

    value for title_245a_search field



122
123
124
# File 'lib/stanford-mods/searchworks.rb', line 122

def sw_short_title
  short_titles ? short_titles.first : nil
end

#sw_sort_authorString

Returns a sortable version of the main_author:

main_author + sorting title

which is the mods approximation of the value created for a marc record

Returns:

  • (String)

    value for author_sort field



91
92
93
94
95
# File 'lib/stanford-mods/searchworks.rb', line 91

def sw_sort_author
  #  substitute java Character.MAX_CODE_POINT for nil main_author so missing main authors sort last
  val = '' + (main_author_w_date ? main_author_w_date : "\u{FFFF} ") + ( sort_title ? sort_title : '')
  val.gsub(/[[:punct:]]*/, '').strip
end

#sw_sort_titleString

Returns a sortable version of the main title

Returns:

  • (String)

    value for title_sort field



183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/stanford-mods/searchworks.rb', line 183

def sw_sort_title
  # get nonSort piece
  outer_nodes = @mods_ng_xml.title_info
  outer_node = outer_nodes ? outer_nodes.first : nil
  if outer_node
    nonSort = outer_node.nonSort.text.strip.empty? ? nil : outer_node.nonSort.text.strip
  end
  
  val = '' + ( sw_full_title ? sw_full_title : '')
  val.sub!(Regexp.new("^" + nonSort), '') if nonSort
  val.gsub!(/[[:punct:]]*/, '').strip
  val.squeeze(" ").strip
end

#sw_subject_names(sep = ', ') ⇒ Array<String>

Values are the contents of:

 subject/name/namePart
"Values from namePart subelements should be concatenated in the order they appear (e.g. "Shakespeare, William, 1564-1616")"

Parameters:

  • sep (String) (defaults to: ', ')
    • the separator string for joining namePart sub elements

Returns:

  • (Array<String>)

    values for names inside subject elements or [] if none



242
243
244
245
246
247
248
249
# File 'lib/stanford-mods/searchworks.rb', line 242

def sw_subject_names(sep = ', ')
  result = []
  @mods_ng_xml.subject.name_el.select { |n_el| n_el.namePart }.each { |name_el_w_np|  
    parts = name_el_w_np.namePart.map { |npn| npn.text unless npn.text.empty? }.compact
    result << parts.join(sep).strip unless parts.empty?
  }
  result
end

#sw_subject_titles(sep = ' ') ⇒ Array<String>

Values are the contents of:

subject/titleInfo/(subelements)

Parameters:

  • sep (String) (defaults to: ' ')
    • the separator string for joining titleInfo sub elements

Returns:

  • (Array<String>)

    values for titles inside subject elements or [] if none



255
256
257
258
259
260
261
262
# File 'lib/stanford-mods/searchworks.rb', line 255

def sw_subject_titles(sep = ' ')
  result = []
  @mods_ng_xml.subject.titleInfo.each { |ti_el|
    parts = ti_el.element_children.map { |el| el.text unless el.text.empty? }.compact
    result << parts.join(sep).strip unless parts.empty?
  }
  result
end

#sw_title_displayString

like sw_full_title without trailing ,/;:. spec from solrmarc-sw sw_index.properties

title_display = custom, removeTrailingPunct(245abdefghijklmnopqrstuvwxyz, [\\\\,/;:], ([A-Za-z]{4}|[0-9]{3}|\\)|\\,))

Returns:

  • (String)

    value for title_display (like title_full_display without trailing punctuation)



166
167
168
169
170
171
172
173
# File 'lib/stanford-mods/searchworks.rb', line 166

def sw_title_display
  result = sw_full_title ? sw_full_title : nil
  if result
    result.sub!(/[\.,;:\/\\]+$/, '')
    result.strip!
  end
  result
end

#topic_facetArray<String>

Values are the contents of:

 subject/topic
 subject/name
 subject/title
 subject/occupation
with trailing comma, semicolon, and backslash (and any preceding spaces) removed

Returns:

  • (Array<String>)

    values for the topic_facet Solr field for this document or nil if none



283
284
285
286
287
288
289
290
291
292
293
# File 'lib/stanford-mods/searchworks.rb', line 283

def topic_facet
  vals = subject_topics ? Array.new(subject_topics) : []
  vals.concat(subject_names) if subject_names
  vals.concat(subject_titles) if subject_titles
  vals.concat(subject_occupations) if subject_occupations
  vals.map! { |val| 
    v = val.sub(/[\\,;]$/, '')
    v.strip
  }
  vals.empty? ? nil : vals
end

#topic_searchArray<String>

Values are the contents of:

mods/genre
mods/subject/topic

Returns:

  • (Array<String>)

    values for the topic_search Solr field for this document or nil if none



268
269
270
271
272
273
274
# File 'lib/stanford-mods/searchworks.rb', line 268

def topic_search
  @topic_search ||= begin
    vals = self.term_values(:genre) || []
    vals.concat(subject_topics) if subject_topics
    vals.empty? ? nil : vals
  end
end