斯坦福解析器的非法参数异常

发布于 2024-09-25 01:43:09 字数 1810 浏览 7 评论 0原文

我尝试使用斯坦福解析器解析一个句子,但出现异常。下面指定了输入文件、代码和异常。

我认为问题是因为输入文件中的 Penn 树不处理标点符号。如何生成也能处理标点符号的潘恩树?

输入文件

(ROOT
  (S
    (NP (DT A) (NN doctor) (NN investigation) (NN system) (NN (DIS)))
    (VP (VBZ is)
      (NP
        (NP (DT a) (NN part))
        (PP (IN of)
          (NP (DT a) (NN hospital) (NN information) (NN system) (NN (HIS).)))))))

代码

            String str="-collapsed -treeFile temp.txt";
            String ar[]=str.split(" ");
            edu.stanford.nlp.trees.EnglishGrammaticalStructure.main(ar);

             try {
                FileOutputStream fw = new FileOutputStream("k.txt");
                PrintStream out = new PrintStream(fw);
                System.setOut(out);



            } catch (Exception e) {
                System.out.print(e);
            }

引发异常:

Head is null: NN-37
Exception in thread "main" java.lang.IllegalArgumentException: governor or dependent cannot be null
        at edu.stanford.nlp.trees.UnnamedDependency.<init>(UnnamedDependency.java:105)
        at edu.stanford.nlp.trees.TreeGraphNode.dependencies(TreeGraphNode.java:519)
        at edu.stanford.nlp.trees.Tree.dependencies(Tree.java:1090)
        at edu.stanford.nlp.trees.GrammaticalStructure.<init>(GrammaticalStructure.java:71)
        at edu.stanford.nlp.trees.EnglishGrammaticalStructure.<init>(EnglishGrammaticalStructure.java:115)
        at edu.stanford.nlp.trees.EnglishGrammaticalStructure.<init>(EnglishGrammaticalStructure.java:89)
        at edu.stanford.nlp.trees.EnglishGrammaticalStructure.<init>(EnglishGrammaticalStructure.java:61)
        at edu.stanford.nlp.trees.EnglishGrammaticalStructure.<init>(EnglishGrammaticalStructure.java:53)

I tried to parse a sentence using Stanford parser, but I get the exception. The input file, code and exception are specified below.

I think the problem is because the penn tree in input file doesn't handle punctuation. How do I generate a penn tree that handles punctuation too?

Input file

(ROOT
  (S
    (NP (DT A) (NN doctor) (NN investigation) (NN system) (NN (DIS)))
    (VP (VBZ is)
      (NP
        (NP (DT a) (NN part))
        (PP (IN of)
          (NP (DT a) (NN hospital) (NN information) (NN system) (NN (HIS).)))))))

code

            String str="-collapsed -treeFile temp.txt";
            String ar[]=str.split(" ");
            edu.stanford.nlp.trees.EnglishGrammaticalStructure.main(ar);

             try {
                FileOutputStream fw = new FileOutputStream("k.txt");
                PrintStream out = new PrintStream(fw);
                System.setOut(out);



            } catch (Exception e) {
                System.out.print(e);
            }

Exception raised :

Head is null: NN-37
Exception in thread "main" java.lang.IllegalArgumentException: governor or dependent cannot be null
        at edu.stanford.nlp.trees.UnnamedDependency.<init>(UnnamedDependency.java:105)
        at edu.stanford.nlp.trees.TreeGraphNode.dependencies(TreeGraphNode.java:519)
        at edu.stanford.nlp.trees.Tree.dependencies(Tree.java:1090)
        at edu.stanford.nlp.trees.GrammaticalStructure.<init>(GrammaticalStructure.java:71)
        at edu.stanford.nlp.trees.EnglishGrammaticalStructure.<init>(EnglishGrammaticalStructure.java:115)
        at edu.stanford.nlp.trees.EnglishGrammaticalStructure.<init>(EnglishGrammaticalStructure.java:89)
        at edu.stanford.nlp.trees.EnglishGrammaticalStructure.<init>(EnglishGrammaticalStructure.java:61)
        at edu.stanford.nlp.trees.EnglishGrammaticalStructure.<init>(EnglishGrammaticalStructure.java:53)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月打碎记忆 2024-10-02 01:43:09

无用的错误消息,但这是因为输入树的格式不正确:最后有一个杂散期。该树应该是格式良好的 s 表达式。

Unhelpful error message, but this is because the input tree is ill-formed: there is that stray period towards the end. The tree should be a well-formed s-expression.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文