Module: MarcXMLBaseMap

Included in:
MarcXMLConverter
Defined in:
backend/app/converters/lib/marcxml_base_map.rb

Constant Summary

AUTH_SUBJECT_SOURCE =
{
  'a'=>"Library of Congress Subject Headings",
  'b'=>"LC subject headings for children's literature",
  'c'=>"Medical Subject Headings",
  'd'=>"National Agricultural Library subject authority file",
  'k'=>"Canadian Subject Headings",
  'n'=>"Not applicable",
  'r'=>"Art and Architecture Thesaurus",
  's'=>"Sears List of Subject Headings",
  'v'=>"R\u00E9pertoire de vedettes-matic\u00E8re",
  'z'=>"Other"
}
BIB_SUBJECT_SOURCE =
{
  '0'=>"Library of Congress Subject Headings",
  '1'=>"LC subject headings for children's literature",
  '2'=>"Medical Subject Headings",
  '3'=>"National Agricultural Library subject authority file",
  '4'=>"Source not specified",
  '5'=>"Canadian Subject Headings",
  '6'=>"R\u00E9pertoire de vedettes-matic\u00E8re"
}

Instance Method Summary (collapse)

Instance Method Details

- (Object) adds_agent_term(term_type, prefix = "")



393
394
395
396
397
398
399
400
401
402
403
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 393

def adds_agent_term(term_type, prefix = "")
  -> agent, node {
    agent['_terms'] ||= []
    make(:term) do |term|
      term.term_type = term_type
      term.term = "#{prefix}: #{node.inner_text}"
      term.vocabulary = '/vocabularies/1'
      agent['_terms'] << term
    end
  }
end

- (Object) adds_prefixed_qualifier(prefix, separator = ': ')



469
470
471
472
473
474
475
476
477
478
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 469

def adds_prefixed_qualifier(prefix, separator = ': ')
  -> name, node {
    val = node.inner_text
    if val
      name.qualifier ||= ""
      name.qualifier += " " unless name.qualifier.empty?
      name.qualifier += prefix + separator + val + "."
    end
  }
end

- (Object) agent_as_subject

agents derived from 600 fields



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 308

def agent_as_subject
  {
    :map => {
      "subfield[@code='v']" => adds_agent_term('genre_form'),
      "subfield[@code='x']" => adds_agent_term('topical'),
      "subfield[@code='y']" => adds_agent_term('temporal'),
      "subfield[@code='z']" => adds_agent_term('geographic'),
      "self::datafield" => {
        :map => {
          "@ind1" => sets_name_order_from_ind1,
          "@ind2" => sets_name_source_from_code,
          "subfield[@code='2']" => sets_other_name_source
        }
      }
    }
  }
end

- (Object) agent_template



73
74
75
76
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
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 73

def agent_template
  {
    :rel => -> resource, agent {
      resource[:linked_agents] << {
        # stashed value for the role
        :role => agent['_role'] || 'subject',
        :terms => agent['_terms'] || [],
        :relator => agent['_relator'],
        :ref => agent.uri
      }
    },
    :map => {
      "subfield[@code='e']" => -> agent, node {
        agent['_relator'] = node.inner_text
      },
      "subfield[@code='4']" => -> agent, node {
        agent['_relator'] = node.inner_text unless agent['_relator']
      },
      "self::datafield" => {
        :defaults => {
          :name_order => 'direct',
          :source => 'ingest'
        
        
        }
      }
    }
  }
end

- (Object) appends_subordinate_name_2



481
482
483
484
485
486
487
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 481

def appends_subordinate_name_2
  -> name, node {
    name.subordinate_name_2 ||= ""
    name.subordinate_name_2 += " " unless name.subordinate_name_2.empty?
    name.subordinate_name_2 += node.inner_text
  }
end

- (Object) BASE_RECORD_MAP

this should be called ‘build_base_map’ because the extending class calls it when it is configuring itself, and the result may depend on methods defined in the extending class.



569
570
571
572
573
574
575
576
577
578
579
580
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
631
632
633
634
635
636
637
638
639
640
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
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 569

