public class TreeUtils extends Object
Constructor and Description |
---|
TreeUtils() |
Modifier and Type | Method and Description |
---|---|
static edu.stanford.nlp.trees.Tree |
createStanfordTree(org.apache.uima.jcas.tcas.Annotation root)
Recursively creates an edu.stanford.nlp.trees.Tree from a ROOT annotation It also saves the
whitespaces before and after a token as
CoreAnnotation.BeforeAnnotation and
CoreAnnotation.AfterAnnotation in the respective label of the current node. |
static edu.stanford.nlp.trees.Tree |
createStanfordTree(org.apache.uima.jcas.tcas.Annotation root,
edu.stanford.nlp.trees.TreeFactory tFact) |
static edu.stanford.nlp.trees.Tree |
createStanfordTreeWithAnnotations(org.apache.uima.jcas.tcas.Annotation root)
Recreates a Stanford Tree from the StanfordParser annotations and saves all
non-StanfordParser-Annotations within the scope of the sentence in the label of the best
fitting node.
|
static List<Token> |
getTokenListFromTree(org.apache.uima.jcas.JCas aJCas,
edu.stanford.nlp.trees.Tree t)
Returns a list of Token annotations from a Tree-object
|
static edu.stanford.nlp.trees.Tree |
pennString2Tree(String pennString)
Reads in a Penn Treebank-style String and returns a tree.
|
static String |
pennString2Words(String penn)
Returns the sentence from its tree representation.
|
static void |
reIndexLeaves(edu.stanford.nlp.trees.Tree t)
Reimplementation of the indexLeaves() method of stanford tree objects.
|
static String |
tree2Words(edu.stanford.nlp.trees.Tree t)
Returns the sentence from its tree representation.
|
public static edu.stanford.nlp.trees.Tree createStanfordTree(org.apache.uima.jcas.tcas.Annotation root)
CoreAnnotation.BeforeAnnotation
and
CoreAnnotation.AfterAnnotation
in the respective label of the current node.root
- the ROOT annotationTree
object representing the syntax structure of the sentencepublic static edu.stanford.nlp.trees.Tree createStanfordTree(org.apache.uima.jcas.tcas.Annotation root, edu.stanford.nlp.trees.TreeFactory tFact)
public static edu.stanford.nlp.trees.Tree createStanfordTreeWithAnnotations(org.apache.uima.jcas.tcas.Annotation root) throws org.apache.uima.cas.CASException
Recreates a Stanford Tree from the StanfordParser annotations and saves all non-StanfordParser-Annotations within the scope of the sentence in the label of the best fitting node.
CAUTION: This method is intended for the use by CAS Multipliers, which create new CASes from this tree. The annotation-spans in the source-CAS will be changed!!!!!! You do NOT want to use the source CAS after this method has been called. The createStanfordTree()-method does not change the CAS, so use this instead, if the annotations do not have to be recovered or accessed in the tree.
TODO: This behavior could be changed by making COPIES of the annotations and changing the copied instead of the originals. However, in order to being able to make copies, a dummy CAS must be introduced to which the annotations can be copied. When they are recovered, they will be copied to the new destination CAS anyway.
root
- the ROOT annotationTree
object representing the syntax structure of the sentenceorg.apache.uima.cas.CASException
- if the JCas cannot be accessed.public static String pennString2Words(String penn)
penn
- the tree representation of the sentencepublic static String tree2Words(edu.stanford.nlp.trees.Tree t)
t
- the tree representation of the sentencepublic static List<Token> getTokenListFromTree(org.apache.uima.jcas.JCas aJCas, edu.stanford.nlp.trees.Tree t)
aJCas
- a JCas.t
- a tree.public static void reIndexLeaves(edu.stanford.nlp.trees.Tree t)
CoreMap
-type labels.t
- a tree with CoreLabel-type labels.Tree.indexLeaves()
public static edu.stanford.nlp.trees.Tree pennString2Tree(String pennString)
pennString
- A Penn Treebank-style String as produced by the StandfordParserCopyright © 2007–2018 Ubiquitous Knowledge Processing (UKP) Lab, Technische Universität Darmstadt. All rights reserved.