0
我想看到的依賴性輸出格式在斯坦福解析器NLP。我從這個鏈接下載了jar文件。 http://nlp.stanford.edu/software/lex-parser.shtml斯坦福分析器(類型Dependencee)異常
然後我在Eclipse中導入它並編寫下面的代碼。
package hammad.NLP;
import java.io.StringReader;
import java.util.Collection;
import java.util.List;
import com.chaoticity.dependensee.Main;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.process.CoreLabelTokenFactory;
import edu.stanford.nlp.process.PTBTokenizer;
import edu.stanford.nlp.process.TokenizerFactory;
import edu.stanford.nlp.trees.GrammaticalStructure;
import edu.stanford.nlp.trees.GrammaticalStructureFactory;
import edu.stanford.nlp.trees.PennTreebankLanguagePack;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreebankLanguagePack;
import edu.stanford.nlp.trees.TypedDependency;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
String text = "A quick brown fox jumped over the lazy dog.";
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
LexicalizedParser lp = LexicalizedParser.loadModel("C:/Stanford Parser/Java/stanford-parser-full-2015-04-20/stanford-parser-3.5.2-models/edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
lp.setOptionFlags(new String[]{"-maxLength", "500", "-retainTmpSubcategories"});
TokenizerFactory<CoreLabel> tokenizerFactory =
PTBTokenizer.factory(new CoreLabelTokenFactory(), "");
List<CoreLabel> wordList = tokenizerFactory.getTokenizer(new StringReader(text)).tokenize();
Tree tree = lp.apply(wordList);
GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed(true);
Main.writeImage(tree,tdl, "image.png",3);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
它提供了以下異常。
Exception in thread "main" java.lang.NoSuchMethodError: edu.stanford.nlp.trees.TypedDependency.gov()Ledu/stanford/nlp/trees/TreeGraphNode;
我搜索TypedDependency,發現政府網站()在它存在,但異常的到來。我搜查了很多關於它的信息,但沒有發現任何幫助。如果你能幫助我,我會很感激你。