stanford-mods 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -0
- data/lib/stanford-mods/searchworks.rb +28 -2
- data/lib/stanford-mods/version.rb +2 -1
- data/spec/searchworks_spec.rb +0 -191
- data/spec/searchworks_subject_spec.rb +384 -0
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -60,6 +60,7 @@ Example Using SearchWorks Mixins:
|
|
60
60
|
|
61
61
|
== Releases
|
62
62
|
|
63
|
+
* <b>0.0.9</b> add sw_subject_names and sw_subject_titles methods to searchworks mixin
|
63
64
|
* <b>0.0.8</b> require stanford-mods/searchworks in stanford-mods (top level)
|
64
65
|
* <b>0.0.7</b> added sw_geographic_search to searchworks mixin
|
65
66
|
* <b>0.0.6</b> various title methods added to searchworks mixin
|
@@ -122,7 +122,7 @@ module Stanford
|
|
122
122
|
# subject/hierarchicalGeographic
|
123
123
|
# subject/geographicCode (only include the translated value if it isn't already present from other mods geo fields)
|
124
124
|
# @param [String] sep - the separator string for joining hierarchicalGeographic sub elements
|
125
|
-
# @return [Array<String>] values for geographic_search Solr field for this document or
|
125
|
+
# @return [Array<String>] values for geographic_search Solr field for this document or [] if none
|
126
126
|
def sw_geographic_search(sep = ' ')
|
127
127
|
result = term_values([:subject, :geographic]) || []
|
128
128
|
|
@@ -142,9 +142,35 @@ module Stanford
|
|
142
142
|
}
|
143
143
|
end
|
144
144
|
|
145
|
-
return nil if result.empty?
|
146
145
|
result
|
147
146
|
end
|
147
|
+
|
148
|
+
# Values are the contents of:
|
149
|
+
# subject/name/namePart
|
150
|
+
# "Values from namePart subelements should be concatenated in the order they appear (e.g. "Shakespeare, William, 1564-1616")"
|
151
|
+
# @param [String] sep - the separator string for joining namePart sub elements
|
152
|
+
# @return [Array<String>] values for names inside subject elements or [] if none
|
153
|
+
def sw_subject_names(sep = ', ')
|
154
|
+
result = []
|
155
|
+
@mods_ng_xml.subject.name_el.select { |n_el| n_el.namePart }.each { |name_el_w_np|
|
156
|
+
parts = name_el_w_np.namePart.map { |npn| npn.text unless npn.text.empty? }.compact
|
157
|
+
result << parts.join(sep).strip unless parts.empty?
|
158
|
+
}
|
159
|
+
result
|
160
|
+
end
|
161
|
+
|
162
|
+
# Values are the contents of:
|
163
|
+
# subject/titleInfo/(subelements)
|
164
|
+
# @param [String] sep - the separator string for joining titleInfo sub elements
|
165
|
+
# @return [Array<String>] values for titles inside subject elements or [] if none
|
166
|
+
def sw_subject_titles(sep = ' ')
|
167
|
+
result = []
|
168
|
+
@mods_ng_xml.subject.titleInfo.each { |ti_el|
|
169
|
+
parts = ti_el.element_children.map { |el| el.text unless el.text.empty? }.compact
|
170
|
+
result << parts.join(sep).strip unless parts.empty?
|
171
|
+
}
|
172
|
+
result
|
173
|
+
end
|
148
174
|
|
149
175
|
end # class Record
|
150
176
|
end # Module Mods
|
data/spec/searchworks_spec.rb
CHANGED
@@ -177,195 +177,4 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
|
|
177
177
|
end
|
178
178
|
end # content sw title methods
|
179
179
|
|
180
|
-
context "sw subject methods" do
|
181
|
-
before(:all) do
|
182
|
-
@genre = 'genre top level'
|
183
|
-
@cart_coord = '6 00 S, 71 30 E'
|
184
|
-
@s_genre = 'genre in subject'
|
185
|
-
@geo = 'Somewhere'
|
186
|
-
@geo_code = 'us'
|
187
|
-
@hier_geo_country = 'France'
|
188
|
-
@s_name = 'name in subject'
|
189
|
-
@occupation = 'worker bee'
|
190
|
-
@temporal = 'temporal'
|
191
|
-
@s_title = 'title in subject'
|
192
|
-
@topic = 'topic'
|
193
|
-
m = "<mods #{@ns_decl}>
|
194
|
-
<genre>#{@genre}</genre>
|
195
|
-
<subject><cartographics><coordinates>#{@cart_coord}</coordinates></cartographics></subject>
|
196
|
-
<subject><genre>#{@s_genre}</genre></subject>
|
197
|
-
<subject><geographic>#{@geo}</geographic></subject>
|
198
|
-
<subject><geographicCode authority='iso3166'>#{@geo_code}</geographicCode></subject>
|
199
|
-
<subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject>
|
200
|
-
<subject><name><namePart>#{@s_name}</namePart></name></subject>
|
201
|
-
<subject><occupation>#{@occupation}</occupation></subject>
|
202
|
-
<subject><temporal>#{@temporal}</temporal></subject>
|
203
|
-
<subject><titleInfo><title>#{@s_title}</title></titleInfo></subject>
|
204
|
-
<subject><topic>#{@topic}</topic></subject>
|
205
|
-
</mods>"
|
206
|
-
@smods_rec.from_str m
|
207
|
-
@sw_geographic_search = @smods_rec.sw_geographic_search
|
208
|
-
end
|
209
|
-
|
210
|
-
context "sw_geographic_search" do
|
211
|
-
it "should contain subject <geographic> subelement data" do
|
212
|
-
@sw_geographic_search.should include(@geo)
|
213
|
-
end
|
214
|
-
it "should contain subject <hierarchicalGeographic> subelement data" do
|
215
|
-
@sw_geographic_search.should include(@hier_geo_country)
|
216
|
-
end
|
217
|
-
it "should contain translation of <geographicCode> subelement data with translated authorities" do
|
218
|
-
m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
|
219
|
-
@smods_rec.from_str m
|
220
|
-
@smods_rec.sw_geographic_search.should include('Estonia')
|
221
|
-
end
|
222
|
-
it "should not contain other subject element data" do
|
223
|
-
@sw_geographic_search.should_not include(@genre)
|
224
|
-
@sw_geographic_search.should_not include(@cart_coord)
|
225
|
-
@sw_geographic_search.should_not include(@s_genre)
|
226
|
-
@sw_geographic_search.should_not include(@s_name)
|
227
|
-
@sw_geographic_search.should_not include(@occupation)
|
228
|
-
@sw_geographic_search.should_not include(@temporal)
|
229
|
-
@sw_geographic_search.should_not include(@topic)
|
230
|
-
@sw_geographic_search.should_not include(@s_title)
|
231
|
-
end
|
232
|
-
it "should be nil if there are no values in the MODS" do
|
233
|
-
m = "<mods #{@ns_decl}><note>notit</note></mods>"
|
234
|
-
@smods_rec.from_str m
|
235
|
-
@smods_rec.sw_geographic_search.should == nil
|
236
|
-
end
|
237
|
-
it "should not be nil if there are only subject/geographic elements" do
|
238
|
-
m = "<mods #{@ns_decl}><subject><geographic>#{@geo}</geographic></subject></mods>"
|
239
|
-
@smods_rec.from_str m
|
240
|
-
@smods_rec.sw_geographic_search.should == [@geo]
|
241
|
-
end
|
242
|
-
it "should not be nil if there are only subject/hierarchicalGeographic" do
|
243
|
-
m = "<mods #{@ns_decl}><subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject></mods>"
|
244
|
-
@smods_rec.from_str m
|
245
|
-
@smods_rec.sw_geographic_search.should == [@hier_geo_country]
|
246
|
-
end
|
247
|
-
it "should not be nil if there are only subject/geographicCode elements" do
|
248
|
-
m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
|
249
|
-
@smods_rec.from_str m
|
250
|
-
@smods_rec.sw_geographic_search.should == ['Estonia']
|
251
|
-
end
|
252
|
-
context "geographic subelement" do
|
253
|
-
it "should have a separate value for each geographic element" do
|
254
|
-
m = "<mods #{@ns_decl}>
|
255
|
-
<subject>
|
256
|
-
<geographic>Mississippi</geographic>
|
257
|
-
<geographic>Tippah County</geographic>
|
258
|
-
</subject>
|
259
|
-
<subject><geographic>Washington (D.C.)</geographic></subject>
|
260
|
-
</mods>"
|
261
|
-
@smods_rec.from_str m
|
262
|
-
@smods_rec.sw_geographic_search.should == ['Mississippi', 'Tippah County', 'Washington (D.C.)']
|
263
|
-
end
|
264
|
-
it "should be nil if there are only empty values in the MODS" do
|
265
|
-
m = "<mods #{@ns_decl}><subject><geographic/></subject><note>notit</note></mods>"
|
266
|
-
@smods_rec.from_str m
|
267
|
-
@smods_rec.sw_geographic_search.should == nil
|
268
|
-
end
|
269
|
-
end
|
270
|
-
context "hierarchicalGeographic subelement" do
|
271
|
-
it "should have a separate value for each hierarchicalGeographic element" do
|
272
|
-
m = "<mods #{@ns_decl}>
|
273
|
-
<subject>
|
274
|
-
<hierarchicalGeographic><area>first</area></hierarchicalGeographic>
|
275
|
-
<hierarchicalGeographic><area>second</area></hierarchicalGeographic>
|
276
|
-
</subject>
|
277
|
-
<subject><hierarchicalGeographic><area>third</area></hierarchicalGeographic></subject>
|
278
|
-
</mods>"
|
279
|
-
@smods_rec.from_str m
|
280
|
-
@smods_rec.sw_geographic_search.should == ['first', 'second', 'third']
|
281
|
-
end
|
282
|
-
it "should be nil if there are only empty values in the MODS" do
|
283
|
-
m = "<mods #{@ns_decl}><subject><hierarchicalGeographic/></subject><note>notit</note></mods>"
|
284
|
-
@smods_rec.from_str m
|
285
|
-
@smods_rec.sw_geographic_search.should == nil
|
286
|
-
end
|
287
|
-
context "combining subelements" do
|
288
|
-
before(:all) do
|
289
|
-
m = "<mods #{@ns_decl}>
|
290
|
-
<subject>
|
291
|
-
<hierarchicalGeographic>
|
292
|
-
<country>Canada</country>
|
293
|
-
<province>British Columbia</province>
|
294
|
-
<city>Vancouver</city>
|
295
|
-
</hierarchicalGeographic>
|
296
|
-
</subject></mods>"
|
297
|
-
@smods_rec.from_str m
|
298
|
-
end
|
299
|
-
it "uses a space as the separator by default" do
|
300
|
-
@smods_rec.sw_geographic_search.should == ['Canada British Columbia Vancouver']
|
301
|
-
end
|
302
|
-
it "honors any string value passed in for the separator" do
|
303
|
-
@smods_rec.sw_geographic_search(' --').should == ['Canada --British Columbia --Vancouver']
|
304
|
-
end
|
305
|
-
end
|
306
|
-
end # hierarchicalGeographic
|
307
|
-
context "geographicCode subelement" do
|
308
|
-
before(:all) do
|
309
|
-
m = "<mods #{@ns_decl}>
|
310
|
-
<subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
|
311
|
-
<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
|
312
|
-
<subject><geographicCode authority='marccountry'>mg</geographicCode></subject>
|
313
|
-
<subject><geographicCode authority='iso3166'>us</geographicCode></subject>
|
314
|
-
</mods>"
|
315
|
-
@smods_rec.from_str m
|
316
|
-
@geo_search_from_codes = @smods_rec.sw_geographic_search
|
317
|
-
end
|
318
|
-
it "should not add untranslated values" do
|
319
|
-
@geo_search_from_codes.should_not include('n-us-md')
|
320
|
-
@geo_search_from_codes.should_not include('e-er')
|
321
|
-
@geo_search_from_codes.should_not include('mg')
|
322
|
-
@geo_search_from_codes.should_not include('us')
|
323
|
-
end
|
324
|
-
it "should translate marcgac codes" do
|
325
|
-
@geo_search_from_codes.should include('Estonia')
|
326
|
-
end
|
327
|
-
it "should translate marccountry codes" do
|
328
|
-
@geo_search_from_codes.should include('Madagascar')
|
329
|
-
end
|
330
|
-
it "should not translate other codes" do
|
331
|
-
@geo_search_from_codes.should_not include('United States')
|
332
|
-
end
|
333
|
-
it "should have a separate value for each geographicCode element" do
|
334
|
-
m = "<mods #{@ns_decl}>
|
335
|
-
<subject>
|
336
|
-
<geographicCode authority='marcgac'>e-er</geographicCode>
|
337
|
-
<geographicCode authority='marccountry'>mg</geographicCode>
|
338
|
-
</subject>
|
339
|
-
<subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
|
340
|
-
</mods>"
|
341
|
-
@smods_rec.from_str m
|
342
|
-
@smods_rec.sw_geographic_search.should == ['Estonia', 'Madagascar', 'Maryland']
|
343
|
-
end
|
344
|
-
it "should be nil if there are only empty values in the MODS" do
|
345
|
-
m = "<mods #{@ns_decl}><subject><geographicCode/></subject><note>notit</note></mods>"
|
346
|
-
@smods_rec.from_str m
|
347
|
-
@smods_rec.sw_geographic_search.should == nil
|
348
|
-
end
|
349
|
-
it "should add the translated value if it wasn't present already" do
|
350
|
-
m = "<mods #{@ns_decl}>
|
351
|
-
<subject><geographic>Somewhere</geographic></subject>
|
352
|
-
<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
|
353
|
-
</mods>"
|
354
|
-
@smods_rec.from_str m
|
355
|
-
@smods_rec.sw_geographic_search.size.should == 2
|
356
|
-
@smods_rec.sw_geographic_search.should include('Estonia')
|
357
|
-
end
|
358
|
-
it "should not add the translated value if it was already present" do
|
359
|
-
m = "<mods #{@ns_decl}>
|
360
|
-
<subject><geographic>Estonia</geographic></subject>
|
361
|
-
<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
|
362
|
-
</mods>"
|
363
|
-
@smods_rec.from_str m
|
364
|
-
@smods_rec.sw_geographic_search.size.should == 1
|
365
|
-
@smods_rec.sw_geographic_search.should == ['Estonia']
|
366
|
-
end
|
367
|
-
end
|
368
|
-
end # sw_geographic_search
|
369
|
-
end # context sw subject methods
|
370
|
-
|
371
180
|
end
|
@@ -0,0 +1,384 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Searchworks mixin for Stanford::Mods::Record" do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@smods_rec = Stanford::Mods::Record.new
|
8
|
+
@ns_decl = "xmlns='#{Mods::MODS_NS}'"
|
9
|
+
end
|
10
|
+
|
11
|
+
context "sw subject methods" do
|
12
|
+
before(:all) do
|
13
|
+
@genre = 'genre top level'
|
14
|
+
@cart_coord = '6 00 S, 71 30 E'
|
15
|
+
@s_genre = 'genre in subject'
|
16
|
+
@geo = 'Somewhere'
|
17
|
+
@geo_code = 'us'
|
18
|
+
@hier_geo_country = 'France'
|
19
|
+
@s_name = 'name in subject'
|
20
|
+
@occupation = 'worker bee'
|
21
|
+
@temporal = 'temporal'
|
22
|
+
@s_title = 'title in subject'
|
23
|
+
@topic = 'topic'
|
24
|
+
m = "<mods #{@ns_decl}>
|
25
|
+
<genre>#{@genre}</genre>
|
26
|
+
<subject><cartographics><coordinates>#{@cart_coord}</coordinates></cartographics></subject>
|
27
|
+
<subject><genre>#{@s_genre}</genre></subject>
|
28
|
+
<subject><geographic>#{@geo}</geographic></subject>
|
29
|
+
<subject><geographicCode authority='iso3166'>#{@geo_code}</geographicCode></subject>
|
30
|
+
<subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject>
|
31
|
+
<subject><name><namePart>#{@s_name}</namePart></name></subject>
|
32
|
+
<subject><occupation>#{@occupation}</occupation></subject>
|
33
|
+
<subject><temporal>#{@temporal}</temporal></subject>
|
34
|
+
<subject><titleInfo><title>#{@s_title}</title></titleInfo></subject>
|
35
|
+
<subject><topic>#{@topic}</topic></subject>
|
36
|
+
</mods>"
|
37
|
+
@smods_rec.from_str m
|
38
|
+
@sw_geographic_search = @smods_rec.sw_geographic_search
|
39
|
+
@sw_subject_titles = @smods_rec.sw_subject_titles
|
40
|
+
@sw_subject_names = @smods_rec.sw_subject_names
|
41
|
+
end
|
42
|
+
|
43
|
+
context "sw_subject_names" do
|
44
|
+
it "should contain <subject><name><namePart> values" do
|
45
|
+
@sw_subject_names.should include(@s_name)
|
46
|
+
end
|
47
|
+
it "should not contain non-name subject subelements" do
|
48
|
+
@sw_subject_names.should_not include(@cart_coord)
|
49
|
+
@sw_subject_names.should_not include(@s_genre)
|
50
|
+
@sw_subject_names.should_not include(@geo)
|
51
|
+
@sw_subject_names.should_not include(@geo_code)
|
52
|
+
@sw_subject_names.should_not include(@hier_geo_country)
|
53
|
+
@sw_subject_names.should_not include(@occupation)
|
54
|
+
@sw_subject_names.should_not include(@temporal)
|
55
|
+
@sw_subject_names.should_not include(@topic)
|
56
|
+
@sw_subject_names.should_not include(@s_title)
|
57
|
+
end
|
58
|
+
it "should not contain subject/name/role" do
|
59
|
+
m = "<mods #{@ns_decl}>
|
60
|
+
<subject><name type='personal'>
|
61
|
+
<namePart>Alterman, Eric</namePart>
|
62
|
+
<displayForm>Eric Alterman</displayForm>
|
63
|
+
<role>
|
64
|
+
<roleTerm type='text'>creator</roleTerm>
|
65
|
+
<roleTerm type='code'>cre</roleTerm>
|
66
|
+
</role>
|
67
|
+
</name></subject></mods>"
|
68
|
+
@smods_rec.from_str m
|
69
|
+
@smods_rec.sw_subject_names.find { |sn| sn =~ /cre/ }.should == nil
|
70
|
+
end
|
71
|
+
it "should not contain subject/name/affiliation" do
|
72
|
+
m = "<mods #{@ns_decl}>
|
73
|
+
<subject><name type='personal'>
|
74
|
+
<namePart type='termsOfAddress'>Dr.</namePart>
|
75
|
+
<namePart>Brown, B. F.</namePart>
|
76
|
+
<affiliation>Chemistry Dept., American University</affiliation>
|
77
|
+
</name></subject></mods>"
|
78
|
+
@smods_rec.from_str m
|
79
|
+
@smods_rec.sw_subject_names.find { |sn| sn =~ /Chemistry/ }.should == nil
|
80
|
+
end
|
81
|
+
it "should not contain subject/name/description" do
|
82
|
+
m = "<mods #{@ns_decl}>
|
83
|
+
<subject><name type='personal'>
|
84
|
+
<namePart>Abrams, Michael</namePart>
|
85
|
+
<description>American artist, 20th c.</description>
|
86
|
+
</name></subject></mods>"
|
87
|
+
@smods_rec.from_str m
|
88
|
+
@smods_rec.sw_subject_names.find { |sn| sn =~ /artist/ }.should == nil
|
89
|
+
end
|
90
|
+
it "should not include top level name element" do
|
91
|
+
m = "<mods #{@ns_decl}>
|
92
|
+
<name type='personal'>
|
93
|
+
<namePart>Abrams, Michael</namePart>
|
94
|
+
<description>American artist, 20th c.</description>
|
95
|
+
</name></mods>"
|
96
|
+
@smods_rec.from_str m
|
97
|
+
@smods_rec.sw_subject_names.should == []
|
98
|
+
end
|
99
|
+
it "should have one value for each name element" do
|
100
|
+
m = "<mods #{@ns_decl}>
|
101
|
+
<subject>
|
102
|
+
<name><namePart>first</namePart></name>
|
103
|
+
<name><namePart>second</namePart></name>
|
104
|
+
</subject>
|
105
|
+
<subject>
|
106
|
+
<name><namePart>third</namePart></name>
|
107
|
+
</subject>
|
108
|
+
</mods>"
|
109
|
+
@smods_rec.from_str m
|
110
|
+
@smods_rec.sw_subject_names.should == ['first', 'second', 'third']
|
111
|
+
end
|
112
|
+
it "should be an empty Array if there are no values in the mods" do
|
113
|
+
m = "<mods #{@ns_decl}><note>notit</note></mods>"
|
114
|
+
@smods_rec.from_str m
|
115
|
+
@smods_rec.sw_subject_names.should == []
|
116
|
+
end
|
117
|
+
it "should be an empty Array if there are empty values in the mods" do
|
118
|
+
m = "<mods #{@ns_decl}><subject><name><namePart/></name></subject><note>notit</note></mods>"
|
119
|
+
@smods_rec.from_str m
|
120
|
+
@smods_rec.sw_subject_names.should == []
|
121
|
+
end
|
122
|
+
context "combining subelements" do
|
123
|
+
before(:all) do
|
124
|
+
m = "<mods #{@ns_decl}>
|
125
|
+
<subject>
|
126
|
+
<name>
|
127
|
+
<namePart>first</namePart>
|
128
|
+
<namePart>second</namePart>
|
129
|
+
</name>
|
130
|
+
</subject>
|
131
|
+
</mods>"
|
132
|
+
@smods_rec.from_str m
|
133
|
+
end
|
134
|
+
it "uses a ', ' as the separator by default" do
|
135
|
+
@smods_rec.sw_subject_names.should == ['first, second']
|
136
|
+
end
|
137
|
+
it "honors any string value passed in for the separator" do
|
138
|
+
@smods_rec.sw_subject_names(' --').should == ['first --second']
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end # sw_subject_names
|
142
|
+
|
143
|
+
context "sw_subject_titles" do
|
144
|
+
it "should contain <subject><titleInfo> subelement values" do
|
145
|
+
@sw_subject_titles.should include(@s_title)
|
146
|
+
end
|
147
|
+
it "should not contain non-name subject subelements" do
|
148
|
+
@sw_subject_titles.should_not include(@cart_coord)
|
149
|
+
@sw_subject_titles.should_not include(@s_genre)
|
150
|
+
@sw_subject_titles.should_not include(@geo)
|
151
|
+
@sw_subject_titles.should_not include(@geo_code)
|
152
|
+
@sw_subject_titles.should_not include(@hier_geo_country)
|
153
|
+
@sw_subject_titles.should_not include(@s_name)
|
154
|
+
@sw_subject_titles.should_not include(@occupation)
|
155
|
+
@sw_subject_titles.should_not include(@temporal)
|
156
|
+
@sw_subject_titles.should_not include(@topic)
|
157
|
+
end
|
158
|
+
it "should not include top level titleInfo element" do
|
159
|
+
m = "<mods #{@ns_decl}><titleInfo><title>Oklahoma</title></titleInfo></mods>"
|
160
|
+
@smods_rec.from_str m
|
161
|
+
@smods_rec.sw_subject_titles.should == []
|
162
|
+
end
|
163
|
+
it "should have one value for each titleInfo element" do
|
164
|
+
m = "<mods #{@ns_decl}>
|
165
|
+
<subject>
|
166
|
+
<titleInfo><title>first</title></titleInfo>
|
167
|
+
<titleInfo><title>second</title></titleInfo>
|
168
|
+
</subject>
|
169
|
+
<subject>
|
170
|
+
<titleInfo><title>third</title></titleInfo>
|
171
|
+
</subject>
|
172
|
+
</mods>"
|
173
|
+
@smods_rec.from_str m
|
174
|
+
@smods_rec.sw_subject_titles.should == ['first', 'second', 'third']
|
175
|
+
end
|
176
|
+
it "should be an empty Array if there are no values in the mods" do
|
177
|
+
m = "<mods #{@ns_decl}><note>notit</note></mods>"
|
178
|
+
@smods_rec.from_str m
|
179
|
+
@smods_rec.sw_subject_titles.should == []
|
180
|
+
end
|
181
|
+
it "should be an empty Array if there are empty values in the mods" do
|
182
|
+
m = "<mods #{@ns_decl}><subject><titleInfo><title/></titleInfo></subject><note>notit</note></mods>"
|
183
|
+
@smods_rec.from_str m
|
184
|
+
@smods_rec.sw_subject_titles.should == []
|
185
|
+
end
|
186
|
+
context "combining subelements" do
|
187
|
+
before(:all) do
|
188
|
+
m = "<mods #{@ns_decl}>
|
189
|
+
<subject>
|
190
|
+
<titleInfo>
|
191
|
+
<title>first</title>
|
192
|
+
<subTitle>second</subTitle>
|
193
|
+
</titleInfo>
|
194
|
+
</subject>
|
195
|
+
</mods>"
|
196
|
+
@smods_rec.from_str m
|
197
|
+
end
|
198
|
+
it "uses a ' ' as the separator by default" do
|
199
|
+
@smods_rec.sw_subject_titles.should == ['first second']
|
200
|
+
end
|
201
|
+
it "honors any string value passed in for the separator" do
|
202
|
+
@smods_rec.sw_subject_titles(' --').should == ['first --second']
|
203
|
+
end
|
204
|
+
it "includes all subelements in the order of occurrence" do
|
205
|
+
m = "<mods #{@ns_decl}>
|
206
|
+
<subject>
|
207
|
+
<titleInfo>
|
208
|
+
<partName>1</partName>
|
209
|
+
<nonSort>2</nonSort>
|
210
|
+
<partNumber>3</partNumber>
|
211
|
+
<title>4</title>
|
212
|
+
<subTitle>5</subTitle>
|
213
|
+
</titleInfo>
|
214
|
+
</subject>
|
215
|
+
</mods>"
|
216
|
+
@smods_rec.from_str m
|
217
|
+
@smods_rec.sw_subject_titles.should == ['1 2 3 4 5']
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end # sw_subject_titles
|
221
|
+
|
222
|
+
|
223
|
+
context "sw_geographic_search" do
|
224
|
+
it "should contain subject <geographic> subelement data" do
|
225
|
+
@sw_geographic_search.should include(@geo)
|
226
|
+
end
|
227
|
+
it "should contain subject <hierarchicalGeographic> subelement data" do
|
228
|
+
@sw_geographic_search.should include(@hier_geo_country)
|
229
|
+
end
|
230
|
+
it "should contain translation of <geographicCode> subelement data with translated authorities" do
|
231
|
+
m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
|
232
|
+
@smods_rec.from_str m
|
233
|
+
@smods_rec.sw_geographic_search.should include('Estonia')
|
234
|
+
end
|
235
|
+
it "should not contain other subject element data" do
|
236
|
+
@sw_geographic_search.should_not include(@genre)
|
237
|
+
@sw_geographic_search.should_not include(@cart_coord)
|
238
|
+
@sw_geographic_search.should_not include(@s_genre)
|
239
|
+
@sw_geographic_search.should_not include(@s_name)
|
240
|
+
@sw_geographic_search.should_not include(@occupation)
|
241
|
+
@sw_geographic_search.should_not include(@temporal)
|
242
|
+
@sw_geographic_search.should_not include(@topic)
|
243
|
+
@sw_geographic_search.should_not include(@s_title)
|
244
|
+
end
|
245
|
+
it "should be [] if there are no values in the MODS" do
|
246
|
+
m = "<mods #{@ns_decl}><note>notit</note></mods>"
|
247
|
+
@smods_rec.from_str m
|
248
|
+
@smods_rec.sw_geographic_search.should == []
|
249
|
+
end
|
250
|
+
it "should not be empty Array if there are only subject/geographic elements" do
|
251
|
+
m = "<mods #{@ns_decl}><subject><geographic>#{@geo}</geographic></subject></mods>"
|
252
|
+
@smods_rec.from_str m
|
253
|
+
@smods_rec.sw_geographic_search.should == [@geo]
|
254
|
+
end
|
255
|
+
it "should not be empty Array if there are only subject/hierarchicalGeographic" do
|
256
|
+
m = "<mods #{@ns_decl}><subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject></mods>"
|
257
|
+
@smods_rec.from_str m
|
258
|
+
@smods_rec.sw_geographic_search.should == [@hier_geo_country]
|
259
|
+
end
|
260
|
+
it "should not be empty Array if there are only subject/geographicCode elements" do
|
261
|
+
m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
|
262
|
+
@smods_rec.from_str m
|
263
|
+
@smods_rec.sw_geographic_search.should == ['Estonia']
|
264
|
+
end
|
265
|
+
context "geographic subelement" do
|
266
|
+
it "should have a separate value for each geographic element" do
|
267
|
+
m = "<mods #{@ns_decl}>
|
268
|
+
<subject>
|
269
|
+
<geographic>Mississippi</geographic>
|
270
|
+
<geographic>Tippah County</geographic>
|
271
|
+
</subject>
|
272
|
+
<subject><geographic>Washington (D.C.)</geographic></subject>
|
273
|
+
</mods>"
|
274
|
+
@smods_rec.from_str m
|
275
|
+
@smods_rec.sw_geographic_search.should == ['Mississippi', 'Tippah County', 'Washington (D.C.)']
|
276
|
+
end
|
277
|
+
it "should be empty Array if there are only empty values in the MODS" do
|
278
|
+
m = "<mods #{@ns_decl}><subject><geographic/></subject><note>notit</note></mods>"
|
279
|
+
@smods_rec.from_str m
|
280
|
+
@smods_rec.sw_geographic_search.should == []
|
281
|
+
end
|
282
|
+
end
|
283
|
+
context "hierarchicalGeographic subelement" do
|
284
|
+
it "should have a separate value for each hierarchicalGeographic element" do
|
285
|
+
m = "<mods #{@ns_decl}>
|
286
|
+
<subject>
|
287
|
+
<hierarchicalGeographic><area>first</area></hierarchicalGeographic>
|
288
|
+
<hierarchicalGeographic><area>second</area></hierarchicalGeographic>
|
289
|
+
</subject>
|
290
|
+
<subject><hierarchicalGeographic><area>third</area></hierarchicalGeographic></subject>
|
291
|
+
</mods>"
|
292
|
+
@smods_rec.from_str m
|
293
|
+
@smods_rec.sw_geographic_search.should == ['first', 'second', 'third']
|
294
|
+
end
|
295
|
+
it "should be empty Array if there are only empty values in the MODS" do
|
296
|
+
m = "<mods #{@ns_decl}><subject><hierarchicalGeographic/></subject><note>notit</note></mods>"
|
297
|
+
@smods_rec.from_str m
|
298
|
+
@smods_rec.sw_geographic_search.should == []
|
299
|
+
end
|
300
|
+
context "combining subelements" do
|
301
|
+
before(:all) do
|
302
|
+
m = "<mods #{@ns_decl}>
|
303
|
+
<subject>
|
304
|
+
<hierarchicalGeographic>
|
305
|
+
<country>Canada</country>
|
306
|
+
<province>British Columbia</province>
|
307
|
+
<city>Vancouver</city>
|
308
|
+
</hierarchicalGeographic>
|
309
|
+
</subject></mods>"
|
310
|
+
@smods_rec.from_str m
|
311
|
+
end
|
312
|
+
it "uses a space as the separator by default" do
|
313
|
+
@smods_rec.sw_geographic_search.should == ['Canada British Columbia Vancouver']
|
314
|
+
end
|
315
|
+
it "honors any string value passed in for the separator" do
|
316
|
+
@smods_rec.sw_geographic_search(' --').should == ['Canada --British Columbia --Vancouver']
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end # hierarchicalGeographic
|
320
|
+
context "geographicCode subelement" do
|
321
|
+
before(:all) do
|
322
|
+
m = "<mods #{@ns_decl}>
|
323
|
+
<subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
|
324
|
+
<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
|
325
|
+
<subject><geographicCode authority='marccountry'>mg</geographicCode></subject>
|
326
|
+
<subject><geographicCode authority='iso3166'>us</geographicCode></subject>
|
327
|
+
</mods>"
|
328
|
+
@smods_rec.from_str m
|
329
|
+
@geo_search_from_codes = @smods_rec.sw_geographic_search
|
330
|
+
end
|
331
|
+
it "should not add untranslated values" do
|
332
|
+
@geo_search_from_codes.should_not include('n-us-md')
|
333
|
+
@geo_search_from_codes.should_not include('e-er')
|
334
|
+
@geo_search_from_codes.should_not include('mg')
|
335
|
+
@geo_search_from_codes.should_not include('us')
|
336
|
+
end
|
337
|
+
it "should translate marcgac codes" do
|
338
|
+
@geo_search_from_codes.should include('Estonia')
|
339
|
+
end
|
340
|
+
it "should translate marccountry codes" do
|
341
|
+
@geo_search_from_codes.should include('Madagascar')
|
342
|
+
end
|
343
|
+
it "should not translate other codes" do
|
344
|
+
@geo_search_from_codes.should_not include('United States')
|
345
|
+
end
|
346
|
+
it "should have a separate value for each geographicCode element" do
|
347
|
+
m = "<mods #{@ns_decl}>
|
348
|
+
<subject>
|
349
|
+
<geographicCode authority='marcgac'>e-er</geographicCode>
|
350
|
+
<geographicCode authority='marccountry'>mg</geographicCode>
|
351
|
+
</subject>
|
352
|
+
<subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
|
353
|
+
</mods>"
|
354
|
+
@smods_rec.from_str m
|
355
|
+
@smods_rec.sw_geographic_search.should == ['Estonia', 'Madagascar', 'Maryland']
|
356
|
+
end
|
357
|
+
it "should be empty Array if there are only empty values in the MODS" do
|
358
|
+
m = "<mods #{@ns_decl}><subject><geographicCode/></subject><note>notit</note></mods>"
|
359
|
+
@smods_rec.from_str m
|
360
|
+
@smods_rec.sw_geographic_search.should == []
|
361
|
+
end
|
362
|
+
it "should add the translated value if it wasn't present already" do
|
363
|
+
m = "<mods #{@ns_decl}>
|
364
|
+
<subject><geographic>Somewhere</geographic></subject>
|
365
|
+
<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
|
366
|
+
</mods>"
|
367
|
+
@smods_rec.from_str m
|
368
|
+
@smods_rec.sw_geographic_search.size.should == 2
|
369
|
+
@smods_rec.sw_geographic_search.should include('Estonia')
|
370
|
+
end
|
371
|
+
it "should not add the translated value if it was already present" do
|
372
|
+
m = "<mods #{@ns_decl}>
|
373
|
+
<subject><geographic>Estonia</geographic></subject>
|
374
|
+
<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
|
375
|
+
</mods>"
|
376
|
+
@smods_rec.from_str m
|
377
|
+
@smods_rec.sw_geographic_search.size.should == 1
|
378
|
+
@smods_rec.sw_geographic_search.should == ['Estonia']
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end # sw_geographic_search
|
382
|
+
end # context sw subject methods
|
383
|
+
|
384
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stanford-mods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-01-
|
13
|
+
date: 2013-01-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mods
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- spec/kolb_spec.rb
|
155
155
|
- spec/name_spec.rb
|
156
156
|
- spec/searchworks_spec.rb
|
157
|
+
- spec/searchworks_subject_spec.rb
|
157
158
|
- spec/spec_helper.rb
|
158
159
|
- stanford-mods.gemspec
|
159
160
|
homepage: https://github.com/sul-dlss/stanford-mods
|
@@ -170,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
171
|
version: '0'
|
171
172
|
segments:
|
172
173
|
- 0
|
173
|
-
hash:
|
174
|
+
hash: 611342479831019770
|
174
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
176
|
none: false
|
176
177
|
requirements:
|
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
180
|
version: '0'
|
180
181
|
segments:
|
181
182
|
- 0
|
182
|
-
hash:
|
183
|
+
hash: 611342479831019770
|
183
184
|
requirements: []
|
184
185
|
rubyforge_project:
|
185
186
|
rubygems_version: 1.8.24
|
@@ -191,5 +192,6 @@ test_files:
|
|
191
192
|
- spec/kolb_spec.rb
|
192
193
|
- spec/name_spec.rb
|
193
194
|
- spec/searchworks_spec.rb
|
195
|
+
- spec/searchworks_subject_spec.rb
|
194
196
|
- spec/spec_helper.rb
|
195
197
|
has_rdoc:
|