def BASE_RECORD_MAP
  {
    :obj => :resource,
    :defaults => {
     :level => 'collection',
    },
    :map => {
      #LEADER
      "//leader" =>  -> resource, node { 
        values = node.inner_text.strip
        set_record_type values[6]

        if resource.respond_to?(:level)
          resource.level = "item" if  values[7] == 'm'  
        end 
      }, 

      #CONTROLFIELD
      "//controlfield[@tag='008']" => -> resource, node {
        control = node.inner_text.strip
        set_record_type nil, control[11]
        resource.language = control[35..37]

        if %w(i k s).include?(control[6])
          make(:date) do |date|
            date.label = 'creation'
            date.date_type = {'i' => 'inclusive',
              'k' => 'bulk',
              's' => 'single'}[control[6]]

            if control[7..10] && control[7..10].match(/^\d{4}$/)
              date.begin = control[7..10]
            end

            if control[11..14] && control[11..14].match(/^\d{4}$/)
              date.end = control[11..14]
            end

            resource.dates << date
          end
        end
      },

      # ID_0, ID_1, ID_2, ID_3
      "datafield[@tag='852']" => -> resource, node {
        id = concatenate_subfields(%w(k h i m), node, '_')
        resource.id_0 = id unless id.empty?
      },


      "datafield[@tag='090']" => -> resource, node {
        if resource.id_0.nil? or resource.id_0.empty?
          id = concatenate_subfields(('a'..'z'), node, '_')
          resource.id_0 = id unless id.empty?
        end
      },

      # description rules
      "datafield[@tag='040']/subfield[@code='e']" => :finding_aid_description_rules,

      # 200s
      "datafield[@tag='210']" => mix(multipart_note('odd', "Abbreviated Title", "{$a: }{$b }{($2)}"), is_fallback_resource_title),

      "datafield[@tag='222']" => mix(multipart_note('odd', "Abbreviated Title", "{$a: }{$b }{($2)}"), is_fallback_resource_title),

      "datafield[@tag='240']" => mix(multipart_note('odd', 'Uniform Title', %q|
                                              $a ({Date of treaty signing-$d; }
                                              {Date of work-$f; }{Medium-$h; }
                                              {Language-$l; }
                                              Medium of performance-$m value;
                                              Arranged statement of performance-$o;
                                              Name of part / section-$p;
                                              Number of part / section-$n; Key for music-$r;
                                              Version-$s; Form subdivision-$k; Miscellaneous-$g)
                                              |), is_fallback_resource_title),

      "datafield[@tag='242']" => multipart_note('odd',  'Translation of Title', "{$a: }{$b }{[$h] }{$n, }{$p, }{$y}){ / $c}"),

      # TITLE
      "datafield[@tag='245']" => -> resource, node {
        resource.title = subfield_template("{$a : }{$b }{[$h] }{$k , }{$n , }{$p , }{$s }{/ $c}", node)

        expression = concatenate_subfields(%w(f g), node, '-')
        unless expression.empty?
          if resource.dates[0]
            resource.dates[0]['expression'] = expression
          else
            make(:date)  do |date|
              date.label = 'creation'
              date.date_type = 'inclusive'
              date.expression = expression
              resource.dates << date
            end
          end
        else
          resource['_needs_date'] = true
        end
      },

      "datafield[@tag='246'][@ind2='0']" => multipart_note('odd',
                                                           -> node {
                                                             {
                                                               '0'=>'Portion of title',
                                                               '1'=>'Parallel title',
                                                               '2'=>'Distinctive title',
                                                               '3'=>'Other title',
                                                               '4'=>'Cover title',
                                                               '5'=>'Added title page title',
                                                               '6'=>'Caption title',
                                                               '7'=>'Running title',
                                                               '8'=>'Spine title'
                                                             }[node.attr('ind2')]
                                                           },
                                                           "{$a: }{$b }{[$h] }{$f, }{$n }{$p, }{$g})"
                                                           ),

      "datafield[@tag='250']" => multipart_note('odd', 'Edition Statement', "{$a} / {$b}"),

      "datafield[@tag='254']" => multipart_note('odd', 'Musical Presentation Statement', "{$a}"),

      "datafield[@tag='255']" => multipart_note('odd', 'Mathematical map data', %q|
                                          Statement of scale--{$a}; Statement of projection--{$b}; Statement of
                                          coordinates--{$c}; Statement of zone--{$d}; Statement of equinox--{$e};
                                          Ourter G-ring coordinate pairs--{$f}; ExclusionG-ring coordinate pairs--{$g}.
                                          |),

      "datafield[@tag='256']" => singlepart_note('physdesc', 'Computer file Characteristics', "{$a}"),

      "datafield[@tag='257']" => multipart_note('odd', 'Country of Producing Entity for Archival Films', "{$a}"),

      "datafield[@tag='258']" => multipart_note('odd', 'Stamp description', "{$a}, {$b}."),

      "datafield[@tag='260']" => mix(multipart_note('odd', 'Publication Date', "{$c}"), {
                                       "self::datafield" => -> resource, node {
                                         if resource['_needs_date']
                                           make(:date) do |date|
                                             date.label = 'publication'
                                             date.date_type = 'single'
                                             date.expression = node.xpath("subfield[@code='c']")
                                             resource.dates << date
                                           end
                                         end
                                       }
                                     }),

      # 300s
      # EXTENTS
      "datafield[@tag='300']" => {
        :obj => :extent,
        :rel => :extents,
        :map => {
          "self::datafield" => -> extent, node {  
            ex = node.xpath('.//subfield[@code="a"]') 
            if ex.length > 0
              ext = ex.first.text 
              if ext =~ /^([0-9\.]+)+\s+(.*)$/
                extent.number = $1
                extent.extent_type = $2
              end 
            end
            
            extent.container_summary = subfield_template("{$3: }{$a }{$b, }{$c }({$e, }{$f, }{$g})", node)
          }
        },
        :defaults => {:portion => 'whole', :number => '1', :extent_type => 'linear_feet'}
      },

      "datafield[@tag='306']" => singlepart_note('physdesc', 'Playing Time', "{$a}"),

      "datafield[@tag='340']" => multipart_note('phystech', 'Physical Medium', %q|
                                          {$3: }{Material base and configuration--$a; }{Dimensions--$b; }
                                          {Materials applied to surface--$c; }{Information recording technique--$d, }
                                          {Support--$e, }{Production rate / ratio--$f, }{Location within medium--$h, }
                                          {Technical specifications of medium--$i}
                                          |),

      "datafield[@tag='342']" => multipart_note('odd',
                                                -> node {
                                                  label = 'Geospatial Reference Dimension: '
                                                  map = {
                                                    'ind1' => {
                                                      '0' => 'Horizontal coordinate system',
                                                      '1' => 'Vertical coordinate system'
                                                    },
                                                    'ind2' => {
                                                      '0'=>'Geographic',
                                                      '1'=>'Map projection',
                                                      '2'=>'Grid coordinate system',
                                                      '3'=>'Local planar',
                                                      '4'=>'Local',
                                                      '5'=>'Geodetic model',
                                                      '6'=>'Altitude',
                                                      '8'=>'Depth',
                                                    }
                                                  }

                                                  if node.attr('ind1') && node.attr('ind2')
                                                    one = map['ind1'][node.attr('ind1')]
                                                    two = node.attr('ind2') == '7' ? one : map['ind2'][node.attr('ind2')]
                                                    label += "#{one}--#{two}"
                                                  elsif node.attr('ind1')
                                                    label += "#{map['ind1'][node.attr('ind1')]}"
                                                  elsif node.attr('ind2')
                                                    label += "#{map['ind2'][node.attr('ind2')]}"
                                                  end

                                                  label
                                                },
                                                %q|
                                          {Name--$a; }{Coordinate or distance units--$b; }{Latitude resolution--$c; }
                                          {Longitude resolution--$d; }{Standard parallel or oblique latitude--$e; }
                                          {Oblique line longitude--$f; }{Longitude of central meridian or projection center--$g; }
                                          {Latitude of projection origin or projection center--$h; }{False easting--$i; }
                                          {False northing--$j; }{Scale factor--$k; }{Height of perspective point above surface--$l; }
                                          {Azimuthal angle--$m; }{Azimuth measure point longitude or straight vertical longitude from pole--$n; }
                                          {Landsat number and path number--$o; }
                                          {Zone identifier--$p; }{Ellipsoid name--$q; }{Semi-major axis--$r; }
                                          {Denominator of flattening ratio--$s; }
                                          {Vertical resolution--$t; }{Vertical encoding method--$u; }
                                          {Local planar, local, or other projection or grid description--$v; }
                                          {Local planar or local georeference information--$w; Reference method used--$2}
                                          |),


      "datafield[@tag='343']" => singlepart_note('physdesc', 'Planar Surface Coordinate System', %q|
                                          {Planar coordinate encoding method--$a; }
                                          {Planar distance units--$b; }
                                          {Abscissa resolution--$c; }{Ordinate resolution--$d; }
                                          {distance resolution--$e; }{Bearing resolution--$f; }
                                          {Bearing units--$g; }{Bearing reference direction--$h; }
                                          {Bearing reference meridian--$i.}
                                          |),

      "datafield[@tag='351']" => multipart_note('arrangement', 'Arrangement', "{$3: }{$a. }{$b. }{$c}"),

      "datafield[@tag='352']" => multipart_note('phystech', 'Digital Graphic Representation', %q|
                                          {Direct reference method--$a; }{Object type--$b; }
                                          {Object count--$c; }{Row count--$d; }{Column count--$e; }
                                          {Vertical count--$f; }{VPF topology level--$g; }{Indirect reference description--$i; }
                                          {Format of the digital image--$q.}|),

      "datafield[@tag='355']" => multipart_note('accessrestrict', 'Security Classification Control',
                                                %q|{@ind1 }
                                          {Security classification--$a; }{Handling instructions--$b; }
                                          {External dissemination information--$c; }{Downgrading or declassification event--$d; }
                                          {Classification system--$e; }{Country of origin code--$f; }
                                          {Downgrading date--$h; }{Authorization--$j}.|,
                                                {'ind1' => {
                                                    '0'=>'Document',
                                                    '1'=>'Title',
                                                    '2'=>'Abstract',
                                                    '3'=>'Contents note',
                                                    '4'=>'Author',
                                                    '5'=>'Record',
                                                    '8'=>'Other element'}
                                                }),

      "datafield[@tag='357']" => multipart_note('odd', 'Originator Dissemination Control', %q|
                                          {Originator control term--$a; }{Originating agency--$b; }
                                          {Authorized recipients of materials--$c; }{Other restrictions--$g}
                                          |),

      # 500s
      "datafield[@tag='500']" => multipart_note('odd', 'General Note', "{$3: }{$a}"),

      "datafield[@tag='501']" => multipart_note('odd', 'With Note', "{$a}"),

      "datafield[@tag='502']" => multipart_note('odd', 'Thesis / Dissertation Note', "{$a}"),

      "datafield[@tag='504']" => bibliography_note_template('Bibliographic References', "{$a }{$b}"),
      
      "datafield[@tag='505']" => multipart_note('odd', 'Cumulative Index/Finding Aids Note', "{$a}"),

      "datafield[@tag='506']" => multipart_note('accessrestrict', ' Restrictions on Access', "{$3: }{$a, }{$b, }{$c, }{$d, }{$e, }{$u}."),

      "datafield[@tag='507']" => multipart_note('odd', 'Scale Note for Graphic Material', "{$a : }{$b}"),

      "datafield[@tag='508']" => multipart_note('odd', 'Production Credits', "{$a}"),

      "datafield[@tag='510']" => bibliography_note_template('Bibliographic References',
                                                            "Indicator 1 {@ind1} -- {$3: }{$a : }{$b : }{$c }{($x)}",
                                                            {'ind1' =>{
                                                                '0'=>'Coverage unknown',
                                                                '1'=>'Coverage complete',
                                                                '2'=>'Coverage is selective',
                                                                '3'=>'Location in source not given',
                                                                '4'=>'Location in source given',
                                                              }}),

      "datafield[@tag='511']" => multipart_note('odd', 'Participants / Performers', "{$a}"),

      "datafield[@tag='513']" => multipart_note('scopecontent', 'Type of report', "{$a} {($b)}"),

      "datafield[@tag='514']" => multipart_note('odd', 'Data quality', %q|
                                          {$z: }{Attribute accuracy report--$a; }{Attribute accuracy value--$b; }
                                          {Attribute accuracy explanation--$c; }{Logical consistency report--$d; }
                                          {Completeness report--$e; }{Horizontal position accuracy report--$f; }
                                          {Horizontal position accuracy value--$g; }{Horizontal position accuracy explanation--$h; }
                                          {Vertical positional accuracy report--$i; }{Vertical positional accuracy value--$j; }
                                          {Vertical positional accuracy explanation--$k; }{Cloud cover--$m; }
                                          {Uniform Resource Identifier--$u}.|),


      "datafield[@tag='518']" => multipart_note('odd', 'Date and Time of Event', "{$3: }{$a.}"),

      "datafield[@tag='520'][@ind1!='3' and @ind1!='8']" => multipart_note(
                                                                           'odd',
                                                                           -> node {
                                                                             {'0'=>'Subject', '1'=>'Review', '2'=>'Scope and content'}[node.attr('ind1')] || "Summary"
                                                                           },
                                                                           "{$3: }{$a. }{($u) }{\n$b}"),

      "datafield[@tag='520'][@ind1='3']" => singlepart_note('abstract', 'Abstract', "{$3: }{$a. }{($u) }{\n$b}"),

      "datafield[@tag='521'][@ind1!='8']" => multipart_note(
                                                            'odd',
                                                            -> node {
                                                              {
                                                                '0'=>'Reading grade level',
                                                                '1'=>'Interest age level',
                                                                '2'=>'Interest grade level',
                                                                '3'=>'Special audience characteristics',
                                                                '4'=>'Motivation interest level',
                                                                '8'=>'No display constant generated'
                                                              }[node.attr('ind1')] || "Audience"
                                                            },
                                                            "{$3: }{$a }{($b)}."),


      "datafield[@tag='522']" => multipart_note('odd', 'Geographic Coverage', "{$a}"),

      "datafield[@tag='524']" => multipart_note('prefercite', 'Preferred Citation', "{$3: }{$a. }{$2}."),

      "datafield[@tag='530']" => multipart_note('altformavail', 'Alternate Form Available', "{$3: }{$a. }{$b. }{$c. }{$d. }{($u)}"),

      "datafield[@tag='533']" => multipart_note('odd', 'Reproduction Note', %q|
                                          {$3: }{Type of reproduction--$a; }{Place of reproduction--$b; }
                                          {Agency responsible for reproduction--$c: }{Date of reproduction--$d. }{Physical description of reproduction--$e. }
                                          {Series statement of reproduction--$f. }{Dates and / or sequential of issues reproduced--$m. }
                                          {Note about reproduction--$n.}|
                                                ),

      "datafield[@tag='534']" => multipart_note('odd', 'Original Version Note', %q|
                                          {$p: }{$a, }{$t, }{$k, }{$c }{($b). }{$f. }{$e, }{$m. }{$n, }{$l. }{($x), }{($z)}.|),

      "datafield[@tag='535']" => multipart_note('originalsloc', 'Location of Originals Note', %q|
                                          Indicator 1 {@ind1: } {$3--}{$a. }{$b, }{$c. }{$d }{($g).}|,
                                                {'ind1'=>{'1'=>'Holder of originals', '2'=>'Holder of duplicates'}}),

      # FINDING AID SPONSOR
      "datafield[@tag='536']" => -> resource, node {
        resource.finding_aid_sponsor=subfield_template(%q|
                                            {Text of note--$a; }{Contract number--$b; }{Grant number--$c; }
                                            {Undifferentiated number--$d; }{Program element number--$f; }{Task number--$g; }
                                            {Work unit number--$h}|, node)
      },

      "datafield[@tag='538']" => multipart_note('phystech', 'System Details Note', "{$3: }{$a }{($u)}."),

      "datafield[@tag='540']" => multipart_note('userestrict', 'Terms Governing Use and Reproduction', "{$3: }{$a. }{$b. }{$c. }{$d }{($u)}."),

      "datafield[@tag='541']" => multipart_note('acqinfo', 'Immediate Source of Acquisition', %q|
                                          {$3: }{Source of acquisition--$a. }{Address--$b. }{Method of acquisition--$c; }
                                          {Date of acquisition--$d. }{Accession number--$e: }{Extent--$n; }
                                          {Type of unit--$o. }{Owner--$f. }{Purchase price--$h}.|),

      "datafield[@tag='544']" => multipart_note('relatedmaterial', 'Related Archival Materials', %q|
                                          {Indicator 1 @ind1--}{$3: }{Title--$t. }{Custodian--$a: }
                                          {Address--$b, }{Country--$c. }{Provenance--$e. }{Note--$n}.|,
                                                {'ind1'=>{'1'=>'Associated Materials', '2'=>'Related Materials'}}),

      "datafield[@tag='545']" => multipart_note(
                                                'bioghist',
                                                -> node {
                                                  {
                                                    '0'=>'Biographical sketch',
                                                    '1'=>'Administrative history',

                                                  }[node.attr('ind1')]
                                                },
                                                "{$a }{($u)}.{\n$b.}"),

      "datafield[@tag='546']" => singlepart_note('langmaterial', 'Language of Material', "{$3: }{$a }{($b)}."),

      "datafield[@tag='561']" => multipart_note('custodhist', 'Ownership and Custodial History', "{$3: }{$a}."),

      "datafield[@tag='562']" => multipart_note('relatedmaterial', 'Copy and Version Identification', %q|
                                          {$3: }{Identifying markings--$a; }{Copy identification--$b; }{Version identification--$c; }
                                          {Presentation format--$d; }{Number of copies--$e}.|),

      "datafield[@tag='563']" => multipart_note('odd', 'Binding Information', "{$3: }{$a }{($u)}."),

      "datafield[@tag='565']" => singlepart_note('materialspec', 'Case File Characteristics Note', %q|
                                          {$3: }{Number of cases / variables--$a; }{name of variable--$b; }
                                          {Unit of analysis--$c; }{Universe of data--$d; }{Filing scheme or code--$e}.|),

      "datafield[@tag='581']" => bibliography_note_template('Publications About Described Materials', "{$3: }{$a }{($z)}."),

      "datafield[starts-with(@tag, '59')]" => multipart_note('odd', 'Local Note'),

      # LINKED AGENTS (PERSON)
      "datafield[@tag='100' or @tag='700'][@ind1='0' or @ind1='1']" => mix(person_template, creators_and_sources),

      "datafield[@tag='600'][@ind1='0' or @ind1='1']" => mix(person_template, agent_as_subject),

      # LINKED AGENTS (FAMILY)
      "datafield[@tag='100' or @tag='700'][@ind1='3']" => mix(family_template, creators_and_sources),

      "datafield[@tag='600'][@ind1='3']" => mix(family_template, agent_as_subject),

      # LINKED AGENTS (CORPORATE)
      "datafield[@tag='110' or @tag='710']" => mix(corp_template, creators_and_sources),

      "datafield[@tag='111' or @tag='711']" => mix(corp_template, creators_and_sources, corp_variation),

      "datafield[@tag='610']" => mix(corp_template, agent_as_subject),

      "datafield[@tag='611']" => mix(corp_template, agent_as_subject, corp_variation),

      #SUBJECTS
      "datafield[@tag='630' or @tag='130' or @tag='430']" => subject_template(
                                                                              -> node {
                                                                                terms = []
                                                                                terms << make_term('uniform_title', concatenate_subfields(%w(a d e f g h k l m n o p r s t), node, ' '))
                                                                                node.xpath("subfield").each do |sf|
                                                                                  terms << make_term(
                                                                                                     {
                                                                                                       'v' => 'genre_form',
                                                                                                       'x' => 'topical',
                                                                                                       'y' => 'temporal',
                                                                                                       'z' => 'geographic'
                                                                                                     }[sf.attr('code')], sf.inner_text)
                                                                                end
                                                                                terms
                                                                              },
                                                                              sets_subject_source),

      "datafield[@tag='650' or @tag='150' or @tag='450']" => subject_template(
                                                                              -> node {
                                                                                terms = []
                                                                                node.xpath("subfield").each do |sf|
                                                                                  terms << make_term(
                                                                                                     {
                                                                                                       'a' => 'topical',
                                                                                                       'b' => 'topical',
                                                                                                       'c' => 'topical',
                                                                                                       'd' => 'topical',
                                                                                                       'v' => 'genre_form',
                                                                                                       'x' => 'topical',
                                                                                                       'y' => 'temporal',
                                                                                                       'z' => 'geographic'
                                                                                                     }[sf.attr('code')], sf.inner_text)
                                                                                end
                                                                                terms
                                                                              },
                                                                              sets_subject_source),

      "datafield[@tag='651' or @tag='151' or @tag='451']" => subject_template(
                                                                              -> node {
                                                                                terms = []
                                                                                node.xpath("subfield").each do |sf|
                                                                                  terms << make_term(
                                                                                                     {
                                                                                                       'a' => 'geographic',
                                                                                                       'v' => 'genre_form',
                                                                                                       'x' => 'topical',
                                                                                                       'y' => 'temporal',
                                                                                                       'z' => 'geographic'
                                                                                                     }[sf.attr('code')], sf.inner_text)
                                                                                end
                                                                                terms
                                                                              },
                                                                              sets_subject_source),

      "datafield[@tag='655' or @tag='155' or @tag = '455']" => subject_template(
                                                                                -> node {
                                                                                  terms = []
                                                                                  # FIXME: subfield `c` not handled
                                                                                  node.xpath("subfield").each do |sf|
                                                                                    terms << make_term(
                                                                                                       {
                                                                                                         'a' => 'genre_form',
                                                                                                         'b' => 'genre_form',
                                                                                                         'v' => 'genre_form',
                                                                                                         'x' => 'topical',
                                                                                                         'y' => 'temporal',
                                                                                                         'z' => 'geographic'
                                                                                                       }[sf.attr('code')], sf.inner_text)
                                                                                  end
                                                                                  terms
                                                                                },
                                                                                sets_subject_source),

      "datafield[@tag='656']" => subject_template(
                                                  -> node {
                                                    terms = []
                                                    node.xpath("subfield").each do |sf|
                                                      terms << make_term(
                                                                         {
                                                                           'a' => 'occupation',
                                                                           'k' => 'genre_form',
                                                                           'v' => 'genre_form',
                                                                           'x' => 'topical',
                                                                           'y' => 'temporal',
                                                                           'z' => 'geographic'
                                                                         }[sf.attr('code')], sf.inner_text)
                                                    end
                                                    terms
                                                  },
                                                  -> node {
                                                    node.attr('ind2') == '7' ? node.xpath("subfield[@code='2']").inner_text : nil
                                                  }),

      "datafield[@tag='657']" => subject_template(
                                                  -> node {
                                                    terms = []
                                                    node.xpath("subfield").each do |sf|
                                                      terms << make_term(
                                                                         {
                                                                           'a' => 'function',
                                                                           'v' => 'genre_form',
                                                                           'x' => 'topical',
                                                                           'y' => 'temporal',
                                                                           'z' => 'geographic'
                                                                         }[sf.attr('code')], sf.inner_text)
                                                    end
                                                    terms
                                                  },
                                                  -> node {
                                                    node.attr('ind2') == '7' ? node.xpath("subfield[@code='2']").inner_text : nil
                                                  }),

      "datafield[starts-with(@tag, '69')]" => subject_template(
                                                               -> node {
                                                                 terms = []
                                                                 hsh = {}
                                                                 node.xpath("subfield").each do |subnode|
                                                                   code = subnode.attr('code')
                                                                   val = subnode.inner_text
                                                                   hsh[code] ||= []
                                                                   hsh[code] << val
                                                                 end
                                                                 srtd_keys = hsh.keys.sort do |one, two|
                                                                   if one == '3'
                                                                     -1
                                                                   elsif two == '3'
                                                                     1
                                                                   elsif one == 'a'
                                                                     -1
                                                                   elsif two == 'a'
                                                                     1
                                                                   else
                                                                     one <=> two
                                                                   end
                                                                 end
                                                                 srtd_keys.each do |k|
                                                                   if hsh[k] and !hsh[k].empty?
                                                                     hsh[k].each do |t|  
                                                                      terms << make_term('topical', t)
                                                                     end 
                                                                   end
                                                                 end
                                                                terms
                                                               },
                                                               -> node {'local'},
                                                               ),

      #700s
      "datafield[@tag='720']['@ind1'='1']" => mix(agent_template,
                                                  {
                                                    :obj => :agent_person,
                                                    :map => {
                                                      "self::datafield" => {
                                                        :obj => :name_person,
                                                        :rel => :names,
                                                        :map => {
                                                          "subfield[@code='a']" => :primary_name,
                                                        },
                                                        :defaults => {
                                                          :source => 'ingest',
                                                        }
                                                      }
                                                    }
                                                  }),

      "datafield[@tag='720']['@ind1'='2']" => mix(agent_template,
                                                  {
                                                    :obj => :agent_corporate_entity,
                                                    :map => {
                                                      "self::datafield" => {
                                                        :obj => :name_corporate_entity,
                                                        :rel => :names,
                                                        :map => {
                                                          "subfield[@code='a']" => :primary_name,
                                                        },
                                                        :defaults => {
                                                          :source => 'ingest',
                                                        }
                                                      }
                                                    }
                                                  }),

      "datafield[@tag='740']" => multipart_note('odd', 'Related / Analytical Title', "{$a }{[$h] }{$p, }{$n}."),

      "datafield[@tag='752']" => subject_template(
                                                  -> node {
                                                    terms = []
                                                    %w(a b c d f g).each do |code|
                                                      val = node.xpath("subfield[@code='#{code}']").inner_text
                                                      terms << make_term('geographic', val)
                                                    end

                                                    terms
                                                  },
                                                  -> node {
                                                    node.xpath("subfield[@code='2']").inner_text
                                                  }),

      "datafield[@tag='754']" => subject_template(
                                                  -> node {
                                                    term = concatenate_subfields(%w(a c d x z), node, '--')
                                                    [make_term('topical', term)]
                                                  },
                                                  -> node {
                                                    node.xpath("subfield[@code='2']").inner_text
                                                  }),

      # last minute checks for the top-level record
      "self::record" => -> resource, node {

        if !resource.title && resource['_fallback_titles'] && !resource['_fallback_titles'].empty?
          resource.title = resource['_fallback_titles'].shift
        end

        if resource.id_0.nil? or resource.id.empty?
          resource.id_0 = "imported-#{SecureRandom.uuid}"
        end
      }
    }
  }
end

- (Object) bibliography_note_template(label, template = nil, *tmpl_args)



343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 343

def bibliography_note_template(label, template=nil, *tmpl_args)
  {
    :obj => :note_bibliography,
    :rel => :notes,
    :map => {
      "self::datafield" => -> note, node {
        content = template ? subfield_template(template, node, *tmpl_args) : node.inner_text
        note.send('label=', label)
        note.content << content
      }
    }
  }
end

- (Object) concatenate_subfields(codearray, node, delim = ' ')

codearray - any enumerable yielding letter / number codes



538
539
540
541
542
543
544
545
546
547
548
549
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 538

def concatenate_subfields(codearray, node, delim=' ')
  result = ""
  codearray.each do |code|
    val = node.xpath("subfield[@code='#{code}']").inner_text
    unless val.empty?
      result += delim unless result.empty?
      result += val
    end
  end

  result
end

- (Object) corp_template



219
220
221
222
223
224
225
226
227
228
229
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
264
265
266
267
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 219

def corp_template
  mix(agent_template, {
    :obj => :agent_corporate_entity,
    :map => {
      # NAMES (CORPORATE)
      "self::datafield" => {
        :obj => :name_corporate_entity,
        :rel => :names,
        :map => name_corp_map,
      },
      "//datafield[@tag='410']" => {
        :obj => :name_corporate_entity,
        :rel => :names,
        :map => name_corp_map,
        :defaults => {
          :name_order => 'direct',
          :source => 'ingest'
        }
      },
      "//datafield[@tag='411']" => {
        :obj => :name_corporate_entity,
        :rel => :names,
        :map => name_corp_map,
        :defaults => {
          :name_order => 'direct',
          :source => 'ingest'
        }
      },
      "//datafield[@tag='610']" => {
        :obj => :name_corporate_entity,
        :rel => :names,
        :map => name_corp_map,
        :defaults => {
          :name_order => 'direct',
          :source => 'ingest'
        }
      },
      "//datafield[@tag='611']" => {
        :obj => :name_corporate_entity,
        :rel => :names,
        :map => name_corp_map,
        :defaults => {
          :name_order => 'direct',
          :source => 'ingest'
        }
      }
    }
  })
