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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/enju_ndl/ndl_search.rb', line 36
def import_record(doc)
iss_itemno = URI.parse(doc.at('//dcndl:BibAdminResource[@rdf:about]').values.first).path.split('/').last
identifier_type = IdentifierType.where(name: 'iss_itemno').first
identifier_type ||= IdentifierType.where(name: 'iss_itemno').create!
identifier = Identifier.where(body: iss_itemno, identifier_type_id: identifier_type.id).first
return identifier.manifestation if identifier
jpno = doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/JPNO"]').try(:content)
publishers = get_publishers(doc)
title = get_title(doc)
pub_date = doc.at('//dcterms:issued').try(:content).to_s.tr('.', '-')
pub_date = nil unless pub_date =~ /^\d+(-\d{0,2}){0,2}$/
if pub_date
date = pub_date.split('-')
date = if date[0] && date[1]
format('%04d-%02d', date[0], date[1])
else
pub_date
end
end
language = Language.where(iso_639_2: get_language(doc)).first
language_id = if language
language.id
else
1
end
isbn = Lisbn.new(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISBN"]').try(:content).to_s).try(:isbn)
issn = StdNum::ISSN.normalize(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISSN"]').try(:content))
issn_l = StdNum::ISSN.normalize(doc.at('//dcterms:identifier[@rdf:datatype="http://ndl.go.jp/dcndl/terms/ISSNL"]').try(:content))
carrier_type = content_type = nil
is_serial = nil
doc.xpath('//dcndl:materialType[@rdf:resource]').each do |d|
case d.attributes['resource'].try(:content)
when 'http://ndl.go.jp/ndltype/Book'
carrier_type = CarrierType.where(name: 'print').first
content_type = ContentType.where(name: 'text').first
when 'http://ndl.go.jp/ndltype/Braille'
content_type = ContentType.where(name: 'tactile_text').first
when 'http://ndl.go.jp/ndltype/ElectronicResource'
carrier_type = CarrierType.where(name: 'file').first
when 'http://ndl.go.jp/ndltype/Journal'
is_serial = true
when 'http://ndl.go.jp/ndltype/Map'
content_type = ContentType.where(name: 'cartographic_image').first
when 'http://ndl.go.jp/ndltype/Music'
content_type = ContentType.where(name: 'performed_music').first
when 'http://ndl.go.jp/ndltype/MusicScore'
content_type = ContentType.where(name: 'notated_music').first
when 'http://ndl.go.jp/ndltype/Painting'
content_type = ContentType.where(name: 'still_image').first
when 'http://ndl.go.jp/ndltype/Photograph'
content_type = ContentType.where(name: 'still_image').first
when 'http://ndl.go.jp/ndltype/PicturePostcard'
content_type = ContentType.where(name: 'still_image').first
when 'http://purl.org/dc/dcmitype/MovingImage'
content_type = ContentType.where(name: 'two_dimensional_moving_image').first
when 'http://purl.org/dc/dcmitype/Sound'
content_type = ContentType.where(name: 'sounds').first
when 'http://purl.org/dc/dcmitype/StillImage'
content_type = ContentType.where(name: 'still_image').first
end
end
admin_identifier = doc.at('//dcndl:BibAdminResource[@rdf:about]').attributes['about'].value
description = doc.at('//dcterms:abstract').try(:content)
price = doc.at('//dcndl:price').try(:content)
volume_number_string = doc.at('//dcndl:volume/rdf:Description/rdf:value').try(:content)
extent = get_extent(doc)
publication_periodicity = doc.at('//dcndl:publicationPeriodicity').try(:content)
statement_of_responsibility = doc.xpath('//dcndl:BibResource/dc:creator').map(&:content).join('; ')
publication_place = doc.at('//dcterms:publisher/foaf:Agent/dcndl:location').try(:content)
edition_string = doc.at('//dcndl:edition').try(:content)
manifestation = Manifestation.where(manifestation_identifier: admin_identifier).first
return manifestation if manifestation
Agent.transaction do
publisher_agents = Agent.import_agents(publishers)
manifestation = Manifestation.new(
manifestation_identifier: admin_identifier,
original_title: title[:manifestation],
title_transcription: title[:transcription],
title_alternative: title[:alternative],
title_alternative_transcription: title[:alternative_transcription],
language_id: language_id,
pub_date: date,
description: description,
volume_number_string: volume_number_string,
price: price,
statement_of_responsibility: statement_of_responsibility,
start_page: extent[:start_page],
end_page: extent[:end_page],
height: extent[:height],
extent: extent[:extent],
dimensions: extent[:dimensions],
publication_place: publication_place,
edition_string: edition_string
)
manifestation.serial = true if is_serial
identifier = {}
if isbn
identifier[:isbn] = Identifier.new(body: isbn)
identifier[:isbn].identifier_type = IdentifierType.find_by(name: 'isbn') || IdnetifierType.create!(name: 'isbn')
end
if iss_itemno
identifier[:iss_itemno] = Identifier.new(body: iss_itemno)
identifier[:iss_itemno].identifier_type = IdentifierType.find_by(name: 'iss_itemno') || IdentifierType.create!(name: 'iss_itemno')
end
if jpno
identifier[:jpno] = Identifier.new(body: jpno)
identifier[:jpno].identifier_type = IdentifierType.find_by(name: 'jpno') || IdentifierType.create!(name: 'jpno')
end
if issn
identifier[:issn] = Identifier.new(body: issn)
identifier[:issn].identifier_type = IdentifierType.find_by(name: 'issn') || IdentifierType.create!(name: 'issn')
end
if issn_l
identifier[:issn_l] = Identifier.new(body: issn_l)
identifier[:issn_l].identifier_type = IdentifierType.where(name: 'issn_l').first || IdentifierType.create!(name: 'issn_l')
end
manifestation.carrier_type = carrier_type if carrier_type
manifestation.manifestation_content_type = content_type if content_type
if manifestation.save
identifier.each do |_k, v|
manifestation.identifiers << v if v.valid?
end
manifestation.publishers << publisher_agents
create_additional_attributes(doc, manifestation)
if is_serial
series_statement = SeriesStatement.new(
original_title: title[:manifestation],
title_alternative: title[:alternative],
title_transcription: title[:transcription],
series_master: true
)
if series_statement.valid?
manifestation.series_statements << series_statement
end
else
create_series_statement(doc, manifestation)
end
end
end
manifestation
end
|