【发布时间】:2016-11-15 07:00:17
【问题描述】:
【问题讨论】:
【问题讨论】:
到目前为止,您尝试了什么?我没有详细查看您链接到的示例,但我很确定您可以通过修改该示例获得想要的位置。 无论如何,这不是很困难:
InputStream modelIn = null;
POSModel POSModel = null;
try{
File f = new File("<location to your tagger model here>");
modelIn = new FileInputStream(f);
POSModel = new POSModel(modelIn);
POSTaggerME tagger = new POSTaggerME(POSModel);
SimpleTokenizer tokenizer= new SimpleTokenizer();
String tokens[] = tokenizer.tokenize("This is a sample sentence.");
String[] tagged = tagger.tag(tokens);
for (int i = 0; i < tagged.length; i++){
if (tagged[i].equalsIgnoreCase("nn")){
System.out.println(tokens[i]);
}
}
}
catch(IOException e){
throw new BadRequestException(e.getMessage());
}
你可以在这里下载标注器模型:http://opennlp.sourceforge.net/models-1.5/
我应该说 SimpleTokenizer 已被弃用。你可能想研究一个更复杂的,但根据我的经验,来自 OpenNLP 的更花哨的也慢很多(而且对于标记化来说通常慢得让人无法接受)。
【讨论】: