java - Stanford Parser (Typed Dependencee) Exception -
i want see dependence output format in stanford parser nlp. downloaded jar file link. http://nlp.stanford.edu/software/lex-parser.shtml
then import in eclipse , wrote following code.
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 on 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(); } }
}
it gives following exception.
exception in thread "main" java.lang.nosuchmethoderror: edu.stanford.nlp.trees.typeddependency.gov()ledu/stanford/nlp/trees/treegraphnode;
i searched typeddependency , found gov() exist in exception coming. searched lot found no regarding this. thankful if me on this.
this due incompatibility between recent releases of stanford nlp code , dependensee, built against v2.0.5 (2013-04-05) of stanford parser. if comment out line main.writeimage(tree,tdl, "image.png",3);
, instead system.out.println(tdl);
works fine.
your options either to: not use dependensee, fix dependensee compatible recent stanford nlp releases (probably easy), or downgrade old version of stanford nlp....
Comments
Post a Comment