Reputation: 1222
I want to see Dependence output format in Stanford Parser for NLP. I downloaded the jar file from this link. http://nlp.stanford.edu/software/lex-parser.shtml
Then I import it in Eclipse and 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 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();
}
}
}
It gives following Exception.
Exception in thread "main" java.lang.NoSuchMethodError: edu.stanford.nlp.trees.TypedDependency.gov()Ledu/stanford/nlp/trees/TreeGraphNode;
I searched for TypedDependency and found that gov() exist in it but exception is coming. I searched a lot about it but found no help regarding this. I will be thankful to you if you help me on this.
Upvotes: 0
Views: 323
Reputation: 9450
This is due to incompatibility between recent releases of Stanford NLP code and DependenSee, which was built against v2.0.5 (2013-04-05) of the Stanford Parser. If you comment out the line Main.writeImage(tree,tdl, "image.png",3);
and instead just do System.out.println(tdl);
then it works fine.
Your options are either to: not use DependenSee, fix DependenSee to be compatible with recent Stanford NLP releases (probably easy), or to downgrade to an old version of the Stanford NLP....
Upvotes: 1