philologic-client 0.0.11 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/HISTORY.rdoc +8 -0
  2. data/PhiloLogicResponseDocumentation.txt +86 -0
  3. data/README.rdoc +54 -32
  4. data/Rakefile +26 -0
  5. data/lib/philologic-client/bibliography.rb +60 -0
  6. data/lib/philologic-client/collocation.rb +61 -0
  7. data/lib/philologic-client/concordance.rb +39 -0
  8. data/lib/philologic-client/document.rb +65 -0
  9. data/lib/philologic-client/frequency.rb +57 -0
  10. data/lib/philologic-client/frequency_row.rb +67 -0
  11. data/lib/philologic-client/link.rb +37 -0
  12. data/lib/philologic-client/occurrence.rb +79 -0
  13. data/lib/philologic-client/response.rb +63 -0
  14. data/lib/philologic-client/version.rb +1 -1
  15. data/lib/philologic-client.rb +102 -286
  16. data/test/data/bibliography.html +182 -0
  17. data/test/data/collocation.html +2594 -0
  18. data/test/data/concordance.html +758 -0
  19. data/test/data/frequency.html +73 -0
  20. data/test/data/navigation.html +69 -0
  21. data/test/data/object.html +20 -0
  22. data/test/test_bibliography.rb +78 -0
  23. data/test/test_client.rb +861 -0
  24. data/test/test_collocation.rb +76 -0
  25. data/test/test_concordance.rb +83 -0
  26. data/test/test_document.rb +127 -0
  27. data/test/test_frequency.rb +78 -0
  28. data/test/test_occurrence.rb +66 -0
  29. data/test/test_response.rb +41 -0
  30. metadata +55 -36
  31. data/doc/PhiloLogicResponseTemplates.txt +0 -46
  32. data/test/data/collocation_links.html +0 -145
  33. data/test/data/collocation_sartre.html +0 -67
  34. data/test/data/doc_file.html +0 -396
  35. data/test/data/frequency_links.html +0 -145
  36. data/test/data/frequency_sartre.html +0 -67
  37. data/test/data/query_sartre.html +0 -151
  38. data/test/data/root_file.html +0 -1851
  39. data/test/test_philologic_client.rb +0 -558
  40. data/test/test_philologic_link.rb +0 -101
