Skip to content

Instantly share code, notes, and snippets.

@sh4869
Created June 17, 2014 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4869/950a254691d67071fb6f to your computer and use it in GitHub Desktop.
Save sh4869/950a254691d67071fb6f to your computer and use it in GitHub Desktop.
日本語解析ライブラリkuromojiのサンプルプログラム
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