Module: MarcXMLBibBaseMap

Included in:
MarcXMLBibConverter
Defined in:
backend/app/converters/lib/marcxml_bib_base_map.rb

Constant Summary collapse

AUTH_SUBJECT_SOURCE =
{
  'a'=>"lcsh",
  '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'=>"lcsh",
  '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

#adds_agent_term(term_type, prefix = "") ⇒ Object



455
456
457
458
459
460
461
462
463
464
465
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 455

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

#adds_prefixed_qualifier(prefix, separator = ': ') ⇒ Object



548
549
550
551
552
553
554
555
556
557
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 548

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

#agent_as_subjectObject

agents derived from 600 fields



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 352

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

#agent_templateObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 93

def agent_template
  {
    :rel => -> resource, agent {
      agent.publish = true
      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'
        }
      },
      "//datafield[@tag='046']" => {
        :obj => :date,
        :rel => :dates_of_existence,
        :map => {
          "self::datafield" => Proc.new {|date, node|
            date.expression = concatenate_subfields(['f', 'q', 's', 'g', 'r', 't'], node, '-', true)
            date.begin      = dates_of_existence_date_for(node, ['f', 'q', 's'])
            end_date        = dates_of_existence_date_for(node, ['g', 'r', 't'])
            if (date.begin and end_date) and (end_date.to_i > date.begin.to_i)
              date.end = end_date
            end
            date.date_type = date.end ? 'range' : 'single'
          }
        },
        :defaults => {
          :label => 'existence',
          :date_type => 'single',
        }
      },
      "//datafield[@tag='678']" => {
        :obj => :note_bioghist,
        :rel => :notes,
        :map => {
          "self::datafield" => Proc.new {|note, node|
            note['subnotes'] << {
              'jsonmodel_type' => 'note_text',
              'content' => concatenate_subfields(['a', 'b', 'u'], node, ' ', true),
              'publish' => true,
            }
          }
        },
        :defaults => {
          :label => 'Biographical / Historical',
          :publish => true,
        }
      },
    }
  }
end

#appends_subordinate_name_2Object



569
570
571
572
573
574
575
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 569

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.chomp(".")
  }
end

#BASE_RECORD_MAPObject

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.



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
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 680

def BASE_RECORD_MAP
  {
    :obj => :resource,
    :defaults => {
     :level => 'collection',
     :finding_aid_language => 'und',
     :finding_aid_script => 'Zyyy'
    },
    :map => {
      #LEADER
      "//leader" =>  -> resource, node {
        values = node.inner_text.strip
        set_record_properties 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_properties nil, control[11], control[10]

        if control[35..37] != "   "
          make(:lang_material) do |lang|
            lang.language_and_script = {'jsonmodel_type' => 'language_and_script', 'language' => control[35..37]}

            resource.lang_materials << lang

          end
        else
          make(:lang_material) do |lang|
            lang.language_and_script = {'jsonmodel_type' => 'language_and_script', 'language' => 'und'}

            resource.lang_materials << lang

          end
        end

        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]
            elsif control[7..10]
              #somewhat hackish, but lets us cope with e.g. 19uu
              date.expression = 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?
      },

      # local LC-style identifer
      "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
      },

      # local non-LC identifier
      "datafield[@tag='099']" => -> 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,

      # language of description
      "datafield[@tag='040']/subfield[@code='b']" => :finding_aid_language,

      # 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 = subfield_template("{$f}", node)
        bulk = subfield_template("{$g}", node)
        unless expression.empty? && bulk.empty?
          if resource.dates[0] && resource.dates[0]['date_type'] != 'bulk' && !expression.empty?
            resource.dates[0]['expression'] = expression
          elsif !expression.empty?
            make(:date) do |date|
             date.label = 'creation'
             date.date_type = 'inclusive'
             date.expression = expression
             resource.dates << date
           end
          end
          unless bulk.empty?
            if resource.dates[0] && resource.dates[0]['date_type'] == 'bulk'
              resource.dates[0]['expression'] = bulk
            else
              make(:date)  do |date|
                date.label = 'creation'
                date.date_type = 'bulk'
                date.expression = bulk
                resource.dates << date
              end
            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
              elsif ext =~ /^([0-9\.,]+)/
                extent.number = $1
              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',
                                                            "{@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!='2' and @ind1!='8']" => multipart_note(
                                                                           'odd',
                                                                           -> node {
                                                                             {'0'=>'Subject', '1'=>'Review'}[node.attr('ind1')] || "Summary"
                                                                           },
                                                                           "{$3: }{$a. }{($u) }{\n$b}"),

      "datafield[@tag='520'][@ind1='2']" => multipart_note('scopecontent', 'Scope and content', "{$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|
                                          {@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|
                                          {$3: }{Title--$d. }{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.}"),

      # ANW-697: Language notes now mapped to language of materials note inside a lang_material record
      "datafield[@tag='546']" => -> resource, node {

        content = subfield_template("{$3: }{$a }{($b)}.", node)

        make(:lang_material) do |lang|
          lang.notes = [{"jsonmodel_type": "note_langmaterial",
                         "type": "langmaterial",
                         "content": [content]}]

          resource.lang_materials << lang

        end

      },

      "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='730']" => 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, ' ', true))
                                                                                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, '430'),

      "datafield[@tag='650' or @tag='150']" => 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, '450'),

      "datafield[@tag='651' or @tag='151']" => 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, '451'),

      "datafield[@tag='655' or @tag='155']" => 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, '455'),

      "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