@@ -0,0 +1,861 @@
1
+ # encoding: utf-8
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'philologic-client'
7
+ require 'test/unit'
8
+ require 'mocha'
9
+
10
+
11
+ class TestClient < Test::Unit::TestCase
12
+
13
+ def setup
14
+ @test_dir = File.expand_path( File.dirname(__FILE__) )
15
+ @data_dir = File.expand_path( File.join( @test_dir, 'data' ) )
16
+ @endpoint = @data_dir
17
+
18
+ @biblio_path = 'bibliography.html' # XXX
19
+ @biblio_file = File.join( @data_dir, @biblio_path ) # XXX
20
+
21
+ @con_path = 'concordance.html' # XXX
22
+ @con_file = File.join( @data_dir, @con_path ) # XXX
23
+
24
+ @nav_path = 'navigation.html' # XXX
25
+ @nav_file = File.join( @data_dir, @nav_path ) # XXX
26
+
27
+ @obj_path = 'object.html' # XXX
28
+ @obj_file = File.join( @data_dir, @obj_path ) # XXX
29
+ end
30
+
31
+
32
+ def test_initialization
33
+ blockable = false
34
+ client = Philologic::Client.new do |client|
35
+ assert_kind_of Philologic::Client, client
36
+ blockable = true
37
+ end
38
+ assert blockable, 'works as block'
39
+ assert_kind_of Philologic::Client, client
40
+ assert_kind_of Philologic::Client, Philologic::Client.new
41
+ end
42
+
43
+ def test_initialization_with_endpoint
44
+ blockable = false
45
+ client = Philologic::Client.new(@endpoint) do |client|
46
+ assert_kind_of Philologic::Client, client
47
+ blockable = true
48
+ assert_not_nil client.endpoint
49
+ assert_equal @endpoint, client.endpoint
50
+ end
51
+ assert blockable, 'works as block'
52
+ assert_kind_of Philologic::Client, client
53
+ assert_kind_of Philologic::Client, Philologic::Client.new
54
+ assert_not_nil client.endpoint
55
+ assert_equal @endpoint, client.endpoint
56
+ end
57
+
58
+ def test_encoding_accessor
59
+ Philologic::Client.new do |client|
60
+ assert_equal Philologic::Client::DEFAULT_ENCODING, client.encoding
61
+ assert_equal 'foo', client.encoding = 'foo'
62
+ assert_equal 'foo', client.encoding
63
+ end
64
+ end
65
+
66
+ def test_endpoint_accessor
67
+ Philologic::Client.new do |client|
68
+ assert_nil client.endpoint, 'defaults to nil'
69
+ assert_equal @endpoint, client.endpoint = @endpoint, 'returns value on set'
70
+ assert_equal @endpoint, client.endpoint, 'returns value on get'
71
+ end
72
+ end
73
+
74
+ def test_get_bibliography_without_an_endpoint
75
+ Philologic::Client.new do |client|
76
+ assert_raise(RuntimeError, 'nil endpoint') { client.bibliography }
77
+ end
78
+ end
79
+
80
+ def test_private_methods
81
+ Philologic::Client.new(@endpoint) do |client|
82
+ r = client.send( :_get, @biblio_path )
83
+ assert_not_nil r
84
+ assert_kind_of Philologic::Client::Bibliography, r
85
+
86
+ assert_nil client.send( :_parse, Nokogiri::HTML("") )
87
+ end
88
+ end
89
+
90
+ def test_get_bibliography
91
+ Philologic::Client.new(@endpoint) do |client|
92
+ h = Nokogiri::HTML( open(@biblio_file) )
93
+ r = client.send( :_parse, Nokogiri::HTML( open(@biblio_file) ) )
94
+
95
+ client.stubs(:_get).with('?title=').returns(r)
96
+ assert_not_nil r
97
+
98
+ b = client.bibliography
99
+ assert_equal r, b
100
+ assert_kind_of Philologic::Client::Bibliography, b
101
+
102
+ assert_not_nil b.titles
103
+ assert_kind_of Array, b.titles
104
+ assert_equal 42, b.titles.size
105
+
106
+ first = b.titles.first
107
+ assert_not_nil first
108
+ assert_kind_of Philologic::Client::Occurrence, first
109
+ assert_equal 'William Shakespeare', first['author']
110
+ assert_equal './1/0/0/0/0', first['href']
111
+ assert_equal 'The First Part of King Henry the Fourth', first['title']
112
+ assert_equal '', first['who']
113
+
114
+ last = b.titles.last
115
+ assert_not_nil last
116
+ assert_kind_of Philologic::Client::Occurrence, last
117
+ assert_equal 'William Shakespeare', last['author']
118
+ assert_equal './42/0/0/0/0', last['href']
119
+ assert_equal "The Winter's Tale", last['title']
120
+ assert_equal '', last['who']
121
+ end
122
+ end
123
+
124
+ def test_get_document_without_path
125
+ Philologic::Client.new do |client|
126
+ assert_raise(ArgumentError, 'nil endpoint') { client.document }
127
+ end
128
+ end
129
+
130
+ def test_get_document_without_an_endpoint
131
+ Philologic::Client.new do |client|
132
+ assert_raise(RuntimeError, 'nil endpoint') { client.document(1) }
133
+ end
134
+ end
135
+
136
+ def test_get_document_that_is_navigation
137
+ Philologic::Client.new do |client|
138
+ doc = client.send( :_parse, Nokogiri::HTML( open(@nav_file) ) )
139
+ client.expects(:_get).with(@nav_path).returns(doc)
140
+ r = client.document(@nav_path)
141
+
142
+ assert_not_nil doc
143
+ assert_equal doc, r
144
+ assert_kind_of Philologic::Client::Response, r
145
+ assert_kind_of Philologic::Client::Document, r
146
+
147
+ assert_not_nil r.keys
148
+ assert_kind_of Array, r.keys
149
+ assert_equal 2, r.keys.size
150
+ assert_equal %w( author title ), r.keys
151
+
152
+ r.each_with_index do |k, idx|
153
+ case idx
154
+ when 0
155
+ assert_equal 'author', k
156
+ assert_equal 'William Shakespeare', r[k]
157
+ when 1
158
+ assert_equal 'title', k
159
+ assert_equal 'The First Part of King Henry the Fourth', r[k]
160
+ end
161
+ end
162
+
163
+ assert_equal 'William Shakespeare', r['author']
164
+ assert_equal 'The First Part of King Henry the Fourth', r['title']
165
+
166
+ assert r.links?
167
+ assert_kind_of Array, r.links
168
+ assert_equal 26, r.links.size
169
+ assert_kind_of Philologic::Client::Link, r.links.first
170
+ assert_equal './1/2', r.links.first.url
171
+ assert_equal '', r.links.first.text
172
+ assert_kind_of Philologic::Client::Link, r.links.last
173
+ assert_equal './1/7/6', r.links.last.url
174
+ assert_equal 'Act 5, Scene 5', r.links.last.text
175
+
176
+ assert !r.text?
177
+ assert_nil r.text
178
+ assert_nil r.html
179
+ end
180
+ end
181
+
182
+ def test_get_document_that_is_text
183
+
184
+ Philologic::Client.new do |client|
185
+ doc = client.send( :_parse, Nokogiri::HTML( open(@obj_file) ) )
186
+ client.expects(:_get).with(@obj_path).returns(doc)
187
+ r = client.document(@obj_path)
188
+
189
+ assert_not_nil doc
190
+ assert_equal doc, r
191
+ assert_kind_of Philologic::Client::Response, r
192
+ assert_kind_of Philologic::Client::Document, r
193
+
194
+ assert_not_nil r.keys
195
+ assert_kind_of Array, r.keys
196
+ assert_equal 2, r.keys.size
197
+ assert_equal %w( author title ), r.keys
198
+
199
+ r.each_with_index do |k, idx|
200
+ case idx
201
+ when 0
202
+ assert_equal 'author', k
203
+ assert_equal 'William Shakespeare', r[k]
204
+ when 1
205
+ assert_equal 'title', k
206
+ assert_equal 'The First Part of King Henry the Fourth', r[k]
207
+ end
208
+ end
209
+
210
+ assert_equal 'William Shakespeare', r['author']
211
+ assert_equal 'The First Part of King Henry the Fourth', r['title']
212
+
213
+ assert !r.links?
214
+ assert_kind_of Array, r.links
215
+ assert_equal 0, r.links.size
216
+
217
+ assert r.text?
218
+ assert_match /^The First Part of King /, r.text.strip
219
+ assert_match /assistants\s+\n The/, r.text.strip
220
+ assert_match /and W\. A\. Wright\.$/, r.text.strip
221
+ assert_match /^The First Part of King /, r.html.strip
222
+ assert_match /<p><\/p> The WordHoard/, r.html.strip
223
+ assert_match /and W\. A\. Wright\.$/, r.html.strip
224
+ end
225
+ end
226
+
227
+ def test_get_concordance_without_endpoint
228
+ Philologic::Client.new do |client|
229
+ assert_raise(RuntimeError, 'nil endpoint') { client.concordance('lion') }
230
+ end
231
+ end
232
+
233
+ def test_get_concordance
234
+ Philologic::Client.new do |client|
235
+ doc = client.send( :_parse, Nokogiri::HTML( open(@con_file) ) )
236
+ client.expects(:_get).with('?q=lion').returns(doc)
237
+ r = client.concordance('lion')
238
+
239
+ assert_not_nil doc
240
+ assert_equal doc, r
241
+ assert_kind_of Philologic::Client::Response, r
242
+ assert_kind_of Philologic::Client::Concordance, r
243
+
244
+ assert r.results?
245
+ assert_kind_of Array, r.results
246
+ assert_equal 50, r.results.size
247
+
248
+ first = r.results.first
249
+ assert_not_nil first
250
+ assert_kind_of Philologic::Client::Occurrence, first
251
+ assert_equal 1, first['hit_n']
252
+ assert_equal 'William Shakespeare', first['author']
253
+ assert_equal 'The First Part of King Henry the Fourth', first['title']
254
+ assert_equal 'Prince', first['who']
255
+ assert first.text?
256
+ assert_not_nil first.text
257
+ assert_match /^ cat or a lugged bear/, first.text
258
+ assert_match /Yea$/, first.text
259
+ assert_not_nil first.html
260
+ assert_match /^ cat or a lugged bear/, first.html
261
+ assert_match /Yea$/, first.html
262
+
263
+ last = r.results.last
264
+ assert_not_nil last
265
+ assert_kind_of Philologic::Client::Occurrence, last
266
+ assert_equal 50, last['hit_n']
267
+ assert_equal 'William Shakespeare', last['author']
268
+ assert_equal "A Midsummer Night's Dream", last['title']
269
+ assert_equal 'Bottom', last['who']
270
+
271
+ assert last.text?
272
+ assert_not_nil last.text
273
+ assert_match /^Masters, you ought to /, last.text.strip
274
+ assert_match /for there is not a more$/, last.text.strip
275
+ assert_not_nil last.html
276
+ assert_match /^Masters, you ought to /, last.html.strip
277
+ assert_match /for there is not a more$/, last.html.strip
278
+ end
279
+ end
280
+
281
+ def test_get_concordance_with_query_parameters
282
+ Philologic::Client.new do |client|
283
+ doc = client.send( :_parse, Nokogiri::HTML( open(@con_file) ) )
284
+ client.expects(:_get).with('?foo=bar&q=lion').returns(doc)
285
+ r = client.concordance( :foo => 'bar', :q => 'lion' )
286
+
287
+ assert_not_nil doc
288
+ assert_equal doc, r
289
+ assert_kind_of Philologic::Client::Response, r
290
+ assert_kind_of Philologic::Client::Concordance, r
291
+
292
+ assert r.results?
293
+ assert_kind_of Array, r.results
294
+ assert_equal 50, r.results.size
295
+
296
+ first = r.results.first
297
+ assert_not_nil first
298
+ assert_kind_of Philologic::Client::Occurrence, first
299
+ assert_equal 1, first['hit_n']
300
+ assert_equal 'William Shakespeare', first['author']
301
+ assert_equal 'The First Part of King Henry the Fourth', first['title']
302
+ assert_equal 'Prince', first['who']
303
+ assert first.text?
304
+ assert_not_nil first.text
305
+ assert_match /^ cat or a lugged bear/, first.text
306
+ assert_match /Yea$/, first.text
307
+ assert_not_nil first.html
308
+ assert_match /^ cat or a lugged bear/, first.html
309
+ assert_match /Yea$/, first.html
310
+
311
+ last = r.results.last
312
+ assert_not_nil last
313
+ assert_kind_of Philologic::Client::Occurrence, last
314
+ assert_equal 50, last['hit_n']
315
+ assert_equal 'William Shakespeare', last['author']
316
+ assert_equal "A Midsummer Night's Dream", last['title']
317
+ assert_equal 'Bottom', last['who']
318
+
319
+ assert last.text?
320
+ assert_not_nil last.text
321
+ assert_match /^Masters, you ought to /, last.text.strip
322
+ assert_match /for there is not a more$/, last.text.strip
323
+ assert_not_nil last.html
324
+ assert_match /^Masters, you ought to /, last.html.strip
325
+ assert_match /for there is not a more$/, last.html.strip
326
+ end
327
+ end
328
+ def test_underscore_build_query_with_invalid_queries
329
+ Philologic::Client.new(@endpoint) do |client|
330
+ assert_raise(RuntimeError, 'no query specified') { client.send(:_build_query, nil) }
331
+ assert_raise(RuntimeError, 'no query specified') { client.send(:_build_query, {}) }
332
+ assert_raise(RuntimeError, 'no query specified') { client.send(:_build_query, []) }
333
+ assert_raise(RuntimeError, 'no query specified') { client.send(:_build_query, '') }
334
+ assert_raise(RuntimeError, 'no query specified') { client.send(:_build_query, 'foo') }
335
+ end
336
+ end
337
+
338
+ def test_get_frequency_without_endpoint
339
+ Philologic::Client.new do |client|
340
+ assert_raise(RuntimeError, 'nil endpoint') { client.frequency('lion') }
341
+ end
342
+ end
343
+
344
+ def test_get_frequency
345
+ Philologic::Client.new do |client|
346
+ doc = client.send( :_parse, Nokogiri::HTML( open( File.join( @data_dir, 'frequency.html' ) ) ) )
347
+ client.expects(:_get).with('?q=lion&report=frequency').returns(doc)
348
+ r = client.frequency('lion')
349
+
350
+ assert_not_nil doc
351
+ assert_equal doc, r
352
+ assert_kind_of Philologic::Client::Response, r
353
+ assert_kind_of Philologic::Client::Frequency, r
354
+
355
+ assert r.results?
356
+ assert_not_nil r.results
357
+ assert_kind_of Array, r.results
358
+ assert_equal 29, r.results.size
359
+
360
+ first = r.results.first
361
+ assert_not_nil first
362
+ assert_kind_of Philologic::Client::FrequencyRow, first
363
+ assert_equal "A Midsummer Night's Dream", first.label
364
+ assert_equal './?q=lion&title=A+Midsummer+Night%27s+Dream', first.link
365
+ assert_equal '30', first.value
366
+
367
+ last = r.results.last
368
+ assert_not_nil last
369
+ assert_kind_of Philologic::Client::FrequencyRow, last
370
+ assert_equal 'As You Like It', last.label
371
+ assert_equal './?q=lion&title=As+You+Like+It', last.link
372
+ assert_equal '1', last.value
373
+ end
374
+ end
375
+
376
+ def test_get_frequency_with_query_parameters
377
+ Philologic::Client.new do |client|
378
+ doc = client.send( :_parse, Nokogiri::HTML( open( File.join( @data_dir, 'frequency.html' ) ) ) )
379
+ client.expects(:_get).with('?foo=bar&q=lion&report=frequency').returns(doc)
380
+ r = client.frequency( :q => 'lion', :foo => 'bar' )
381
+
382
+ assert_not_nil doc
383
+ assert_equal doc, r
384
+ assert_kind_of Philologic::Client::Response, r
385
+ assert_kind_of Philologic::Client::Frequency, r
386
+
387
+ assert r.results?
388
+ assert_not_nil r.results
389
+ assert_kind_of Array, r.results
390
+ assert_equal 29, r.results.size
391
+
392
+ first = r.results.first
393
+ assert_not_nil first
394
+ assert_kind_of Philologic::Client::FrequencyRow, first
395
+ assert_equal "A Midsummer Night's Dream", first.label
396
+ assert_equal './?q=lion&title=A+Midsummer+Night%27s+Dream', first.link
397
+ assert_equal '30', first.value
398
+
399
+ last = r.results.last
400
+ assert_not_nil last
401
+ assert_kind_of Philologic::Client::FrequencyRow, last
402
+ assert_equal 'As You Like It', last.label
403
+ assert_equal './?q=lion&title=As+You+Like+It', last.link
404
+ assert_equal '1', last.value
405
+ end
406
+ end
407
+ # def test_get_children_without_an_endpoint
408
+ # Philologic::Client.new do |client|
409
+ # assert_raises(RuntimeError) { client.children }
410
+ # end
411
+ # end
412
+
413
+
414
+ # # TODO What are we actually testing here?
415
+ # def test_get_children
416
+ # Philologic::Client.new do |client|
417
+ # h = Nokogiri::HTML( open(@root_file) )
418
+ # children = client.send( :_parse, Nokogiri::HTML( open(@root_file) ) )
419
+ # client.stubs(:_get).with('/?title=').returns(children)
420
+ # assert_not_nil children
421
+ # assert_equal children, client.children
422
+ # end
423
+ # end
424
+
425
+ # def test_parse_children
426
+ # Philologic::Client.new do |client|
427
+ # client.endpoint = @endpoint
428
+ # children = client.children(@root_path)
429
+ # assert_not_nil children
430
+ # assert_kind_of Array, children
431
+ # assert_equal 1845, children.size
432
+ # children.each do |child|
433
+ # assert_kind_of Philologic::Link, child
434
+ # assert_equal 'philologic_cite', child['class']
435
+ # assert_not_nil child['href']
436
+ # assert_nil child['some random attribute']
437
+ # assert_not_nil child['author']
438
+ # assert_not_nil child['filename']
439
+ # assert_not_nil child['title']
440
+ # assert_not_nil child.text
441
+ # end
442
+ #
443
+ # assert_equal './1/0/0/0/0/0/0', children.first['href']
444
+ # assert_equal 'Conon, de Béthune, ca. 1160-1219 or 20.', children.first['author']
445
+ # assert_equal 'Les Chansons', children.first['title']
446
+ # assert_equal 'TLF.0.tei', children.first['filename']
447
+ # assert_match /^Conon, de Béthune, ca. 1160-1219 or 20./, children.first.text
448
+ # assert_equal './1/0/0/0/0/0/0', children.first.to_s
449
+ #
450
+ # assert_equal './1845/0/0/0/0/0/0', children.last['href']
451
+ # assert_equal 'Sartre J.-P.', children.last['author']
452
+ # assert_equal 'Les Mots', children.last['title']
453
+ # assert_equal 'TLF.1879.tei', children.last['filename']
454
+ # assert_equal "Sartre J.-P., Les Mots: TLF.1879.tei", children.last.text
455
+ # assert_equal './1845/0/0/0/0/0/0', children.last.to_s
456
+ #
457
+ # end
458
+ # end
459
+
460
+ # def test_parse_document
461
+ # Philologic::Client.new do |client|
462
+ # client.endpoint = @endpoint
463
+ # doc = client.document(@doc_path)
464
+ # assert_not_nil doc
465
+ #
466
+ # assert_kind_of Philologic::Document, doc
467
+ # assert_equal 'philologic_object', doc['class']
468
+ # assert_nil doc['some random attribute']
469
+ # assert_kind_of String, doc.html
470
+ # assert_match /^<div class="context_container" id="1">/, doc.html
471
+ # assert_match %r{par tans la verité." </div>}, doc.html
472
+ # assert_kind_of String, doc.text
473
+ # assert_match /^Conon, de Béthune/, doc.text
474
+ # assert_match /verité." $/, doc.text
475
+ # end
476
+ # end
477
+
478
+ # def test_get_document_from_cite_through_client
479
+ # Philologic::Client.new do |client|
480
+ # client.endpoint = @endpoint
481
+ # child = client.children(@root_path).first
482
+ # assert_not_nil child
483
+ # assert_kind_of Philologic::Link, child
484
+ # doc = client.send( :_parse, Nokogiri::HTML( open(@doc_file) ) )
485
+ # client.stubs(:_get).with('./1/0/0/0/0/0/0').returns(doc) # TODO Improve
486
+ # assert_equal doc, client.document( child['href'] )
487
+ # end
488
+ # end
489
+
490
+ # def test_get_document_from_cite
491
+ # Philologic::Client.new do |client|
492
+ # client.endpoint = @endpoint
493
+ # child = client.children(@root_path).first
494
+ # assert_not_nil child
495
+ # assert_kind_of Philologic::Link, child
496
+ # doc = client.send( :_parse, Nokogiri::HTML( open(@doc_file) ) )
497
+ # client.stubs(:_get).with('./1/0/0/0/0/0/0').returns(doc) # TODO Improve
498
+ # assert_equal doc, child.document
499
+ # end
500
+ # end
501
+
502
+ # def test_underscore_query
503
+ # Philologic::Client.new(@endpoint) do |client|
504
+ # doc = client.send( :_parse, Nokogiri::HTML( open(@query_file) ) )
505
+ # client.stubs(:_get).with('?q=lion').returns(doc)
506
+ # assert_equal doc, client.send( :_query, :q => 'lion' )
507
+ # end
508
+ # end
509
+
510
+ # Philologic::Client.new(@endpoint) do |client|
511
+ # assert_equal '?q=lion', client.send( :_build_query, :q => 'lion' )
512
+ # assert_equal '?foo=bar&q=lion', client.send( :_build_query, :q => 'lion', :foo => 'bar' )
513
+ # end
514
+ # end
515
+
516
+ # def test_search_with_invalid_queries
517
+ # Philologic::Client.new(@endpoint) do |client|
518
+ # [ nil, [], {}, '', [ '' ], [ nil ], Object.new ].each do |q|
519
+ # assert_raise(RuntimeError, 'invalid query') { client.search(q) }
520
+ # end
521
+ # end
522
+ # end
523
+
524
+ # def test_search
525
+ # Philologic::Client.new(@endpoint) do |client|
526
+ # doc = client.send( :_parse, Nokogiri::HTML( open(@query_file) ) )
527
+ # client.stubs(:_get).with('?q=lion').returns(doc)
528
+
529
+ # results = client.search('lion')
530
+
531
+ # assert_not_nil results
532
+ # assert_kind_of Array, results
533
+ # assert_equal 50, results.size
534
+ # results.each do |result|
535
+ # assert_kind_of Philologic::Link, result
536
+ # assert_equal 'philologic_occurrence', result['class']
537
+ # assert_not_nil result['href']
538
+ # assert_nil result['some random attribute']
539
+ # assert_not_nil result['author']
540
+ # assert_not_nil result['hit_n']
541
+ # assert_nil result['filename']
542
+ # assert_not_nil result['title']
543
+ # assert_not_nil result.text
544
+ # end
545
+
546
+ # assert_equal './1/3/3/1/25/?byte=33845', results.first['href']
547
+ # assert_equal 'William Shakespeare', results.first['author']
548
+ # assert_equal 'The First Part of King Henry the Fourth', results.first['title']
549
+ # assert_equal '1', results.first['hit_n']
550
+ # assert_match /^1\. William Shakespeare, The First Part/, results.first.text
551
+ # assert_match './1/3/3/1/25/?byte=33845', results.first.to_s
552
+
553
+ # assert_equal './24/5/2/1/14/?byte=124024', results.last['href']
554
+ # assert_equal 'William Shakespeare', results.last['author']
555
+ # assert_equal "A Midsummer Night's Dream", results.last['title']
556
+ # assert_equal '50', results.last['hit_n']
557
+ # assert_match /^50\. William Shakespeare,/, results.last.text
558
+ # assert_equal './24/5/2/1/14/?byte=124024', results.last.to_s
559
+
560
+ # end
561
+ # end
562
+
563
+ # def test_search_with_key_value_pairs
564
+ # Philologic::Client.new(@endpoint) do |client|
565
+ # doc = client.send( :_parse, Nokogiri::HTML( open(@query_file) ) )
566
+ # client.stubs(:_get).with('?q=lion').returns(doc)
567
+
568
+ # results = client.search( :q => 'lion' )
569
+
570
+ # assert_not_nil results
571
+ # assert_kind_of Array, results
572
+ # assert_equal 50, results.size
573
+ # results.each do |result|
574
+ # assert_kind_of Philologic::Link, result
575
+ # assert_equal 'philologic_occurrence', result['class']
576
+ # assert_not_nil result['href']
577
+ # assert_nil result['some random attribute']
578
+ # assert_not_nil result['author']
579
+ # assert_nil result['filename']
580
+ # assert_not_nil result['hit_n']
581
+ # assert_not_nil result['title']
582
+ # assert_not_nil result.text
583
+ # end
584
+
585
+ # assert_equal './1/3/3/1/25/?byte=33845', results.first['href']
586
+ # assert_equal 'William Shakespeare', results.first['author']
587
+ # assert_equal 'The First Part of King Henry the Fourth', results.first['title']
588
+ # assert_equal '1', results.first['hit_n']
589
+ # assert_match /^1\. William Shakespeare, The First Part/, results.first.text
590
+ # assert_match './1/3/3/1/25/?byte=33845', results.first.to_s
591
+
592
+ # assert_equal './24/5/2/1/14/?byte=124024', results.last['href']
593
+ # assert_equal 'William Shakespeare', results.last['author']
594
+ # assert_equal '50', results.last['hit_n']
595
+ # assert_equal "A Midsummer Night's Dream", results.last['title']
596
+ # assert_match /^50\. William Shakespeare,/, results.last.text
597
+ # assert_equal './24/5/2/1/14/?byte=124024', results.last.to_s
598
+
599
+ # end
600
+ # end
601
+
602
+ # def test_frequency_search_with_invalid_queries
603
+ # Philologic::Client.new(@endpoint) do |client|
604
+ # [ nil, [], {}, '', [ '' ], [ nil ], Object.new ].each do |q|
605
+ # assert_raise(RuntimeError, 'invalid query') { client.frequency(q) }
606
+ # end
607
+ # end
608
+ # end
609
+
610
+ # def test_frequency_search
611
+ # Philologic::Client.new(@endpoint) do |client|
612
+ # doc = client.send( :_parse, Nokogiri::HTML( open(@freq_file) ) )
613
+ # client.stubs(:_get).with('?q=lion&report=frequency').returns(doc)
614
+ #
615
+ # results = client.frequency('lion')
616
+ #
617
+ # assert_not_nil results
618
+ # assert_kind_of Array, results
619
+ # assert_equal 15, results.size
620
+ # results.each do |result|
621
+ # assert_kind_of Philologic::TableRow, result
622
+ # assert_equal 'philologic_frequency_row', result['class']
623
+ # assert_nil result['href']
624
+ # assert_nil result['some random attribute']
625
+ # assert_nil result['author']
626
+ # assert_nil result['filename']
627
+ # assert_nil result['title']
628
+ # assert_not_nil result.count
629
+ # assert_not_nil result.field
630
+ # assert_not_nil result.href
631
+ # assert_not_nil result.text
632
+ # end
633
+ #
634
+ # assert_equal 'author', results.first.field
635
+ # assert_equal 48, results.first.count
636
+ # assert_equal './?q=lion&author=Beauvoir+S.+de&title=', results.first.href
637
+ # assert_equal 'Beauvoir S. de', results.first.text
638
+ # assert_equal 'author | 48 | Beauvoir S. de', results.first.to_s
639
+ #
640
+ # assert_equal 'author', results.last.field
641
+ # assert_equal 1, results.last.count
642
+ # assert_equal './?q=lion&author=Schaeffer+P.&title=', results.last.href
643
+ # assert_equal 'Schaeffer P.', results.last.text
644
+ # assert_equal 'author | 1 | Schaeffer P.', results.last.to_s
645
+ # end
646
+ # end
647
+
648
+ # def test_frequency_search_with_key_value_pairs
649
+ # Philologic::Client.new(@endpoint) do |client|
650
+ # doc = client.send( :_parse, Nokogiri::HTML( open(@freq_file) ) )
651
+ # client.stubs(:_get).with('?q=lion&report=frequency').returns(doc)
652
+ #
653
+ # results = client.frequency( :q => 'lion' )
654
+ #
655
+ # assert_not_nil results
656
+ # assert_kind_of Array, results
657
+ # assert_equal 15, results.size
658
+ # results.each do |result|
659
+ # assert_kind_of Philologic::TableRow, result
660
+ # assert_equal 'philologic_frequency_row', result['class']
661
+ # assert_nil result['href']
662
+ # assert_nil result['some random attribute']
663
+ # assert_nil result['author']
664
+ # assert_nil result['filename']
665
+ # assert_nil result['title']
666
+ # assert_not_nil result.count
667
+ # assert_not_nil result.field
668
+ # assert_not_nil result.href
669
+ # assert_not_nil result.text
670
+ # end
671
+ #
672
+ # assert_equal 'author', results.first.field
673
+ # assert_equal 48, results.first.count
674
+ # assert_equal './?q=lion&author=Beauvoir+S.+de&title=', results.first.href
675
+ # assert_equal 'Beauvoir S. de', results.first.text
676
+ # assert_equal 'author | 48 | Beauvoir S. de', results.first.to_s
677
+ #
678
+ # assert_equal 'author', results.last.field
679
+ # assert_equal 1, results.last.count
680
+ # assert_equal './?q=lion&author=Schaeffer+P.&title=', results.last.href
681
+ # assert_equal 'Schaeffer P.', results.last.text
682
+ # assert_equal 'author | 1 | Schaeffer P.', results.last.to_s
683
+ #
684
+ # end
685
+ # end
686
+
687
+ # def test_philologic_frequency_tablerow_links
688
+ # Philologic::Client.new(@endpoint) do |client|
689
+ # freq_doc = client.send( :_parse, Nokogiri::HTML( open(@freq_file) ) )
690
+ # freq_links_doc = client.send( :_parse, Nokogiri::HTML( open(@freq_links_file) ) )
691
+ # client.stubs(:_get).with('?q=lion&report=frequency').returns(freq_doc)
692
+ # client.stubs(:_get).with('?author=Beauvoir+S.+de&q=lion&title=').returns(freq_links_doc)
693
+ #
694
+ # results = client.frequency( :q => 'lion' )
695
+ # assert_not_nil results
696
+ #
697
+ # links = results.first.links
698
+ #
699
+ # assert_not_nil links
700
+ # assert_kind_of Array, links
701
+ # assert_equal 48, links.size
702
+ #
703
+ # links.each do |link|
704
+ # assert_kind_of Philologic::Link, link
705
+ # assert_equal 'philologic_occurence', link['class']
706
+ # assert_not_nil link['href']
707
+ # assert_nil link['some random attribute']
708
+ # assert_not_nil link['author']
709
+ # assert_nil link['filename']
710
+ # assert_not_nil link['title']
711
+ # assert_not_nil link.text
712
+ # end
713
+ #
714
+ # assert_equal './1839/3/0/0', links.first['href']
715
+ # assert_equal 'Beauvoir S. de', links.first['author']
716
+ # assert_equal 'Memoires Jeune Fille Rangee', links.first['title']
717
+ # assert_nil links.first['filename']
718
+ # assert_match /^Beauvoir S. de/, links.first.text
719
+ # assert_equal './1839/3/0/0 | Memoires Jeune Fille Rangee | Beauvoir S. de', links.first.to_s
720
+ #
721
+ # assert_equal './1839/4/0/0', links.last['href']
722
+ # assert_equal 'Beauvoir S. de', links.last['author']
723
+ # assert_equal 'Memoires Jeune Fille Rangee', links.last['title']
724
+ # assert_nil links.last['filename']
725
+ # assert_match /^Beauvoir S. de,/, links.last.text
726
+ # assert_equal './1839/4/0/0 | Memoires Jeune Fille Rangee | Beauvoir S. de', links.last.to_s
727
+ #
728
+ # end
729
+ # end
730
+
731
+ # def test_collocation_search_with_invalid_queries
732
+ # Philologic::Client.new(@endpoint) do |client|
733
+ # [ nil, [], {}, '', [ '' ], [ nil ], Object.new ].each do |q|
734
+ # assert_raise(RuntimeError, 'invalid query') { client.collocation(q) }
735
+ # end
736
+ # end
737
+ # end
738
+
739
+ # def test_collocation_search
740
+ # Philologic::Client.new(@endpoint) do |client|
741
+ # doc = client.send( :_parse, Nokogiri::HTML( open(@coll_file) ) )
742
+ # client.stubs(:_get).with('?field=collocates&q=lion&report=frequency').returns(doc)
743
+ #
744
+ # results = client.collocation('lion')
745
+ #
746
+ # assert_not_nil results
747
+ # assert_kind_of Array, results
748
+ # assert_equal 15, results.size
749
+ # results.each do |result|
750
+ # assert_kind_of Philologic::TableRow, result
751
+ # assert_equal 'philologic_frequency_row', result['class']
752
+ # assert_nil result['href']
753
+ # assert_nil result['some random attribute']
754
+ # assert_nil result['author']
755
+ # assert_nil result['filename']
756
+ # assert_nil result['title']
757
+ # assert_not_nil result.count
758
+ # assert_not_nil result.field
759
+ # assert_not_nil result.href
760
+ # assert_not_nil result.text
761
+ # end
762
+ #
763
+ # assert_equal 'author', results.first.field
764
+ # assert_equal 48, results.first.count
765
+ # assert_equal './?q=lion&author=Beauvoir+S.+de&title=', results.first.href
766
+ # assert_equal 'Beauvoir S. de', results.first.text
767
+ # assert_equal 'author | 48 | Beauvoir S. de', results.first.to_s
768
+ #
769
+ # assert_equal 'author', results.last.field
770
+ # assert_equal 1, results.last.count
771
+ # assert_equal './?q=lion&author=Schaeffer+P.&title=', results.last.href
772
+ # assert_equal 'Schaeffer P.', results.last.text
773
+ # assert_equal 'author | 1 | Schaeffer P.', results.last.to_s
774
+ # end
775
+ # end
776
+
777
+ # def test_collocation_search_with_key_value_pairs
778
+ # Philologic::Client.new(@endpoint) do |client|
779
+ # doc = client.send( :_parse, Nokogiri::HTML( open(@coll_file) ) )
780
+ # client.stubs(:_get).with('?field=collocates&q=lion&report=frequency').returns(doc)
781
+ #
782
+ # results = client.collocation( :q => 'lion' )
783
+ #
784
+ # assert_not_nil results
785
+ # assert_kind_of Array, results
786
+ # assert_equal 15, results.size
787
+ # results.each do |result|
788
+ # assert_kind_of Philologic::TableRow, result
789
+ # assert_equal 'philologic_frequency_row', result['class']
790
+ # assert_nil result['href']
791
+ # assert_nil result['some random attribute']
792
+ # assert_nil result['author']
793
+ # assert_nil result['filename']
794
+ # assert_nil result['title']
795
+ # assert_not_nil result.count
796
+ # assert_not_nil result.field
797
+ # assert_not_nil result.href
798
+ # assert_not_nil result.text
799
+ # end
800
+ #
801
+ # assert_equal 'author', results.first.field
802
+ # assert_equal 48, results.first.count
803
+ # assert_equal './?q=lion&author=Beauvoir+S.+de&title=', results.first.href
804
+ # assert_equal 'Beauvoir S. de', results.first.text
805
+ # assert_equal 'author | 48 | Beauvoir S. de', results.first.to_s
806
+ #
807
+ # assert_equal 'author', results.last.field
808
+ # assert_equal 1, results.last.count
809
+ # assert_equal './?q=lion&author=Schaeffer+P.&title=', results.last.href
810
+ # assert_equal 'Schaeffer P.', results.last.text
811
+ # assert_equal 'author | 1 | Schaeffer P.', results.last.to_s
812
+ #
813
+ # end
814
+ # end
815
+
816
+ # def test_philologic_collocation_tablerow_links
817
+ # Philologic::Client.new(@endpoint) do |client|
818
+ # coll_doc = client.send( :_parse, Nokogiri::HTML( open(@coll_file) ) )
819
+ # coll_links_doc = client.send( :_parse, Nokogiri::HTML( open(@coll_links_file) ) )
820
+ # client.stubs(:_get).with('?field=collocates&q=lion&report=frequency').returns(coll_doc)
821
+ # client.stubs(:_get).with('?author=Beauvoir+S.+de&q=lion&title=').returns(coll_links_doc)
822
+ #
823
+ # results = client.collocation( :q => 'lion' )
824
+ # assert_not_nil results
825
+ #
826
+ # links = results.first.links
827
+ #
828
+ # assert_not_nil links
829
+ # assert_kind_of Array, links
830
+ # assert_equal 48, links.size
831
+ #
832
+ # links.each do |link|
833
+ # assert_kind_of Philologic::Link, link
834
+ # assert_equal 'philologic_occurence', link['class']
835
+ # assert_not_nil link['href']
836
+ # assert_nil link['some random attribute']
837
+ # assert_not_nil link['author']
838
+ # assert_nil link['filename']
839
+ # assert_not_nil link['title']
840
+ # assert_not_nil link.text
841
+ # end
842
+ #
843
+ # assert_equal './1839/3/0/0', links.first['href']
844
+ # assert_equal 'Beauvoir S. de', links.first['author']
845
+ # assert_equal 'Memoires Jeune Fille Rangee', links.first['title']
846
+ # assert_nil links.first['filename']
847
+ # assert_match /^Beauvoir S. de/, links.first.text
848
+ # assert_equal './1839/3/0/0 | Memoires Jeune Fille Rangee | Beauvoir S. de', links.first.to_s
849
+ #
850
+ # assert_equal './1839/4/0/0', links.last['href']
851
+ # assert_equal 'Beauvoir S. de', links.last['author']
852
+ # assert_equal 'Memoires Jeune Fille Rangee', links.last['title']
853
+ # assert_nil links.last['filename']
854
+ # assert_match /^Beauvoir S. de/, links.last.text
855
+ # assert_equal './1839/4/0/0 | Memoires Jeune Fille Rangee | Beauvoir S. de', links.last.to_s
856
+ #
857
+ # end
858
+ # end
859
+
860
+ end
861
+