forked from ontoportal/ontologies_api
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_search_controller.rb
360 lines (317 loc) · 14.2 KB
/
test_search_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
require_relative '../test_case'
class TestSearchController < TestCase
def self.before_suite
count, acronyms, bro = LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: "BROSEARCHTEST",
name: "BRO Search Test",
file_path: "./test/data/ontology_files/BRO_v3.2.owl",
ont_count: 1,
submission_count: 1,
ontology_type: "VALUE_SET_COLLECTION"
})
count, acronyms, mccl = LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: "MCCLSEARCHTEST",
name: "MCCL Search Test",
file_path: "./test/data/ontology_files/CellLine_OWL_BioPortal_v1.0.owl",
ont_count: 1,
submission_count: 1
})
@@ontologies = bro.concat(mccl)
@@test_user = LinkedData::Models::User.new(
username: "test_search_user",
email: "[email protected]",
password: "test_user_password"
)
@@test_user.save
# Create a test ROOT provisional class
@@test_pc_root = LinkedData::Models::ProvisionalClass.new({
creator: @@test_user,
label: "Provisional Class - ROOT",
synonym: ["Test synonym for Prov Class ROOT", "Test syn ROOT provisional class"],
definition: ["Test definition for Prov Class ROOT"],
ontology: @@ontologies[0]
})
@@test_pc_root.save
@@cls_uri = RDF::URI.new("http://bioontology.org/ontologies/ResearchArea.owl#Area_of_Research")
# Create a test CHILD provisional class
@@test_pc_child = LinkedData::Models::ProvisionalClass.new({
creator: @@test_user,
label: "Provisional Class - CHILD",
synonym: ["Test synonym for Prov Class CHILD", "Test syn CHILD provisional class"],
definition: ["Test definition for Prov Class CHILD"],
ontology: @@ontologies[0],
subclassOf: @@cls_uri
})
@@test_pc_child.save
end
def self.after_suite
@@test_pc_root.delete
@@test_pc_child.delete
LinkedData::SampleData::Ontology.delete_ontologies_and_submissions
@@test_user.delete
LinkedData::Models::Ontology.indexClear
LinkedData::Models::Ontology.indexCommit
end
def test_search
get '/search?q=ontology'
assert last_response.ok?
acronyms = @@ontologies.map {|ont|
ont.bring_remaining
ont.acronym
}
results = MultiJson.load(last_response.body)
results["collection"].each do |doc|
acronym = doc["links"]["ontology"].split('/')[-1]
assert acronyms.include? (acronym)
end
end
def test_search_ontology_filter
acronym = "MCCLSEARCHTEST-0"
get "/search?q=cell%20li*&ontologies=#{acronym}"
assert last_response.ok?
results = MultiJson.load(last_response.body)
doc = results["collection"][0]
assert_equal "cell line", doc["prefLabel"]
assert doc["links"]["ontology"].include? acronym
results["collection"].each do |doc|
acr = doc["links"]["ontology"].split('/')[-1]
assert_equal acr, acronym
end
end
def test_search_other_filters
acronym = "MCCLSEARCHTEST-0"
get "/search?q=receptor%20antagonists&ontologies=#{acronym}&require_exact_match=true"
assert last_response.ok?
results = MultiJson.load(last_response.body)
assert_equal 1, results["collection"].length
get "search?q=data&require_definitions=true"
assert last_response.ok?
results = MultiJson.load(last_response.body)
assert_equal 26, results["collection"].length
get "search?q=data&require_definitions=false"
assert last_response.ok?
results = MultiJson.load(last_response.body)
assert results["collection"].length > 26
# testing "also_search_obsolete" flag
acronym = "BROSEARCHTEST-0"
get "search?q=Integration%20and%20Interoperability&ontologies=#{acronym}"
results = MultiJson.load(last_response.body)
assert_equal 22, results["collection"].length
get "search?q=Integration%20and%20Interoperability&ontologies=#{acronym}&also_search_obsolete=false"
results = MultiJson.load(last_response.body)
assert_equal 22, results["collection"].length
get "search?q=Integration%20and%20Interoperability&ontologies=#{acronym}&also_search_obsolete=true"
results = MultiJson.load(last_response.body)
assert_equal 29, results["collection"].length
# testing "subtree_root_id" parameter
get "search?q=training&ontologies=#{acronym}"
results = MultiJson.load(last_response.body)
assert_equal 3, results["collection"].length
get "search?q=training&ontology=#{acronym}&subtree_root_id=http%3A%2F%2Fbioontology.org%2Fontologies%2FActivity.owl%23Activity"
results = MultiJson.load(last_response.body)
assert_equal 1, results["collection"].length
# testing cui and semantic_types flags
get "search?q=Funding%20Resource&ontologies=#{acronym}&include=prefLabel,synonym,definition,notation,cui,semanticType"
results = MultiJson.load(last_response.body)
assert_equal 35, results["collection"].length
assert_equal "Funding Resource", results["collection"][0]["prefLabel"]
assert_equal "T028", results["collection"][0]["semanticType"][0]
assert_equal "X123456", results["collection"][0]["cui"][0]
get "search?q=Funding&ontologies=#{acronym}&include=prefLabel,synonym,definition,notation,cui,semanticType&cui=X123456"
results = MultiJson.load(last_response.body)
assert_equal 1, results["collection"].length
assert_equal "X123456", results["collection"][0]["cui"][0]
get "search?q=Funding&ontologies=#{acronym}&include=prefLabel,synonym,definition,notation,cui,semanticType&semantic_types=T028"
results = MultiJson.load(last_response.body)
assert_equal 1, results["collection"].length
assert_equal "T028", results["collection"][0]["semanticType"][0]
end
def test_subtree_search
acronym = "BROSEARCHTEST-0"
class_id = RDF::IRI.new "http://bioontology.org/ontologies/Activity.owl#Activity"
pc1 = LinkedData::Models::ProvisionalClass.new({label: "Test Provisional Parent for Training", subclassOf: class_id, creator: @@test_user, ontology: @@ontologies[0]})
pc1.save
pc2 = LinkedData::Models::ProvisionalClass.new({label: "Test Provisional Leaf for Training", subclassOf: pc1.id, creator: @@test_user, ontology: @@ontologies[0]})
pc2.save
get "search?q=training&ontology=#{acronym}&subtree_root_id=#{CGI.escape(class_id.to_s)}"
results = MultiJson.load(last_response.body)
assert_equal 1, results["collection"].length
get "search?q=training&ontology=#{acronym}&subtree_root_id=#{CGI.escape(class_id.to_s)}&also_search_provisional=true"
results = MultiJson.load(last_response.body)
assert_equal 3, results["collection"].length
pc2.delete
pc2 = LinkedData::Models::ProvisionalClass.find(pc2.id).first
assert_nil pc2
pc1.delete
pc1 = LinkedData::Models::ProvisionalClass.find(pc1.id).first
assert_nil pc1
end
def test_wildcard_search
get "/search?q=lun*"
assert last_response.ok?
results = MultiJson.load(last_response.body)
coll = results["collection"]
end
def test_search_provisional_class
acronym = "BROSEARCHTEST-0"
ontology_type = "VALUE_SET_COLLECTION"
# roots only with provisional class test
get "search?also_search_provisional=true&valueset_roots_only=true&ontology_types=#{ontology_type}&ontologies=#{acronym}"
results = MultiJson.load(last_response.body)
assert_equal 10, results["collection"].length
provisional = results["collection"].select {|res| assert_equal ontology_type, res["ontologyType"]; res["provisional"]}
assert_equal 1, provisional.length
assert_equal @@test_pc_root.label, provisional[0]["prefLabel"]
# subtree root with provisional class test
get "search?ontology=#{acronym}&subtree_root_id=#{CGI::escape(@@cls_uri.to_s)}&also_search_provisional=true"
results = MultiJson.load(last_response.body)
assert_equal 20, results["collection"].length
provisional = results["collection"].select {|res| res["provisional"]}
assert_equal 1, provisional.length
assert_equal @@test_pc_child.label, provisional[0]["prefLabel"]
end
def test_search_obo_id
ncit_acronym = 'NCIT'
ogms_acronym = 'OGMS'
cno_acronym = 'CNO'
begin
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: ncit_acronym,
acronym_suffix: '',
name: "NCIT Search Test",
pref_label_property: "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#P108",
synonym_property: "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#P90",
definition_property: "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#P97",
file_path: "./test/data/ontology_files/ncit_test.owl",
ontology_format: 'OWL',
ont_count: 1,
submission_count: 1
})
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: ogms_acronym,
acronym_suffix: '',
name: "OGMS Search Test",
file_path: "./test/data/ontology_files/ogms_test.owl",
ontology_format: 'OWL',
ont_count: 1,
submission_count: 1
})
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: cno_acronym,
acronym_suffix: '',
name: "CNO Search Test",
file_path: "./test/data/ontology_files/CNO_05.owl",
ontology_format: 'OWL',
ont_count: 1,
submission_count: 1
})
# mdorf, 3/2/2024, when the : is followed by a LETTER, as in NCIT:C20480,
# then Solr does not split the query on the tokens,
# but when the : is followed by a number, as in OGMS:0000071,
# then Solr does split this on tokens and shows the other resuluts
get "/search?q=OGMS:0000071"
assert last_response.ok?
results = MultiJson.load(last_response.body)
docs = results["collection"]
assert_equal 6, docs.size
assert_equal ogms_acronym, LinkedData::Utils::Triples.last_iri_fragment(docs[0]["links"]["ontology"])
assert_equal cno_acronym, LinkedData::Utils::Triples.last_iri_fragment(docs[1]["links"]["ontology"])
assert_equal ncit_acronym, LinkedData::Utils::Triples.last_iri_fragment(docs[2]["links"]["ontology"])
assert_equal 'realization', docs[1]["prefLabel"]
assert_equal 'realization', docs[2]["prefLabel"]
assert docs[3]["prefLabel"].upcase.include?('OGMS ')
assert docs[4]["prefLabel"].upcase.include?('OGMS ')
assert docs[5]["prefLabel"].upcase.include?('OGMS ')
get "/search?q=CNO:0000002"
assert last_response.ok?
results = MultiJson.load(last_response.body)
docs = results["collection"]
assert_equal 7, docs.size
assert_equal cno_acronym, LinkedData::Utils::Triples.last_iri_fragment(docs[0]["links"]["ontology"])
acr_1 = LinkedData::Utils::Triples.last_iri_fragment(docs[1]["links"]["ontology"])
assert acr_1 === ncit_acronym || acr_1 === ogms_acronym
acr_2= LinkedData::Utils::Triples.last_iri_fragment(docs[2]["links"]["ontology"])
assert acr_2 === ncit_acronym || acr_2 === ogms_acronym
assert docs[3]["prefLabel"].upcase.include?('CNO ')
assert docs[4]["prefLabel"].upcase.include?('CNO ')
assert docs[5]["prefLabel"].upcase.include?('CNO ')
assert docs[6]["prefLabel"].upcase.include?('CNO ')
# mdorf, 3/2/2024, when the : is followed by a LETTER, as in NCIT:C20480,
# then Solr does not split the query on the tokens,
# but when the : is followed by a number, as in OGMS:0000071,
# then Solr does split this on tokens and shows the other resuluts
get "/search?q=Thesaurus:C20480"
assert last_response.ok?
results = MultiJson.load(last_response.body)
docs = results["collection"]
assert_equal 1, docs.size
assert_equal 'Cellular Process', docs[0]["prefLabel"]
get "/search?q=NCIT:C20480"
assert last_response.ok?
results = MultiJson.load(last_response.body)
docs = results["collection"]
assert_equal 1, docs.size
assert_equal 'Cellular Process', docs[0]["prefLabel"]
get "/search?q=Leukocyte Apoptotic Process&ontologies=#{ncit_acronym}"
assert last_response.ok?
results = MultiJson.load(last_response.body)
docs = results["collection"]
assert_equal 'Leukocyte Apoptotic Process', docs[0]["prefLabel"]
assert_equal 'Leukocyte Apoptotic Test Class', docs[1]["prefLabel"]
assert_equal 'Lymphocyte Apoptotic Process', docs[2]["prefLabel"]
ensure
ont = LinkedData::Models::Ontology.find(ncit_acronym).first
ont.delete if ont
ont = LinkedData::Models::Ontology.find(ncit_acronym).first
assert ont.nil?
ont = LinkedData::Models::Ontology.find(ogms_acronym).first
ont.delete if ont
ont = LinkedData::Models::Ontology.find(ogms_acronym).first
assert ont.nil?
ont = LinkedData::Models::Ontology.find(cno_acronym).first
ont.delete if ont
ont = LinkedData::Models::Ontology.find(cno_acronym).first
assert ont.nil?
end
end
def test_search_short_id
vario_acronym = 'VARIO'
begin
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: vario_acronym,
acronym_suffix: "",
name: "VARIO OBO Search Test",
file_path: "./test/data/ontology_files/vario_test.obo",
ontology_format: 'OBO',
ont_count: 1,
submission_count: 1
})
get "/search?q=VariO:0012&ontologies=#{vario_acronym}"
assert last_response.ok?
results = MultiJson.load(last_response.body)
docs = results["collection"]
assert_equal 1, docs.size
get "/search?q=Blah:0012&ontologies=#{vario_acronym}"
assert last_response.ok?
results = MultiJson.load(last_response.body)
docs = results["collection"]
assert_equal 0, docs.size
get "/search?q=Vario:12345&ontologies=#{vario_acronym}"
assert last_response.ok?
results = MultiJson.load(last_response.body)
docs = results["collection"]
assert_equal 0, docs.size
ensure
ont = LinkedData::Models::Ontology.find(vario_acronym).first
ont.delete if ont
ont = LinkedData::Models::Ontology.find(vario_acronym).first
assert ont.nil?
end
end
end