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

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: e2209f3100b1ef6f8a75496347d890fc36e44648f4e7b30e9f9cf9d64b2d9c59
4
- data.tar.gz: ac399ed9e3d69a4099b299c1f9cc1748cc41d077158f2bb941473c1b4f34cc80
3
+ metadata.gz: a2d3d26973c143811af3354af94b83eaf429542cb41dc8e869ee51e933e6f2d7
4
+ data.tar.gz: e33c4fe018e422245516cd200f57d4a9e2077a9874b5ba01a3107ce8c2a533d7
5
5
  SHA512:
6
- metadata.gz: d33a665fe14482f365d6325d00edb75b5d74648153b80c328f24aac7bd885d922d0dc4488b0a54e612e85d3f6f93967c3b403e4c21efc8a0aac79a33483b3a8e
7
- data.tar.gz: fbd0162cac88ded47ce62d97e6ac5a70928529c699890d4dba9ed098d9523ee37a629512fc918aafa229df696651d56e70017e81e93c6253078658b79ba4ec94
6
+ metadata.gz: 9aeaebb296e9940cc2a07f50cff70955c6f4ea40093c21cbe44529e19d329406812fd12fbf25243b65fdc178c752dbe38ffe89c9574b8e5323cea8e4247d13c5
7
+ data.tar.gz: 8dd7b93a1683d5fbed86f97a17f6e655769ce2f7b81a2af798519b222a64e526a2b3a153ef1d0863c6c280f8f6388a54cb04f928a813c12c9ae91c1e59312024
@@ -94,7 +94,10 @@ module GoogleLocalResultsAiParser
94
94
  results, label_order, duplicates = description_as_hours_confusion(results, label_order, duplicates)
95
95
  results, label_order, duplicates = description_as_type_confusion(results, label_order, duplicates)
96
96
  results, label_order, duplicates = reviews_as_rating_confusion(results, label_order, duplicates)
97
+ results, label_order, duplicates = reviews_as_price_confusion(results, label_order, duplicates)
97
98
  results, label_order, duplicates = button_text_as_hours_confusion(results, label_order, duplicates)
99
+ results, label_order, duplicates = button_text_as_address_confusion(results, label_order, duplicates)
100
+ results, label_order, duplicates = button_text_as_service_options_confusion(results, label_order, duplicates)
98
101
 
99
102
  # General clashes
100
103
  line_result = check_if_on_different_lines(results, duplicates, unsplit_text)
@@ -240,6 +243,73 @@ module GoogleLocalResultsAiParser
240
243
  return results, label_order, duplicates
241
244
  end
242
245
 
