<commit_before>#
# Centralizes all the geocoding logic we need
class GeocodingService

  attr_accessor :raw_address, :results, :sensor, :bounds, :components, :errors

  INCLUDED_TYPES = %w{
    airport 
    establishment
    intersection 
    natural_feature 
    park 
    point_of_interest
    premise
    route 
    street_address 
  }
  
  def initialize(attrs = {})
    # reset the current state
    reset
    @sensor = false
    @components = Rails.application.config.geocoder_components
    @bounds = Rails.application.config.geocoder_bounds
    attrs.each do |k, v|
      self.send "#{k}=", v
    end
  end
    
  def has_errors
    return @errors.count > 1
  end 
  
  def reverse_geocode(lat, lon)
    Rails.logger.debug "GEOCODE #{[lat, lon]}"
    # reset the current state
    reset
    @raw_address = [lat, lon]
    begin
      res = Geocoder.search(@raw_address)
      process_results(res)
    rescue Exception => e
      Rails.logger.error format_exception(e)
      @errors << e.message
    end
    [@errors.empty?, @errors, @results]
  end

  def geocode(raw_address)
    Rails.logger.debug "GEOCODE #{raw_address}"
    # reset the current state
    reset
    @raw_address = raw_address
    if raw_address.blank?
      return @results
    end
    begin
      res = Geocoder.search(@raw_address, :sensor => @sensor, :components => @components, :bounds => @bounds)
      Rails.logger.debug res.ai
      process_results(res)
    rescue Exception => e
      Rails.logger.error format_exception(e)
      @errors << e.message
    end
    [@errors.empty?, @errors, @results]
  end
  
protected
  <commit_msg>Add geocoder region into geocoding service so non-us addresses can be geocoded<commit_after>#
# Centralizes all the geocoding logic we need
class GeocodingService

  attr_accessor :raw_address, :results, :sensor, :bounds, :region, :components, :errors

  INCLUDED_TYPES = %w{
    airport 
    establishment
    intersection 
    natural_feature 
    park 
    point_of_interest
    premise
    route 
    street_address 
  }
  
  def initialize(attrs = {})
    # reset the current state
    reset
    @sensor = false
    @components = Rails.application.config.geocoder_components
    @bounds = Rails.application.config.geocoder_bounds
    @region = Rails.application.config.geocoder_region
    attrs.each do |k, v|
      self.send "#{k}=", v
    end
  end
    
  def has_errors
    return @errors.count > 1
  end 
  
  def reverse_geocode(lat, lon)
    Rails.logger.debug "GEOCODE #{[lat, lon]}"
    # reset the current state
    reset
    @raw_address = [lat, lon]
    begin
      res = Geocoder.search(@raw_address)
      process_results(res)
    rescue Exception => e
      Rails.logger.error format_exception(e)
      @errors << e.message
    end
    [@errors.empty?, @errors, @results]
  end

  def geocode(raw_address)
    Rails.logger.debug "GEOCODE #{raw_address}"
    # reset the current state
    reset
    @raw_address = raw_address
    if raw_address.blank?
      return @results
    end
    begin
      res = Geocoder.search(@raw_address, :sensor => @sensor, :components => @components, :region => @region, :bounds => @bounds)
      Rails.logger.debug res.ai
      process_results(res)
    rescue Exception => e
      Rails.logger.error format_exception(e)
      @errors << e.message
    end
    [@errors.empty?, @errors, @results]
  end
  
protected
  
{'fraction_non_alphanumeric': 0.09665976943541235, 'fraction_numerical': 0.0005911912503694946, 'mean_word_length': 2.789473684210526, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, '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': '5087469', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1082, 'n_words': 274}