DependenSee: A Dependency Parse Visualisation/Visualization Tool

 

There aren’t many tools which allow you to visualise sentences parsed with dependency grammars. Here’s a small tool which generates a PNG of the dependency graph of a given sentence using the Stanford Parser. You can generate the image for Einey’s quote below by following these steps.

out

  1. Click here to download DependenSee.2.0.5.jar.
  2. Download the latest version of the Stanford Parser.  I am using version 2.0.5 (For older versions, drop me an email)
  3. Extract stanford-parser.jar and stanford-parser-2.0.5-models.jar in the same folder as DependenSee.jar.
  4. On the command prompt, run
    java -cp DependenSee.jar;stanford-parser.jar;stanford-parser-2.0.5-models.jar com.chaoticity.dependensee.Main "Example isn't another way to teach, it is the only way to teach." out.png
    (If you are on *nix, replace the semicolon by a colon and make sure you have Arial installed. If you have an already parsed dependency output file, replace the sentence by -t input.txt .)
  5. Open out.png and admire :)

I have added Part-of-Speech tags and very basic edge overlap management and might add more eye candy later (curved/coloured edges ?). You can link the library in your code as well. An example is given below. Comments and queries are welcome. You can also find the source at github.

import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.parser.lexparser.*;
import edu.stanford.nlp.process.*;
import com.chaoticity.dependensee.*;
import java.util.Collection;
import java.util.*;
import java.io.*;

class Test {
   public static void main(String []args) throws Exception {
      String text = "A quick brown fox jumped over the lazy dog.";
      TreebankLanguagePack tlp = new PennTreebankLanguagePack();
      GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
      LexicalizedParser lp = LexicalizedParser.loadModel(            "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz" );
      lp.setOptionFlags(new String[]{"-maxLength", "500", "-retainTmpSubcategories"});
      TokenizerFactory tokenizerFactory = PTBTokenizer.factory( new CoreLabelTokenFactory(), "");
      List wordList = tokenizerFactory.getTokenizer(new StringReader(text)).tokenize();
      Tree tree = lp.apply(wordList);
      GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
      Collection tdl = gs.typedDependenciesCCprocessed(true);
      Main.writeImage(tree,tdl, "image.png",3);
   }
}

116 thoughts on “DependenSee: A Dependency Parse Visualisation/Visualization Tool

  1. Hi, your dependency parser visualiser is very cool. I was wondering if you might have any code snippets that show how one might generate an image from a Stanford Tree object when run from within Java rather than through the main() call via command line? How do you use the Node, Edge, and Graph classes?

    I tried iterating over the various tagged word and dependency collections from Tree but got many errors such as

    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1937)
    at com.chaoticity.dependensee.Node.(Node.java:41)

    Many thanks!

  2. Ah! Missed that. I just updated the jar and you can now generate an image from a Tree as well.

    LexicalizedParser lp = new LexicalizedParser("englishPCFG.ser.gz");
    lp.setOptionFlags(new String[]{"-maxLength", "500", "-retainTmpSubcategories"});
    Tree tree = lp.apply("Hello World!");
    writeImage(tree, "image.png");

    Hope this helps.

    1. from the top of my mind, java takes a : instead of a ; as a separator on *nix so it should work if you use the command pasted below. You might have to install the Arial font though.
      java-cp DependenSee.jar:stanford-parser.jar com.chaoticity.dependensee.Main "Example isn't another way to teach, it is the only way to teach." out.png

  3. Hi,
    This looks wonderful; I cannot get it to work. Perhaps you can help? I have placed these 3 in a folder: DependenSee.jar/
    englishPCFG.ser.gz
    stanford-parser.jar

    And then try running the command you posted, and get this usage error (see output below): -bash: ./stanford-parser.jar: cannot execute binary file

    Thanks!
    Y

    l
    total 7464
    -rwxr-xr-x@ 1880577 Aug 20 10:31 stanford-parser.jar*
    -rw-r–r–@ 1934638 Aug 20 10:31 englishPCFG.ser.gz
    drwx—— 170 Nov 2 11:09 DependenSee.jar/
    $ java -cp DependenSee.jar;stanford-parser.jar com.chaoticity.dependensee.Main “Example isn’t another way to teach, it is the only way to teach.” out.png
    Usage: java [-options] class [args...]
    (to execute a class)
    or java [-options] -jar jarfile [args...]
    (to execute a jar file)

    where options include:
    -d32 use a 32-bit data model if available
    -d64 use a 64-bit data model if available (implies -server, only for x86_64)
    -client to select the “client” VM
    -server to select the “server” VM
    -jvm is a synonym for the “client” VM [deprecated]
    -hotspot is a synonym for the “client” VM [deprecated]
    The default VM is client.

    -cp
    -classpath
    A : separated list of directories, JAR archives,
    and ZIP archives to search for class files.
    -D=
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version and exit
    -version:
    require the specified version to run
    -showversion print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
    include/exclude user private JREs in the version search
    -? -help print this help message
    -X print help on non-standard options
    -ea[:...|:]
    -enableassertions[:...|:]
    enable assertions
    -da[:...|:]
    -disableassertions[:...|:]
    disable assertions
    -esa | -enablesystemassertions
    enable system assertions
    -dsa | -disablesystemassertions
    disable system assertions
    -agentlib:[=]
    load native agent library , e.g. -agentlib:hprof
    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:[=]
    load native agent library by full pathname
    -javaagent:[=]
    load Java programming language agent, see java.lang.instrument
    -bash: ./stanford-parser.jar: cannot execute binary file

  4. Hi, is there a way to specify options, such as that I want to use the CCPropagatedDependencies option to get propogated conjunctions rather than the basic dependencies? Thanks!!

    1. I agree with Y. It would be interesting to allow the user to add to the command any option provided by the Stanford Parser (using as input POS tagged sentences for example). You could probably concatenate these options to the lp.setOptionFlags parameter.

  5. Hi,
    This works perfectly with Stanford parser. Awesome. Great work!
    Just wonder whether I can use this with some other GR representations. For example RASP GR output (Cambridge). If so what is the command line input? Is there a way to format input GRs?

    Just went through your profile and came to know that you are also from Cambridge. Same here!

    Have fun,
    Sriwantha Attanayake

  6. This is really great! It works fine.

    Is there a way to control the size and the resolution of the generated image. It’s now relatively small and resizing it using image editing tools makes the text unreadable.

  7. hello;

    i want to know for using above code

    LexicalizedParser lp = new LexicalizedParser(“englishPCFG.ser.gz”);
    lp.setOptionFlags(new String[]{“-maxLength”, “500″, “-retainTmpSubcategories”});
    Tree tree = lp.apply(“Hello World!”);
    writeImage(tree, “image.png”);

    i have to import which package for [ writeImage(tree,"image.png");]

    i already upload librarires ( DependenSee.jar , stanford-parser.jar)

  8. hello all;

    can any one provide me code of

    1. tokenizer
    2. Sentence generation from paragraph
    3. group the phrases to find the sentence from tokens.

    Please reply fast!!!!!!

  9. This is an awesome tool. Thanks!!

    I linked your jar as a library, but I couldn’t find the class that contains the function writeImage() in the Main.class.

    Is there are class that I can create for that?

    Thanks !

    1. TRY IT!!!!!!!!!!!!

      STEPS TO RUN:

      1. ADD following jars:

      DependenSee.jar,stanford-parser.jar

      2. Make “textfile.text” on dekstop and write sentence in it , my sentence is “Paraphrasing is a type of plagiarism.

      3. Just copy & paste the code on Eclipse(IDE).

      import java.io.*;
      import java.util.*;
      import edu.stanford.nlp.trees.*;

      import edu.stanford.nlp.process.*;
      import edu.stanford.nlp.objectbank.TokenizerFactory;

      import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
      import edu.stanford.nlp.ling.Sentence;

      import edu.stanford.nlp.ling.TaggedWord;

      import edu.stanford.nlp.ling.HasWord;
      import rita.wordnet.*;
      import edu.stanford.nlp.tagger.maxent.MaxentTagger;

      public class parser {
      public static void main(String[] args) // start of the main method

      {
      // RiWordnet wordnet = new RiWordnet(null);
      System.out.println(“nnnSTARTnnn”); // print START

      try // device to handle potential errors

      {
      // open file whose path is passed
      // as the first argument of the main method:
      FileInputStream fstream = new FileInputStream(“C:/Users/nidhi/Desktop/textfile.txt”);
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));

      // prepare Parser, Tokenizer and Tree printer:

      LexicalizedParser lp = new LexicalizedParser(“englishPCFG.ser.gz”);

      TokenizerFactory tf = PTBTokenizer.factory(false, new WordTokenFactory());

      TreePrint tp = new TreePrint(“penn,typedDependenciesCollapsed”);

      String sentence; // initialization
      // for each line of the file
      // retrieve it as a string called ‘sentence’:

      while ((sentence = br.readLine()) != null)

      {
      // print sentence:

      System.out.println (“nnnnORIGINAL:nn” + sentence);// put tokens in a list:

      List tokens = tf.getTokenizer(new StringReader(sentence)).tokenize();
      System.out.println(“Sentence is:” + sentence);
      System.out.println(“Tokens” +tokens);

      lp.parse(tokens); // parse the tokens

      Tree t = lp.getBestParse(); // get the best parse tree

      System.out.println(“nPROCESSED:nn”); tp.printTree(t); // print tree

      }
      in.close(); // close input file
      }

      catch (Exception e) // catch error if any

      {
      System.err.println(“ERROR: ” + e.getMessage()); // print error message
      }

      System.out.println(“nnnTHE ENDnnn”); // print THE END
      } // end of the main method
      }
      // end of the myParser class

      4. See the output its amazing………..

      START

      Loading parser from serialized file englishPCFG.ser.gz … done [4.4 sec].

      ORIGINAL:

      Paraphrasing is a type of plagiarism.
      Sentence is:Paraphrasing is a type of plagiarism.
      Tokens[Paraphrasing, is, a, type, of, plagiarism, .]

      PROCESSED:

      (ROOT
      (S
      (NP (NN Paraphrasing))
      (VP (VBZ is)
      (NP
      (NP (DT a) (NN type))
      (PP (IN of)
      (NP (NN plagiarism)))))
      (. .)))

      nsubj(type-4, Paraphrasing-1)
      cop(type-4, is-2)
      det(type-4, a-3)
      prep_of(type-4, plagiarism-6)

      THE END

    1. Hi,

      I am also getting similar error

      Exception in thread “main” java.lang.IncompatibleClassChangeError: Found interface edu.stanford.nlp.trees.GrammaticalStructureFactory, but class was expected

      in the following code

      Tree tree = sentence.get(TreeAnnotation.class);
      SemanticGraph dependencies = Sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
      Main.writeImage(tree, dependencies.typedDependencies(), “image.png”,3);

      I am using stanford corenlp 1.3.5. Is this also a version problem?

      Thanks.

  10. Hi,
    I’m using Charniak’s parser and that Stanford tool which provides the corresponding dependency structure:

    [...]
    Collection tDeps = gs.typedDependenciesCCprocessed(true);

    Is there a method like ‘writeImage(tDeps, “img.png”)’? I cannot find one in ‘Main’.

    1. For now, the graph nodes and the POS labels are constructed using the parse tree just to make sure that nodes without dependencies are included. If you can paste the code which generates the grammatical structure (gs) here, I’ll take a look if there is a way to get the parse tree from it. Otherwise, let me know and I’ll add a function which takes just dependencies.

      1. my code:

        TreeReader tReader = new PennTreeReader(new StringReader(parsedSentence), new LabeledScoredTreeFactory());
        EnglishGrammaticalStructure egStructure = new EnglishGrammaticalStructure(tReader.readTree());
        Collection collection = egStructure.typedDependenciesCCprocessed(true);

        1. try this:


          ...
          Tree tree = tReader.readTree();
          EnglishGrammaticalStructure egStructure = new EnglishGrammaticalStructure(tree);
          Collection collection = egStructure.typedDependenciesCCprocessed(true);
          ...
          Main.writeImage(tree,collection, "image.png");

  11. Do you mean ‘com.chaoticity.dependensee.Main.writeImage(tree, collection, “image.png”);’?

    My IDE does not find any method like ‘writeImage’.

  12. Awais, this is an awesome effort and I really liked this idea. But I see some problems stated so far- all about wrtiteImage method in the Main class.

    We all are having same problem- we included the Dependensee.jar and stanford-parser.jar and tried you Test class. But we are getting
    “The method writeImage(Tree, Collection, String, int) is undefined for the type Main” problem.

    This means the in the Main class of the jar file Dependensee does not contain the method writeImage.

    Can you please resolve the issue? I don’t know how it worked for many folks.

  13. try this:
    class Test {

    public static void main(String []args) throws Exception {
    String text = “Slovenija gre naprej!!”;
    String outImage = “image.png”;
    com.chaoticity.dependensee.Main.main(new String[]{text, outImage});
    }

    I believe the function is protected or private. Reverse engineer to find out – I do not have time now. You can still call private functions in Java, but it in an ugly way – check Java Bible book.

    Br,
    Slavko

  14. Hello,

    After installing the jars and running the command, I get an error (see below).
    Is it an issue with the latest parser version or is something wrong with my setup?
    Thanks in advance for looking at this!

    java -cp DependenSee.jar:stanford-parser.jar com.chaoticity.dependensee.Main “Example isn’t another way to teach, it is the only way to teach.” out.png

    Loading parser from serialized file englishPCFG.ser.gz … done [3.5 sec].
    Exception in thread “main” java.lang.NoSuchMethodError: edu.stanford.nlp.trees.Tree.taggedYield()Ledu/stanford/nlp/ling/Sentence;
    at com.chaoticity.dependensee.Main.getGraph(Main.java:105)
    at com.chaoticity.dependensee.Main.writeImage(Main.java:232)
    at com.chaoticity.dependensee.Main.writeImage(Main.java:216)
    at com.chaoticity.dependensee.Main.writeImage(Main.java:198)
    at com.chaoticity.dependensee.Main.main(Main.java:50)

  15. Rita and sveter,

    My bad! I never updated the file after the new API changes. The latest version of DependenSee.jar should work with v1.6.7 of parser now. Let me know if it doesn’t.

  16. I get this exception:

    java.util.NoSuchElementException
    at java.util.AbstractList$Itr.next(AbstractList.java:)
    at com.chaoticity.dependensee.Main.getGraph(Main.java:)
    at Foo.parseString(Foo.java:)

    using this phrase “a dog is an animal that barks” with your code:

    Tree tree = lexParser.apply(text);

    TreebankLanguagePack tlp = new PennTreebankLanguagePack();
    GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
    GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
    List tdl = gs.typedDependenciesCCprocessed();

    /*
    EnglishGrammaticalStructure gs = new EnglishGrammaticalStructure(tree);
    Collection tdl = gs.typedDependenciesCCprocessed(true);
    */

    writeImage(tree, tdl, “image.png”);

    (omitting the tdl argument causes no exception)

  17. Hi, I already have the dependency graph for the sentence, and I’d just like to use this code to visualize the graph. How can I do that? Some DGs are from previous versions of the Parser, some are from the most current. Thanks!

    1. Assuming you have one file per sentence which contains only the dependency text, download the latest version and use the -t switch. I have tested using the following command line

      java -cp DependenSee.jar;stanford-parser.jar com.chaoticity.dependensee.Main -t input.txt out.png

      when input.txt contains the following text. POS tags have not been handled yet.


      nsubj(way-5, Example-1)
      cop(way-5, is-2)
      neg(way-5, n't-3)
      det(way-5, another-4)
      ccomp(way-13, way-5)
      aux(teach-7, to-6)
      infmod(way-5, teach-7)
      nsubj(way-13, it-9)
      cop(way-13, is-10)
      det(way-13, the-11)
      amod(way-13, only-12)
      aux(teach-15, to-14)
      infmod(way-13, teach-15)

  18. Brother Awais…

    I want to extract the the location of a word in a sentence. During the extraction of typed dependency extraction, stanford parser provied it like “dobj(love-2, country-4)” where love is at location 2 and country is at location 4. But how can i control and display programatically these location value. Is there any function is available in Stanford-parser API.
    Please Help me

    1. given a TypedDependency object td, you can probably get the indices by td.dep().index() - 1 and td.gov().index() - 1 . There are other methods as well. Just open up the src directory and see the toString method of the related class.

      1. Brother Awais Thanks for ur support…..

        I need some more help. Basically i am working on Ontology learning from text. So the first phase of that is to parse the whole text. Now I m using Stanford Parser.

        Can I Handle the dependency relation between between two word from the whol dependency graph….

        For example
        a sentense “I Love my coutnry”…..so the depencies are

        nsubj(love-2, I-1)
        poss(country-4, my-3)
        dobj(love-2, country-4)

        Now i want to work with the third dependency relation i.e. “dobj(love-2, country-4)”

        Basically brother….I want to make some semantic patterns and apply on these dependecny relation programtically…..

        can you help me in this regard
        I need some snippest of code that how to extract the index as well as how get the single dependency relation from graph…
        i m new in NLP…So please help me…..have u any messenger ID

  19. Hi Awais,

    very nice work. I was able to use it in my Java project. For another project I would like to visualize the PTB trees. However, when calling
    Main.writeImage(ptbTree,”image.png”);
    the tool display’s again the dependency parse tree’s instead of the PTB tree. Is there any possibility to visualize that?

    Best,
    Philippe

    1. Thanks Philippe

      This tool was created for dependencies only. I’ll see if I can modify it to get a general tree structure but there are some tool out there which already do so. GrammarScope is one of them (http://grammarscope.sourceforge.net/). Personally I prefer running the modified output of the pennPrint through phpSyntaxTree.

      ptbTree.pennString().replaceAll("\[.*\]|rn| ", "").replaceAll("[ ]*\(", "\[").replaceAll("[ ]*\)", "\]"))

      Hope this helps

  20. Hi, could you provide a version of your dependency parse visualization tool where the path to the language model is not hard-coded (i.e. englishPCFG.ser.gz)?
    This would make testing your tool on other languages possible, and I guess it’s just a matter of making the path to the language model a variable.
    Thanks.

    1. I guess you can use the code given at the end of the post and change the string parameter passed to the variable lp. Tell me if that doesn’t work.

  21. Hi, this is such a cool program and it works fine on my machine. But can you please tell how could i read the parsed structure in the form of pure text? Thank you in advance for your reply.

  22. I get an error, why? can anyone explain ?

    Exception in thread “main” java.lang.NullPointerException
    at com.chaoticity.dependensee.Graph.addEdge(Graph.java:50)
    at com.chaoticity.dependensee.Main.getGraph(Main.java:116)
    at com.chaoticity.dependensee.Main.writeImage(Main.java:253)
    at com.chaoticity.dependensee.Main.writeImage(Main.java:237)

      1. Alex, please use the updated DependenSee.jar file. The problem was due to a version update in the Stanford parser and should be fixed now. Let me know if there are any problems. Hope this helps.

        1. Hi awais,I have a basic question about the stanford parser dependency relation.
          “the mp3 is great but much more expensive” . I want to find the “shortest dependency path ” between the word “mp3″ and “expensive”. if there is a simple
          implemention? thanks!

          1. Tree.pathNodeToNode method is used to find the syntactic path between two words , not used to find the dependency path between two words. Thank you very much!

  23. Seems that it has problem to display Chinese dependency

    I‘m using the xinhuaPCFG.ser.gz and using ChineseTreebankLanguagePack() instead of PennTreebankLanguagePack().
    TreebankLanguagePack tlp = new ChineseTreebankLanguagePack();

    I got the following exception:

    java.lang.RuntimeException: Failed to invoke public edu.stanford.nlp.trees.EnglishGrammaticalStructure(edu.stanford.nlp.trees.Tree)
    at edu.stanford.nlp.trees.GrammaticalStructureFactory.newGrammaticalStructure(GrammaticalStructureFactory.java:104)
    at com.chaoticity.dependensee.Main.getGraph(Main.java:149)
    at com.chaoticity.dependensee.Main.writeImage(Main.java:255)
    at DependencySee.showCNDependency(DependencySee.java:60)
    at DependencySee.main(DependencySee.java:17)

  24. Hello awais!

    This is a great tool which I want to use for some research visualization aspects.
    I simply have one problem for which I couldn’t find any solution browsing this web page:
    Is there any way to specify the type of output which has to be done using the tool from command line? In the Java code examples you stated a method like: Main.writeImage(tree,tdl, “image.png”,3); which seems to print the tree as well as the dependencies. But the command line command you provided only prints the dependencies.
    I read that you included a scaling function for the image. It would also be nice to define the scaling factor from the command line.

    Thank you in advance and have a nice day!
    Lars

    1. Sorry, scaling is only exposed in the API. You can easily write a program to take the scaling factor from the command line though. Pasting a few untested lines below which should work for something like Test "This is an example sentence" 3 . Let me know if you can’t get it to work and I’ll update the command line interface


      import edu.stanford.nlp.trees.*;
      import edu.stanford.nlp.parser.lexparser.*;
      import com.chaoticity.dependensee.*;
      import java.util.Collection;
      class Test {
      public static void main(String []args) throws Exception {
      TreebankLanguagePack tlp = new PennTreebankLanguagePack();
      GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
      LexicalizedParser lp = LexicalizedParser.loadModel();
      Tree tree = lp.apply(args[0]);
      GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
      Collection tdl = gs.typedDependenciesCCprocessed(true);
      Main.writeImage(tree,tdl, "image.png",Integer.parseInt(args[1]));
      }
      }

      1. Thank you for your instant answere. I managed to write the program according to your untested code example. But I encountered a problem: Using your tool (no matter if I call it from command line or if I use the API) the tree is not rendered.
        The rendering of the dependencies works fine.

      2. Thank you for your instant answere. I managed to write the program according to your untested code example. But I encountered a problem: Using your tool (no matter if I call it from command line or if I use the API) the tree is not rendered. Do you have any idea why?
        The rendering of the dependencies works fine.

          1. Ah, I think i misunderstood a comment of John (http://chaoticity.com/dependensee-a-dependency-parse-visualisation-tool/#comment-5527).
            I thought he was asking for a tree visualization function within your tool and you told him where to find. But the question was how to directly print the dependency graph image from a parse tree, right?

            Do you know any nice tool to vizualize a parse tree from Stanford Parser?

            Thank you again in advance and for your very quick reply!
            Lars

  25. Ah, nice! I would use it if I wouldn’t already have done it using http://www.matijs.net/software/synttree/ :(
    Now I have a command line tool which is able to print a Stanford parse tree to PDF and rendering a nice visualization of the Stanford Typed Dependencies with scaling factor. :)

    Thank you for the support and have a nice week.
    Lars

  26. Hi, I just tried to use your example with a simple chinese Sentence. “熟知三国史的志狼,会对历史产生甚么影响?”

    String text = “熟知三国史的志狼,会对历史产生甚么影响?”;
    TreebankLanguagePack tlp = new ChineseTreebankLanguagePack();
    GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
    LexicalizedParser lp =LexicalizedParser.loadModel(“edu/stanford/nlp/models/lexparser/chineseFactored.ser.gz;
    Tree tree = lp.apply(text);
    tree.pennPrint();
    GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
    @SuppressWarnings(“rawtypes”)
    Collection tdl = gs.typedDependenciesCCprocessed(true);
    Main.writeImage(tree, tdl, “image.png”, 3);
    System.out.println(tdl);

    but it didn’t work.
    All I get is:
    [root(ROOT-0, 熟知三国史的志狼,会对历史产生甚么影响?-1)]

    But it works here: http://nlp.stanford.edu:8080/parser/index.jsp
    How should I do it correctly?

    Thank you.
    Dan

  27. Hello,

    I am trying to run the code but I get the following error:

    Exception in thread “main” java.lang.IncompatibleClassChangeError: Found interface edu.stanford.nlp.trees.GrammaticalStructureFactory, but class was expected
    at com.chaoticity.dependensee.Main.getGraph(Main.java:94)
    at com.chaoticity.dependensee.Main.writeImage(Main.java:204)
    at com.chaoticity.dependensee.Main.writeImage(Main.java:170)
    at com.chaoticity.dependensee.Main.writeImage(Main.java:156)
    at com.chaoticity.dependensee.Main.main(Main.java:32)

    The following is the command I used:

    java -cp DependenSee.jar:stanford-corenlp-1.3.4.jar:stanford-corenlp-1.3.4-models.jar com.chaoticity.dependensee.Main “Foreign Minister Don McKinnon said that terrorist bombings this month of U.S. embassies in Nairobi, Kenya and Dar es Salaam, Tanzania, “show that terrorism is an indiscriminate killer of innocent people.”” out1.png

    I am using the current version of Stanford NLP parser, could there be a problem with versions? Thanks.

    1. Definitely a version problem. I’ll see if I can opensource it now that I haven’t been putting much effort in maintaining the current version.

  28. Getting following error when i executed from commnad prompt
    Exception in thread “main” jana.lang.NoClassDefFoundError

    1. What did you enter on the command line? Are all the jar files in the current directory? What’s the 2nd and 3rd line of the error stacktrace?

  29. Can you please let me know the jar files you’ve included?
    I’m working on eclipse right now. I’ve included the following jars:
    Stanford-Parser, Stanford-POS-tagger, CoreNLP, RitaWordNet.
    I’m getting errors on the following lines:
    LexicalizedParser lp = new LexicalizedParser(“englishPCFG.ser.gz”);

    TokenizerFactory tf = PTBTokenizer.factory(false, new WordTokenFactory());

    Why are these two lines not getting recognised? Any other jar is to be included?

    1. I include the following jar files.

      DependenSee.jar;stanford-parser.jar;stanford-parser-2.0.5-models.jar

      You might be running into a version conflict. What errors are you getting?

  30. I’m using DependenSee.jar(2.0.5); stanford-parser.jar(2.0.5); stanford-parser-2.0.5-models.jar

    I’m getting the following errors:
    1. The import edu.stanford.nlp.objectbank.TokenizerFactory cannot be resolved
    2. Multiple markers at this line
    - The constructor LexicalizedParser(String) is
    undefined
    3. Multiple markers at this line
    - The method factory(boolean, boolean) in the type PTBTokenizer is not applicable for the arguments (boolean, WordTokenFactory)

    1. You are probably missing the new paths. You might want to include the lines below in your program.
      import edu.stanford.nlp.process.*;
      import java.util.*;
      import java.io.*;

      Hope this helps.

      -a

  31. I have used the code snippet which nidhi has provided in the earlier comment, since I’m interested to extract the typed dependencies as her sample output presents.
    Those import statements have been already included!
    Would be glad if you could help me out with this.

    1. Lewis, I’ve just updated and recompiled the code (Stanford parser 2.0.5) and it seems to be working on my side (JDK 1.7). May be you can send over a pastebin URL of the minimal code you want to work.

  32. The code snippet I employed is in the 20th conversation/thought of this post. (Posted by nidhi which lists out the typed dependencies). Please let me know your thoughts on this…

    1. Sorry, I don’t have RitaWordNet at the moment. But the code I reposted is working for 2.0.5 (of the parser, not coreNLP). May be if you can take out the wordnet dependency (no pun intended) and try running the code above to see if it works… If not, send over a link to the source and I’ll take a look.

Leave a Reply

Your email address will not be published. Required fields are marked *