use of edu.stanford.nlp.ling.StringLabelFactory in project CoreNLP by stanfordnlp.
the class DependencyIndexITest method testPositions.
public void testPositions() {
try {
// System.err.println();
// System.err.println("One.");
// check a tree loaded from a reader, using StringLabelFactory
Tree tree = (new PennTreeReader(new StringReader("(S (NP (NNP Mary)) (VP (VBD had) (NP (DT a) (JJ little) (NN lamb))) (. .))"), new LabeledScoredTreeFactory(new StringLabelFactory()))).readTree();
//System.out.println(tree.pennString());
checkTree(tree);
// System.err.println("Two.");
// check a tree created using Tree.valueOf()
tree = Tree.valueOf("(S (NP (NNP Mary)) (VP (VBD had) (NP (DT a) (JJ little) (NN lamb))) (. .))");
//System.out.println(tree.pennString());
checkTree(tree);
// System.err.println("Three.");
// check a tree loaded from a reader, using CoreLabelFactory
tree = (new PennTreeReader(new StringReader("(S (NP (NNP Mary)) (VP (VBD had) (NP (DT a) (JJ little) (NN lamb))) (. .))"), new LabeledScoredTreeFactory(CoreLabel.factory()))).readTree();
//System.out.println(tree.pennString());
checkTree(tree);
// System.err.println("Four.");
// check a tree generated by the parser
LexicalizedParser parser = LexicalizedParser.loadModel();
tree = parser.parse("Mary had a little lamb .");
// System.out.println(tree.pennString());
tree.indexLeaves();
checkTree(tree);
} catch (IOException e) {
// this should never happen
fail("IOException shouldn't happen.");
}
}
use of edu.stanford.nlp.ling.StringLabelFactory in project CoreNLP by stanfordnlp.
the class TreeJPanel method main.
public static void main(String[] args) throws IOException {
TreeJPanel tjp = new TreeJPanel();
// String ptbTreeString1 = "(ROOT (S (NP (DT This)) (VP (VBZ is) (NP (DT a) (NN test))) (. .)))";
String ptbTreeString = "(ROOT (S (NP (NNP Interactive_Tregex)) (VP (VBZ works)) (PP (IN for) (PRP me)) (. !))))";
if (args.length > 0) {
ptbTreeString = args[0];
}
Tree tree = (new PennTreeReader(new StringReader(ptbTreeString), new LabeledScoredTreeFactory(new StringLabelFactory()))).readTree();
tjp.setTree(tree);
tjp.setBackground(Color.white);
JFrame frame = new JFrame();
frame.getContentPane().add(tjp, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
frame.setVisible(true);
}
Aggregations