end

- (Object) corp_variation



327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 327

def corp_variation
  {
    :map => {
      "self::datafield" => {
        :map => {
          "subfield[@code='e'][0]" => :subordinate_name_1,
          "subfield[@code='e'][1]" => :subordinate_name_2,
          "subfield[@code='e'][2]" => appends_subordinate_name_2,
          "subfield[@code='e'][3]" => appends_subordinate_name_2,
        },
      }
    }
  }
end

- (Object) creators_and_sources

agents from 100 and 700 field are creators or sources



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 271

def creators_and_sources
  {
    :map => {
      "subfield[@code='d']" => :dates,  
      "subfield[@code='e']" => -> agent, node {
        agent['_role'] = case
                         when ['Auctioneer (auc)',
                               'Bookseller (bsl)',
                               'Collector (col)',
                               'Depositor (dpt)',
                               'Donor (dnr)',
                               'Former owner (fmo)',
                               'Funder (fnd)',
                               'Owner (own)'].include?(node.inner_text)
                          'source'
                         else
                          'creator'
                         end
      },
      "self::datafield" => {
        :map => {
          "//controlfield[@tag='001']" => :authority_id, 
          "@ind1" => sets_name_order_from_ind1,
          "subfield[@code='v']" => adds_prefixed_qualifier('Form subdivision'),
          "subfield[@code='x']" => adds_prefixed_qualifier('General subdivision'),
          "subfield[@code='y']" => adds_prefixed_qualifier('Chronological subdivision'),
          "subfield[@code='z']" => adds_prefixed_qualifier('Geographic subdivision'),
        },
        :defaults => {
          :source => 'ingest',
        }
      }
    }
  }
