使用斯坦福 CoreNLP 解决共指问题 - 无法加载解析器模型

2023-12-26

我想做一项非常简单的工作:给定一个包含代词的字符串,我想解析它们。

例如,我想把这句话“Mary has a Littlelamb. She is Cute.”在《玛丽有一只小羊羔,玛丽很可爱》中。

我尝试过使用斯坦福 CoreNLP。但是,我似乎无法启动解析器。我已经使用 Eclipse 导入了项目中包含的所有 jar,并且为 JVM 分配了 3GB (-Xmx3g)。

错误非常尴尬:

线程“main”中的异常java.lang.NoSuchMethodError: edu.stanford.nlp.parser.lexparser.LexicalizedParser.loadModel(Ljava/lang/String;[Ljava/lang/String;)Ledu/stanford/nlp/parser/lexparser/LexicalizedParser;

我不明白那个 L 来自哪里,我认为这是我问题的根源......这很奇怪。我试图进入源文件,但那里没有错误的引用。

Code:

import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation;
import edu.stanford.nlp.dcoref.CorefCoreAnnotations.CorefChainAnnotation;
import edu.stanford.nlp.dcoref.CorefCoreAnnotations.CorefGraphAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.NamedEntityTagAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;
import edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.dcoref.CorefChain;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.util.CoreMap;
import edu.stanford.nlp.util.IntTuple;
import edu.stanford.nlp.util.Pair;
import edu.stanford.nlp.util.Timing;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import java.util.Properties;

public class Coref {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException, ClassNotFoundException {
    // creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution 
    Properties props = new Properties();
    props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

    // read some text in the text variable
    String text = "Mary has a little lamb. She is very cute."; // Add your text here!

    // create an empty Annotation just with the given text
    Annotation document = new Annotation(text);

    // run all Annotators on this text
    pipeline.annotate(document);

    // these are all the sentences in this document
    // a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
    List<CoreMap> sentences = document.get(SentencesAnnotation.class);

    for(CoreMap sentence: sentences) {
      // traversing the words in the current sentence
      // a CoreLabel is a CoreMap with additional token-specific methods
      for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
        // this is the text of the token
        String word = token.get(TextAnnotation.class);
        // this is the POS tag of the token
        String pos = token.get(PartOfSpeechAnnotation.class);
        // this is the NER label of the token
        String ne = token.get(NamedEntityTagAnnotation.class);       
      }

      // this is the parse tree of the current sentence
      Tree tree = sentence.get(TreeAnnotation.class);
      System.out.println(tree);

      // this is the Stanford dependency graph of the current sentence
      SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
    }

    // This is the coreference link graph
    // Each chain stores a set of mentions that link to each other,
    // along with a method for getting the most representative mention
    // Both sentence and token offsets start at 1!
    Map<Integer, CorefChain> graph = 
      document.get(CorefChainAnnotation.class);
    System.out.println(graph);
  }
}

完整的堆栈跟踪:

添加注释器 tokenize 添加注释器 ssplit 添加注释器 pos 正在加载 POS 模型 [edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger] ...从经过训练的标记器 edu/stanford/nlp/models/pos-tagger/english 加载默认属性-left3words/english-left3words-distsim.tagger 从 edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger 读取 POS 标注器模型...完成 [2.1 秒]。 完成 [2.2 秒]。 添加注释器引理 添加注释器 从 edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz 加载分类器...完成 [4.0 秒]。 从 edu/stanford/nlp/models/ner/english.muc.distsim.crf.ser.gz 加载分类器...完成 [3.0 秒]。 从 edu/stanford/nlp/models/ner/english.conll.distsim.crf.ser.gz 加载分类器...完成 [3.3 秒]。 添加注释器解析 线程“main”中的异常 java.lang.NoSuchMethodError: edu.stanford.nlp.parser.lexparser.LexicalizedParser.loadModel(Ljava/lang/String;[Ljava/lang/String;)Ledu/stanford/nlp/parser/lexparser/词法化解析器; 在 edu.stanford.nlp.pipeline.ParserAnnotator.loadModel(ParserAnnotator.java:115) 在 edu.stanford.nlp.pipeline.ParserAnnotator。(ParserAnnotator.java:64) 在 edu.stanford.nlp.pipeline.StanfordCoreNLP$12.create(StanfordCoreNLP.java:603) 在 edu.stanford.nlp.pipeline.StanfordCoreNLP$12.create(StanfordCoreNLP.java:585) 在 edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:62) 在 edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:329) 在 edu.stanford.nlp.pipeline.StanfordCoreNLP。(StanfordCoreNLP.java:196) 在 edu.stanford.nlp.pipeline.StanfordCoreNLP。(StanfordCoreNLP.java:186) 在 edu.stanford.nlp.pipeline.StanfordCoreNLP。(StanfordCoreNLP.java:178) 在 Coref.main(Coref.java:41)


是的,自 Java 1.0 以来,L 就是 Sun 的一个奇怪的东西。

LexicalizedParser.loadModel(String, String ...)是添加到解析器的新方法,但未找到。我怀疑这意味着您的类路径中有另一个版本的解析器正在被使用。

试试这个:在任何 IDE 外部的 shell 上,给出这些命令(适当给出 stanford-corenlp 的路径,并将 : 更改为 ; 如果在 Windows 上:

javac -cp ".:stanford-corenlp-2012-04-09/*" Coref.java
java -mx3g -cp ".:stanford-corenlp-2012-04-09/*" Coref

解析器加载并且您的代码对我来说正确运行 - 只需添加一些打印语句,以便您可以看到它做了什么:-)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用斯坦福 CoreNLP 解决共指问题 - 无法加载解析器模型 的相关文章

