google-local-results-ai-parser 0.2.1 → 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: 32115a821e2e34cb64ab9e0b28e7c5be3a5b0de03006617c429e094bddd3e38d
4
- data.tar.gz: c298704a904a2867528bf4ff9827bf50fdbde288fcffd5d8076447d1817e400e
3
+ metadata.gz: 62925be13b2ff224585862444f2e77bdea9f7975316b2f66253e7e2fa7a6fe34
4
+ data.tar.gz: e2ec29030b6c442f955b3d4c54b21473a23f214d3db0944e2006c6ac3c7c9446
5
5
  SHA512:
6
- metadata.gz: '0782715755059bf87928160366f3bb6168f1b12fab37f9e66cee5cf46a22406d2a05d6fd19e7e17f3f0f0c8925a5cfcdead320f009ed4b58b7f7aff8829ef896'
7
- data.tar.gz: c0b8d099c542dcc5e64219594db5f2fa3f9f634835e0f6c2b18818b067d341bee8666045afc9f4c2da889ee86637949d7572f3bd03493395f47d1f5e2de1d023
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
@@ -63,7 +64,7 @@ module GoogleLocalResultsAiParser
63
64
 
64
65
  if final_results[label]
65
66
  # Combine the text for same elements
66
- final_results[label] = unsplit_text[/#{final_results[label]}[.|\n]+#{value}/]
67
+ final_results[label] = unsplit_text[/#{final_results[label]}(.+|\n)#{value}/]
67
68
  else
68
69
  # Directly assign values
69
70
  final_results[label] = value
@@ -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.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emirhan Akdeniz