end

- (Object) family_template



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 170

def family_template
  mix(agent_template, {
    :obj => :agent_family,
    :map => {
      # NAMES (FAMILY)
      "self::datafield" => {
        :obj => :name_family,
        :rel => :names,
        :map => name_family_map,
      },
      "//datafield[@tag='400'][@ind1='3']" => {
        :obj => :name_family,
        :rel => :names,
        :map => name_family_map,
        :defaults => {
          :name_order => 'direct',
          :source => 'ingest'
        }
      }
    }
  })
end

- (Object) is_fallback_resource_title



552
553
554
555
556
557
558
559
560
561
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 552

def is_fallback_resource_title
  {
    :rel => -> resource, obj {
      resource['_fallback_titles'] ||= []
      if obj.respond_to?(:subnotes)
        resource['_fallback_titles'] << obj.subnotes[0]['content']
      end
    }
  }
end

- (Object) make_term(term_type, term)



55
56
57
58
59
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 55

def make_term(term_type, term)
  if !term.empty? && !term_type.nil?
    {:term_type => term_type, :term => term, :vocabulary => '/vocabularies/1'}
  end
end

- (Object) multipart_note(note_type, label = nil, template = nil, *tmpl_args)



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 374

def multipart_note(note_type, label = nil, template=nil, *tmpl_args)
  {
    :obj => :note_multipart,
    :rel => :notes,
    :map => {
      "self::datafield" => -> note, node {
        content = template ? subfield_template(template, node, *tmpl_args) : node.inner_text

        label = label.call(node) if label.is_a?(Proc)

        note.send('label=', label) if label
        note.type = note_type
        note.subnotes = [{'jsonmodel_type' => 'note_text', 'content' => content}]
      }
    }
  }
