enju_loc 0.1.0.pre4 → 0.1.0.pre5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/app/helpers/loc_search_helper.rb +1 -1
- data/app/models/loc_search.rb +12 -11
- data/app/views/loc_search/index.html.erb +1 -1
- data/lib/enju_loc/loc_search.rb +105 -104
- data/lib/enju_loc/version.rb +1 -1
- data/spec/cassette_library/LocSearch/_ModsRecord/should_parse_MODS_metadata.yml +8 -8
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_create_a_valid_manifestation.yml +9 -9
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_create_lcsh_subjects_only.yml +9 -9
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_create_multiple_series_statements.yml +9 -9
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_distinguish_title_information_with_subject.yml +9 -9
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_a_manifestation_that_has_invalid_classification.yml +9 -9
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_another_serial.yml +22 -22
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_audio_book.yml +9 -9
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_e-resource.yml +12 -13
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_e-resource_packaged_.yml +25 -25
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_lccn_exact_math.yml +57 -0
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_notated_music.yml +55 -56
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_note_fields.yml +9 -9
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_publication_year.yml +14 -14
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_serial.yml +22 -23
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_import_video_publication.yml +10 -10
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_parse_title_information_properly.yml +10 -10
- data/spec/cassette_library/LocSearch/_import_from_sru_response/should_support_name_and_title_subjects.yml +10 -10
- data/spec/cassette_library/LocSearch/_search/should_return_a_search_result.yml +119 -83
- data/spec/cassette_library/LocSearchController/GET_index/should_get_index.yml +119 -83
- data/spec/cassette_library/LocSearchController/GET_index/should_get_index_with_page_parameter.yml +99 -102
- data/spec/cassette_library/LocSearchController/POST_create/should_create_a_bibliographic_record_if_lccn_is_set.yml +12 -12
- data/spec/cassette_library/LocSearchController/POST_create/should_not_create_a_bibliographic_record_if_lccn_is_not_set.yml +7 -7
- data/spec/dummy/app/assets/javascripts/application.js +2 -2
- data/spec/models/loc_search_spec.rb +6 -0
- metadata +35 -21
- data/spec/dummy/app/models/setting.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae84ef37831bd60f287da64e91b8e37128c281c8
|
4
|
+
data.tar.gz: 1c749625e555c67d1059f68ebacddadc67df260f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89d1aa88540c8554f5147c18ecbe5c605c4cd8a5763d2e257d5996ded6f97265db8e6bd72a45addf90e1c2e9be9915980393004bf3b33898f378cfd239d505e
|
7
|
+
data.tar.gz: 1649bf7e6028c3fcecaa672ffa71dde9f67e651b31fe66f02d8a6362aa039d663785c26bd07a4f7a287130be5a6054dacdaaf03d3795e9451d5cd48b0c926dea
|
data/MIT-LICENSE
CHANGED
@@ -9,7 +9,7 @@ module LocSearchHelper
|
|
9
9
|
.id).first.try(:manifestation)
|
10
10
|
end
|
11
11
|
unless manifestation
|
12
|
-
|
12
|
+
button_to t('enju_loc.add'), loc_search_index_path(book: {lccn: lccn}), method: :post, data: {disable_with: t('page.saving')}
|
13
13
|
else
|
14
14
|
link_to t('enju_loc.already_exists'), manifestation
|
15
15
|
end
|
data/app/models/loc_search.rb
CHANGED
@@ -49,7 +49,7 @@ class LocSearch
|
|
49
49
|
def title
|
50
50
|
@node.xpath( './/dc:title', DC_NS ).first.content
|
51
51
|
end
|
52
|
-
def lccn
|
52
|
+
def lccn
|
53
53
|
@node.xpath( './/dc:identifier[@type="lccn"]', DC_NS ).first.content
|
54
54
|
end
|
55
55
|
def creator
|
@@ -64,8 +64,8 @@ class LocSearch
|
|
64
64
|
options[ :startRecord ] = ( page - 1 ) * 10 + 1
|
65
65
|
options.delete :page
|
66
66
|
end
|
67
|
-
options = { :
|
68
|
-
options = options.merge( { :
|
67
|
+
options = { maximumRecords: 10, recordSchema: :mods }.merge(options)
|
68
|
+
options = options.merge( { query: query, version: "1.1", operation: "searchRetrieve" } )
|
69
69
|
params = options.map do |k, v|
|
70
70
|
"#{ URI.escape( k.to_s ) }=#{ URI.escape( v.to_s ) }"
|
71
71
|
end.join( '&' )
|
@@ -73,14 +73,14 @@ class LocSearch
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def self.search( query, options = {} )
|
76
|
-
if query and
|
76
|
+
if query and !query.empty?
|
77
77
|
url = make_sru_request_uri(query, options)
|
78
78
|
doc = Nokogiri::XML(Faraday.get(url).body)
|
79
79
|
items = doc.search('//zs:record').map{|e| ModsRecord.new e }
|
80
|
-
@results = { :
|
81
|
-
:
|
80
|
+
@results = { items: items,
|
81
|
+
total_entries: doc.xpath('//zs:numberOfRecords').first.try(:content).to_i }
|
82
82
|
else
|
83
|
-
{ :
|
83
|
+
{ items: [], total_entries: 0 }
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -89,11 +89,12 @@ class LocSearch
|
|
89
89
|
identifier_type_lccn = IdentifierType.create!(name: 'lccn') unless identifier_type_lccn
|
90
90
|
identifier = Identifier.where(body: lccn, identifier_type_id: identifier_type_lccn.id).first
|
91
91
|
return if identifier
|
92
|
-
url = make_sru_request_uri("bath.lccn
|
93
|
-
response = Nokogiri::XML(Faraday.get(url).body)
|
94
|
-
|
92
|
+
url = make_sru_request_uri("bath.lccn=\"^#{ lccn }\"")
|
93
|
+
response = Nokogiri::XML(Faraday.get(url).body)
|
94
|
+
record = response.at( '//zs:recordData', {"zs" => "http://www.loc.gov/zing/srw/"} )
|
95
|
+
return unless record.try(:content)
|
95
96
|
doc = Nokogiri::XML::Document.new
|
96
|
-
doc <<
|
97
|
+
doc << record.at( "//mods:mods", { "mods" => "http://www.loc.gov/mods/v3" } )
|
97
98
|
Manifestation.import_record_from_loc(doc)
|
98
99
|
end
|
99
100
|
end
|
data/lib/enju_loc/loc_search.rb
CHANGED
@@ -14,7 +14,7 @@ module EnjuLoc
|
|
14
14
|
startrecord = 1
|
15
15
|
end
|
16
16
|
url = LOC_SRU_BASEURL + "?operation=searchRetrieve&version=1.1&=query=#{ URI.escape(query) }"
|
17
|
-
cont =
|
17
|
+
cont = Faraday.get(url).body
|
18
18
|
parser = LibXML::XML::Parser.string( cont )
|
19
19
|
doc = parser.parse
|
20
20
|
end
|
@@ -38,11 +38,11 @@ module EnjuLoc
|
|
38
38
|
record_identifier = doc.at( '//mods:recordInfo/mods:recordIdentifier', NS ).try(:content)
|
39
39
|
identifier_type = IdentifierType.where(name: 'loc_identifier').first
|
40
40
|
identifier_type = IdentifierType.create!(name: 'loc_identifier') unless identifier_type
|
41
|
-
loc_identifier = Identifier.where(:
|
41
|
+
loc_identifier = Identifier.where(body: record_identifier, :identifier_type_id => identifier_type.id).first
|
42
42
|
return loc_identifier.manifestation if loc_identifier
|
43
43
|
|
44
44
|
publishers = []
|
45
|
-
doc.xpath('//mods:publisher',NS).each do |publisher|
|
45
|
+
doc.xpath('//mods:publisher', NS).each do |publisher|
|
46
46
|
publishers << {
|
47
47
|
:full_name => publisher.content,
|
48
48
|
#:agent_identifier => publisher.attributes["about"].try(:content)
|
@@ -64,22 +64,22 @@ module EnjuLoc
|
|
64
64
|
language_id = 1
|
65
65
|
end
|
66
66
|
|
67
|
-
isbn = Lisbn.new(doc.at('/mods:mods/mods:identifier[@type="isbn"]',NS).try(:content).to_s).try(:isbn)
|
68
|
-
lccn = StdNum::LCCN.normalize(doc.at('/mods:mods/mods:identifier[@type="lccn"]',NS).try(:content).to_s)
|
69
|
-
issn = StdNum::ISSN.normalize(doc.at('/mods:mods/mods:identifier[@type="issn"]',NS).try(:content).to_s)
|
70
|
-
issn_l = StdNum::ISSN.normalize(doc.at('/mods:mods/mods:identifier[@type="issn-l"]',NS).try(:content).to_s)
|
67
|
+
isbn = Lisbn.new(doc.at('/mods:mods/mods:identifier[@type="isbn"]', NS).try(:content).to_s).try(:isbn)
|
68
|
+
lccn = StdNum::LCCN.normalize(doc.at('/mods:mods/mods:identifier[@type="lccn"]', NS).try(:content).to_s)
|
69
|
+
issn = StdNum::ISSN.normalize(doc.at('/mods:mods/mods:identifier[@type="issn"]', NS).try(:content).to_s)
|
70
|
+
issn_l = StdNum::ISSN.normalize(doc.at('/mods:mods/mods:identifier[@type="issn-l"]', NS).try(:content).to_s)
|
71
71
|
|
72
72
|
types = get_mods_carrier_and_content_types( doc )
|
73
73
|
content_type = types[ :content_type ]
|
74
74
|
carrier_type = types[ :carrier_type ]
|
75
75
|
|
76
|
-
record_identifier = doc.at('//mods:recordInfo/mods:recordIdentifier',NS).try(:content)
|
77
|
-
description = doc.xpath('//mods:abstract',NS).collect(&:content).join("\n")
|
78
|
-
edition_string = doc.at('//mods:edition',NS).try(:content)
|
76
|
+
record_identifier = doc.at('//mods:recordInfo/mods:recordIdentifier', NS).try(:content)
|
77
|
+
description = doc.xpath('//mods:abstract', NS).collect(&:content).join("\n")
|
78
|
+
edition_string = doc.at('//mods:edition', NS).try(:content)
|
79
79
|
extent = get_mods_extent(doc)
|
80
80
|
note = get_mods_note(doc)
|
81
81
|
frequency = get_mods_frequency(doc)
|
82
|
-
issuance = doc.at('//mods:issuance',NS).try(:content)
|
82
|
+
issuance = doc.at('//mods:issuance', NS).try(:content)
|
83
83
|
is_serial = true if issuance == "serial"
|
84
84
|
statement_of_responsibility = get_mods_statement_of_responsibility(doc)
|
85
85
|
access_address = get_mods_access_address(doc)
|
@@ -105,27 +105,27 @@ module EnjuLoc
|
|
105
105
|
:access_address => access_address,
|
106
106
|
:note => note,
|
107
107
|
:publication_place => publication_place,
|
108
|
-
:serial => is_serial
|
108
|
+
:serial => is_serial
|
109
109
|
)
|
110
110
|
identifier = {}
|
111
111
|
if isbn
|
112
|
-
identifier[:isbn] = Identifier.new(:
|
112
|
+
identifier[:isbn] = Identifier.new(body: isbn)
|
113
113
|
identifier[:isbn].identifier_type = IdentifierType.where(name: 'isbn').first || IdnetifierType.create!(name: 'isbn')
|
114
114
|
end
|
115
115
|
if loc_identifier
|
116
|
-
identifier[:loc_identifier] = Identifier.new(:
|
116
|
+
identifier[:loc_identifier] = Identifier.new(body: loc_identifier)
|
117
117
|
identifier[:loc_identifier].identifier_type = IdentifierType.where(name: 'loc_identifier').first || IdnetifierType.create!(name: 'loc_identifier')
|
118
118
|
end
|
119
119
|
if lccn
|
120
|
-
identifier[:lccn] = Identifier.new(:
|
120
|
+
identifier[:lccn] = Identifier.new(body: lccn)
|
121
121
|
identifier[:lccn].identifier_type = IdentifierType.where(name: 'lccn').first || IdentifierType.create!(name: 'lccn')
|
122
122
|
end
|
123
123
|
if issn
|
124
|
-
identifier[:issn] = Identifier.new(:
|
124
|
+
identifier[:issn] = Identifier.new(body: issn)
|
125
125
|
identifier[:issn].identifier_type = IdentifierType.where(name: 'issn').first || IdentifierType.create!(name: 'issn')
|
126
126
|
end
|
127
127
|
if issn_l
|
128
|
-
identifier[:issn_l] = Identifier.new(:
|
128
|
+
identifier[:issn_l] = Identifier.new(body: issn_l)
|
129
129
|
identifier[:issn_l].identifier_type = IdentifierType.where(name: 'issn_l').first || IdentifierType.create!(name: 'issn_l')
|
130
130
|
end
|
131
131
|
manifestation.carrier_type = carrier_type if carrier_type
|
@@ -137,10 +137,10 @@ module EnjuLoc
|
|
137
137
|
end
|
138
138
|
manifestation.publishers << publisher_agents
|
139
139
|
manifestation.creators << creator_agents
|
140
|
-
|
141
|
-
|
140
|
+
create_loc_subject_related_elements(doc, manifestation)
|
141
|
+
create_loc_series_statement(doc, manifestation)
|
142
142
|
if is_serial
|
143
|
-
|
143
|
+
create_loc_series_master(doc, manifestation)
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
@@ -148,13 +148,14 @@ module EnjuLoc
|
|
148
148
|
end
|
149
149
|
|
150
150
|
private
|
151
|
-
|
151
|
+
|
152
|
+
def create_loc_subject_related_elements(doc, manifestation)
|
152
153
|
subjects = get_mods_subjects(doc)
|
153
154
|
classifications = get_mods_classifications(doc)
|
154
155
|
if defined?(EnjuSubject)
|
155
156
|
subject_heading_type = SubjectHeadingType.where(name: 'lcsh').first || SubjectHeadingType.create!(name: 'lcsh')
|
156
157
|
subjects.each do |term|
|
157
|
-
subject = Subject.where(:
|
158
|
+
subject = Subject.where(term: term[:term]).first
|
158
159
|
unless subject
|
159
160
|
subject = Subject.new(term)
|
160
161
|
subject.subject_heading_type = subject_heading_type
|
@@ -176,8 +177,8 @@ module EnjuLoc
|
|
176
177
|
end
|
177
178
|
end
|
178
179
|
|
179
|
-
def
|
180
|
-
doc.xpath('//mods:relatedItem[@type="series"]/mods:titleInfo/mods:title',NS).each do |series|
|
180
|
+
def create_loc_series_statement(doc, manifestation)
|
181
|
+
doc.xpath('//mods:relatedItem[@type="series"]/mods:titleInfo/mods:title', NS).each do |series|
|
181
182
|
series_title = title = series.try(:content)
|
182
183
|
if title
|
183
184
|
series_title = title.split(';')[0].strip
|
@@ -191,12 +192,12 @@ module EnjuLoc
|
|
191
192
|
end
|
192
193
|
end
|
193
194
|
|
194
|
-
def
|
195
|
+
def create_loc_series_master(doc, manifestation)
|
195
196
|
titles = get_mods_titles(doc)
|
196
197
|
series_statement = SeriesStatement.new(
|
197
198
|
:original_title => titles[:original_title],
|
198
199
|
:title_alternative => titles[:title_alternative],
|
199
|
-
:series_master => true
|
200
|
+
:series_master => true
|
200
201
|
)
|
201
202
|
if series_statement.try(:save)
|
202
203
|
manifestation.series_statements << series_statement
|
@@ -206,19 +207,19 @@ module EnjuLoc
|
|
206
207
|
def get_mods_titles(doc)
|
207
208
|
original_title = ""
|
208
209
|
title_alternatives = []
|
209
|
-
doc.xpath('//mods:mods/mods:titleInfo',NS).each do |e|
|
210
|
+
doc.xpath('//mods:mods/mods:titleInfo', NS).each do |e|
|
210
211
|
type = e.attributes["type"].try(:content)
|
211
212
|
case type
|
212
213
|
when "alternative", "translated", "abbreviated", "uniform"
|
213
|
-
title_alternatives << e.at('./mods:title',NS).content
|
214
|
+
title_alternatives << e.at('./mods:title', NS).content
|
214
215
|
else
|
215
|
-
nonsort = e.at('./mods:nonSort',NS).try(:content)
|
216
|
+
nonsort = e.at('./mods:nonSort', NS).try(:content)
|
216
217
|
original_title << nonsort if nonsort
|
217
|
-
original_title << e.at('./mods:title',NS).try(:content)
|
218
|
-
subtitle = e.at('./mods:subTitle',NS).try(:content)
|
218
|
+
original_title << e.at('./mods:title', NS).try(:content)
|
219
|
+
subtitle = e.at('./mods:subTitle', NS).try(:content)
|
219
220
|
original_title << " : #{ subtitle }" if subtitle
|
220
|
-
partnumber = e.at('./mods:partNumber',NS).try(:content)
|
221
|
-
partname = e.at('./mods:partName',NS).try(:content)
|
221
|
+
partnumber = e.at('./mods:partNumber', NS).try(:content)
|
222
|
+
partname = e.at('./mods:partName', NS).try(:content)
|
222
223
|
partname = [ partnumber, partname ].compact.join( ": " )
|
223
224
|
original_title << ". #{ partname }" unless partname.blank?
|
224
225
|
end
|
@@ -227,81 +228,81 @@ module EnjuLoc
|
|
227
228
|
end
|
228
229
|
|
229
230
|
def get_mods_language(doc)
|
230
|
-
language = doc.at('//mods:language/mods:languageTerm[@authority="iso639-2b"]',NS).try(:content)
|
231
|
+
language = doc.at('//mods:language/mods:languageTerm[@authority="iso639-2b"]', NS).try(:content)
|
231
232
|
end
|
232
233
|
|
233
234
|
def get_mods_access_address(doc)
|
234
235
|
access_address = nil
|
235
|
-
url = doc.at('//mods:location/mods:url',NS)
|
236
|
+
url = doc.at('//mods:location/mods:url', NS)
|
236
237
|
if url
|
237
238
|
usage = url.attributes["usage"].try(:content)
|
238
239
|
case usage
|
239
240
|
when "primary display", "primary"
|
240
|
-
|
241
|
+
access_address = url.try(:content)
|
242
|
+
end
|
241
243
|
end
|
244
|
+
access_address
|
242
245
|
end
|
243
|
-
access_address
|
244
|
-
end
|
245
246
|
|
246
|
-
|
247
|
-
|
248
|
-
|
247
|
+
def get_mods_publication_place(doc)
|
248
|
+
place = doc.at('//mods:originInfo/mods:place/mods:placeTerm[@type="text"]', NS).try(:content)
|
249
|
+
end
|
249
250
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
251
|
+
def get_mods_extent(doc)
|
252
|
+
extent = doc.at('//mods:extent', NS).try(:content)
|
253
|
+
value = {:start_page => nil, :end_page => nil, :height => nil}
|
254
|
+
if extent
|
255
|
+
extent = extent.split(';')
|
256
|
+
page = extent[0].try(:strip)
|
257
|
+
if page =~ /(\d+)\s*(p|page)/
|
258
|
+
value[:start_page] = 1
|
259
|
+
value[:end_page] = $1.dup.to_i
|
260
|
+
end
|
261
|
+
height = extent[1].try(:strip)
|
262
|
+
if height =~ /(\d+)\s*cm/
|
263
|
+
value[:height] = $1.dup.to_i
|
264
|
+
end
|
263
265
|
end
|
266
|
+
value
|
264
267
|
end
|
265
|
-
value
|
266
|
-
end
|
267
268
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
269
|
+
def get_mods_statement_of_responsibility(doc)
|
270
|
+
note = doc.at('//mods:note[@type="statement of responsibility"]', NS).try(:content)
|
271
|
+
if note.blank?
|
272
|
+
note = get_mods_creators(doc).map{|e| e[:full_name] }.join( " ; " )
|
273
|
+
end
|
274
|
+
note
|
272
275
|
end
|
273
|
-
note
|
274
|
-
end
|
275
276
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
277
|
+
def get_mods_note(doc)
|
278
|
+
notes = []
|
279
|
+
doc.xpath('//mods:note', NS).each do |note|
|
280
|
+
type = note.attributes['type'].try(:content)
|
281
|
+
next if type == "statement of responsibility"
|
282
|
+
note_s = note.try( :content )
|
283
|
+
notes << note_s unless note_s.blank?
|
284
|
+
end
|
285
|
+
if notes.empty?
|
286
|
+
nil
|
287
|
+
else
|
288
|
+
notes.join( ";\n" )
|
289
|
+
end
|
288
290
|
end
|
289
|
-
end
|
290
291
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
292
|
+
def get_mods_date_of_publication(doc)
|
293
|
+
dates = []
|
294
|
+
doc.xpath('//mods:dateIssued', NS).each do |pub_date|
|
295
|
+
pub_date = pub_date.content.sub( /\A[cp]/, '' )
|
296
|
+
next unless pub_date =~ /^\d+(-\d\d?){0,2}$/
|
297
|
+
date = pub_date.split('-')
|
298
|
+
if date[0] and date[1]
|
299
|
+
dates << sprintf("%04d-%02d", date[0], date[1])
|
300
|
+
else
|
301
|
+
dates << pub_date
|
302
|
+
end
|
301
303
|
end
|
304
|
+
dates.compact.first
|
302
305
|
end
|
303
|
-
dates.compact.first
|
304
|
-
end
|
305
306
|
|
306
307
|
# derived from marcfrequency: http://www.loc.gov/standards/valuelist/marcfrequency.html
|
307
308
|
MARCFREQUENCY = [
|
@@ -321,11 +322,11 @@ module EnjuLoc
|
|
321
322
|
"Annual",
|
322
323
|
"Biennial",
|
323
324
|
"Triennial",
|
324
|
-
"Completely irregular"
|
325
|
+
"Completely irregular"
|
325
326
|
]
|
326
327
|
def get_mods_frequency(doc)
|
327
328
|
frequencies = []
|
328
|
-
doc.xpath('//mods:frequency',NS).each do |freq|
|
329
|
+
doc.xpath('//mods:frequency', NS).each do |freq|
|
329
330
|
frequency = freq.try(:content)
|
330
331
|
MARCFREQUENCY.each do |freq_regex|
|
331
332
|
if /\A(#{freq_regex})/ =~ frequency
|
@@ -339,9 +340,9 @@ module EnjuLoc
|
|
339
340
|
|
340
341
|
def get_mods_creators(doc)
|
341
342
|
creators = []
|
342
|
-
doc.xpath('/mods:mods/mods:name',NS).each do |creator|
|
343
|
+
doc.xpath('/mods:mods/mods:name', NS).each do |creator|
|
343
344
|
creators << {
|
344
|
-
:
|
345
|
+
full_name: creator.xpath('./mods:namePart', NS).collect(&:content).join(", ")
|
345
346
|
}
|
346
347
|
end
|
347
348
|
creators.uniq
|
@@ -350,26 +351,26 @@ module EnjuLoc
|
|
350
351
|
# TODO:only LCSH-based parsing...
|
351
352
|
def get_mods_subjects(doc)
|
352
353
|
subjects = []
|
353
|
-
doc.xpath('//mods:subject[@authority="lcsh"]',NS).each do |s|
|
354
|
+
doc.xpath('//mods:subject[@authority="lcsh"]', NS).each do |s|
|
354
355
|
subject = []
|
355
|
-
s.xpath('./*',NS).each do |subelement|
|
356
|
+
s.xpath('./*', NS).each do |subelement|
|
356
357
|
type = subelement.name
|
357
358
|
case subelement.name
|
358
359
|
when "topic", "geographic", "genre", "temporal"
|
359
|
-
subject << { :
|
360
|
+
subject << { type: type , term: subelement.try(:content) }
|
360
361
|
when "titleInfo"
|
361
|
-
subject << { :
|
362
|
+
subject << { type: type, term: subelement.at('./mods:title', NS).try(:content) }
|
362
363
|
when "name"
|
363
|
-
name = subelement.xpath('./mods:namePart',NS).map{|e| e.try(:content) }.join(
|
364
|
-
subject << { :
|
364
|
+
name = subelement.xpath('./mods:namePart', NS).map{|e| e.try(:content) }.join(", ")
|
365
|
+
subject << { type: type, term: name }
|
365
366
|
end
|
366
367
|
end
|
367
368
|
next if subject.compact.empty?
|
368
369
|
if subject.size > 1 and subject[0][:type] == "name" and subject[1][:type] == "titleInfo"
|
369
|
-
subject[0..1] = { :
|
370
|
+
subject[0..1] = { term: subject[0..1].map{|e|e[:term]}.join(". ") }
|
370
371
|
end
|
371
372
|
subjects << {
|
372
|
-
:
|
373
|
+
term: subject.map{|e|e[:term]}.compact.join("--")
|
373
374
|
}
|
374
375
|
end
|
375
376
|
subjects
|
@@ -378,7 +379,7 @@ module EnjuLoc
|
|
378
379
|
# TODO:support only DDC.
|
379
380
|
def get_mods_classifications(doc)
|
380
381
|
classifications = []
|
381
|
-
doc.xpath('//mods:classification[@authority="ddc"]',NS).each do|c|
|
382
|
+
doc.xpath('//mods:classification[@authority="ddc"]', NS).each do|c|
|
382
383
|
ddc = c.content
|
383
384
|
if ddc
|
384
385
|
classifications << ddc.split(/[^\d\.]/).first.try(:strip)
|
@@ -389,7 +390,7 @@ module EnjuLoc
|
|
389
390
|
|
390
391
|
def get_mods_carrier_and_content_types(doc)
|
391
392
|
carrier_type = content_type = nil
|
392
|
-
doc.xpath('//mods:form',NS).each do |e|
|
393
|
+
doc.xpath('//mods:form', NS).each do |e|
|
393
394
|
authority = e.attributes['authority'].try(:content)
|
394
395
|
case authority
|
395
396
|
when "gmd"
|
@@ -440,7 +441,7 @@ module EnjuLoc
|
|
440
441
|
#carrier_type = CarrierType.where(name: 'other').first
|
441
442
|
when "motion picture", "film cartridge", "film cassette", "film reel"
|
442
443
|
content_type = ContentType.where(name: 'two_dimensional_moving_image').first
|
443
|
-
when "sound recording", "cylinder", "roll", "sound cartridge", "sound cassette","sound-tape reel", "sound-track film", "wire recording"
|
444
|
+
when "sound recording", "cylinder", "roll", "sound cartridge", "sound cassette","sound-tape reel", "sound-track film", "wire recording"
|
444
445
|
content_type = ContentType.where(name: 'performed_music').first
|
445
446
|
when "sound disc"
|
446
447
|
content_type = ContentType.where(name: 'performed_music').first
|
@@ -491,7 +492,7 @@ module EnjuLoc
|
|
491
492
|
end
|
492
493
|
end
|
493
494
|
end
|
494
|
-
doc.xpath('//mods:genre',NS).each do |e|
|
495
|
+
doc.xpath('//mods:genre', NS).each do |e|
|
495
496
|
authority = e.attributes['authority'].try(:content)
|
496
497
|
case authority
|
497
498
|
when "rdacontent"
|
@@ -499,7 +500,7 @@ module EnjuLoc
|
|
499
500
|
content_type = ContentType.where(name: 'other').first unless content_type
|
500
501
|
end
|
501
502
|
end
|
502
|
-
type = doc.at('//mods:typeOfResource',NS).try(:content)
|
503
|
+
type = doc.at('//mods:typeOfResource', NS).try(:content)
|
503
504
|
case type
|
504
505
|
when "text"
|
505
506
|
content_type = ContentType.where(name: 'text').first
|