1
私はPOS(音声の部品)にタグを付けるためにopenNLPを使用しています。JavaのPostaggerを使用して、異なるPOS(品詞)を別のファイルに保存しますか?
InputStream inputStream = new
FileInputStream("C:/en-pos-maxent.bin");
POSModel model = new POSModel(inputStream);
POSTaggerME tagger = new POSTaggerME(model);
String sentence = "This is not a song for the broken-hearted" +
" No silent prayer for the faith-departed " +
" I am not gonna be just a face in the crowd " +
" You are gonna hear my voice " +
" When I shout it out loud";
String simple = "[.?!-]";
String[] splitString = (sentence.split(simple));
SimpleTokenizer simpleTokenizer = SimpleTokenizer.INSTANCE;
//String tokens[] = simpleTokenizer.tokenize();
for(int i = 0;i<splitString.length;i++)
{
String tokens[] = simpleTokenizer.tokenize(splitString[i]);
String[] tags = tagger.tag(tokens);
//POSSample sample = new POSSample(tokens, tags);
/*for(String token : tokens) {
System.out.println(token);
}*/
for(int j= 0;j < tags.length;j++)
{
if(tags[j].equals("DT"))
{
//System.out.println(tokens[j]);
File file = new File("DT.txt");
try {
PrintWriter output = new PrintWriter(file);
output.println(tokens[j]);
output.close();
} catch (Exception e) {
// TODO: handle exception
}
私はloop.Itでのprintlnを使用し、私は、ファイル名DT.txtでこれを保存しようと思ってたときに私に必要なvalue.Butを示しました。テキストファイルに1つの値を保存するだけです。 Text file output Printed Output in console