Skip to content

Commit

Permalink
Fix the confusion around mislabeled keys for address
Browse files Browse the repository at this point in the history
- Fix the confusion around mislabeled keys for address (caused by service options duplicate prevention mechanism)
- Bump up the version
  • Loading branch information
kagermanov27 committed Jun 21, 2023
1 parent a075216 commit c8cb0b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion google-local-results-ai-parser.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "google-local-results-ai-parser"
spec.version = "0.2.2"
spec.version = "0.2.3"
spec.summary = "A gem to be used with serpapi/bert-base-local-results model to predict different parts of Google Local Listings."
spec.description = "A gem to be used with serpapi/bert-base-local-results model to predict different parts of Google Local Listings. This gem uses BERT model at https://huggingface.co/serpapi/bert-base-local-results in the background. For serving private servers, head to https://github.com/serpapi/google-local-results-ai-server to get more information."
spec.homepage = "https://github.com/serpapi/google-local-results-ai-parser"
Expand Down
16 changes: 9 additions & 7 deletions lib/google-local-results-ai-parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'http'
require 'parallel'
require 'json'
require 'pry'

module GoogleLocalResultsAiParser
DEFAULT_SERVER = 'https://api-inference.huggingface.co/models/serpapi/bert-base-local-results'.freeze
Expand Down Expand Up @@ -465,16 +466,17 @@ def service_options_as_description_or_type_confusion(results, label_order, dupli
"Takeaway"
]
caught_results_indices = results.map.with_index {|result, index| index if known_errors.include?(result[:input])}.compact
return results, label_order, duplicates if caught_results_indices == []

not_service_option_duplicates = duplicates.select.with_index do |duplicate, duplicate_index|
caught_results_indices.each do |caught_index|
not_service_option_duplicates = []
caught_results_indices.each do |caught_index|
duplicates.each.with_index do |duplicate, duplicate_index|
if duplicate.include?(caught_index) && results[caught_index][:result][0][0]["label"] != "service_options"
duplicate_index
not_service_option_duplicates << duplicate_index
end
end
end

return results, label_order, duplicates if not_service_option_duplicates == []
# Zero out the `type` or `description`, and put it to last position
caught_results_indices.each do |caught_index|
service_options_hash = results[caught_index][:result][0].find {|hash| hash["label"] == "service options" }
Expand All @@ -491,12 +493,12 @@ def service_options_as_description_or_type_confusion(results, label_order, dupli

# Rearranging duplicates
not_service_option_duplicates.each do |not_service_option_duplicate|
last_item = duplicates[duplicates.index(not_service_option_duplicate)][-1]
duplicates[duplicates.index(not_service_option_duplicate)].delete(last_item)
last_item = duplicates[not_service_option_duplicate][-1]
duplicates[not_service_option_duplicate].delete(last_item)
end

not_service_option_duplicates.each do |not_service_option_duplicate|
if (duplicate_arr = duplicates[duplicates.index(not_service_option_duplicate)]) && duplicate_arr.size == 1
if (duplicate_arr = duplicates[not_service_option_duplicate]) && duplicate_arr.size == 1
duplicates.delete(duplicate_arr)
end
end
Expand Down

0 comments on commit c8cb0b0

Please sign in to comment.