ebsco-eds 0.3.15.pre → 0.3.16.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0ed32f227645931d31d5ee595ca1b8793f4be7f
4
- data.tar.gz: b5085f8c0c463f7bf5b084104119baf15befff4a
3
+ metadata.gz: 6206f86a831177ab81411229592b72dd87fbfeb0
4
+ data.tar.gz: d0e3f92c58dd4e6b2e04c1a5bfcef6f0176f16d2
5
5
  SHA512:
6
- metadata.gz: 72e23e4ee620db0170f53541684aa44d83f33822a44ec1d896f258c32908eeab0accf8041a860438e631e5dc0fe7b5366a48c205d68e8b293236c37abf1c8fcb
7
- data.tar.gz: 929364e6faa8bebaa6f30288806cca3dff1d06bb3319c6603fab2091cf2ca7f76b36b9c9d2481fdf4dc8ff5ad2a489f4f62b2edcff5a0e598b1c465499237a3f
6
+ metadata.gz: ee47135ece9be172b171db28893b4114c9446db9321d8a2eb2e855f11d518c9927196bf9c583fe860d788e00b3cdeb3245159fa8e507fa5625e363bec6789f4b
7
+ data.tar.gz: 8ddcac147ee1523a013de97b8aba02cf4cf941ab2236b5db93b6bf2a5d2c32635bd1f91de643897317410361bed6cf660ea7ef5b9236f9b14d0b9e12d77251a5
@@ -0,0 +1,79 @@
1
+ module EBSCO
2
+ module EDS
3
+ class Titleize
4
+
5
+ SMALL_WORDS = %w{a an and as at but by en for if in of on or the to v v. via vs vs.}
6
+ ACRONYMS = %w{u.s. usa npr ieee llc g.p.o. n.y. n.c. b.v.}
7
+
8
+ def titleize(title, opts={})
9
+ title = title.dup
10
+ title.downcase! unless title[/[[:lower:]]/] # assume all-caps need fixing
11
+
12
+ small_words = SMALL_WORDS + (opts[:small_words] || [])
13
+ small_words = small_words + small_words.map { |small| small.capitalize }
14
+
15
+ acronyms = ACRONYMS + (opts[:acronyms] || [])
16
+ acronyms = acronyms + acronyms.map { |acronym| acronym.downcase }
17
+
18
+ phrases(title).map do |phrase|
19
+ words = phrase.split
20
+ words.map.with_index do |word, index|
21
+
22
+ if acronyms.include?(word.gsub(/[()]/,''))
23
+ word.upcase
24
+ else
25
+
26
+ def word.capitalize
27
+ # like String#capitalize, but it starts with the first letter
28
+ self.sub(/[[:alpha:]].*/) {|subword| subword.capitalize}
29
+ end
30
+
31
+ case word
32
+ when /[[:alpha:]]\.[[:alpha:]]/ # words with dots in, like "example.com"
33
+ word
34
+ when /[-‑]/ # hyphenated word (regular and non-breaking)
35
+ word.split(/([-‑])/).map do |part|
36
+ SMALL_WORDS.include?(part) ? part : part.capitalize
37
+ end.join
38
+ when /^[[:alpha:]].*[[:upper:]]/ # non-first letter capitalized already
39
+ word
40
+ when /^[[:digit:]]/ # first character is a number
41
+ word
42
+ when *small_words
43
+ if index == 0 || index == words.size - 1
44
+ word.capitalize
45
+ else
46
+ word.downcase
47
+ end
48
+ else
49
+ word.capitalize
50
+ end
51
+
52
+ end
53
+
54
+ end.join(' ')
55
+ end.join(' ')
56
+ end
57
+
58
+ def phrases(title)
59
+ phrases = [[]]
60
+ title.split.each do |word|
61
+ phrases.last << word
62
+ phrases << [] if ends_with_punctuation?(word) && !small_word?(word)
63
+ end
64
+ phrases.reject(&:empty?).map { |phrase| phrase.join ' ' }
65
+ end
66
+
67
+ private
68
+
69
+ def small_word?(word)
70
+ SMALL_WORDS.include? word.downcase
71
+ end
72
+
73
+ def ends_with_punctuation?(word)
74
+ word =~ /[:.;?!]$/
75
+ end
76
+ end
77
+
78
+ end
79
+ end
@@ -139,6 +139,10 @@ module EBSCO
139
139
  @available_search_criteria.fetch('AvailableDidYouMeanOptions',{}).find{|item| item['Id'] == 'AutoSuggest'}['DefaultOn']
