List of usage examples for edu.stanford.nlp.trees Tree treeFactory
public abstract TreeFactory treeFactory();
From source file:CollapseUnaryTransformer.java
License:Apache License
public Tree transformTree(Tree tree) { if (tree.isPreTerminal() || tree.isLeaf()) { return tree.deepCopy(); }//from w w w. ja va2 s .c o m Label label = tree.label().labelFactory().newLabel(tree.label()); Tree[] children = tree.children(); while (children.length == 1 && !children[0].isLeaf()) { children = children[0].children(); } List<Tree> processedChildren = Generics.newArrayList(); for (Tree child : children) { processedChildren.add(transformTree(child)); } return tree.treeFactory().newTreeNode(label, processedChildren); }
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();//from w ww . j a v a 2s .c o m } }
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 * /* w w w . ja v a 2 s . c o m*/ * @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()); }// w w w.j av a2s . co m tree.indexLeaves(); this.tree = tree; }