随机推荐

  • 线程相对于 Runnable 的优势[重复]

    这个问题在这里已经有答案了 可能的重复 Java 实现 Runnable 与 扩展线程 https stackoverflow com questions 541487 java implements runnable vs extends
  • 在 PostgreSQL 查询中按降序聚合字符串

    除了问题之外如何在 PostgreSQL group by 查询中连接字符串字段的字符串 https stackoverflow com questions 43870 how to concatenate strings of a str
  • Python - 将非常大 (6.4GB) XML 文件转换为 JSON

    本质上 我有一个 6 4GB XML 文件 我想将其转换为 JSON 然后将其保存到磁盘 我目前正在运行 OSX 10 8 4 配备 i7 2700k 和 16GB 内存 并运行 Python 64 位 双重检查 我收到一个错误 提示我没有
  • 如何使用 beforeUpdate Hook Sequelize 中止更新操作

    我如何使用sequelize上的beforeUpdate钩子中止更新操作并返回一个对象作为中止更新的结果 如果我有类似的东西 User beforeUpdate function user options if user name exam
  • TWTRTwitter sessionStore 现在返回 TWTRAuthSession:那么现在如何访问 userName 属性呢?

    使用 Swift 中的 TwitterKit 3 3 0sharedInstance sessionStore session 现在返回一个TWTRAuthSession而不是一个TWTRSession 像之前一样 事情发生了变化 但这很好
  • PerformBlockAndWait 造成死锁

    我正在编写一个执行一些 CoreData 操作的函数 我希望该函数仅返回after所有 CoreData 操作均已执行 CoreData 的内容涉及在后台上下文中创建一个对象 然后在父上下文中执行更多操作 void myFunction N
  • 声明和未声明变量的影响

    JavaScript 声明变量和未声明变量之间的主要区别是什么 删除运算符对声明的变量不起作用 var y 43 declares a new variable x 42 delete x returns true x is a prope
  • 我是否正确消毒/逃生?

    我用 PHP 编写了一个简单的搜索脚本 用于搜索 mySQL 数据库并输出结果 它的工作原理是这样的 用户通过搜索表单搜索 jack s 我的 PHP 脚本GET就是这个搜索 并对其进行清理 然后是脚本 使用SELECT and LIKE
  • 检查 C++ 中多个值的相等性

    我正在 C 中寻找一种简单 快速且描述性的方法来检查某个值是否包含在一组固定的其他值中 就像在 Python 中一样 人们可以在其中编写 if some function in 2 3 5 7 11 do something 一些明显的选择
  • Java 自动装箱和三元运算符的疯狂

    刚刚花了几个小时调试这段代码 令人沮丧 LinkedHashMap
  • 使用 monad 读取 INI 文件

    我正在尝试使用 monads 使用 haskell 读取 INI 文件 这是我的代码 import Control Monad import Data Ini main do config lt readIniFile configs co
  • 是否可以在拉取请求(Github)中更改其他人的代码?

    在 Github 项目上 我看到有人在Pull Requests部分 但我发现他犯了很多错误 因此他的代码需要更正 与其要求他改他的代码 是不是可以自己动手 就是我想自己改他的代码 如何 我也是该项目的成员 而且我是新人 对现有拉取请求启用
  • Fabric 网络 - 当宕机的对等点连接回网络时会发生什么?

    我最近使用 Docker compose 部署了结构网络 我试图模拟一个宕机的对等点 本质上是这样的 使用运行结构网络的 docker compose 将 4 个对等点联机 1 个对等点 即第 4 个对等点出现故障 通过 docker st
  • Liferay 搜索容器分页

    我在代码中使用了 liferay ui search container 搜索结果会正确显示 直到我单击 下一步 该 portlet 正在重新加载 这会将我带到该 portlet 的第一页 从而破坏了所显示的搜索结果 即使在 portlet
  • Laravel 5.8 - 如何将文件从存储目录移动到公共目录?

    我想将我的一个文件从storageLaravel 中的文件目录publiclaravel 中的文件目录 无需更改我的文件系统配置 这可能吗 是的 你可以这样做存储 移动 https laravel com docs 5 8 filesyst
  • 网格中两点之间的最短路径。有一个捕获

    我遇到这个问题 我必须通过向右或向下移动来找到 NxM 网格中从 A 点 总是左上角 到 B 点 总是右下角 的最短路径 听起来很容易 是吗 问题是 我只能移动我现在坐在的图块上显示的数字 让我举例说明 2 5 1 2 9 2 5 3 3
  • 防止 jquery mobile 设置元素样式

    我想在页面上隐藏一个复选框 我明显的第一次尝试如下
  • 来自 EventEmitter 的热共享 Observable

    有没有办法从一个EventEmitter 或 Angular 2 alpha 46 RxJS 5 alpha 中可用的等效项 IE 如果我们在值解析后订阅 它将使用之前解析的值触发 类似于我们总是返回相同的承诺 理想情况下 仅使用 Angu
  • 在 PHP 中实现切削库存算法

    我需要实施下料问题 http en wikipedia org wiki Cutting stock problem与 php 脚本 由于我的数学能力不是很好 所以我只是想用暴力来解决 从这些参数开始 inventory 是可剪切的长度数组
  • 使用斯坦福 CoreNLP 解决共指问题 - 无法加载解析器模型

    我想做一项非常简单的工作 给定一个包含代词的字符串 我想解析它们 例如 我想把这句话 Mary has a Littlelamb She is Cute 在 玛丽有一只小羊羔 玛丽很可爱 中 我尝试过使用斯坦福 CoreNLP 但是 我似乎