awaisathar / dependensee Goto Github PK
View Code? Open in Web Editor NEWA dependency tree visualizer for the Stanford Typed-Dependency Parser
License: GNU General Public License v2.0
A dependency tree visualizer for the Stanford Typed-Dependency Parser
License: GNU General Public License v2.0
This is a parsed tree (produced by stanford parser) that DependenSee failed to produce a picture:
advmod(blocked-9, Moreover-1)
amod(activity-7, simian-3)
nn(activity-7, virus-4)
num(activity-7, 40-5)
nn(activity-7, enhancer-6)
nsubjpass(blocked-9, activity-7)
nsubjpass(blocked-9', activity-7)
auxpass(blocked-9, was-8)
root(ROOT-0, blocked-9)
conj_negcc(blocked-9, blocked-9')
det(fragment-13, the-11)
amod(fragment-13, MnlI-AluI-12)
agent(blocked-9, fragment-13)
nn(cells-16, HeLa-15)
prep_in(fragment-13, cells-16)
nn(cells-21, B-20)
prep_in(blocked-9', cells-21)
This is the error message:
Exception in thread "main" java.lang.NumberFormatException: For input string: "9'"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at com.chaoticity.dependensee.Node.<init>(Node.java:47)
at com.chaoticity.dependensee.Graph.addNode(Graph.java:65)
at com.chaoticity.dependensee.Main.writeFromTextFile(Main.java:376)
at com.chaoticity.dependensee.Main.main(Main.java:57)
Hi,
When I run the following code, there is a null pointer exception in com.chaoticity.dependensee.Graph.addEdge()
(See below the code). The list of typed dependencies is printed in the output.
The code:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import com.chaoticity.dependensee.*;
import edu.stanford.nlp.process.Tokenizer;
import edu.stanford.nlp.process.TokenizerFactory;
import edu.stanford.nlp.process.CoreLabelTokenFactory;
import edu.stanford.nlp.process.DocumentPreprocessor;
import edu.stanford.nlp.process.PTBTokenizer;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.parser.nndep.DependencyParser;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
import edu.stanford.nlp.ling.TaggedWord;
...
String text = "I can almost always tell when movies use fake dinosaurs.";
String taggerPath = "edu/stanford/nlp/models/pos-tagger/english-left3words/" +
"english-left3words-distsim.tagger";
String modelPath = DependencyParser.DEFAULT_MODEL;
String writeFilePath = ROOT_DIR + "sts2016" + sep + "test" + sep;
MaxentTagger tagger = new MaxentTagger(taggerPath);
DependencyParser parser = DependencyParser.loadFromModelFile(modelPath);
DocumentPreprocessor tokenizer = new DocumentPreprocessor(new StringReader(text));
for (List<HasWord> sentence : tokenizer) {
List<TaggedWord> tagged = tagger.tagSentence(sentence);
GrammaticalStructure gs = parser.predict(tagged);
// Print typed dependencies
System.out.println(gs.typedDependenciesCCprocessed());
try {
Main.writeImage(gs.root(), gs.typedDependenciesCCprocessed(),
writeFilePath + "littletest1.png");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
Output from running the code:
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [1.3 sec].
Loading depparse model file: edu/stanford/nlp/models/parser/nndep/english_UD.gz ...
PreComputed 100000, Elapsed Time: 2.034 (s)
Initializing dependency parser done [5.0 sec].
[nsubj(tell-5, I-1), aux(tell-5, can-2), advmod(always-4, almost-3), advmod(tell-5, always-4), root(ROOT-0, tell-5), advmod(use-8, when-6), nsubj(use-8, movies-7), advcl(tell-5, use-8), amod(dinosaurs-10, fake-9), dobj(use-8, dinosaurs-10), punct(tell-5, .-11)]
java.lang.NullPointerException
at com.chaoticity.dependensee.Graph.addEdge(Graph.java:51)
at com.chaoticity.dependensee.Main.getGraph(Main.java:117)
at com.chaoticity.dependensee.Main.writeImage(Main.java:208)
at Test.Test27(Test.java:119)
at Test.main(Test.java:1045)
Thank you for your patience with my request. I'm learning about dependency parsing.
Your graphical tool is great ! Thank you for coding.
For dependency parsing, an option for the parser which forces some verbs to be the parse tree root is "makeCopulaHead" ; works nicely for the stanford demo.
I was wondering if there was any way to incorporate "makeCopulaHead" as an option which you pass to the parser before you create your .png ?
For example, the parse for the sentence "The apple is red." becomes:
det(apple-3, The-2)
nsubj(is-4, apple-3)
root(ROOT-0, is-4)
acomp(is-4, red-5)
instead of:
det(apple-3, The-2)
nsubj(red-5, apple-3)
cop(red-5, is-4)
root(ROOT-0, red-5)
There seems to be school of thought which says that dependency trees should start with a verb if possible.
Thanks for any feedback !
Kent
I am doing experiment in python with nltk. Can I make any figure in python?
I got this error, I am on a macosx 10.7.5
$ 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
Error: Could not find or load main class com.chaoticity.dependensee.Main
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.