7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

kuromojiでユーザー辞書を使用する

Last updated at Posted at 2014-05-13

環境

Windows7

sbt

sample.sbt
resolvers += "ATILIKA dependencies" at "http://www.atilika.org/nexus/content/repositories/atilika" 

libraryDependencies ++= Seq(
  "org.atilika.kuromoji" % "kuromoji" % "0.7.7" ,
  "com.typesafe" % "config" % "1.2.1"
)

コード

コードは以下の通り

sample.scala
object ExTokenizer {
  def tokenize(text: String): Iterator[Token] = {
    Tokenizer.builder()
      .userDictionary(".\\src\\main\\resources\\userdict.txt")
      .build().tokenize(text).iterator().toIterator
  }
}
Main.scala
object Main {
  def main(args: Array[String]): Unit = {
    ExTokenizer.tokenize("銀聯売上").foreach{token =>
      println(token.getSurfaceForm)
    }
  }
}
userdict.txt
# カスタム辞書
銀聯,銀聯,ギンレン,カスタム名詞

注意点

userdict.txt ですが、 utf-8 では上手く動きませんでした。
試しに windows-31J にしたら想定通りの動きをしてくれました。
(気づくまでに時間がかかりました。。。)

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?