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

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

Introduction

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

Prototype

@Override
public Label label() 

Source Link

Document

Returns the label associated with the current node, or null if there is no label.

Usage

From source file:elkfed.coref.mentions.Mention.java

License:Apache License

public String computeAppType(Mention np) {

    /*//from  w  w  w  .ja va 2 s  .c om
     * this probably shouldn't work properly it's used by discourse_entities
     * but hP and lP are inconsistent with it ToDo: unify with other appo
     * stuff (olga)
     */

    String headAppo = null;
    Tree lowestProjection = np.getLowestProjection();
    Tree highestProjection = np.getHighestProjection();
    if (highestProjection == null)
        return headAppo;
    if (highestProjection.children() == null)
        return headAppo;
    if (highestProjection.children().length <= 2)
        return headAppo;
    if (!highestProjection.children()[1].label().toString().equals(","))
        return headAppo;

    Tree h0 = highestProjection.children()[0].headPreTerminal(getStHeadFinder());
    Tree h2 = highestProjection.children()[2].headPreTerminal(getStHeadFinder());
    if (h0 == null)
        return headAppo;
    if (h2 == null)
        return headAppo;

    if (highestProjection.children()[0] == lowestProjection
            && highestProjection.children()[2].label().toString().equals("NP")
            && !h0.label().toString().equals("NNP") && h2.label().toString().equals("NN"))

        return highestProjection.children()[2].headTerminal(getStHeadFinder()).toString();

    if (highestProjection.children()[0].label().toString().equals("NP")
            && highestProjection.children()[2] == lowestProjection && h2.label().toString().equals("NNP")
            && h0.label().toString().equals("NN"))
        return highestProjection.children()[0].headTerminal(getStHeadFinder()).toString();

    return headAppo;
}

From source file:elkfed.coref.mentions.Mention.java

License:Apache License

public String computePredicationType(Mention np) {
    String predType = null;/*from ww  w . java  2  s  . c  o  m*/
    Tree mentionTree = np.getHighestProjection();
    Tree sentenceTree = np.getSentenceTree();
    Tree parentNode = null;
    if (mentionTree == null && ConfigProperties.getInstance().getDbgPrint()) {
        System.out.println("No mentionTree for " + np.toString());
    }
    if (mentionTree != null)
        parentNode = mentionTree.ancestor(1, sentenceTree);
    if (!(parentNode == null) && parentNode.children().length > 1
            && parentNode.children()[1].label().toString().equals("VP")
            && parentNode.children()[1].children().length > 1) {
        String hword10 = parentNode.children()[1].children()[0].headTerminal(new ModCollinsHeadFinder())
                .toString();
        if (hword10.equals("is") || hword10.equals("are") || hword10.equals("was") || hword10.equals("were")) {
            Tree pchild11 = parentNode.children()[1].children()[1];
            if (pchild11 != null) {// &&
                if (pchild11.label().toString().equals("NP")) {
                    String pchild11_headpos = pchild11.headPreTerminal(new ModCollinsHeadFinder()).label()
                            .toString();
                    if (!pchild11_headpos.equals("JJS") && !pchild11_headpos.equals("NNP")) {
                        predType = pchild11.headTerminal(new ModCollinsHeadFinder()).toString();
                    }
                }
            }
        }
    }
    return predType;
}

From source file:elkfed.lang.ItalianLanguagePlugin.java

License:Apache License

@Override
public List<Tree>[] calcParseInfo(Tree sentTree, int startWord, int endWord, MentionType mentionType) {
    /* now, the *proper* way to do this would be to find the
     * head(s) and look for everything non-head. Instead,
     * we just look for children that look like modifiers,
     * which means that we get weird results
     * (i) for appositions/*from   w  ww.j a  v a2 s . c om*/
     * (ii) for elliptic NPs (e.g., 'la gialla'),
     *      where the head 'gialla' also gets recruited as a modifier
     */
    List<Tree>[] result = new List[3];
    List<Tree> projections = new ArrayList<Tree>();
    List<Tree> premod = new ArrayList<Tree>();
    List<Tree> postmod = new ArrayList<Tree>();
    result[0] = projections;
    result[1] = premod;
    result[2] = postmod;
    Tree node = calcLowestProjection(sentTree, startWord, endWord);
    NodeCategory ncat = labelCat(node.label().value());
    if (startWord == endWord
            && (ncat == NodeCategory.CN || ncat == NodeCategory.PRO || ncat == NodeCategory.PN)) {
        node = node.parent(sentTree);
    }
    projections.add(node);
    for (Tree n : node.children()) {
        String cat = n.value();
        if (attr_node.matcher(cat).matches()) {
            premod.add(n);
        } else if (rel_node.matcher(cat).matches()) {
            postmod.add(n);
        }
    }
    return result;
}

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++;//from   w  w  w  .java  2 s  .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