end

- (Object) name_corp_map



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 194

def name_corp_map
  {
    "subfield[@code='a']" => :primary_name,
    "subfield[@code='b'][1]" => :subordinate_name_1,
    "subfield[@code='b'][2]" => :subordinate_name_2,
    "subfield[@code='b'][3]" => appends_subordinate_name_2,
    "subfield[@code='b'][4]" => appends_subordinate_name_2,
    "subfield[@code='c']" => adds_prefixed_qualifier('Location of meeting'),
    "subfield[@code='d']" => adds_prefixed_qualifier('Date of meeting or treaty signing'),
    "subfield[@code='f']" => adds_prefixed_qualifier('Date of work'),
    "subfield[@code='n']" => :number,
    "subfield[@code='g']" => adds_prefixed_qualifier('Miscellaneous information'),
    "subfield[@code='h']" => adds_prefixed_qualifier('Medium'),
    "subfield[@code='k']" => adds_prefixed_qualifier('Form subheading'),
    "subfield[@code='l']" => adds_prefixed_qualifier('Language of a work'),
    "subfield[@code='o']" => adds_prefixed_qualifier('Arranged statement for music'),
    "subfield[@code='p']" => adds_prefixed_qualifier('Name of a part/section of a work'),
    "subfield[@code='r']" => adds_prefixed_qualifier('Key for music'),
    "subfield[@code='s']" => adds_prefixed_qualifier('Version'),
    "subfield[@code='t']" => adds_prefixed_qualifier('Title of work'),
    "subfield[@code='u']" => adds_prefixed_qualifier('Affiliation'),
  }
