我想使用 JAVA 制作一个词性标注器和词 block 划分器。但我无法弄清楚我应该从哪里开始。所有库都需要什么?
最佳答案
您可以使用各种库
我在我的项目中使用了 OpenNLP。我认为本说明将帮助您浏览 OpenNLP 库。关注此document
- 首先从这个page下载模型
- 然后将它们添加到您的项目中
- 您还需要
Tokenizer
模型将句子分解为标记。然后将这些 token 传递到 POS Tagger。
代码示例
<小时/>加载模型
InputStream modelIn = null;
try {
modelIn = new FileInputStream("en-pos-maxent.bin");
POSModel model = new POSModel(modelIn);
}
catch (IOException e) {
// Model loading failed, handle the error
e.printStackTrace();
}
finally {
if (modelIn != null) {
try {
modelIn.close();
}
catch (IOException e) {
}
}
}
<小时/>
实例化 POSTaggerME
POSTaggerME tagger = new POSTaggerME(model);
<小时/>
生成标签
String sent[] = new String[]{"Most", "large", "cities", "in", "the", "US", "had",
"morning", "and", "afternoon", "newspapers", "."};
//This is manual String tokens of a sentence. To Generate word token use [Tokenizer Model][6]
String tags[] = tagger.tag(sent);
链接
关于machine-learning - 词性标注器和词 block 划分器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28002136/