140
140
  end
141
141
 
142
+ def default_auto_correct
143
+ @available_search_criteria.fetch('AvailableDidYouMeanOptions',{}).find{|item| item['Id'] == 'AutoCorrect'}['DefaultOn']
144
+ end
145
+
142
146
  # ====================================================================================
143
147
  # RESULTS VIEW SETTINGS
144
148
  # ====================================================================================
@@ -61,12 +61,6 @@ module EBSCO
61
61
  end
62
62
  end
63
63
 
64
- def eds_sanitize(str)
65
- pattern = /([)(:,])/
66
- str = str.gsub(pattern){ |match| '\\' + match }
67
- str
68
- end
69
-
70
64
  # def is_valid_action(action, info)
71
65
  # # actions in info that require an enumerated value (e.g., addlimiter(LA99:Bulgarian))
72
66
  # _available_actions = info.available_actions
@@ -116,6 +110,9 @@ module EBSCO
116
110
  # auto-suggest
117
111
  qs << '&autosuggest=' + @SearchCriteria.AutoSuggest
118
112
 
113
+ # auto-correct
114
+ qs << '&autocorrect=' + @SearchCriteria.AutoCorrect
115
+
119
116
  # limiters
120
117
  unless @SearchCriteria.Limiters.nil?
121
118
  qs << '&limiter=' + @SearchCriteria.Limiters.join(',')
@@ -162,7 +159,7 @@ module EBSCO
162
159
  class SearchCriteria
163
160
  include JSONable
164
161
  attr_accessor :Queries, :SearchMode, :IncludeFacets, :FacetFilters, :Limiters, :Sort, :PublicationId,
165
- :RelatedContent, :AutoSuggest, :Expanders
162
+ :RelatedContent, :AutoSuggest, :Expanders, :AutoCorrect
166
163
 
167
164
  def initialize(options = {}, info)
168
165
 
@@ -171,6 +168,7 @@ module EBSCO
171
168
  @IncludeFacets = 'y'
172
169
  @Sort = 'relevance'
173
170
  @AutoSuggest = info.default_auto_suggest
171
+ @AutoCorrect = info.default_auto_correct
174
172
  _has_query = false
175
173
 
176
174
  @Expanders = info.default_expander_ids
@@ -275,20 +273,6 @@ module EBSCO
275
273
  when :facet_filters
276
274
  @FacetFilters = value
277
275
 
278
- # # handle solr facets without causing the page to reset to 1 again?
279
- # when 'f'
280
- #
281
- # if value.has_key?('content_provider_facet')
282
- # f_filter = {'FilterId' => 1, 'FacetValues' => []}
283
- # flist = value['content_provider_facet']
284
- # flist.each do |item|
285
- # item = eds_sanitize item
286
- # f_filter['FacetValues'].push({'Id' => 'ContentProvider', 'Value' => item})
287
- # end
288
- # @FacetFilters.push f_filter
289
- # puts 'FACET FILTERS: ' + @FacetFilters.inspect
290
- # end
291
-
292
276
  # ====================================================================================
293
277
  # sort
294
278
  # ====================================================================================
@@ -313,9 +297,15 @@ module EBSCO
313
297
  when :publication_id
314
298
  @PublicationId = value
315
299
 
316
- when :auto_suggest
300
+ # ====================================================================================
301
+ # auto suggest & correct
302
+ # ====================================================================================
303
+ when :auto_suggest, 'auto_suggest'
317
304
  @AutoSuggest = value ? 'y' : 'n'
318
305
 
306
+ when :auto_correct, 'auto_correct'
307
+ @AutoCorrect = value ? 'y' : 'n'
308
+
319
309
  # ====================================================================================
320
310
  # expanders
321
311
  # ====================================================================================
@@ -379,7 +369,6 @@ module EBSCO
379
369
  if value.has_key?('eds_language_facet')
380
370
  lang_list = value['eds_language_facet']
381
371
  lang_list.each do |item|
382
- item = eds_sanitize item
383
372
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'Language', 'Value' => item}]})
384
373
  filter_id += 1
385
374
  end
@@ -388,7 +377,6 @@ module EBSCO
388
377
  if value.has_key?('eds_subject_topic_facet')
389
378
  subj_list = value['eds_subject_topic_facet']
390
379
  subj_list.each do |item|
391
- item = eds_sanitize item
392
380
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'SubjectEDS', 'Value' => item}]})
393
381
  filter_id += 1
394
382
  end
@@ -397,7 +385,6 @@ module EBSCO
397
385
  if value.has_key?('eds_subjects_geographic_facet')
398
386
  subj_list = value['eds_subjects_geographic_facet']
399
387
  subj_list.each do |item|
400
- item = eds_sanitize item
401
388
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'SubjectGeographic', 'Value' => item}]})
402
389
  filter_id += 1
403
390
  end
@@ -406,7 +393,6 @@ module EBSCO
406
393
  if value.has_key?('eds_publisher_facet')
407
394
  subj_list = value['eds_publisher_facet']
408
395
  subj_list.each do |item|
409
- item = eds_sanitize item
410
396
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'Publisher', 'Value' => item}]})
411
397
  filter_id += 1
412
398
  end
@@ -415,7 +401,6 @@ module EBSCO
415
401
  if value.has_key?('eds_journal_facet')
416
402
  subj_list = value['eds_journal_facet']
417
403
  subj_list.each do |item|
418
- item = eds_sanitize item
419
404
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'Journal', 'Value' => item}]})
420
405
  filter_id += 1
421
406
  end
@@ -424,7 +409,6 @@ module EBSCO
424
409
  if value.has_key?('eds_category_facet')
425
410
  subj_list = value['eds_category_facet']
426
411
  subj_list.each do |item|
427
- item = eds_sanitize item
428
412
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'Category', 'Value' => item}]})
429
413
  filter_id += 1
430
414
  end
@@ -433,7 +417,6 @@ module EBSCO
433
417
  if value.has_key?('eds_library_location_facet')
434
418
  subj_list = value['eds_library_location_facet']
435
419
  subj_list.each do |item|
436
- item = eds_sanitize item
437
420
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'LocationLibrary', 'Value' => item}]})
438
421
  filter_id += 1
439
422
  end
@@ -442,7 +425,6 @@ module EBSCO
442
425
  if value.has_key?('eds_library_collection_facet')
443
426
  subj_list = value['eds_library_collection_facet']
444
427
  subj_list.each do |item|
445
- item = eds_sanitize item
446
428
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'CollectionLibrary', 'Value' => item}]})
447
429
  filter_id += 1
448
430
  end
@@ -451,7 +433,6 @@ module EBSCO
451
433
  if value.has_key?('eds_author_university_facet')
452
434
  subj_list = value['eds_author_university_facet']
453
435
  subj_list.each do |item|
454
- item = eds_sanitize item
455
436
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'AuthorUniversity', 'Value' => item}]})
456
437
  filter_id += 1
457
438
  end
@@ -471,7 +452,6 @@ module EBSCO
471
452
  if value.has_key?('eds_publication_type_facet')
472
453
  f_list = value['eds_publication_type_facet']
473
454
  f_list.each do |item|
474
- item = eds_sanitize item
475
455
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'SourceType', 'Value' => item}]})
476
456
  filter_id += 1
477
457
  end
@@ -480,7 +460,6 @@ module EBSCO
480
460
  if value.has_key?('eds_content_provider_facet')
481
461
  subj_list = value['eds_content_provider_facet']
482
462
  subj_list.each do |item|
483
- item = eds_sanitize item
484
463
  @FacetFilters.push({'FilterId' => filter_id, 'FacetValues' => [{'Id' => 'ContentProvider', 'Value' => item}]})
485
464
  filter_id += 1
486
465
  end
@@ -551,12 +530,6 @@ module EBSCO
551
530
 
552
531
  end
553
532
 
554
- def eds_sanitize(str)
555
- pattern = /([)(:,])/
556
- str = str.gsub(pattern){ |match| '\\' + match }
557
- str
558
- end
559
-
560
533
  end
561
534
 
562
535
  class RetrievalCriteria
@@ -1,4 +1,5 @@
1
1
  require 'ebsco/eds/record'
2
+ require 'ebsco/eds/facet_titleize'
2
3
  require 'yaml'
3
4
  require 'cgi'
4
5
  require 'date'
@@ -87,6 +88,9 @@ module EBSCO
87
88
  end
88
89
  end
89
90
 
91
+ # titleize facets
92
+ @titleize_facets = %w[Language Journal SubjectEDS SubjectGeographic Publisher]
93
+
90
94
  end
91
95
 
92
96
  # returns solr search response format
@@ -207,24 +211,47 @@ module EBSCO
207
211
  # "freq":1}]}],
208
212
  # "correctlySpelled":false}}
209
213
  def solr_spellcheck
214
+
215
+ suggestions = []
210
216
  unless did_you_mean.nil?
217
+ suggestions = [
218
+ search_terms.first.to_s, {
219
+ 'numFound' => 1,
220
+ 'startOffset' => 0,
221
+ 'endOffset' => 7,
222
+ 'origFreq' => 0,
223
+ 'suggestion' => [{
224
+ 'word' => did_you_mean.to_s,
225
+ 'freq' => 1 }]
226
+ }
227
+ ]
228
+ end
229
+
230
+ corrections = []
231
+ unless auto_corrections.nil?
232
+ corrections = [
233
+ search_terms.first.to_s, {
234
+ 'numFound' => 1,
235
+ 'startOffset' => 0,
236
+ 'endOffset' => 7,
237
+ 'origFreq' => 0,
238
+ 'correction' => [{
239
+ 'word' => auto_corrections.to_s,
240
+ 'freq' => 1 }]
241
+ }
242
+ ]
243
+ end
244
+
245
+ unless did_you_mean.nil? && auto_corrections.nil?
211
246
  {
212
247
  'spellcheck' => {
213
- 'suggestions' => [
214
- search_terms.first.to_s, {
215
- 'numFound' => 1,
216
- 'startOffset' => 0,
217
- 'endOffset' => 7,
218
- 'origFreq' => 0,
219
- 'suggestion' => [{
220
- 'word' => did_you_mean.to_s,
221
- 'freq' => 1 }]
222
- }
223
- ],
248
+ 'suggestions' => suggestions,
249
+ 'corrections' => corrections,
224
250
  'correctlySpelled' => false
225
251
  }
226
252
  }
227
253
  end
254
+
228
255
  end
229
256
 
230
257
  # Publication date facets:
@@ -292,7 +319,8 @@ module EBSCO
292
319
  # "Expanders"=>["fulltext", "thesaurus", "relatedsubjects"],
293
320
  # "Sort"=>"relevance",
294
321
  # "RelatedContent"=>["rs"],
295
- # "AutoSuggest"=>"n"
322
+ # "AutoSuggest"=>"n",
323
+ # "AutoCorrect"=>"n"
296
324
  # }
297
325
  def search_criteria
298
326
  if @results['SearchRequestGet'] && @results['SearchRequestGet']['QueryString']
@@ -302,6 +330,7 @@ module EBSCO
302
330
  sc['IncludeFacets'] = params['includefacets'].nil? ? 'y' : params['includefacets'][0].to_s
303
331
  sc['Sort'] = params['sort'].nil? ? 'relevance' : params['sort'][0].to_s
304
332
  sc['AutoSuggest'] = params['autosuggest'].nil? ? 'n' : params['autosuggest'][0].to_s
333
+ sc['AutoCorrect'] = params['autocorrect'].nil? ? 'n' : params['autocorrect'][0].to_s
305
334
  sc['Expanders'] = params['expander'].nil? ? [] : params['expander'][0].to_s.split(',')