#bibliography_note_template(label, template = nil, *tmpl_args) ⇒ Object



389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 389

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

#concatenate_subfields(codearray, node, delim = ' ', subfield_order = false) ⇒ Object

codearray - any enumerable yielding letter / number codes



632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 632

def concatenate_subfields(codearray, node, delim=' ', subfield_order = false)
  result = ""
  if subfield_order
    result = node.children.map do |subfield|
      codearray.include?(subfield[:code]) ? subfield.inner_text : ''
    end.join(delim).squeeze(delim).strip
  else
    codearray.each do |code|
      val = node.xpath("subfield[@code='#{code}']").inner_text
      unless val.empty?
        result += delim unless result.empty?
        result += val
      end
    end
  end

  result
end

#corp_templateObject



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
306
307
308
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 278

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(true, true),
      },
      "//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'
        }
      }
    }
  })
end

#corp_variationObject



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 371

def corp_variation
  {
    :map => {
      "self::datafield" => {
        :map => {
          "subfield" => sets_conference_meeting,
          "subfield[@code='e'][0]" => trim('subordinate_name_1', '.'),
          "subfield[@code='e'][1]" => trim('subordinate_name_2', '.'),
          "subfield[@code='e'][2]" => appends_subordinate_name_2,
          "subfield[@code='e'][3]" => appends_subordinate_name_2,
          "subfield[@code='q']" => trim('qualifier', '.')
        },
      }
    }
  }
end

#creators_and_sourcesObject

agents from 100 and 700 field are creators or sources



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 312

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 => {
          "@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',
        }
      }
    },
    :defaults => {
      '_role' => 'creator'
    }
  }
end

#dates_of_existence_date_for(node, subfields) ⇒ Object



652
653
654
655
656
657
658
659
660
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 652

def dates_of_existence_date_for(node, subfields)
  date = nil
  subfields.each do |sc|
    date_node = node.at_xpath("subfield[@code='#{sc}']")
    date      = date_node.inner_text.strip.gsub(/[^\d]/, '') if date_node
    date      = (date and date.length >= 4) ? date[0..3] : nil
  end
  date
end

#family_templateObject



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 228

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

#is_fallback_resource_titleObject



663
664
665
666
667
668
669
670
671
672
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 663

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

#langmaterial_note(*tmpl_args) ⇒ Object



439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 439

def langmaterial_note(*tmpl_args)
  {
    :obj => :note_langmaterial,
    :rel => :notes,
    :map => {
      "self::datafield" => -> note, node {
        content = template ? subfield_template(template, node, *tmpl_args) : node.inner_text
        note.label = 'Language of Material'
        note.type = 'langmaterial'
        note.content << content
      }
    }
  }
end

#make_term(term_type, term) ⇒ Object



75
76
77
78
79
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 75

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

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



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 420

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

#name_corp_map(primary = false, authorized = false) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 252

