stanford-mods 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -1
- data/lib/stanford-mods.rb +0 -1
- data/lib/stanford-mods/{mappings.rb → old_mappings_4_ref.rb} +2 -0
- data/lib/stanford-mods/searchworks.rb +31 -5
- data/lib/stanford-mods/version.rb +1 -1
- data/spec/{values_for_req_sw_spec.rb → ignore_me_sw_required_flds_spec.rb} +1 -3
- data/spec/kolb_spec.rb +1 -3
- data/spec/searchworks_spec.rb +193 -5
- metadata +7 -7
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Stanford::Mods
|
2
2
|
|
3
|
-
{<img src="https://secure.travis-ci.org/sul-dlss/stanford-mods.png?branch=master" alt="Build Status" />}[http://travis-ci.org/sul-dlss/stanford-mods]
|
3
|
+
{<img src="https://secure.travis-ci.org/sul-dlss/stanford-mods.png?branch=master" alt="Build Status" />}[http://travis-ci.org/sul-dlss/stanford-mods] {<img src="https://gemnasium.com/sul-dlss/stanford-mods.png" alt="Dependency Status" />}[https://gemnasium.com/sul-dlss/stanford-mods]
|
4
4
|
|
5
5
|
A Gem with Stanford specific wranglings of MODS (Metadata Object Description Schema) metadata from DOR, the Stanford Digital Object Repository.
|
6
6
|
|
@@ -60,6 +60,7 @@ Example Using SearchWorks Mixins:
|
|
60
60
|
|
61
61
|
== Releases
|
62
62
|
|
63
|
+
* <b>0.0.7</b> added sw_geographic_search to searchworks mixin
|
63
64
|
* <b>0.0.6</b> various title methods added to searchworks mixin
|
64
65
|
* <b>0.0.5</b> main_author_w_date, additional_authors_w_dates added to Stanford::Mods::Record; various author methods added to searchworks mixin
|
65
66
|
* <b>0.0.4</b> KolbRecord started
|
data/lib/stanford-mods.rb
CHANGED
@@ -7,11 +7,6 @@ module Stanford
|
|
7
7
|
|
8
8
|
class Record < ::Mods::Record
|
9
9
|
|
10
|
-
# if it's coming from DOR, then it is available online
|
11
|
-
def sw_access_facet
|
12
|
-
['Online']
|
13
|
-
end
|
14
|
-
|
15
10
|
# include langagues known to SearchWorks; try to error correct when possible (e.g. when ISO-639 disagrees with MARC standard)
|
16
11
|
def sw_language_facet
|
17
12
|
result = []
|
@@ -119,6 +114,37 @@ module Stanford
|
|
119
114
|
val = '' + ( sort_title ? sort_title : '')
|
120
115
|
val.gsub(/[[:punct:]]*/, '').strip
|
121
116
|
end
|
117
|
+
|
118
|
+
# ---- SUBJECT ----
|
119
|
+
|
120
|
+
# Values are the contents of:
|
121
|
+
# subject/geographic
|
122
|
+
# subject/hierarchicalGeographic
|
123
|
+
# subject/geographicCode (only include the translated value if it isn't already present from other mods geo fields)
|
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 nil if none
|
126
|
+
def sw_geographic_search(sep = ' ')
|
127
|
+
result = term_values([:subject, :geographic]) || []
|
128
|
+
|
129
|
+
# hierarchicalGeographic has sub elements
|
130
|
+
@mods_ng_xml.subject.hierarchicalGeographic.each { |hg_node|
|
131
|
+
hg_vals = []
|
132
|
+
hg_node.element_children.each { |e|
|
133
|
+
hg_vals << e.text unless e.text.empty?
|
134
|
+
}
|
135
|
+
result << hg_vals.join(sep) unless hg_vals.empty?
|
136
|
+
}
|
137
|
+
|
138
|
+
trans_code_vals = @mods_ng_xml.subject.geographicCode.translated_value
|
139
|
+
if trans_code_vals
|
140
|
+
trans_code_vals.each { |val|
|
141
|
+
result << val if !result.include?(val)
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
return nil if result.empty?
|
146
|
+
result
|
147
|
+
end
|
122
148
|
|
123
149
|
end # class Record
|
124
150
|
end # Module Mods
|
@@ -39,9 +39,7 @@ describe "Values for SearchWorks Solr" do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
context "strongly recommended fields" do
|
42
|
-
|
43
|
-
Stanford::Mods::Record.new.sw_access_facet.should == ['Online']
|
44
|
-
end
|
42
|
+
# access_facet has nothing to do with mods
|
45
43
|
# title convenience methods are implemented in the Mods gem; no special work here
|
46
44
|
context "title fields" do
|
47
45
|
context "for display" do
|
data/spec/kolb_spec.rb
CHANGED
@@ -94,9 +94,7 @@ describe "Kolb Collection Mods Record" do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
context "strongly recommended" do
|
97
|
-
|
98
|
-
@krec.sw_access_facet.should == ['Online']
|
99
|
-
end
|
97
|
+
# access_facet has nothing to do with mods
|
100
98
|
context "title" do
|
101
99
|
context "for display and searching" do
|
102
100
|
it "short title" do
|
data/spec/searchworks_spec.rb
CHANGED
@@ -9,10 +9,6 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
|
|
9
9
|
@ns_decl = "xmlns='#{Mods::MODS_NS}'"
|
10
10
|
end
|
11
11
|
|
12
|
-
it "sw_access_facet" do
|
13
|
-
@smods_rec.sw_access_facet.should == ['Online']
|
14
|
-
end
|
15
|
-
|
16
12
|
context "languages" do
|
17
13
|
it "should use the SearchWorks controlled vocabulary" do
|
18
14
|
m = "<mods #{@ns_decl}><language><languageTerm authority='iso639-2b' type='code'>per ara, dut</languageTerm></language></mods>"
|
@@ -180,5 +176,197 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
|
|
180
176
|
r.sw_sort_title.should =~ /^Jerk$/
|
181
177
|
end
|
182
178
|
end
|
183
|
-
end
|
179
|
+
end # content sw title methods
|
180
|
+
|
181
|
+
context "sw subject methods" do
|
182
|
+
before(:all) do
|
183
|
+
@genre = 'genre top level'
|
184
|
+
@cart_coord = '6 00 S, 71 30 E'
|
185
|
+
@s_genre = 'genre in subject'
|
186
|
+
@geo = 'Somewhere'
|
187
|
+
@geo_code = 'us'
|
188
|
+
@hier_geo_country = 'France'
|
189
|
+
@s_name = 'name in subject'
|
190
|
+
@occupation = 'worker bee'
|
191
|
+
@temporal = 'temporal'
|
192
|
+
@s_title = 'title in subject'
|
193
|
+
@topic = 'topic'
|
194
|
+
m = "<mods #{@ns_decl}>
|
195
|
+
<genre>#{@genre}</genre>
|
196
|
+
<subject><cartographics><coordinates>#{@cart_coord}</coordinates></cartographics></subject>
|
197
|
+
<subject><genre>#{@s_genre}</genre></subject>
|
198
|
+
<subject><geographic>#{@geo}</geographic></subject>
|
199
|
+
<subject><geographicCode authority='iso3166'>#{@geo_code}</geographicCode></subject>
|
200
|
+
<subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject>
|
201
|
+
<subject><name><namePart>#{@s_name}</namePart></name></subject>
|
202
|
+
<subject><occupation>#{@occupation}</occupation></subject>
|
203
|
+
<subject><temporal>#{@temporal}</temporal></subject>
|
204
|
+
<subject><titleInfo><title>#{@s_title}</title></titleInfo></subject>
|
205
|
+
<subject><topic>#{@topic}</topic></subject>
|
206
|
+
</mods>"
|
207
|
+
@smods_rec.from_str m
|
208
|
+
@sw_geographic_search = @smods_rec.sw_geographic_search
|
209
|
+
end
|
210
|
+
|
211
|
+
context "sw_geographic_search" do
|
212
|
+
it "should contain subject <geographic> subelement data" do
|
213
|
+
@sw_geographic_search.should include(@geo)
|
214
|
+
end
|
215
|
+
it "should contain subject <hierarchicalGeographic> subelement data" do
|
216
|
+
@sw_geographic_search.should include(@hier_geo_country)
|
217
|
+
end
|
218
|
+
it "should contain translation of <geographicCode> subelement data with translated authorities" do
|
219
|
+
m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
|
220
|
+
@smods_rec.from_str m
|
221
|
+
@smods_rec.sw_geographic_search.should include('Estonia')
|
222
|
+
end
|
223
|
+
it "should not contain other subject element data" do
|
224
|
+
@sw_geographic_search.should_not include(@genre)
|
225
|
+
@sw_geographic_search.should_not include(@cart_coord)
|
226
|
+
@sw_geographic_search.should_not include(@s_genre)
|
227
|
+
@sw_geographic_search.should_not include(@s_name)
|
228
|
+
@sw_geographic_search.should_not include(@occupation)
|
229
|
+
@sw_geographic_search.should_not include(@temporal)
|
230
|
+
@sw_geographic_search.should_not include(@topic)
|
231
|
+
@sw_geographic_search.should_not include(@s_title)
|
232
|
+
end
|
233
|
+
it "should be nil if there are no values in the MODS" do
|
234
|
+
m = "<mods #{@ns_decl}><note>notit</note></mods>"
|
235
|
+
@smods_rec.from_str m
|
236
|
+
@smods_rec.sw_geographic_search.should == nil
|
237
|
+
end
|
238
|
+
it "should not be nil if there are only subject/geographic elements" do
|
239
|
+
m = "<mods #{@ns_decl}><subject><geographic>#{@geo}</geographic></subject></mods>"
|
240
|
+
@smods_rec.from_str m
|
241
|
+
@smods_rec.sw_geographic_search.should == [@geo]
|
242
|
+
end
|
243
|
+
it "should not be nil if there are only subject/hierarchicalGeographic" do
|
244
|
+
m = "<mods #{@ns_decl}><subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject></mods>"
|
245
|
+
@smods_rec.from_str m
|
246
|
+
@smods_rec.sw_geographic_search.should == [@hier_geo_country]
|
247
|
+
end
|
248
|
+
it "should not be nil if there are only subject/geographicCode elements" do
|
249
|
+
m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
|
250
|
+
@smods_rec.from_str m
|
251
|
+
@smods_rec.sw_geographic_search.should == ['Estonia']
|
252
|
+
end
|
253
|
+
context "geographic subelement" do
|
254
|
+
it "should have a separate value for each geographic element" do
|
255
|
+
m = "<mods #{@ns_decl}>
|
256
|
+
<subject>
|
257
|
+
<geographic>Mississippi</geographic>
|
258
|
+
<geographic>Tippah County</geographic>
|
259
|
+
</subject>
|
260
|
+
<subject><geographic>Washington (D.C.)</geographic></subject>
|
261
|
+
</mods>"
|
262
|
+
@smods_rec.from_str m
|
263
|
+
@smods_rec.sw_geographic_search.should == ['Mississippi', 'Tippah County', 'Washington (D.C.)']
|
264
|
+
end
|
265
|
+
it "should be nil if there are only empty values in the MODS" do
|
266
|
+
m = "<mods #{@ns_decl}><subject><geographic/></subject><note>notit</note></mods>"
|
267
|
+
@smods_rec.from_str m
|
268
|
+
@smods_rec.sw_geographic_search.should == nil
|
269
|
+
end
|
270
|
+
end
|
271
|
+
context "hierarchicalGeographic subelement" do
|
272
|
+
it "should have a separate value for each hierarchicalGeographic element" do
|
273
|
+
m = "<mods #{@ns_decl}>
|
274
|
+
<subject>
|
275
|
+
<hierarchicalGeographic><area>first</area></hierarchicalGeographic>
|
276
|
+
<hierarchicalGeographic><area>second</area></hierarchicalGeographic>
|
277
|
+
</subject>
|
278
|
+
<subject><hierarchicalGeographic><area>third</area></hierarchicalGeographic></subject>
|
279
|
+
</mods>"
|
280
|
+
@smods_rec.from_str m
|
281
|
+
@smods_rec.sw_geographic_search.should == ['first', 'second', 'third']
|
282
|
+
end
|
283
|
+
it "should be nil if there are only empty values in the MODS" do
|
284
|
+
m = "<mods #{@ns_decl}><subject><hierarchicalGeographic/></subject><note>notit</note></mods>"
|
285
|
+
@smods_rec.from_str m
|
286
|
+
@smods_rec.sw_geographic_search.should == nil
|
287
|
+
end
|
288
|
+
context "combining subelements" do
|
289
|
+
before(:all) do
|
290
|
+
m = "<mods #{@ns_decl}>
|
291
|
+
<subject>
|
292
|
+
<hierarchicalGeographic>
|
293
|
+
<country>Canada</country>
|
294
|
+
<province>British Columbia</province>
|
295
|
+
<city>Vancouver</city>
|
296
|
+
</hierarchicalGeographic>
|
297
|
+
</subject></mods>"
|
298
|
+
@smods_rec.from_str m
|
299
|
+
end
|
300
|
+
it "uses a space as the separator by default" do
|
301
|
+
@smods_rec.sw_geographic_search.should == ['Canada British Columbia Vancouver']
|
302
|
+
end
|
303
|
+
it "honors any string value passed in for the separator" do
|
304
|
+
@smods_rec.sw_geographic_search(' --').should == ['Canada --British Columbia --Vancouver']
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end # hierarchicalGeographic
|
308
|
+
context "geographicCode subelement" do
|
309
|
+
before(:all) do
|
310
|
+
m = "<mods #{@ns_decl}>
|
311
|
+
<subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
|
312
|
+
<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
|
313
|
+
<subject><geographicCode authority='marccountry'>mg</geographicCode></subject>
|
314
|
+
<subject><geographicCode authority='iso3166'>us</geographicCode></subject>
|
315
|
+
</mods>"
|
316
|
+
@smods_rec.from_str m
|
317
|
+
@geo_search_from_codes = @smods_rec.sw_geographic_search
|
318
|
+
end
|
319
|
+
it "should not add untranslated values" do
|
320
|
+
@geo_search_from_codes.should_not include('n-us-md')
|
321
|
+
@geo_search_from_codes.should_not include('e-er')
|
322
|
+
@geo_search_from_codes.should_not include('mg')
|
323
|
+
@geo_search_from_codes.should_not include('us')
|
324
|
+
end
|
325
|
+
it "should translate marcgac codes" do
|
326
|
+
@geo_search_from_codes.should include('Estonia')
|
327
|
+
end
|
328
|
+
it "should translate marccountry codes" do
|
329
|
+
@geo_search_from_codes.should include('Madagascar')
|
330
|
+
end
|
331
|
+
it "should not translate other codes" do
|
332
|
+
@geo_search_from_codes.should_not include('United States')
|
333
|
+
end
|
334
|
+
it "should have a separate value for each geographicCode element" do
|
335
|
+
m = "<mods #{@ns_decl}>
|
336
|
+
<subject>
|
337
|
+
<geographicCode authority='marcgac'>e-er</geographicCode>
|
338
|
+
<geographicCode authority='marccountry'>mg</geographicCode>
|
339
|
+
</subject>
|
340
|
+
<subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
|
341
|
+
</mods>"
|
342
|
+
@smods_rec.from_str m
|
343
|
+
@smods_rec.sw_geographic_search.should == ['Estonia', 'Madagascar', 'Maryland']
|
344
|
+
end
|
345
|
+
it "should be nil if there are only empty values in the MODS" do
|
346
|
+
m = "<mods #{@ns_decl}><subject><geographicCode/></subject><note>notit</note></mods>"
|
347
|
+
@smods_rec.from_str m
|
348
|
+
@smods_rec.sw_geographic_search.should == nil
|
349
|
+
end
|
350
|
+
it "should add the translated value if it wasn't present already" do
|
351
|
+
m = "<mods #{@ns_decl}>
|
352
|
+
<subject><geographic>Somewhere</geographic></subject>
|
353
|
+
<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
|
354
|
+
</mods>"
|
355
|
+
@smods_rec.from_str m
|
356
|
+
@smods_rec.sw_geographic_search.size.should == 2
|
357
|
+
@smods_rec.sw_geographic_search.should include('Estonia')
|
358
|
+
end
|
359
|
+
it "should not add the translated value if it was already present" do
|
360
|
+
m = "<mods #{@ns_decl}>
|
361
|
+
<subject><geographic>Estonia</geographic></subject>
|
362
|
+
<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
|
363
|
+
</mods>"
|
364
|
+
@smods_rec.from_str m
|
365
|
+
@smods_rec.sw_geographic_search.size.should == 1
|
366
|
+
@smods_rec.sw_geographic_search.should == ['Estonia']
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end # sw_geographic_search
|
370
|
+
end # context sw subject methods
|
371
|
+
|
184
372
|
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.7
|
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:
|
13
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mods
|
@@ -146,15 +146,15 @@ files:
|
|
146
146
|
- config/mappings_hash.rb
|
147
147
|
- lib/stanford-mods.rb
|
148
148
|
- lib/stanford-mods/kolb.rb
|
149
|
-
- lib/stanford-mods/
|
149
|
+
- lib/stanford-mods/old_mappings_4_ref.rb
|
150
150
|
- lib/stanford-mods/searchworks.rb
|
151
151
|
- lib/stanford-mods/searchworks_languages.rb
|
152
152
|
- lib/stanford-mods/version.rb
|
153
|
+
- spec/ignore_me_sw_required_flds_spec.rb
|
153
154
|
- spec/kolb_spec.rb
|
154
155
|
- spec/name_spec.rb
|
155
156
|
- spec/searchworks_spec.rb
|
156
157
|
- spec/spec_helper.rb
|
157
|
-
- spec/values_for_req_sw_spec.rb
|
158
158
|
- stanford-mods.gemspec
|
159
159
|
homepage: https://github.com/sul-dlss/stanford-mods
|
160
160
|
licenses: []
|
@@ -170,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
170
|
version: '0'
|
171
171
|
segments:
|
172
172
|
- 0
|
173
|
-
hash:
|
173
|
+
hash: -1663649951940663346
|
174
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
175
|
none: false
|
176
176
|
requirements:
|
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
179
|
version: '0'
|
180
180
|
segments:
|
181
181
|
- 0
|
182
|
-
hash:
|
182
|
+
hash: -1663649951940663346
|
183
183
|
requirements: []
|
184
184
|
rubyforge_project:
|
185
185
|
rubygems_version: 1.8.24
|
@@ -187,9 +187,9 @@ signing_key:
|
|
187
187
|
specification_version: 3
|
188
188
|
summary: Stanford specific wrangling of MODS metadata
|
189
189
|
test_files:
|
190
|
+
- spec/ignore_me_sw_required_flds_spec.rb
|
190
191
|
- spec/kolb_spec.rb
|
191
192
|
- spec/name_spec.rb
|
192
193
|
- spec/searchworks_spec.rb
|
193
194
|
- spec/spec_helper.rb
|
194
|
-
- spec/values_for_req_sw_spec.rb
|
195
195
|
has_rdoc:
|