stanford-mods 0.0.23 → 0.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/.gitignore +2 -0
- data/.travis.yml +6 -3
- data/README.rdoc +1 -0
- data/lib/stanford-mods/searchworks.rb +156 -136
- data/lib/stanford-mods/version.rb +1 -1
- data/spec/searchworks_format_spec.rb +103 -0
- data/spec/searchworks_pub_dates_spec.rb +236 -0
- data/spec/searchworks_spec.rb +4 -0
- data/spec/searchworks_subject_raw_spec.rb +384 -0
- data/spec/searchworks_subject_spec.rb +358 -347
- metadata +9 -9
- data/.rvmrc +0 -1
- data/lib/stanford-mods/kolb.rb +0 -14
- data/spec/kolb_spec.rb +0 -234
- data/spec/searchworks_gdor_spec.rb +0 -771
@@ -1,384 +1,395 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe "Searchworks mixin for Stanford::Mods::Record" do
|
4
|
+
describe "Searchworks Subject fields from Searchworks mixin for Stanford::Mods::Record" do
|
5
5
|
|
6
6
|
before(:all) do
|
7
7
|
@smods_rec = Stanford::Mods::Record.new
|
8
8
|
@ns_decl = "xmlns='#{Mods::MODS_NS}'"
|
9
|
+
@genre = 'genre top level'
|
10
|
+
@cart_coord = '6 00 S, 71 30 E'
|
11
|
+
@s_genre = 'genre in subject'
|
12
|
+
@geo = 'Somewhere'
|
13
|
+
@geo_code = 'us'
|
14
|
+
@hier_geo_country = 'France'
|
15
|
+
@s_name = 'name in subject'
|
16
|
+
@occupation = 'worker bee'
|
17
|
+
@temporal = 'temporal'
|
18
|
+
@s_title = 'title in subject'
|
19
|
+
@topic = 'topic'
|
20
|
+
@subject_mods = "<mods #{@ns_decl}>
|
21
|
+
<genre>#{@genre}</genre>
|
22
|
+
<subject><cartographics><coordinates>#{@cart_coord}</coordinates></cartographics></subject>
|
23
|
+
<subject><genre>#{@s_genre}</genre></subject>
|
24
|
+
<subject><geographic>#{@geo}</geographic></subject>
|
25
|
+
<subject><geographicCode authority='iso3166'>#{@geo_code}</geographicCode></subject>
|
26
|
+
<subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject>
|
27
|
+
<subject><name><namePart>#{@s_name}</namePart></name></subject>
|
28
|
+
<subject><occupation>#{@occupation}</occupation></subject>
|
29
|
+
<subject><temporal>#{@temporal}</temporal></subject>
|
30
|
+
<subject><titleInfo><title>#{@s_title}</title></titleInfo></subject>
|
31
|
+
<subject><topic>#{@topic}</topic></subject>
|
32
|
+
</mods>"
|
33
|
+
@smods_rec = Stanford::Mods::Record.new
|
34
|
+
@smods_rec.from_str(@subject_mods)
|
35
|
+
@ng_mods = Nokogiri::XML(@subject_mods)
|
36
|
+
m_no_subject = "<mods #{@ns_decl}><note>notit</note></mods>"
|
37
|
+
@ng_mods_no_subject = Nokogiri::XML(m_no_subject)
|
9
38
|
end
|
10
39
|
|
11
|
-
context "
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
40
|
+
context "search fields" do
|
41
|
+
context "topic_search" do
|
42
|
+
it "should be nil if there are no values in the MODS" do
|
43
|
+
m = "<mods #{@ns_decl}></mods>"
|
44
|
+
@smods_rec = Stanford::Mods::Record.new
|
45
|
+
@smods_rec.from_str(m)
|
46
|
+
@smods_rec.topic_search.should == nil
|
140
47
|
end
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
it "should contain <
|
145
|
-
@
|
146
|
-
end
|
147
|
-
it "should not contain
|
148
|
-
@
|
149
|
-
@
|
150
|
-
@
|
151
|
-
@
|
152
|
-
@
|
153
|
-
@
|
154
|
-
@
|
155
|
-
@
|
156
|
-
@
|
157
|
-
end
|
158
|
-
it "should not
|
159
|
-
m = "<mods #{@ns_decl}><
|
160
|
-
@smods_rec.
|
161
|
-
@smods_rec.
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
48
|
+
it "should contain subject <topic> subelement data" do
|
49
|
+
@smods_rec.topic_search.should include(@topic)
|
50
|
+
end
|
51
|
+
it "should contain top level <genre> element data" do
|
52
|
+
@smods_rec.topic_search.should include(@genre)
|
53
|
+
end
|
54
|
+
it "should not contain other subject element data" do
|
55
|
+
@smods_rec.topic_search.should_not include(@cart_coord)
|
56
|
+
@smods_rec.topic_search.should_not include(@s_genre)
|
57
|
+
@smods_rec.topic_search.should_not include(@geo)
|
58
|
+
@smods_rec.topic_search.should_not include(@geo_code)
|
59
|
+
@smods_rec.topic_search.should_not include(@hier_geo_country)
|
60
|
+
@smods_rec.topic_search.should_not include(@s_name)
|
61
|
+
@smods_rec.topic_search.should_not include(@occupation)
|
62
|
+
@smods_rec.topic_search.should_not include(@temporal)
|
63
|
+
@smods_rec.topic_search.should_not include(@s_title)
|
64
|
+
end
|
65
|
+
it "should not be nil if there are only subject/topic elements (no <genre>)" do
|
66
|
+
m = "<mods #{@ns_decl}><subject><topic>#{@topic}</topic></subject></mods>"
|
67
|
+
@smods_rec = Stanford::Mods::Record.new
|
68
|
+
@smods_rec.from_str(m)
|
69
|
+
@smods_rec.topic_search.should == [@topic]
|
70
|
+
end
|
71
|
+
it "should not be nil if there are only <genre> elements (no subject/topic elements)" do
|
72
|
+
m = "<mods #{@ns_decl}><genre>#{@genre}</genre></mods>"
|
73
|
+
@smods_rec = Stanford::Mods::Record.new
|
74
|
+
@smods_rec.from_str(m)
|
75
|
+
@smods_rec.topic_search.should == [@genre]
|
76
|
+
end
|
77
|
+
context "topic subelement" do
|
78
|
+
it "should have a separate value for each topic element" do
|
188
79
|
m = "<mods #{@ns_decl}>
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
@smods_rec.from_str
|
197
|
-
|
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']
|
80
|
+
<subject>
|
81
|
+
<topic>first</topic>
|
82
|
+
<topic>second</topic>
|
83
|
+
</subject>
|
84
|
+
<subject><topic>third</topic></subject>
|
85
|
+
</mods>"
|
86
|
+
@smods_rec = Stanford::Mods::Record.new
|
87
|
+
@smods_rec.from_str(m)
|
88
|
+
@smods_rec.topic_search.should == ['first', 'second', 'third']
|
203
89
|
end
|
204
|
-
it "
|
205
|
-
m = "<mods #{@ns_decl}>
|
206
|
-
|
207
|
-
|
208
|
-
|
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']
|
90
|
+
it "should be nil if there are only empty values in the MODS" do
|
91
|
+
m = "<mods #{@ns_decl}><subject><topic/></subject><note>notit</note></mods>"
|
92
|
+
@smods_rec = Stanford::Mods::Record.new
|
93
|
+
@smods_rec.from_str(m)
|
94
|
+
@smods_rec.topic_search.should == nil
|
218
95
|
end
|
219
96
|
end
|
220
|
-
end #
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
@
|
97
|
+
end # topic_search
|
98
|
+
|
99
|
+
context "geographic_search" do
|
100
|
+
it "should call sw_geographic_search (from stanford-mods gem)" do
|
101
|
+
m = "<mods #{@ns_decl}><subject><geographic>#{@geo}</geographic></subject></mods>"
|
102
|
+
@smods_rec = Stanford::Mods::Record.new
|
103
|
+
@smods_rec.from_str(m)
|
104
|
+
@smods_rec.should_receive(:sw_geographic_search)
|
105
|
+
@smods_rec.geographic_search
|
226
106
|
end
|
227
|
-
it "should
|
228
|
-
@
|
107
|
+
it "should log an info message when it encounters a geographicCode encoding it doesn't translate" do
|
108
|
+
m = "<mods #{@ns_decl}><subject><geographicCode authority='iso3166'>ca</geographicCode></subject></mods>"
|
109
|
+
@smods_rec = Stanford::Mods::Record.new
|
110
|
+
@smods_rec.from_str(m)
|
111
|
+
@smods_rec.sw_logger.should_receive(:info).with(/#{@fake_druid} has subject geographicCode element with untranslated encoding \(iso3166\): <geographicCode authority=.*>ca<\/geographicCode>/)
|
112
|
+
@smods_rec.geographic_search
|
229
113
|
end
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
114
|
+
end # geographic_search
|
115
|
+
|
116
|
+
context "subject_other_search" do
|
117
|
+
it "should call sw_subject_names (from stanford-mods gem)" do
|
118
|
+
smods_rec = Stanford::Mods::Record.new
|
119
|
+
smods_rec.from_str(@subject_mods)
|
120
|
+
smods_rec.should_receive(:sw_subject_names)
|
121
|
+
smods_rec.subject_other_search
|
122
|
+
end
|
123
|
+
it "should call sw_subject_titles (from stanford-mods gem)" do
|
124
|
+
@smods_rec.should_receive(:sw_subject_titles)
|
125
|
+
@smods_rec.subject_other_search
|
126
|
+
end
|
127
|
+
it "should be nil if there are no values in the MODS" do
|
128
|
+
m = "<mods #{@ns_decl}></mods>"
|
129
|
+
@smods_rec = Stanford::Mods::Record.new
|
130
|
+
@smods_rec.from_str(m)
|
131
|
+
@smods_rec.subject_other_search.should == nil
|
132
|
+
end
|
133
|
+
it "should contain subject <name> SUBelement data" do
|
134
|
+
@smods_rec.subject_other_search.should include(@s_name)
|
135
|
+
end
|
136
|
+
it "should contain subject <occupation> subelement data" do
|
137
|
+
@smods_rec.subject_other_search.should include(@occupation)
|
138
|
+
end
|
139
|
+
it "should contain subject <titleInfo> SUBelement data" do
|
140
|
+
@smods_rec = Stanford::Mods::Record.new
|
141
|
+
@smods_rec.from_str(@subject_mods)
|
142
|
+
@smods_rec.subject_other_search.should include(@s_title)
|
234
143
|
end
|
235
144
|
it "should not contain other subject element data" do
|
236
|
-
@
|
237
|
-
@
|
238
|
-
@
|
239
|
-
@
|
240
|
-
@
|
241
|
-
@
|
242
|
-
@
|
243
|
-
@
|
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]
|
145
|
+
@smods_rec.subject_other_search.should_not include(@genre)
|
146
|
+
@smods_rec.subject_other_search.should_not include(@cart_coord)
|
147
|
+
@smods_rec.subject_other_search.should_not include(@s_genre)
|
148
|
+
@smods_rec.subject_other_search.should_not include(@geo)
|
149
|
+
@smods_rec.subject_other_search.should_not include(@geo_code)
|
150
|
+
@smods_rec.subject_other_search.should_not include(@hier_geo_country)
|
151
|
+
@smods_rec.subject_other_search.should_not include(@temporal)
|
152
|
+
@smods_rec.subject_other_search.should_not include(@topic)
|
254
153
|
end
|
255
|
-
it "should not be
|
256
|
-
m = "<mods #{@ns_decl}><subject><
|
257
|
-
@smods_rec.
|
258
|
-
@smods_rec.
|
154
|
+
it "should not be nil if there are only subject/name elements" do
|
155
|
+
m = "<mods #{@ns_decl}><subject><name><namePart>#{@s_name}</namePart></name></subject></mods>"
|
156
|
+
@smods_rec = Stanford::Mods::Record.new
|
157
|
+
@smods_rec.from_str(m)
|
158
|
+
@smods_rec.subject_other_search.should == [@s_name]
|
259
159
|
end
|
260
|
-
it "should not be
|
261
|
-
m = "<mods #{@ns_decl}><subject><
|
262
|
-
@smods_rec.
|
263
|
-
@smods_rec.
|
160
|
+
it "should not be nil if there are only subject/occupation elements" do
|
161
|
+
m = "<mods #{@ns_decl}><subject><occupation>#{@occupation}</occupation></subject></mods>"
|
162
|
+
@smods_rec = Stanford::Mods::Record.new
|
163
|
+
@smods_rec.from_str(m)
|
164
|
+
@smods_rec.subject_other_search.should == [@occupation]
|
264
165
|
end
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
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
|
166
|
+
it "should not be nil if there are only subject/titleInfo elements" do
|
167
|
+
m = "<mods #{@ns_decl}><subject><titleInfo><title>#{@s_title}</title></titleInfo></subject></mods>"
|
168
|
+
@smods_rec = Stanford::Mods::Record.new
|
169
|
+
@smods_rec.from_str(m)
|
170
|
+
@smods_rec.subject_other_search.should == [@s_title]
|
282
171
|
end
|
283
|
-
context "
|
284
|
-
it "should have a separate value for each
|
172
|
+
context "occupation subelement" do
|
173
|
+
it "should have a separate value for each occupation element" do
|
285
174
|
m = "<mods #{@ns_decl}>
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
@smods_rec.
|
293
|
-
@smods_rec.
|
294
|
-
|
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 == []
|
175
|
+
<subject>
|
176
|
+
<occupation>first</occupation>
|
177
|
+
<occupation>second</occupation>
|
178
|
+
</subject>
|
179
|
+
<subject><occupation>third</occupation></subject>
|
180
|
+
</mods>"
|
181
|
+
@smods_rec = Stanford::Mods::Record.new
|
182
|
+
@smods_rec.from_str(m)
|
183
|
+
@smods_rec.subject_other_search.should == ['first', 'second', 'third']
|
299
184
|
end
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
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
|
185
|
+
it "should be nil if there are only empty values in the MODS" do
|
186
|
+
m = "<mods #{@ns_decl}><subject><occupation/></subject><note>notit</note></mods>"
|
187
|
+
@smods_rec = Stanford::Mods::Record.new
|
188
|
+
@smods_rec.from_str(m)
|
189
|
+
@smods_rec.subject_other_search.should == nil
|
318
190
|
end
|
319
|
-
end
|
320
|
-
|
321
|
-
|
191
|
+
end
|
192
|
+
end # subject_other_search
|
193
|
+
|
194
|
+
context "subject_other_subvy_search" do
|
195
|
+
it "should be nil if there are no values in the MODS" do
|
196
|
+
@smods_rec = Stanford::Mods::Record.new
|
197
|
+
@smods_rec.from_str(@ng_mods_no_subject.to_s)
|
198
|
+
@smods_rec.subject_other_subvy_search.should == nil
|
199
|
+
end
|
200
|
+
it "should contain subject <temporal> subelement data" do
|
201
|
+
@smods_rec.subject_other_subvy_search.should include(@temporal)
|
202
|
+
end
|
203
|
+
it "should contain subject <genre> SUBelement data" do
|
204
|
+
@smods_rec.subject_other_subvy_search.should include(@s_genre)
|
205
|
+
end
|
206
|
+
it "should not contain other subject element data" do
|
207
|
+
@smods_rec.subject_other_subvy_search.should_not include(@genre)
|
208
|
+
@smods_rec.subject_other_subvy_search.should_not include(@cart_coord)
|
209
|
+
@smods_rec.subject_other_subvy_search.should_not include(@geo)
|
210
|
+
@smods_rec.subject_other_subvy_search.should_not include(@geo_code)
|
211
|
+
@smods_rec.subject_other_subvy_search.should_not include(@hier_geo_country)
|
212
|
+
@smods_rec.subject_other_subvy_search.should_not include(@s_name)
|
213
|
+
@smods_rec.subject_other_subvy_search.should_not include(@occupation)
|
214
|
+
@smods_rec.subject_other_subvy_search.should_not include(@topic)
|
215
|
+
@smods_rec.subject_other_subvy_search.should_not include(@s_title)
|
216
|
+
end
|
217
|
+
it "should not be nil if there are only subject/temporal elements (no subject/genre)" do
|
218
|
+
m = "<mods #{@ns_decl}><subject><temporal>#{@temporal}</temporal></subject></mods>"
|
219
|
+
@smods_rec = Stanford::Mods::Record.new
|
220
|
+
@smods_rec.from_str(m)
|
221
|
+
@smods_rec.subject_other_subvy_search.should == [@temporal]
|
222
|
+
end
|
223
|
+
it "should not be nil if there are only subject/genre elements (no subject/temporal)" do
|
224
|
+
m = "<mods #{@ns_decl}><subject><genre>#{@s_genre}</genre></subject></mods>"
|
225
|
+
@smods_rec = Stanford::Mods::Record.new
|
226
|
+
@smods_rec.from_str(m)
|
227
|
+
@smods_rec.subject_other_subvy_search.should == [@s_genre]
|
228
|
+
end
|
229
|
+
context "temporal subelement" do
|
230
|
+
it "should have a separate value for each temporal element" do
|
322
231
|
m = "<mods #{@ns_decl}>
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
232
|
+
<subject>
|
233
|
+
<temporal>1890-1910</temporal>
|
234
|
+
<temporal>20th century</temporal>
|
235
|
+
</subject>
|
236
|
+
<subject><temporal>another</temporal></subject>
|
327
237
|
</mods>"
|
328
|
-
@smods_rec.
|
329
|
-
@
|
330
|
-
|
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')
|
238
|
+
@smods_rec = Stanford::Mods::Record.new
|
239
|
+
@smods_rec.from_str(m)
|
240
|
+
@smods_rec.subject_other_subvy_search.should == ['1890-1910', '20th century', 'another']
|
339
241
|
end
|
340
|
-
it "should
|
341
|
-
@
|
242
|
+
it "should log an info message when it encounters an encoding it doesn't translate" do
|
243
|
+
m = "<mods #{@ns_decl}><subject><temporal encoding='iso8601'>197505</temporal></subject></mods>"
|
244
|
+
@smods_rec = Stanford::Mods::Record.new
|
245
|
+
@smods_rec.from_str(m)
|
246
|
+
@smods_rec.sw_logger.should_receive(:info).with(/#{@fake_druid} has subject temporal element with untranslated encoding: <temporal encoding=.*>197505<\/temporal>/)
|
247
|
+
@smods_rec.subject_other_subvy_search
|
342
248
|
end
|
343
|
-
it "should
|
344
|
-
|
249
|
+
it "should be nil if there are only empty values in the MODS" do
|
250
|
+
m = "<mods #{@ns_decl}><subject><temporal/></subject><note>notit</note></mods>"
|
251
|
+
@smods_rec = Stanford::Mods::Record.new
|
252
|
+
@smods_rec.from_str(m)
|
253
|
+
@smods_rec.subject_other_subvy_search.should == nil
|
345
254
|
end
|
346
|
-
|
347
|
-
|
348
|
-
|
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
|
255
|
+
end
|
256
|
+
context "genre subelement" do
|
257
|
+
it "should have a separate value for each genre element" do
|
363
258
|
m = "<mods #{@ns_decl}>
|
364
|
-
|
365
|
-
|
259
|
+
<subject>
|
260
|
+
<genre>first</genre>
|
261
|
+
<genre>second</genre>
|
262
|
+
</subject>
|
263
|
+
<subject><genre>third</genre></subject>
|
366
264
|
</mods>"
|
367
|
-
@smods_rec.
|
368
|
-
@smods_rec.
|
369
|
-
@smods_rec.
|
265
|
+
@smods_rec = Stanford::Mods::Record.new
|
266
|
+
@smods_rec.from_str(m)
|
267
|
+
@smods_rec.subject_other_subvy_search.should == ['first', 'second', 'third']
|
370
268
|
end
|
371
|
-
it "should
|
372
|
-
m = "<mods #{@ns_decl}>
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
@smods_rec.from_str m
|
377
|
-
@smods_rec.sw_geographic_search.size.should == 1
|
378
|
-
@smods_rec.sw_geographic_search.should == ['Estonia']
|
269
|
+
it "should be nil if there are only empty values in the MODS" do
|
270
|
+
m = "<mods #{@ns_decl}><subject><genre/></subject><note>notit</note></mods>"
|
271
|
+
@smods_rec = Stanford::Mods::Record.new
|
272
|
+
@smods_rec.from_str(m)
|
273
|
+
@smods_rec.subject_other_subvy_search.should == nil
|
379
274
|
end
|
380
275
|
end
|
381
|
-
end #
|
382
|
-
|
276
|
+
end # subject_other_subvy_search
|
277
|
+
|
278
|
+
context "subject_all_search" do
|
279
|
+
it "should be nil if there are no values in the MODS" do
|
280
|
+
@smods_rec = Stanford::Mods::Record.new
|
281
|
+
@smods_rec.from_str(@ng_mods_no_subject.to_s)
|
282
|
+
@smods_rec.subject_all_search.should == nil
|
283
|
+
end
|
284
|
+
it "should contain top level <genre> element data" do
|
285
|
+
@smods_rec.subject_all_search.should include(@genre)
|
286
|
+
end
|
287
|
+
it "should not contain cartographic sub element" do
|
288
|
+
@smods_rec.subject_all_search.should_not include(@cart_coord)
|
289
|
+
end
|
290
|
+
it "should not include codes from hierarchicalGeographic sub element" do
|
291
|
+
@smods_rec.subject_all_search.should_not include(@geo_code)
|
292
|
+
end
|
293
|
+
it "should contain all other subject subelement data" do
|
294
|
+
@smods_rec = Stanford::Mods::Record.new
|
295
|
+
@smods_rec.from_str(@subject_mods)
|
296
|
+
@smods_rec.subject_all_search.should include(@s_genre)
|
297
|
+
@smods_rec.subject_all_search.should include(@geo)
|
298
|
+
@smods_rec.subject_all_search.should include(@hier_geo_country)
|
299
|
+
@smods_rec.subject_all_search.should include(@s_name)
|
300
|
+
@smods_rec.subject_all_search.should include(@occupation)
|
301
|
+
@smods_rec.subject_all_search.should include(@temporal)
|
302
|
+
@smods_rec.subject_all_search.should include(@s_title)
|
303
|
+
@smods_rec.subject_all_search.should include(@topic)
|
304
|
+
end
|
305
|
+
end # subject_all_search
|
306
|
+
|
307
|
+
end # search fields
|
308
|
+
|
309
|
+
context "facet fields" do
|
310
|
+
|
311
|
+
context "topic_facet" do
|
312
|
+
it "should include topic subelement" do
|
313
|
+
@smods_rec.topic_facet.should include(@topic)
|
314
|
+
end
|
315
|
+
it "should include sw_subject_names" do
|
316
|
+
@smods_rec.topic_facet.should include(@s_name)
|
317
|
+
end
|
318
|
+
it "should include sw_subject_titles" do
|
319
|
+
@smods_rec.topic_facet.should include(@s_title)
|
320
|
+
end
|
321
|
+
it "should include occupation subelement" do
|
322
|
+
@smods_rec.topic_facet.should include(@occupation)
|
323
|
+
end
|
324
|
+
it "should have the trailing punctuation removed" do
|
325
|
+
m = "<mods #{@ns_decl}><subject>
|
326
|
+
<topic>comma,</topic>
|
327
|
+
<occupation>semicolon;</occupation>
|
328
|
+
<titleInfo><title>backslash \\</title></titleInfo>
|
329
|
+
<name><namePart>internal, punct;uation</namePart></name>
|
330
|
+
</subject></mods>"
|
331
|
+
@smods_rec = Stanford::Mods::Record.new
|
332
|
+
@smods_rec.from_str(m)
|
333
|
+
@smods_rec.topic_facet.should include('comma')
|
334
|
+
@smods_rec.topic_facet.should include('semicolon')
|
335
|
+
@smods_rec.topic_facet.should include('backslash')
|
336
|
+
@smods_rec.topic_facet.should include('internal, punct;uation')
|
337
|
+
end
|
338
|
+
it "should be nil if there are no values" do
|
339
|
+
@smods_rec = Stanford::Mods::Record.new
|
340
|
+
@smods_rec.from_str(@ng_mods_no_subject.to_s)
|
341
|
+
@smods_rec.topic_facet.should == nil
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
context "geographic_facet" do
|
346
|
+
it "should call geographic_search" do
|
347
|
+
@smods_rec.should_receive(:geographic_search)
|
348
|
+
@smods_rec.geographic_facet
|
349
|
+
end
|
350
|
+
it "should be like geographic_search with the trailing punctuation (and preceding spaces) removed" do
|
351
|
+
m = "<mods #{@ns_decl}><subject>
|
352
|
+
<geographic>comma,</geographic>
|
353
|
+
<geographic>semicolon;</geographic>
|
354
|
+
<geographic>backslash \\</geographic>
|
355
|
+
<geographic>internal, punct;uation</geographic>
|
356
|
+
</subject></mods>"
|
357
|
+
@smods_rec = Stanford::Mods::Record.new
|
358
|
+
@smods_rec.from_str(m)
|
359
|
+
@smods_rec.geographic_facet.should include('comma')
|
360
|
+
@smods_rec.geographic_facet.should include('semicolon')
|
361
|
+
@smods_rec.geographic_facet.should include('backslash')
|
362
|
+
@smods_rec.geographic_facet.should include('internal, punct;uation')
|
363
|
+
end
|
364
|
+
it "should be nil if there are no values" do
|
365
|
+
@smods_rec = Stanford::Mods::Record.new
|
366
|
+
@smods_rec.from_str(@ng_mods_no_subject.to_s)
|
367
|
+
@smods_rec. geographic_facet.should == nil
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context "era_facet" do
|
372
|
+
it "should be temporal subelement with the trailing punctuation removed" do
|
373
|
+
m = "<mods #{@ns_decl}><subject>
|
374
|
+
<temporal>comma,</temporal>
|
375
|
+
<temporal>semicolon;</temporal>
|
376
|
+
<temporal>backslash \\</temporal>
|
377
|
+
<temporal>internal, punct;uation</temporal>
|
378
|
+
</subject></mods>"
|
379
|
+
@smods_rec = Stanford::Mods::Record.new
|
380
|
+
@smods_rec.from_str(m)
|
381
|
+
@smods_rec.era_facet.should include('comma')
|
382
|
+
@smods_rec.era_facet.should include('semicolon')
|
383
|
+
@smods_rec.era_facet.should include('backslash')
|
384
|
+
@smods_rec.era_facet.should include('internal, punct;uation')
|
385
|
+
end
|
386
|
+
it "should be nil if there are no values" do
|
387
|
+
@smods_rec = Stanford::Mods::Record.new
|
388
|
+
@smods_rec.from_str(@ng_mods_no_subject.to_s)
|
389
|
+
@smods_rec.era_facet.should == nil
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
end # facet fields
|
383
394
|
|
384
395
|
end
|