0
我試圖使用Stanford解析器解析一個句子,但我得到了異常。輸入文件,代碼和例外如下所述。Stanford Parser的非法論據異常
我認爲這個問題是因爲輸入文件中的penn樹不處理標點符號。如何生成處理標點符號的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)