google-local-results-ai-parser 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78ecf24cc717254a2d3b597868e582f715fc86c7ca160aadbdef5183a3cdb9e7
4
- data.tar.gz: '09818139bdc702f86693ff1b48519b6ecbc1d4a5264d9969faf315a04fa901f2'
3
+ metadata.gz: 62925be13b2ff224585862444f2e77bdea9f7975316b2f66253e7e2fa7a6fe34
4
+ data.tar.gz: e2ec29030b6c442f955b3d4c54b21473a23f214d3db0944e2006c6ac3c7c9446
5
5
  SHA512:
6
- metadata.gz: e69e9916971731c5461b3060c558b84e5373a411197b7cd90252601f9ce35d8b07ab9854a5d8663ea6b9f70c21d94f4aa37e182e0956e320e44c687c36ef06e9
7
- data.tar.gz: 1e34f84316101ba580189b4b783f42a20c814f3ae1b2e4337a7f46373c842de492bde9f54448e86f02432327309649d0a38d973129ac946bbe3bc39b193f3f4c
6
+ metadata.gz: 48054b17769730be43150502b909a82666adca5f35b2bf6fa235cf4b96da37040338eb41c62382da0320729158b3d70898efb6d595ad6cef7363d212aa4414f1
7
+ data.tar.gz: af7d2196995a5991c017940af28de5816e1fc9535b1424c070670db65cf4f6df546d76d2c77ed0f64281810dda649f769e7ead071e5c99c68f43a18c4dbf89ee
@@ -2,6 +2,7 @@ require 'nokolexbor'
2
2
  require 'http'
3
3
  require 'parallel'
4
4
  require 'json'
5
+ require 'pry'
5
6
 
6
7
  module GoogleLocalResultsAiParser
7
8
  DEFAULT_SERVER = 'https://api-inference.huggingface.co/models/serpapi/bert-base-local-results'.freeze
@@ -465,16 +466,17 @@ module GoogleLocalResultsAiParser
465
466
  "Takeaway"
466
467
  ]
467
468
  caught_results_indices = results.map.with_index {|result, index| index if known_errors.include?(result[:input])}.compact
468
- return results, label_order, duplicates if caught_results_indices == []
469
469
 
470
- not_service_option_duplicates = duplicates.select.with_index do |duplicate, duplicate_index|
471
- caught_results_indices.each do |caught_index|
470
+ not_service_option_duplicates = []
471
+ caught_results_indices.each do |caught_index|
472
+ duplicates.each.with_index do |duplicate, duplicate_index|
472
473
  if duplicate.include?(caught_index) && results[caught_index][:result][0][0]["label"] != "service_options"
473
- duplicate_index
474
+ not_service_option_duplicates << duplicate_index
474
475
  end
475
476
  end
476
477
  end
477
478
 
479
+ return results, label_order, duplicates if not_service_option_duplicates == []
478
480
  # Zero out the `type` or `description`, and put it to last position
479
481
  caught_results_indices.each do |caught_index|
480
482
  service_options_hash = results[caught_index][:result][0].find {|hash| hash["label"] == "service options" }
@@ -491,12 +493,12 @@ module GoogleLocalResultsAiParser
491
493
 
492
494
  # Rearranging duplicates
493
495
  not_service_option_duplicates.each do |not_service_option_duplicate|
494
- last_item = duplicates[duplicates.index(not_service_option_duplicate)][-1]
495
- duplicates[duplicates.index(not_service_option_duplicate)].delete(last_item)
496
+ last_item = duplicates[not_service_option_duplicate][-1]
497
+ duplicates[not_service_option_duplicate].delete(last_item)
496
498
  end
497
499
 
498
500
  not_service_option_duplicates.each do |not_service_option_duplicate|
499
- if (duplicate_arr = duplicates[duplicates.index(not_service_option_duplicate)]) && duplicate_arr.size == 1
501
+ if (duplicate_arr = duplicates[not_service_option_duplicate]) && duplicate_arr.size == 1
500
502
  duplicates.delete(duplicate_arr)
501
503
  end
502
504
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-local-results-ai-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emirhan Akdeniz