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

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

Introduction

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

Prototype

public boolean isLeaf() 

Source Link

Document

Says whether a node is a leaf.

Usage

From source file:tml.utils.StanfordUtils.java

License:Apache License

public static String getPennTagMinimalPhrase(Tree t) {
    if (t.isLeaf())
        return "LEAF";

    if (t.isPrePreTerminal())
        return t.value();

    return getPennTagMinimalPhrase(t.children()[0]);
}

From source file:tml.utils.StanfordUtils.java

License:Apache License

public static String getPennTagFirstBranch(Tree orig, Tree t, Tree pt) {
    if (t.isLeaf())
        return "NOBRANCH";

    List<Tree> trees = t.siblings(orig);
    if (trees != null && trees.size() > 0 && pt != null)
        return pt.value();

    return getPennTagFirstBranch(orig, t.getChild(0), t);
}

From source file:weka.filters.unsupervised.attribute.PartOfSpeechTagging.java

License:Open Source License

/**
 * Traverses the tree and adds the leaf data to the string buffer.
 *
 * @param parentTree   the tree to process
 * @param content   the string buffer to add the content to
 * @param pattern     the pattern that the labels must match (null for match-all)
 *//* w  ww.j av  a 2  s.c o  m*/
protected void traverseTree(Tree parentTree, StringBuilder content, Pattern pattern) {
    Tree childTree;
    int i;
    String word;
    String label;

    for (i = 0; i < parentTree.children().length; i++) {
        childTree = parentTree.children()[i];
        if (childTree.isLeaf()) {
            label = parentTree.label().value();
            word = childTree.label().value();
            // stopword?
            if (m_Stopwords.isStopword(word))
                continue;
            // keep label?
            if ((pattern != null) && !pattern.matcher(label).matches())
                continue;
            if (content.length() > 0)
                content.append(" ");
            if (!m_SuppressLabelPrefixes)
                content.append(label + ":");
            content.append(word);
        }
        traverseTree(childTree, content, pattern);
    }
}