-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathds_mets_mapper.rb
More file actions
85 lines (76 loc) · 4.32 KB
/
ds_mets_mapper.rb
File metadata and controls
85 lines (76 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true
module DS
module Mapper
class DSMetsMapper < DS::Mapper::BaseMapper
attr_reader :iiif_lookup
attr_reader :ia_url_lookup
def initialize(source_dir:, timestamp:)
super(
source_dir: source_dir,
timestamp: timestamp,
source: DS::Source::DSMetsXML.new
)
end
def extract_record entry
locator = DS::Extractor::XmlRecordLocator.new
source_file_path = File.join source_dir, entry.filename
xml = source.load_source source_file_path
record = locator.locate_record xml, entry.institutional_id, entry.institutional_id_location_in_source
return record if record.present?
raise "Unable to locate record for #{entry.institutional_id} (errors: #{locator.errors.join(', ')})"
end
##
# @param [DS::Manifest::Entry] entry entry instance for a manifest row
# @return [Hash] the mapped record
def map_record entry
record = extract_record entry
source_type = entry.source_type
source_file = entry.filename
ds_id = entry.ds_id
date_added = nil
date_last_updated = nil
cataloging_convention = DS::Extractor::DsMetsXmlExtractor.extract_cataloging_convention(record)
holding_institution_ds_qid = entry.institution_ds_qid
holding_institution_as_recorded = entry.institution_wikidata_label
holding_institution_id_number = entry.institutional_id
holding_institution_shelfmark = entry.call_number
link_to_holding_institution_record = entry.link_to_institutional_record
iiif_manifest = entry.iiif_manifest_url
production_date_as_recorded = DS::Extractor::DsMetsXmlExtractor.extract_production_date_as_recorded(record).join '|'
production_date = DS::Extractor::DsMetsXmlExtractor.extract_date_range(record, range_sep: '^').join '|'
century = DS.transform_dates_to_centuries production_date
century_aat = DS.transform_centuries_to_aat century
dated = DS::Extractor::DsMetsXmlExtractor.dated_by_scribe? record
physical_description = DS::Extractor::DsMetsXmlExtractor.extract_physical_description(record).join '|'
note = DS::Extractor::DsMetsXmlExtractor.extract_notes(record).join '|'
acknowledgments = DS::Extractor::DsMetsXmlExtractor.extract_acknowledgments(record).join '|'
data_processed_at = timestamp
data_source_modified = entry.record_last_updated
{
ds_id: ds_id,
date_added: date_added,
date_last_updated: date_last_updated,
dated: dated,
cataloging_convention: cataloging_convention,
source_type: source_type,
holding_institution_ds_qid: holding_institution_ds_qid,
holding_institution_as_recorded: holding_institution_as_recorded,
holding_institution_id_number: holding_institution_id_number,
holding_institution_shelfmark: holding_institution_shelfmark,
link_to_holding_institution_record: link_to_holding_institution_record,
iiif_manifest: iiif_manifest,
production_date_as_recorded: production_date_as_recorded,
production_date: production_date,
century: century,
century_aat: century_aat,
physical_description: physical_description,
note: note,
acknowledgments: acknowledgments,
data_processed_at: data_processed_at,
data_source_modified: data_source_modified,
source_file: source_file,
}.update build_term_maps DS::Extractor::DsMetsXmlExtractor, record
end
end
end
end