google-local-results-ai-parser 0.2.2 → 0.2.3
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 +4 -4
- data/lib/google-local-results-ai-parser.rb +9 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62925be13b2ff224585862444f2e77bdea9f7975316b2f66253e7e2fa7a6fe34
|
4
|
+
data.tar.gz: e2ec29030b6c442f955b3d4c54b21473a23f214d3db0944e2006c6ac3c7c9446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
471
|
-
|
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[
|
495
|
-
duplicates[
|
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[
|
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
|