def name_corp_map(primary = false, authorized = false)
  {
    "//controlfield[@tag='001']" => sets_authority_properties(primary, authorized),
    "subfield[@code='a']" => trim('primary_name', '.'),
    "subfield[@code='b'][1]" => trim('subordinate_name_1', '.'),
    "subfield[@code='b'][2]" => trim('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']" => trim('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

#name_family_map(primary = false, authorized = false) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 211

def name_family_map(primary = false, authorized = false)
  {
    "//controlfield[@tag='001']" => sets_authority_properties(primary, authorized),
    "subfield[@code='a']" => trim('family_name', ',', ['(', ')']),
    "subfield[@code='c']" => trim('qualifier', ',', ['(', ')']),
    "subfield[@code='d']" => trim('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

#name_person_map(primary = false, authorized = false) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 159

def name_person_map(primary = false, authorized = false)
  {
    "//controlfield[@tag='001']" => sets_authority_properties(primary, authorized),
    "@ind1" => sets_name_order_from_ind1,
    "subfield[@code='a']" => sets_primary_and_rest_of_name,
    "subfield[@code='b']" => trim('number'),
    "subfield[@code='c']" => trim('title'),

    "subfield[@code='d']" => trim('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']" => trim('fuller_form', ',', ['(', ')']),
  }
end

#person_templateObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 187

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

#record_properties(type_of_record = nil, source = nil, rules = nil) ⇒ Object Also known as: set_record_properties



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

def record_properties(type_of_record = nil, source = nil, rules = nil)
  @properties ||= { type: :bibliographic, source: nil , rules: nil}
  if type_of_record
    @properties[:type] = type_of_record == 'z' ? :authority : :bibliographic
  end
  if @properties[:type] == :authority
    @properties[:source] = source if source
    @properties[:rules]  = rules  if rules
  end
  @properties
end

#sets_authority_properties(primary = false, authorized = false, type = :name) ⇒ Object



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 468

def sets_authority_properties(primary = false, authorized = false, type = :name)
  -> auth, node {
    if record_properties[:type] == :authority
      authority_id = primary ? node.inner_text : nil
      auth['authority_id'] = authority_id
      if authorized
        auth['authorized']      = true
        auth['is_display_name'] = true
      end
      if type == :name
        auth['rules']  = ['b', 'c', 'd'].include?(record_properties[:rules]) ? 'aacr' : nil
        auth['source'] = (record_properties[:source] == 'a' ? 'naf' : 'ingest')
      end
    end
  }
end

#sets_conference_meetingObject



577
578
579
580
581
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 577

def sets_conference_meeting
  -> name, node {
    name.conference_meeting = true
  }
end

#sets_name_order_from_ind1Object



498
499
500
501
502
503
504
505
506
507
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 498

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

#sets_name_source_from_codeObject



510
511
512
513
514
515
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 510

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

#sets_other_name_sourceObject



518
519
520
521
522
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 518

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

#sets_primary_and_rest_of_nameObject



485
486
487
488
489
490
491
492
493
494
495
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 485

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

#sets_subject_sourceObject



82
83
84
85
86
87
88
89
90
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 82

def sets_subject_source
  -> node {
    if record_properties[:type] == :authority
      AUTH_SUBJECT_SOURCE[ record_properties[: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

#sets_use_date_from_code_dObject



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 525

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

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



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

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

#subfield_template(template, node, map = nil) ⇒ Object

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.



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
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 588

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

#subject_template(getterms, getsrc, variant_tag = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 41

def subject_template(getterms, getsrc, variant_tag = nil)
  {
    :obj => :subject,
    :rel => :subjects,
    :map => {
      "//controlfield[@tag='001']" => sets_authority_properties(true, false, :subject),
      "self::datafield" => -> subject, node {
        subject.publish = true
        subject.terms = getterms.call(node)
        subject.source = getsrc.call(node)
        subject.vocabulary = '/vocabularies/1'
      },
      "//datafield[@tag='680']" => -> subject, node {
        subject.scope_note = concatenate_subfields(['a', 'i'], node, ' ', true)
      },
      # update source if this is lcgft: https://www.loc.gov/catdir/cpso/genre_form_faq.pdf
      "//datafield[@tag='040']" => -> subject, node {
        if record_properties[:type] == :authority
          if subject.source == 'Other' and node.at_xpath("subfield[@code='f']").inner_text == 'lcgft'
            subject.source = 'lcgft'
          end
        end
      },
      # skip handling variant (4XX) headings until subject / term data model
      # supports authorized / unauthorized and multiple headings per subject
      # these just pollute the database as is
      # "//datafield[@tag='#{variant_tag || '999'}']" => -> subject, node {
      #   # TODO
      # }
    }
  }
end

#trim(property, trailing_char = ',', remove_chars = []) ⇒ Object



560
561
562
563
564
565
566
# File 'backend/app/converters/lib/marcxml_bib_base_map.rb', line 560

def trim(property, trailing_char = ',', remove_chars = [])
  -> name, node {
    val = node.inner_text
    remove_chars.each { |char| val = val.gsub(/#{Regexp.escape(char)}/, '') }
    name[property] = val.chomp(trailing_char)
  }
end