2
1

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.

【Coldfusion】Kuromoji で形態素解析を行う

Posted at

ColdFusionから、Javaの形態素解析器のKuromojiを使ってみる。
手順は下記を参考。
[Java製形態素解析器「Kuromoji」を試してみる]
(http://www.mwsoft.jp/programming/lucene/kuromoji.html)

下記よりダウンロードしたファイルを展開して任意の場所に保存する。
Download Packages
今回は"C:¥Kuromoji¥kuromoji-0.7.7.jar"に保存した前提とする。

jarファイルの読み込みはColdFusion10以降であれば、Application.cfc内に記載でOK
Java ライブラリの統合

Application.cfc

<cfscript>
this.javaSettings = {LoadPaths = ["C:/Kuromoji/kuromoji-0.7.7.jar"], reloadOnChange= true};
</cfscript>

以下のように呼び出す。

test.cfm

  <cfscript>
  Tokenizer = createObject("java", "org.atilika.kuromoji.Tokenizer");

  tokenizer = Tokenizer.builder().build();
  tokens = tokenizer.tokenize("すもももももももものうち");
  
  for (token in tokens) { 
   WriteOutput("---------------------------------<br>");
   WriteOutput("getSurfaceForm:" & token.getSurfaceForm() & "<br>");
   WriteOutput("getPartOfSpeech:" & token.getPartOfSpeech() & "<br>");
   WriteOutput("getBaseForm:" & token.getBaseForm() & "<br>");
   WriteOutput("getReading:" & token.getReading() & "<br>");
   WriteOutput("isKnown:" & token.isKnown() & "<br>");
   WriteOutput("isUser:" & token.isUser() & "<br>");
   WriteOutput("getAllFeatures:" & token.getAllFeatures() & "<br>");
   WriteOutput("getPosition:" & token.getPosition() & "<br>");
   WriteOutput("getAllFeaturesArray:" & arrayToList(token.getAllFeaturesArray()) & "<br>");
  }
  </cfscript>
  


その出力結果


---------------------------------
getSurfaceForm:すもも
getPartOfSpeech:名詞,一般,*,*
getBaseForm:すもも
getReading:スモモ
isKnown:YES
isUser:NO
getAllFeatures:名詞,一般,*,*,*,*,すもも,スモモ,スモモ
getPosition:0
getAllFeaturesArray:名詞,一般,*,*,*,*,すもも,スモモ,スモモ
---------------------------------
getSurfaceForm:も
getPartOfSpeech:助詞,係助詞,*,*
getBaseForm:も
getReading:モ
isKnown:YES
isUser:NO
getAllFeatures:助詞,係助詞,*,*,*,*,も,モ,モ
getPosition:3
getAllFeaturesArray:助詞,係助詞,*,*,*,*,も,モ,モ
---------------------------------
getSurfaceForm:もも
getPartOfSpeech:名詞,一般,*,*
getBaseForm:もも
getReading:モモ
isKnown:YES
isUser:NO
getAllFeatures:名詞,一般,*,*,*,*,もも,モモ,モモ
getPosition:4
getAllFeaturesArray:名詞,一般,*,*,*,*,もも,モモ,モモ
---------------------------------
getSurfaceForm:も
getPartOfSpeech:助詞,係助詞,*,*
getBaseForm:も
getReading:モ
isKnown:YES
isUser:NO
getAllFeatures:助詞,係助詞,*,*,*,*,も,モ,モ
getPosition:6
getAllFeaturesArray:助詞,係助詞,*,*,*,*,も,モ,モ
---------------------------------
getSurfaceForm:もも
getPartOfSpeech:名詞,一般,*,*
getBaseForm:もも
getReading:モモ
isKnown:YES
isUser:NO
getAllFeatures:名詞,一般,*,*,*,*,もも,モモ,モモ
getPosition:7
getAllFeaturesArray:名詞,一般,*,*,*,*,もも,モモ,モモ
---------------------------------
getSurfaceForm:の
getPartOfSpeech:助詞,連体化,*,*
getBaseForm:の
getReading:ノ
isKnown:YES
isUser:NO
getAllFeatures:助詞,連体化,*,*,*,*,の,ノ,ノ
getPosition:9
getAllFeaturesArray:助詞,連体化,*,*,*,*,の,ノ,ノ
---------------------------------
getSurfaceForm:うち
getPartOfSpeech:名詞,非自立,副詞可能,*
getBaseForm:うち
getReading:ウチ
isKnown:YES
isUser:NO
getAllFeatures:名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
getPosition:10
getAllFeaturesArray:名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?