Example usage for edu.stanford.nlp.trees Tree deepCopy

List of usage examples for edu.stanford.nlp.trees Tree deepCopy

Introduction

In this page you can find the example usage for edu.stanford.nlp.trees Tree deepCopy.

Prototype


@SuppressWarnings({ "unchecked" })
public Tree deepCopy(TreeFactory tf, LabelFactory lf) 

Source Link

Document

Makes a deep copy of not only the Tree structure but of the labels as well.

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.corenlp.internal.CoreNlp2DKPro.java

License:Open Source License

public static void convertPennTree(JCas aJCas, Annotation aDocument) {
    for (CoreMap s : aDocument.get(SentencesAnnotation.class)) {
        Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class);
        int begin = s.get(CharacterOffsetBeginAnnotation.class);
        int end = s.get(CharacterOffsetEndAnnotation.class);

        // create tree with simple labels and get penn string from it
        tree = tree.deepCopy(tree.treeFactory(), StringLabel.factory());

        // write Penn Treebank-style string to cas
        PennTree pTree = new PennTree(aJCas, begin, end);
        pTree.setPennTree(tree.pennString());
        pTree.addToIndexes();//  ww w . j  av  a2  s . c  om
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.util.StanfordAnnotator.java

License:Open Source License

/**
 * Creates annotation with Penn Treebank style representations of the syntax tree
 * //from  w  w  w . j  a va  2s .  c  om
 * @param aBegin
 *            start offset.
 * @param aEnd
 *            end offset.
 */
public void createPennTreeAnnotation(int aBegin, int aEnd) {
    Tree t = tokenTree.getTree();

    // write Penn Treebank-style string to cas
    PennTree pTree = new PennTree(jCas, aBegin, aEnd);

    // create tree with simple labels and get penn string from it
    t = t.deepCopy(t.treeFactory(), StringLabel.factory());

    pTree.setPennTree(t.pennString());
    pTree.addToIndexes();
}

From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.util.TreeWithTokens.java

License:Open Source License

public void setTree(Tree tree) {
    if (!(tree.label() instanceof CoreLabel)) {
        tree = tree.deepCopy(tree.treeFactory(), CoreLabel.factory());
    }//from ww  w  . j a  v a2 s.c  o m

    tree.indexLeaves();

    this.tree = tree;
}