java - 构建词性标注器(词性标注器)

标签 java nlp pos-tagger

我需要用 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/

相关文章:

java - JVM 预热查询

Python:用短语标记

python - 在 python 中创建代码以从列表中获取最常见的标签和值对

python - 从数据框中获取文本的最佳方法,先按句子标记,然后按单词标记

nlp - 从 Penn Treebank 格式的文本中提取子句

python - 在 python 中使用 stanford 标记器时出错

java - 斯坦福 POS 标记器 : How to preserve newlines in the output?

java - android ViewFlipper - 具有异步图像加载的图像幻灯片

java - Eclipse 从 String 创建 CompilationUnit 句柄

java - 在测试中使用@SpringApplicationConfiguration会抛出异常?