google-local-results-ai-parser 0.1.3 → 0.1.5

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: 7b078ffd7df8466aa1859da5120725c18b9425ddb331a16a54c913811af0d3b8
4
- data.tar.gz: 637c78ed81d02642834e083b1bbcbab1962a09afd218e490e02ffc9ae0232013
3
+ metadata.gz: f879eea0293f78de7556e0b7b2c899d7c1460ab75955b3e014c9ec8341c183bd
4
+ data.tar.gz: 5e4b4ba286d337ac577fa2750344d910ec297b981c0b57c53b25cf94be6fb10f
5
5
  SHA512:
6
- metadata.gz: 216e1a13a42b32294a5196f26bd34a05f05cf53cfbf4b50f05b2f7ba93f1f8349a1eff7becd6900f6d96e2c18af910af96be8c92b6a5e467262d672aff4e97d5
7
- data.tar.gz: 3dc359ac52dd5e3475bdb4817135f17cc98621a1a59d21078c13090d3e16d6bf10b37520c627fbc0e203f3c6fa51257bb3ae682e65e8b146b5eb8bc1ed187a13
6
+ metadata.gz: 3e6b363af552c4bf34da4ac387830720c98bfbc5c1a2331c2fe1fed8c373d3d0f66bb1bd303b8565d2fcaadeeabfca6969fb4f5a13f25c9efc24f2d44923a288
7
+ data.tar.gz: 801b68771772460632e704cca817d01a2662b8958415510cce48c57af2b37592493e9826d226b4f5bfd67ef5cb432ba8e7fa9b7bac63b84914791ef4a216f1c9
@@ -98,6 +98,7 @@ module GoogleLocalResultsAiParser
98
98
  results, label_order, duplicates = button_text_as_hours_confusion(results, label_order, duplicates)
99
99
  results, label_order, duplicates = button_text_as_address_confusion(results, label_order, duplicates)
100
100
  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)
101
102
 
102
103
  # General clashes
103
104
  line_result = check_if_on_different_lines(results, duplicates, unsplit_text)
@@ -355,16 +356,16 @@ module GoogleLocalResultsAiParser
355
356
  # Zero out the `price`, and put it to last position
356
357
  reviews_hash = results[price_duplicate[-1]][:result][0].find {|hash| hash["label"] == "reviews" }
357
358
  reviews_index = results[price_duplicate[-1]][:result][0].index(reviews_hash)
358
- results[price_duplicate[-1]][:result][0][0] = {"label" => "reviews", "score" => 1.0}
359
- results[price_duplicate[-1]][:result][0].delete_at(reviews_index)
360
- results[price_duplicate[-1]][:result][0] << {"label" => "price", "score" => 0.0}
359
+ results[price_duplicate[0]][:result][0][0] = {"label" => "reviews", "score" => 1.0}
360
+ results[price_duplicate[0]][:result][0].delete_at(reviews_index)
361
+ results[price_duplicate[0]][:result][0] << {"label" => "price", "score" => 0.0}
361
362
 
362
363
  # Rearranging `label_order`
363
- label_order[price_duplicate[-1]] = "reviews"
364
+ label_order[price_duplicate[0]] = "reviews"
364
365
 
365
366
  # Rearranging duplicates
366
- last_item = duplicates[duplicates.index(price_duplicate)][-1]
367
- duplicates[duplicates.index(price_duplicate)].delete(last_item)
367
+ first_item = duplicates[duplicates.index(price_duplicate)][0]
368
+ duplicates[duplicates.index(price_duplicate)].delete(first_item)
368
369
 
369
370
  if (duplicate_arr = duplicates[duplicates.index(price_duplicate)]) && duplicate_arr.size == 1
370
371
  duplicates.delete(duplicate_arr)
@@ -437,6 +438,49 @@ module GoogleLocalResultsAiParser
437
438
  return results, label_order, duplicates
438
439
  end
439
440
 
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
+
440
484
  # Takeaway ⋅ Dine-in ...
441
485
  # Fixes `Takeaway`
442
486
  def service_options_as_type_confusion(results, label_order, duplicates)
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.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emirhan Akdeniz