<commit_before># frozen_string_literal: true
module WoeidHelper
  def self.convert_woeid_name(woeid)
    # search by woeid, return place
    #
    # param woeid: integer. example: 244444
    # return place: string. format: "City, State, Country"
    #

    locale = I18n.locale
    key = 'woeid_' + locale.to_s + '_' + woeid.to_s
    value = Rails.cache.fetch(key)
    return value if value

    GeoPlanet.appid = Rails.application.secrets['geoplanet_app_id']
    begin
      place_raw = GeoPlanet::Place.new(woeid.to_i, lang: locale)
      place = YahooLocation.new(place_raw)

      return nil unless place.town?

      value = { full: place.fullname , short: place.name }
      Rails.cache.write(key, value)
      return value
  rescue GeoPlanet::NotFound
    return nil
    end
  end

  def self.search_by_name(name)
    # search by name, return possible places
    #
    # param name: string. example: "Madrid"
    # return places: list.
    #        format: [[full name, woeid, ad_count], ...]
    #        example: [["Madrid, Madrid, Spain (2444 anuncios)",766273]]
    #<commit_msg>Fix Style/SpaceBeforeComma offenses<commit_after># frozen_string_literal: true
module WoeidHelper
  def self.convert_woeid_name(woeid)
    # search by woeid, return place
    #
    # param woeid: integer. example: 244444
    # return place: string. format: "City, State, Country"
    #

    locale = I18n.locale
    key = 'woeid_' + locale.to_s + '_' + woeid.to_s
    value = Rails.cache.fetch(key)
    return value if value

    GeoPlanet.appid = Rails.application.secrets['geoplanet_app_id']
    begin
      place_raw = GeoPlanet::Place.new(woeid.to_i, lang: locale)
      place = YahooLocation.new(place_raw)

      return nil unless place.town?

      value = { full: place.fullname, short: place.name }
      Rails.cache.write(key, value)
      return value
  rescue GeoPlanet::NotFound
    return nil
    end
  end

  def self.search_by_name(name)
    # search by name, return possible places
    #
    # param name: string. example: "Madrid"
    # return places: list.
    #        format: [[full name, woeid, ad_count], ...]
    #        example: [["Madrid, Madrid, Spain (2444 anuncios)",766273]]
    #
{'fraction_non_alphanumeric': 0.10949568378009995, 'fraction_numerical': 0.01635620172648796, 'mean_word_length': 2.842931937172775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2331330', 'n_tokens_mistral': 787, 'n_tokens_neox': 741, 'n_words': 184}