Last active
August 29, 2015 14:27
-
-
Save sccu/d4a7a3f19f7a248d5e93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object PoiMapping { | |
type Poi = Int | |
type Grade = Int | |
case class MatchResult(poi: Poi, grade: Grade) | |
private def searchMatchingCandidates(poi: Poi): Seq[Poi] = 1 to 300 by 3 | |
private def evaluateMatching(p: Poi, c: Poi): Grade = (p - c).abs | |
private def findBestMatch(p: Poi, candidates: Seq[Poi]): MatchResult = | |
candidates.map(c => MatchResult(c, evaluateMatching(p, c))).sortBy(_.grade).head | |
def manOf[T: Manifest](t: T): Manifest[T] = manifest[T] | |
def main(args: Array[String]) { | |
import org.json4s._ | |
import org.json4s.native.JsonMethods._ | |
import scala.sys.process._ | |
implicit val formats = DefaultFormats | |
val response = Seq("curl", "-s", "http://172.19.106.242/tmap_dev/1.0/search/all.json?q=하동관&sort=score&start=0&rows=10&area_name=&coord.focus.radius=&coord.focus.y=37.5663727512167&coord.focus.x=126.985023021698&coord.focus.type=wgs84").!! | |
val json = parse(response) | |
(json \ "response" \ "docs" \\ "name4" \ classOf[JString]).foreach(println) | |
val pois: Seq[Poi] = 1 to 200 by 2 | |
pois.par. | |
map(p => (p, searchMatchingCandidates(p))). | |
map { case(p, candidates) => (p, findBestMatch(p, candidates)) }. | |
foreach(println) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment