Created
June 17, 2014 13:20
-
-
Save sh4869/950a254691d67071fb6f to your computer and use it in GitHub Desktop.
日本語解析ライブラリkuromojiのサンプルプログラム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kuromoji_test; | |
import java.util.*; | |
import java.util.Random; | |
import org.atilika.kuromoji.Token; | |
import org.atilika.kuromoji.Tokenizer; | |
public class kuromoji_test { | |
public static void main(String[] args) { | |
Tokenizer tokenizer = Tokenizer.builder().build(); | |
String word; | |
ArrayList<String> list = new ArrayList<String>(); | |
Random rnd =new Random(); | |
for (Token token : tokenizer.tokenize("焼肉と時間とパソコンと寿司が欲しいナ。")){ | |
if(token.getPartOfSpeech().indexOf("名詞") != -1){ | |
word = token.getSurfaceForm(); | |
list.add(word); | |
} | |
} | |
list.remove(null); | |
int num = list.size(); | |
int index = rnd.nextInt(num); | |
System.out.println(list.get(index)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment