Search in sources :

Example 6 with StringLabelFactory

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.");
    }
}
Also used : PennTreeReader(edu.stanford.nlp.trees.PennTreeReader) StringLabelFactory(edu.stanford.nlp.ling.StringLabelFactory) LexicalizedParser(edu.stanford.nlp.parser.lexparser.LexicalizedParser) StringReader(java.io.StringReader) Tree(edu.stanford.nlp.trees.Tree) IOException(java.io.IOException) LabeledScoredTreeFactory(edu.stanford.nlp.trees.LabeledScoredTreeFactory)

Example 7 with StringLabelFactory

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);
}
Also used : PennTreeReader(edu.stanford.nlp.trees.PennTreeReader) StringLabelFactory(edu.stanford.nlp.ling.StringLabelFactory) WindowEvent(java.awt.event.WindowEvent) StringReader(java.io.StringReader) Tree(edu.stanford.nlp.trees.Tree) WindowAdapter(java.awt.event.WindowAdapter) LabeledScoredTreeFactory(edu.stanford.nlp.trees.LabeledScoredTreeFactory)

Aggregations

StringLabelFactory (edu.stanford.nlp.ling.StringLabelFactory)7 StringReader (java.io.StringReader)3 LabeledScoredTreeFactory (edu.stanford.nlp.trees.LabeledScoredTreeFactory)2 PennTreeReader (edu.stanford.nlp.trees.PennTreeReader)2 Tree (edu.stanford.nlp.trees.Tree)2 IOException (java.io.IOException)2 LexicalizedParser (edu.stanford.nlp.parser.lexparser.LexicalizedParser)1 ClassicCounter (edu.stanford.nlp.stats.ClassicCounter)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1