end

- (Object) name_family_map



154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 154

def name_family_map
  {
    "subfield[@code='a']" => :family_name,
    "subfield[@code='c']" => :qualifier,
    "subfield[@code='d']" => :dates,
    "subfield[@code='f']" => adds_prefixed_qualifier('Date of work'),
    "subfield[@code='g']" => adds_prefixed_qualifier('Miscellaneous information'),
    "subfield[@code='q']" => adds_prefixed_qualifier('', ''),
    "subfield[@code='r']" => adds_prefixed_qualifier('Key for music'),
    "subfield[@code='s']" => adds_prefixed_qualifier('Version'),
    "subfield[@code='t']" => adds_prefixed_qualifier('Title of work'),
    "subfield[@code='u']" => adds_prefixed_qualifier('Affiliation'),
  }
end

- (Object) name_person_map



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 104

def name_person_map
  {
    "subfield[@code='a']" => sets_primary_and_rest_of_name,
    "subfield[@code='b']" => :number,
    "subfield[@code='c']" => :title,

    "subfield[@code='d']" => :dates,
    "subfield[@code='f']" => adds_prefixed_qualifier('Date of work'),
    "subfield[@code='g']" => adds_prefixed_qualifier('Miscellaneous information'),
    "subfield[@code='h']" => adds_prefixed_qualifier('Medium'),
    "subfield[@code='j']" => adds_prefixed_qualifier('Attribution qualifier', ' -- '),
    "subfield[@code='k']" => adds_prefixed_qualifier('Form subheading'),
    "subfield[@code='l']" => adds_prefixed_qualifier('Language of a work'),
    "subfield[@code='m']" => adds_prefixed_qualifier('Medium of performance for music'),
    "subfield[@code='n']" => adds_prefixed_qualifier('Number of part/section of a work'),
    "subfield[@code='o']" => adds_prefixed_qualifier('Arranged statement for music'),
    "subfield[@code='p']" => adds_prefixed_qualifier('Name of a part/section of a work'),
    "subfield[@code='r']" => adds_prefixed_qualifier('Key for music'),
    "subfield[@code='s']" => adds_prefixed_qualifier('Version'),
    "subfield[@code='t']" => adds_prefixed_qualifier('Title of work'),
    "subfield[@code='u']" => adds_prefixed_qualifier('Affiliation'),
    "subfield[@code='q']" => :fuller_form,
  }
