Skip to content

Commit cae2d75

Browse files
committed
Fix an issue born from recent change to values
- Fix an issue born from recent change to values (some description are parsed as service options in SerpApi traditional results) - Bump up the version
1 parent 8370cb1 commit cae2d75

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

google-local-results-ai-parser.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = "google-local-results-ai-parser"
3-
spec.version = "0.1.4"
3+
spec.version = "0.1.5"
44
spec.summary = "A gem to be used with serpapi/bert-base-local-results model to predict different parts of Google Local Listings."
55
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."
66
spec.homepage = "https://github.com/serpapi/google-local-results-ai-parser"

lib/google-local-results-ai-parser.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def sort_results(results, extracted_text, unsplit_text, iteration, doc)
9898
results, label_order, duplicates = button_text_as_hours_confusion(results, label_order, duplicates)
9999
results, label_order, duplicates = button_text_as_address_confusion(results, label_order, duplicates)
100100
results, label_order, duplicates = button_text_as_service_options_confusion(results, label_order, duplicates)
101+
results, label_order, duplicates = service_options_as_description_or_type_confusion(results, label_order, duplicates)
101102

102103
# General clashes
103104
line_result = check_if_on_different_lines(results, duplicates, unsplit_text)
@@ -437,6 +438,49 @@ def description_as_hours_confusion(results, label_order, duplicates)
437438
return results, label_order, duplicates
438439
end
439440

441+
# On-site services, Online appointments
442+
# Fixes `On-site services`, `Online appointments`
443+
def service_options_as_description_or_type_confusion(results, label_order, duplicates)
444+
known_errors = ["On-site services", "On-site services not available", "Online appointments", "Online appointments not available"]
445+
caught_results_indices = results.map.with_index {|result, index| index if known_errors.include?(result[:input])}.compact
446+
return results, label_order, duplicates if caught_results_indices == []
447+
448+
not_service_option_duplicate = duplicates.find.with_index do |duplicate, duplicate_index|
449+
caught_results_indices.each do |caught_index|
450+
if results[caught_index][:result][0][0]["label"] != "service_options"
451+
duplicate_index
452+
end
453+
end
454+
end
455+
456+
# Zero out the `type` or `description`, and put it to last position
457+
caught_results_indices.each do |caught_index|
458+
service_options_hash = results[caught_index][:result][0].find {|hash| hash["label"] == "service options" }
459+
service_options_index = results[caught_index][:result][0].index(service_options_hash)
460+
old_result_hash = results[caught_index][:result][0][0]
461+
results[caught_index][:result][0][0] = {"label" => "service options", "score" => 1.0}
462+
results[caught_index][:result][0].delete_at(service_options_index)
463+
old_result_hash["score"] = 0.0
464+
results[caught_index][:result][0] << old_result_hash
465+
end
466+
467+
# Rearranging `label_order`
468+
caught_results_indices.each {|caught_index| label_order[caught_index] = "service_options"}
469+
470+
# Rearranging duplicates
471+
not_service_option_duplicate.each do |duplicate_index|
472+
duplicate_arr = duplicates.find{|duplicate| duplicate.include?(2)}
473+
last_item = duplicate_arr[-1]
474+
duplicates[duplicates.index(duplicate_arr)].delete(last_item)
475+
end
476+
477+
if (duplicate_arr = duplicates[duplicates.index(not_service_option_duplicate)]) && duplicate_arr.size == 1
478+
duplicates.delete(duplicate_arr)
479+
end
480+
481+
return results, label_order, duplicates
482+
end
483+
440484
# Takeaway ⋅ Dine-in ...
441485
# Fixes `Takeaway`
442486
def service_options_as_type_confusion(results, label_order, duplicates)

0 commit comments

Comments
 (0)