Skip to content

Instantly share code, notes, and snippets.

@letusfly85
Last active August 29, 2015 14:00
Show Gist options
  • Save letusfly85/68ebc5ab62f5146b9bb4 to your computer and use it in GitHub Desktop.
Save letusfly85/68ebc5ab62f5146b9bb4 to your computer and use it in GitHub Desktop.
name := "use-kuromoji"
version := "1.0"
scalaVersion := "2.10.2"
libraryDependencies ++= Seq(
"org.apache.lucene" % "lucene-core" % "3.6.0"
)
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
import org.apache.lucene.analysis.ja.JapaneseAnalyzer
import org.apache.lucene.util.Version
import org.apache.lucene.analysis.TokenStream
import java.io.StringReader
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute
/**
* http://hideaki-t.blogspot.jp/2012/03/kuromojilucene36java7.html
*
*/
object Main {
def main(args: Array[String]) {
try {
val analyzer: JapaneseAnalyzer = new JapaneseAnalyzer(Version.LUCENE_36)
val stream: TokenStream = analyzer.reusableTokenStream(
"txt", new StringReader("今日はこどもの日です。"))
while (stream.incrementToken()) {
val term: CharTermAttribute =
stream.getAttribute(classOf[CharTermAttribute])
println(term)
}
} catch {
case e: Exception =>
e.printStackTrace()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment