<commit_before>package org.talkingpuffin.geo

import com.google.common.collect.MapMaker
import java.net.URL
import _root_.scala.xml.XML
import ui.util.{ResourceReady, BackgroundResourceFetcher}

/**
 * Geocoding.
 */
object GeoCoder {
  private val locationCache: java.util.Map[String, String] = new MapMaker().softValues().makeMap()
  private val num = """(-?\d+\.\d*)"""
  private val latLongRegex = ("""\D*""" + num + """,\s*""" + num).r

  def extractLatLong(location: String): Option[String] = {
    try {
      val latLongRegex(lat, long) = location
      Some(lat + "," + long)
    } catch {
      case e: MatchError => None
    }
  }
  
}

class GeoCoder(processResults: (ResourceReady[String,String]) => Unit) 
    extends BackgroundResourceFetcher[String, String](processResults) {

  protected def getResourceFromSource(latLong: String): String = {
    val url = new URL("http://maps.google.com/maps/geo?ll=" + latLong + "&output=xml&oe=utf-8")
    val placemarks = XML.load(url.openConnection.getInputStream) \ "Response" \ "Placemark"
    placemarks.length match {
      case 0 => latLong
      case _ => (placemarks(0) \ "address").text
    }
  }
  
}<commit_msg>Support negative numbers in lat/longs<commit_after>package org.talkingpuffin.geo

import com.google.common.collect.MapMaker
import java.net.URL
import _root_.scala.xml.XML
import ui.util.{ResourceReady, BackgroundResourceFetcher}

/**
 * Geocoding.
 */
object GeoCoder {
  private val locationCache: java.util.Map[String, String] = new MapMaker().softValues().makeMap()
  private val num = """(-?\d+\.\d*)"""
  private val latLongRegex = ("""[^-\d]*""" + num + """,\s*""" + num).r

  def extractLatLong(location: String): Option[String] = {
    try {
      val latLongRegex(lat, long) = location
      Some(lat + "," + long)
    } catch {
      case e: MatchError => None
    }
  }
  
}

class GeoCoder(processResults: (ResourceReady[String,String]) => Unit) 
    extends BackgroundResourceFetcher[String, String](processResults) {

  protected def getResourceFromSource(latLong: String): String = {
    val url = new URL("http://maps.google.com/maps/geo?ll=" + latLong + "&output=xml&oe=utf-8")
    val placemarks = XML.load(url.openConnection.getInputStream) \ "Response" \ "Placemark"
    placemarks.length match {
      case 0 => latLong
      case _ => (placemarks(0) \ "address").text
    }
  }
  
}
{'fraction_non_alphanumeric': 0.1574307304785894, 'fraction_numerical': 0.0025188916876574307, 'mean_word_length': 3.663405088062622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2401666', 'n_tokens_mistral': 794, 'n_tokens_neox': 785, 'n_words': 162}