レコメンドIndexをScalaで
| Revision | 46a89d3a50bdf8df3c0cbedb3cf060955cae072c (tree) |
|---|---|
| Time | 2011-02-24 17:07:59 |
| Author | tachiki <tachiki@p-wi...> |
| Commiter | tachiki |
簡単なparserを実装
| @@ -5,7 +5,7 @@ import scala.actors.Actor | ||
| 5 | 5 | import com.parrotstudio.recommend.ro.model._ |
| 6 | 6 | |
| 7 | 7 | class RecommendWorker(val index: Int) extends Actor with RecommendMessage { |
| 8 | - val parser = """.*<div id="more">(.*?)</div>.*""".r | |
| 8 | + val parser = """.*<title>Angel, alone.*孤独な天使.*-(.*)-</title>.*<div id="more">(.*?)</div>.*""".r | |
| 9 | 9 | |
| 10 | 10 | def act { |
| 11 | 11 | loop { |
| @@ -28,17 +28,22 @@ class RecommendWorker(val index: Int) extends Actor with RecommendMessage { | ||
| 28 | 28 | |
| 29 | 29 | def parse(p: Page): Article = { |
| 30 | 30 | p.page match { |
| 31 | - case parser(art) => Article("本文", art) | |
| 32 | - case _ => Article("", "") | |
| 31 | + case parser(title, ext) => Article(normalize(title), "本文", normalize(ext)) | |
| 32 | + case _ => new Article() | |
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | def analysis(a: Article): Terms = { |
| 37 | 37 | |
| 38 | - new Terms() | |
| 38 | + Terms() | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | def createVector(t: Terms) = { |
| 42 | 42 | |
| 43 | 43 | } |
| 44 | + | |
| 45 | + private def normalize(text: String): String = { | |
| 46 | + text.trim.replaceAll("<br.*?/?>", "\n").replaceAll("<a.+href=.*?>", "").replaceAll("</a>", "") | |
| 47 | + } | |
| 48 | + | |
| 44 | 49 | } |
| \ No newline at end of file |
| @@ -1,5 +1,9 @@ | ||
| 1 | 1 | package com.parrotstudio.recommend.ro.model |
| 2 | 2 | |
| 3 | -case class Article(val body: String, val extend: String) { | |
| 3 | +case class Article(val title: String, val body: String, val extend: String) { | |
| 4 | + | |
| 5 | + def this(title: String, body: String) = this(title, body, "") | |
| 6 | + def this(title: String) = this(title, "") | |
| 7 | + def this() = this("") | |
| 4 | 8 | |
| 5 | 9 | } |