google-local-results-ai-parser 0.1.4 → 0.1.6

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: a2d3d26973c143811af3354af94b83eaf429542cb41dc8e869ee51e933e6f2d7
4
- data.tar.gz: e33c4fe018e422245516cd200f57d4a9e2077a9874b5ba01a3107ce8c2a533d7
3
+ metadata.gz: b1d9420283a21ee83c026e452292a42ded13528261d395e8cadc4d8aa2cc1e6f
4
+ data.tar.gz: b1a7ed2399121ab91dfb219af73b245ebc0a0a0ca6e6e3b75de27541c4224572
5
5
  SHA512:
6
- metadata.gz: 9aeaebb296e9940cc2a07f50cff70955c6f4ea40093c21cbe44529e19d329406812fd12fbf25243b65fdc178c752dbe38ffe89c9574b8e5323cea8e4247d13c5
7
- data.tar.gz: 8dd7b93a1683d5fbed86f97a17f6e655769ce2f7b81a2af798519b222a64e526a2b3a153ef1d0863c6c280f8f6388a54cb04f928a813c12c9ae91c1e59312024
6
+ metadata.gz: 1b7dbed7555e7a80c9191b404766a2b5ed758b49a0cb3f867eab3f608b611155c3f6203c483428e2d616adf76b634446393d248fe2b78970ae1d3196751f9f55
7
+ data.tar.gz: 9f5528a15881f0798de4d62084ec263debed89d6a42b8b95481e371daba9fc82171af5c2c4bfa15aa0abacaec953d25b1db1251e4bcc2386df6992f5da1a3309
@@ -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)
@@ -437,6 +438,50 @@ 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_duplicates = duplicates.select.with_index do |duplicate, duplicate_index|
449
+ caught_results_indices.each do |caught_index|
450
+ if duplicate.include?(caught_index) && 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_duplicates.each do |not_service_option_duplicate|
472
+ last_item = duplicates[duplicates.index(not_service_option_duplicate)][-1]
473
+ duplicates[duplicates.index(not_service_option_duplicate)].delete(last_item)
474
+ end
475
+
476
+ not_service_option_duplicates.each do |not_service_option_duplicate|
477
+ if (duplicate_arr = duplicates[duplicates.index(not_service_option_duplicate)]) && duplicate_arr.size == 1
478
+ duplicates.delete(duplicate_arr)
479
+ end
480
+ end
481
+
482
+ return results, label_order, duplicates
483
+ end
484
+
440
485
  # Takeaway ⋅ Dine-in ...
441
486
  # Fixes `Takeaway`
442
487
  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.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emirhan Akdeniz