end

- (Object) person_template



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 130

def person_template
  mix(agent_template, {
    :obj => :agent_person,
    :map => {
      # NAMES (PERSON)
      "self::datafield" => {
        :obj => :name_person,
        :rel => :names,
        :map => name_person_map
      },
      "//datafield[@tag='400'][@ind1='0' or @ind1='1']" => {
        :obj => :name_person,
        :rel => :names,
        :map => name_person_map,
        :defaults => {
          :name_order => 'direct',
          :source => 'ingest'
        }
      }
    }
  })
end

- (Object) record_type(type_of_record = nil, subject_source = nil) Also known as: set_record_type



27
28
29
30
31
32
33
34
35
36
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 27

def record_type(type_of_record = nil, subject_source = nil)
  @type ||= { type: :bibliographic, subject_source: nil }
  if type_of_record
    @type[:type] = type_of_record == 'z' ? :authority : :bibliographic
  end
  if subject_source
    @type[:subject_source] = subject_source and @type[:type] == :authority ? subject_source : nil
  end
  @type
end

- (Object) sets_name_order_from_ind1



419
420
421
422
423
424
425
426
427
428
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 419

def sets_name_order_from_ind1
  -> name, node {
    name['name_order'] = case node.value
                         when '1'
                           'inverted'
                         when '0'
                           'direct'
                         end
  }
end

- (Object) sets_name_source_from_code



431
432
433
434
435
436
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 431

def sets_name_source_from_code
  -> name, node {
    src = ASpaceMappings::MARC21.get_aspace_source_code(node.value)
    name.source = src if src
  }
end

- (Object) sets_other_name_source



439
440
441
442
443
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 439

def sets_other_name_source
  -> name, node {
    name.source = node.inner_text unless name.source
  }
end

- (Object) sets_primary_and_rest_of_name



406
407
408
409
410
411
412
413
414
415
416
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 406

def sets_primary_and_rest_of_name
  -> name, node {
    val = node.inner_text
    if val.match(/\A(.+),\s*(.+)\s*\Z/)
      name['primary_name'] = $1
      name['rest_of_name'] = $2
    else
      name['primary_name'] = val
    end
  }
end

- (Object) sets_subject_source



62
63
64
65
66
67
68
69
70
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 62

def sets_subject_source
  -> node {
    if record_type[:type] == :authority
      AUTH_SUBJECT_SOURCE[ record_type[:subject_source] ] || 'Source not specified'
    else
      BIB_SUBJECT_SOURCE[node.attr('ind2')] || ( !node.at_xpath("subfield[@code='2']").nil? ? node.at_xpath("subfield[@code='2']").inner_text : 'Source not specified' )
    end
  }
end

- (Object) sets_use_date_from_code_d



446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 446

def sets_use_date_from_code_d
  -> name, node {
    
    date_begin, date_end = nil
    date_type = 'single'
    
    if  node.inner_text.strip =~ /^([0-9]{4})-([0-9]{4})$/
      date_begin,date_end = node.inner_text.strip.split("-")  
      date_type = "range"
    end
    
    make(:date) do |date|
      date.label = 'other'
      date.date_type = date_type
      date.begin = date_begin
      date.end = date_end
      date.expression = node.inner_text
      name.use_dates << date
    end
  }
end

- (Object) singlepart_note(note_type, label, template = nil, *tmpl_args)



358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 358

def singlepart_note(note_type, label, template=nil, *tmpl_args)
  {
    :obj => :note_singlepart,
    :rel => :notes,
    :map => {
      "self::datafield" => -> note, node {
        content = template ? subfield_template(template, node, *tmpl_args) : node.inner_text
        note.send('label=', label)
        note.type = note_type
        note.content << content
      }
    }
  }
end

- (Object) subfield_template(template, node, map = nil)

Create Note content strings from a template E.g., “1 @ind1–{$3: }{$a: }{$b: }{$c }($x)” Sections wrapped in ‘{}’ should only appear if the value can be produced. A chain of sketcky substitutions at the end attempts to keep the punctuation normal.



494
495
496
497
498
499
500
501
502
503
504
505
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
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 494

def subfield_template(template, node, map=nil)
  result = template.clone
  section = /\{([^@${]*)([@$])(ind[0-9]|\S{1})([^}]*)\}/

  while result.match(section)
    if $2 == '@'
      val = node.attr("#{$3}")
    else
      val = ""
      node.xpath("subfield[@code='#{$3}']").each do |subnode|
        postpend = subnode.inner_text
        unless postpend.empty?
          val += " " unless val.empty?
          val += postpend
        end
      end
    end
    val.strip!
    val = val.empty? ? nil : val

    val = map && map.has_key?($3) && map[$3].has_key?(val) ? map[$3][val] : val

    if val
      result.sub!(section, "#{$1}#{val}#{$4}")
    else
      result.sub!(section, '')
    end
  end

  result.strip
        .gsub(/\[\]/, '')
        .gsub(/\(\)/, '')
        .gsub(/\(\s+/, '(')
        .gsub(/\s+\)/, ')')
        .gsub(/,\)/, ')')
        .gsub(/[:;,]$/, '')
        .gsub(/[:;,](\s?)\s*([()])/, '\1\2')
        .gsub(/\s+/, ' ')
        .gsub(/,\s*([^A-Za-z0-9_\s])/, '\1')
        .gsub(/[.:;]?\s*\./, '.')
        .strip
end

- (Object) subject_template(getterms, getsrc)



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'backend/app/converters/lib/marcxml_base_map.rb', line 40

def subject_template(getterms, getsrc)
  {
    :obj => :subject,
    :rel => :subjects,
    :map => {
      "self::datafield" => -> subject, node {
        subject.terms = getterms.call(node)
        subject.source = getsrc.call(node)
        subject.vocabulary = '/vocabularies/1'
      }
    }
  }
end