Example usage for edu.stanford.nlp.ling Label value

List of usage examples for edu.stanford.nlp.ling Label value

Introduction

In this page you can find the example usage for edu.stanford.nlp.ling Label value.

Prototype

public String value();

Source Link

Document

Return a String representation of just the "main" value of this label.

Usage

From source file:edu.cmu.ark.AnalysisUtilities.java

License:Open Source License

/**
 * Remove traces and non-terminal decorations (e.g., "-SUBJ" in "NP-SUBJ") from a Penn Treebank-style tree.
 *
 * @param inputTree//w w w  . j av  a2s. c  o m
 */
public void normalizeTree(Tree inputTree) {
    inputTree.label().setFromString("ROOT");

    List<Pair<TregexPattern, TsurgeonPattern>> ops = new ArrayList<Pair<TregexPattern, TsurgeonPattern>>();
    List<TsurgeonPattern> ps = new ArrayList<TsurgeonPattern>();
    String tregexOpStr;
    TregexPattern matchPattern;
    TsurgeonPattern p;
    TregexMatcher matcher;

    tregexOpStr = "/\\-NONE\\-/=emptynode";
    matchPattern = TregexPatternFactory.getPattern(tregexOpStr);
    matcher = matchPattern.matcher(inputTree);
    ps.add(Tsurgeon.parseOperation("prune emptynode"));
    matchPattern = TregexPatternFactory.getPattern(tregexOpStr);
    p = Tsurgeon.collectOperations(ps);
    ops.add(new Pair<TregexPattern, TsurgeonPattern>(matchPattern, p));
    Tsurgeon.processPatternsOnTree(ops, inputTree);

    Label nonterminalLabel;

    tregexOpStr = "/.+\\-.+/=nonterminal < __";
    matchPattern = TregexPatternFactory.getPattern(tregexOpStr);
    matcher = matchPattern.matcher(inputTree);
    while (matcher.find()) {
        nonterminalLabel = matcher.getNode("nonterminal");
        if (nonterminalLabel == null)
            continue;
        nonterminalLabel.setFromString(tlp.basicCategory(nonterminalLabel.value()));
    }

}

From source file:elkfed.expletives.ExpletiveInstance.java

License:Apache License

public ExpletiveInstance(Tree root, Tree pronoun, String id) {
    _root = root;/*from ww  w . jav a 2s.  c om*/
    _pronoun = pronoun;
    _id = id;

    List<Tree> wordsT = root.getLeaves();
    List<Label> posT = root.preTerminalYield();
    // get words and POS into an array so that
    // we get an idea of the pronoun's surrounding
    String[] words = new String[wordsT.size()];
    String[] pos = new String[wordsT.size()];
    if (!root.dominates(pronoun)) {
        System.err.format("%s does not dominate %s. WTF?", root, pronoun);
    }
    for (int here = 0; here < wordsT.size(); here++) {
        Tree w1 = wordsT.get(here);
        Label p1 = posT.get(here);
        words[here] = w1.toString();
        pos[here] = p1.value();
        if (w1 == pronoun) {
            _idx = here;
        } else if (pronoun.dominates(w1)) {
            _idx = here;
            pronoun = w1;
        }
    }
    assert _idx >= 0 : String.format("wanted %s in %s", pronoun, root);
    assert pos[_idx].equals("PRP") : String.format("wanted PRP got '%s'", pos[_idx]);
    _words = words;
    _pos = pos;
}

From source file:elkfed.mmax.pipeline.P2Chunker.java

License:Apache License

private void normalizeTree(Tree tree) {
    // for leaves -- add positions
    // for nps -- add whether they are basic or not

    int leaveIndex = 0;
    for (Iterator<Tree> treeIt = tree.iterator(); treeIt.hasNext();) {
        Tree currentTree = treeIt.next();
        Label nodeLabel = currentTree.label();
        if (currentTree.isLeaf()) {
            nodeLabel.setValue(nodeLabel.value() + INDEX_SEPARATOR + leaveIndex);
            leaveIndex++;/* w w  w.  j ava2s.c o  m*/
        } else {

            if (currentTree.value().toLowerCase().startsWith("np")) {

                Boolean found = false;

                //adjust this np for keeping (if not already discarded
                if (!currentTree.value().endsWith("0") && !currentTree.value().endsWith("2"))
                    currentTree.label().setValue("NP" + NPSTATUS_SEPARATOR + "1");

                //adjust upper np for discarding

                Tree p = currentTree;
                Tree head = p.headTerminal(getHeadFinder());
                while (p != null && !found) {
                    p = p.parent(tree);
                    if (p != null && p.value().toLowerCase().startsWith("np")
                            && p.headTerminal(getHeadFinder()) == head && (!iscoordnp(p))) {
                        found = true;
                        p.label().setValue("NP" + NPSTATUS_SEPARATOR + "0");
                        currentTree.label().setValue("NP" + NPSTATUS_SEPARATOR + "2");
                    }
                }

            } else {
                nodeLabel.setValue(nodeLabel.value().toUpperCase());
            }
        }
    }
}

From source file:elkfed.mmax.pipeline.SemTagger.java

License:Apache License

/** Given a tree, uppercases all its non-terminal label (so that the
 *  CollinsHeadFinder can be applied to it) and add a positional index to
 *  the terminal nodes.// w  ww . j a  v  a2s  . c  o  m
 * 
 * @param tree the tree whose labels are to be uppercased
 */
private void normalizeTree(Tree tree) {
    int leaveIndex = 0;
    for (Iterator<Tree> treeIt = tree.iterator(); treeIt.hasNext();) {
        Tree currentTree = treeIt.next();
        Label nodeLabel = currentTree.label();
        if (currentTree.isLeaf()) {
            nodeLabel.setValue(nodeLabel.value() + INDEX_SEPARATOR + leaveIndex);
            leaveIndex++;
        } else {
            nodeLabel.setValue(nodeLabel.value().toUpperCase());
        }
    }
}

From source file:info.mhaas.ma.Evaluation.CCEvaluator.java

public static int collapseFineGrained(Label label) {
    return collapseFineGrained(label.value());
}

From source file:qmul.util.treekernel.Production.java

License:Open Source License

/**
 * Set the BNF-style production for this node
 *///www  .j  ava2 s .  com
private void setBnf() {
    List<Tree> children = node.getChildrenAsList();
    Label nodeLabel = node.label();
    // System.out.println(nodeLabel.value());
    String bnf;
    if (nodeLabel == null) {
        bnf = "";
    } else {
        bnf = nodeLabel.value();
    }
    for (Tree child : children) {
        Label childLabel = child.label();
        if (childLabel == null) {
            bnf += "";
        } else {
            bnf += SEPARATOR + childLabel.value();
        }
    }
    this.bnf = bnf;
}