306
335
  sc['RelatedContent'] = params['relatedcontent'].nil? ? [] : params['relatedcontent'][0].to_s.split(',')
307
336
  query1 = params['query-1'][0].to_s.split(',')
@@ -489,6 +518,10 @@ module EBSCO
489
518
  facet_values = []
490
519
  available_facet['AvailableFacetValues'].each do |available_facet_value|
491
520
  facet_value = available_facet_value['Value']
521
+ if @titleize_facets.include?(facet_id)
522
+ title = EBSCO::EDS::Titleize.new
523
+ facet_value = title.titleize(facet_value)
524
+ end
492
525
  facet_count = available_facet_value['Count']
493
526
  facet_action = available_facet_value['AddAction']
494
527
  facet_values.push({value: facet_value, hitcount: facet_count, action: facet_action})
@@ -514,6 +547,10 @@ module EBSCO
514
547
  if available_facet['Id'] == facet_provided_id || facet_provided_id == 'all'
515
548
  available_facet['AvailableFacetValues'].each do |available_facet_value|
516
549
  facet_value = available_facet_value['Value']
550
+ if @titleize_facets.include?(facet_provided_id)
551
+ title = EBSCO::EDS::Titleize.new
552
+ facet_value = title.titleize(facet_value)
553
+ end
517
554
  facet_count = available_facet_value['Count']
518
555
  facet_values.push(facet_value, facet_count)
519
556
  end
@@ -554,6 +591,14 @@ module EBSCO
554
591
  nil
555
592
  end
556
593
 
594
+ def auto_corrections
595
+ auto_corrected_terms = @results.fetch('SearchResult', {}).fetch('AutoCorrectedTerms',{})
596
+ auto_corrected_terms.each do |term|
597
+ return term
598
+ end
599
+ nil
600
+ end
601
+
557
602
  # Returns a simple list of the search terms used. Boolean operators are not indicated.
558
603
  # ==== Example
559
604
  # ["earthquakes", "california"]
@@ -788,6 +788,9 @@ module EBSCO
788
788
  if jump_payload.SearchCriteria.instance_variable_defined?(:@AutoSuggest)
789
789
  jump_payload.SearchCriteria.remove_instance_variable(:@AutoSuggest)
790
790
  end
791
+ if jump_payload.SearchCriteria.instance_variable_defined?(:@AutoCorrect)
792
+ jump_payload.SearchCriteria.remove_instance_variable(:@AutoCorrect)
793
+ end
791
794
  if jump_payload.SearchCriteria.instance_variable_defined?(:@Expanders)
792
795
  jump_payload.SearchCriteria.remove_instance_variable(:@Expanders)
793
796
  end
@@ -1039,7 +1042,8 @@ module EBSCO
1039
1042
  'SearchMode'=>'',
1040
1043
  'IncludeFacets'=>'y',
1041
1044
  'Sort'=>'relevance',
1042
- 'AutoSuggest'=>'n'
1045
+ 'AutoSuggest'=>'n',
1046
+ 'AutoCorrect'=>'n'
1043
1047
  },
1044
1048
  'RetrievalCriteria'=>
1045
1049
  {
@@ -1,5 +1,5 @@
1
1
  module EBSCO
2
2
  module EDS
3
- VERSION = '0.3.15.pre'
3
+ VERSION = '0.3.16.pre'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebsco-eds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.15.pre
4
+ version: 0.3.16.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill McKinney
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-09-18 00:00:00.000000000 Z
12
+ date: 2017-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -381,6 +381,7 @@ files:
381
381
  - lib/ebsco/eds/csl/styles/chicago-author-date.csl
382
382
  - lib/ebsco/eds/csl/styles/modern-language-association.csl
383
383
  - lib/ebsco/eds/error.rb
384
+ - lib/ebsco/eds/facet_titleize.rb
384
385
  - lib/ebsco/eds/info.rb
385
386
  - lib/ebsco/eds/jsonable.rb
386
387
  - lib/ebsco/eds/options.rb