我需要用 Java 构建一个 POS 标记器,并且需要知道如何开始。是否有代码示例或其他资源可以帮助说明 POS 标记器的工作原理?
最佳答案
试试 Apache OpenNLP .它包括一个 POS 标记工具。您可以从 here 下载现成的英文模型。 .
该文档提供了有关如何从 Java 应用程序使用它的详细信息。基本上你需要以下内容:
加载POS模型
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) {
}
}
}
实例化 POS 标记器
POSTaggerME tagger = new POSTaggerME(model);
执行它
String sent[] = new String[]{"Most", "large", "cities", "in", "the", "US", "had", "morning", "and", "afternoon", "newspapers", "."};
String tags[] = tagger.tag(sent);
请注意,POS 标注器需要一个标记化的句子。 Apache OpenNLP 还提供工具和模型来帮助完成这些任务。
如果您必须训练自己的模型,请参阅此 documentation .
关于java - 构建词性标注器(词性标注器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7088871/