/** Finds the index of the head of a (non-basal) semantic role phrase */
private int findSemanticRoleHeadIndex(Markable semroleMarkable) {

    // 1. Get the syntactic tree semroleMarkable is contained into
    final int srStart = semroleMarkable.getLeftmostDiscoursePosition();
    final int srEnd = semroleMarkable.getRightmostDiscoursePosition();

    for (int i = 0; i < parseTrees.size(); i++) {
        final int sentStart = parseStart.get(i);
        final int sentEnd = parseEnd.get(i);
        if (srStart >= sentStart && srEnd <= sentEnd) {
            // GOTCHA!
            Tree tree = parseTrees.get(i);

            // 2. Find the lowest node containing the markable at its leaves
            final int srOnset = srStart - sentStart;
            final int srOffset = srEnd - sentStart;

            final List<Tree> leaves = tree.getLeaves();
            final Tree startNode = leaves.get(srOnset);
            final Tree endNode = leaves.get(srOffset);

            Tree parentNode = startNode;
            while (parentNode != null && !parentNode.dominates(endNode)) {
                parentNode = parentNode.parent(tree);
            }//from w  w  w .  ja va2s .  c  o  m

            Tree lowestProjection = null;
            if (parentNode == null) {
                lowestProjection = startNode;
            } else {
                lowestProjection = parentNode;
            }

            // 3. Find the head and return its index
            Tree headWord = lowestProjection.headTerminal(headFinder);
            return Integer.valueOf(headWord.label().value().split(INDEX_SEPARATOR)[1]) + sentStart;
        }
    }
    return -1;
}

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./*from  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:elkfed.mmax.pipeline.StanfordParser.java

License:Apache License

/**
* Creates the printed form of a parse tree as a bracketed <code>String</code>
*
* @return String returns the <code>String</code>
*///  w  w w.java  2 s. co m
public String normalizeTree(Tree t, StringBuffer sb) {
    sb.append("(");
    sb.append(t.label().toString());
    Tree[] daughterTrees = t.children();
    for (int i = 0; i < daughterTrees.length; i++) {
        sb.append(" ");
        normalizeTree(daughterTrees[i], sb);
    }
    return sb.append(")").toString();
}

From source file:Engines.Test.StanfordParser.TreeHandling.java

License:Open Source License

private static Tree putOnBranch(TypedDependency dep, Tree tree) {
    /*/*from w  w w .j  a va 2  s  .  com*/
     * Each node is a tree with a single child 
     */
    Tree mySubtree = lstf.newTreeNode(dep.gov().backingLabel(), new LinkedList<Tree>());
    mySubtree.setValue("[<-" + dep.reln() + "-] " + dep.dep().value());//nudge in the dependency relation information 

    if (tree.children().length == 0) {
        if (tree.label().value().toString().equals("DUMMYROOT")) {
            tree.addChild(mySubtree);
            return tree;
        } else {
            //Shouldn't happen 
            System.err.println("Forgot to add a child earlier.");
            return null;
        }
    } else {
        //   System.err.println(dep.dep().label() +"\t[on]\t" + tree.label()); 
        for (Tree child : tree.children()) {
            //if dep is child's parent, insert dep between child and its parent 
            if (((CoreLabel) child.label()).index() == ((CoreLabel) ((Labeled) dep.dep()).label()).index()) {
                tree.removeChild(tree.objectIndexOf(child));
                mySubtree.addChild(child);
            }
        }
        if (mySubtree.children().length > 1) {
            tree.addChild(mySubtree);
            return tree;
        }

        for (Tree child : tree.children()) {
            //if dep is Child's sibling, or child 
            if (((CoreLabel) child.label()).index() == ((CoreLabel) ((Labeled) dep.gov()).label()).index()) {
                tree.addChild(mySubtree);
                return tree;
            }

            if (child.children().length > 0) {
                if (putOnBranch(dep, child) != null) {
                    return tree;
                }
            }
        }
    }
    //    tree.getLeaves() == null 
    //check its childrens, recurisively. 
    return null;
}

From source file:englishparser.EnglishParser.java

private static boolean isNP(Tree t) {
    //        return t.label().value().equals("NNS") || t.label().value().equals("NP") || t.label().value().equals("NN");
    return t.label().value().equals("NP");
}

From source file:englishparser.EnglishParser.java

private static boolean isNN(Tree t) {
    //        return t.label().value().equals("NNS") || t.label().value().equals("NP") || t.label().value().equals("NN");
    return t.label().value().equals("NN") || t.label().value().equals("NNS");
}