246
+ # 104 Ave ... Share
247
+ # Fixes `Share`
248
+ def button_text_as_address_confusion(results, label_order, duplicates)
249
+ known_errors = ["Share"]
250
+ confusion_condition = results.any? {|result| known_errors.include?(result[:input])}
251
+ return results, label_order, duplicates unless confusion_condition
252
+
253
+ address_duplicate = duplicates.find.with_index do |duplicate, duplicate_index|
254
+ if results[duplicate[0]][:result][0][0]["label"] == "address"
255
+ duplicate_index
256
+ end
257
+ end
258
+
259
+ # Delete the known button text directly
260
+ results.delete_at(address_duplicate[-1])
261
+
262
+ # Rearranging `label_order`
263
+ label_order.delete_at(address_duplicate[-1])
264
+
265
+ # Rearranging duplicates
266
+ last_item = duplicates[duplicates.index(address_duplicate)][-1]
267
+ duplicates[duplicates.index(address_duplicate)].delete(last_item)
268
+
269
+ if (duplicate_arr = duplicates[duplicates.index(address_duplicate)]) && duplicate_arr.size == 1
270
+ duplicates.delete(duplicate_arr)
271
+ end
272
+
273
+ return results, label_order, duplicates
274
+ end
275
+
276
+ # Order pickup
277
+ # Fixes `Order pickup`
278
+ def button_text_as_service_options_confusion(results, label_order, duplicates)
279
+ known_errors = ["Order pickup"]
280
+ confusion_condition = results.any? {|result| known_errors.include?(result[:input])}
281
+ return results, label_order, duplicates unless confusion_condition
282
+
283
+ service_options_indexes = results.map {|result| results.index(result) if known_errors.include?(result[:input])}.compact
284
+
285
+ service_options_duplicate = duplicates.find.with_index do |duplicate, duplicate_index|
286
+ if results[duplicate[0]][:result][0][0]["label"] == "service options"
287
+ duplicate_index
288
+ end
289
+ end
290
+
291
+ # Delete the known button text directly
292
+ service_options_indexes.each {|index| results.delete_at(index)}
293
+
294
+ # Rearranging `label_order`
295
+ service_options_indexes.each {|index| label_order.delete_at(index)}
296
+
297
+ # Rearranging duplicates
298
+ service_options_indexes.each do |index|
299
+ duplicates.each_with_index do |duplicate, duplicate_index|
300
+ if duplicate.include?(index)
301
+ duplicates[duplicate_index].delete(index)
302
+ end
303
+ end
304
+ end
305
+
306
+ if service_options_duplicate && (duplicate_arr = duplicates[duplicates.index(service_options_duplicate)]) && duplicate_arr.size == 1
307
+ duplicates.delete(duplicate_arr)
308
+ end
309
+
310
+ return results, label_order, duplicates
311
+ end
312
+
243
313
  # 3.4 .. (1.4K)
244
314
  # Fixes `(1.4K)`
245
315
  def reviews_as_rating_confusion(results, label_order, duplicates)
@@ -272,6 +342,38 @@ module GoogleLocalResultsAiParser
272
342
  return results, label_order, duplicates
273
343
  end
274
344
 
345
+ # (1.6K) .. $
346
+ # Fixes `(1.6K)`
347
+ def reviews_as_price_confusion(results, label_order, duplicates)
348
+ price_duplicate = duplicates.find.with_index do |duplicate, duplicate_index|
349
+ if results[duplicate[0]][:result][0][0]["label"] == "price"
350
+ duplicate_index
351
+ end
352
+ end
353
+
354
+ if price_duplicate && results[price_duplicate[0]][:input][/\(\d+\.\d+\w\)/]
355
+ # Zero out the `price`, and put it to last position
356
+ reviews_hash = results[price_duplicate[-1]][:result][0].find {|hash| hash["label"] == "reviews" }
357
+ reviews_index = results[price_duplicate[-1]][:result][0].index(reviews_hash)
358
+ results[price_duplicate[0]][:result][0][0] = {"label" => "reviews", "score" => 1.0}
359
+ results[price_duplicate[0]][:result][0].delete_at(reviews_index)
360
+ results[price_duplicate[0]][:result][0] << {"label" => "price", "score" => 0.0}
361
+
362
+ # Rearranging `label_order`
363
+ label_order[price_duplicate[0]] = "reviews"
364
+
365
+ # Rearranging duplicates
366
+ first_item = duplicates[duplicates.index(price_duplicate)][0]
367
+ duplicates[duplicates.index(price_duplicate)].delete(first_item)
368
+
369
+ if (duplicate_arr = duplicates[duplicates.index(price_duplicate)]) && duplicate_arr.size == 1
370
+ duplicates.delete(duplicate_arr)
371
+ end
372
+ end
373
+
374
+ return results, label_order, duplicates
375
+ end
376
+
275
377
  # Coffee shop ... Iconic Seattle-based coffeehouse chain
276
378
  # Fixes `Iconic Seattle-based coffeehouse chain`
277
379
  def description_as_type_confusion(results, label_order, duplicates)
metadata CHANGED
@@ -1,14 +1,14 @@
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.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emirhan Akdeniz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-19 00:00:00.000000000 Z
11
+ date: 2023-06-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem to be used with serpapi/bert-base-local-results model to predict
14
14
  different parts of Google Local Listings. This gem uses BERT model at https://huggingface.co/serpapi/bert-base-local-results