• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

レコメンドIndexをScalaで


Commit MetaInfo

Revision46a89d3a50bdf8df3c0cbedb3cf060955cae072c (tree)
Time2011-02-24 17:07:59
Authortachiki <tachiki@p-wi...>
Commitertachiki

Log Message

簡単なparserを実装

Change Summary

Incremental Difference

--- a/src/com/parrotstudio/recommend/ro/RecommendWorker.scala
+++ b/src/com/parrotstudio/recommend/ro/RecommendWorker.scala
@@ -5,7 +5,7 @@ import scala.actors.Actor
55 import com.parrotstudio.recommend.ro.model._
66
77 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
99
1010 def act {
1111 loop {
@@ -28,17 +28,22 @@ class RecommendWorker(val index: Int) extends Actor with RecommendMessage {
2828
2929 def parse(p: Page): Article = {
3030 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()
3333 }
3434 }
3535
3636 def analysis(a: Article): Terms = {
3737
38- new Terms()
38+ Terms()
3939 }
4040
4141 def createVector(t: Terms) = {
4242
4343 }
44+
45+ private def normalize(text: String): String = {
46+ text.trim.replaceAll("<br.*?/?>", "\n").replaceAll("<a.+href=.*?>", "").replaceAll("</a>", "")
47+ }
48+
4449 }
\ No newline at end of file
--- a/src/com/parrotstudio/recommend/ro/model/Article.scala
+++ b/src/com/parrotstudio/recommend/ro/model/Article.scala
@@ -1,5 +1,9 @@
11 package com.parrotstudio.recommend.ro.model
22
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("")
48
59 }