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

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

Introduction

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

Prototype

public Tree getChild(int i) 

Source Link

Document

Return the child at some daughter index.

Usage

From source file:uk.ac.gla.mir.util.TripletExtractor.java

License:Open Source License

private static Entity getObject(final Tree sentence, final Tree root, final Tree subjectTree) {
    Entity e = new Entity();
    if (sentence == null)
        return e;
    final List<Tree> childList = sentence.getChildrenAsList();
    for (int i = 0; i < childList.size(); i++) {
        final Tree tempTree = childList.get(i);
        if ((isNounPhrase(tempTree) || isPrepositionPhrase(tempTree)) && tempTree != subjectTree) {
            Tree object = getSubjectNode(tempTree, false);
            if (object != null && object.getChildrenAsList().size() > 0) {
                e.type = object.value();
                e.attributes = getSubjectAttributes(tempTree, true, root, object);
                e.name = object.getChild(0).value();
                e.tree = object;//from   w  w  w .  j av  a  2s  . com
            }
        } else if (isAdjectivePhrase(tempTree) && tempTree != subjectTree) {
            Tree object = getAdjectiveNode(tempTree);
            if (object != null && object.getChildrenAsList().size() > 0) {
                e.attributes = getSubjectAttributes(tempTree, true, root, object);
                e.name = object.getChild(0).value();
                e.type = object.value();
                e.tree = object;
            }
        }
        if (!e.name.trim().equalsIgnoreCase("")) {
            break;
        }
    }
    return e;
}

From source file:uk.ac.gla.mir.util.TripletExtractor.java

License:Open Source License

private static Entity getVerb(final Tree sentence, final Tree root, final boolean checkWordNet) {
    Entity e = new Entity();
    verbDepth = 0;//www.ja  v a 2s. c om
    deepestVerbPhrase = sentence;
    Tree verb = getDeepestVerb(sentence, 0, checkWordNet);
    if (verb != null && verb.getChildrenAsList().size() > 0) {
        List<Entity> attribs = getVerbAttributes(deepestVerbPhrase, true, root, verb);
        e.attributes = attribs;
        e.type = verb.value();
        e.name = verb.getChild(0).value();
        e.tree = verb;
        e.treeParent = sentence;
    }
    return e;
}

From source file:uk.ac.gla.mir.util.TripletExtractor.java

License:Open Source License

private static Tree getDeepestVerb(Tree tempTree, int depth, boolean checkwordNet) {
    Tree verb = null;// ww w. j a  va2s. c o m
    final List<Tree> childList = tempTree.getChildrenAsList();
    for (int i = 0; i < childList.size(); i++) {
        final Tree child = childList.get(i);
        String word = child.getChildrenAsList().size() > 0 ? child.getChild(0).value() : "";

        if ((isVerb(child) || checkwordNet) && depth >= verbDepth) {
            deepestVerbPhrase = tempTree;
            verbDepth = depth;
            verb = child;
        } else {
            if (!isNounPhrase(child) && !child.value().equalsIgnoreCase("ADVP")
                    && !child.value().equalsIgnoreCase("PRT")) {
                Tree tmp = getDeepestVerb(child, depth + 1, checkwordNet);
                if (tmp != null)
                    verb = tmp;
            }
        }
    }
    return verb;
}

From source file:wtute.engine.TreeHelper.java

public static Tree nextSibling(Tree child, Tree root) {
    Tree parent = child.parent(root);
    List<Tree> preList = parent.getChildrenAsList();
    int indexOfChild = preList.indexOf(child);

    try {/* w  ww.  j a  v  a 2 s .c  om*/
        return parent.getChild(indexOfChild + 1);
    } catch (Exception e) {
        return null;
    }
}

From source file:wtute.engine.TreeHelper.java

public static Tree prevSibling(Tree child, Tree root) {
    Tree parent = child.parent(root);
    List<Tree> postList = parent.getChildrenAsList();
    int indexOfChild = postList.indexOf(child);
    ListIterator liter = postList.listIterator();

    try {/*from   w  w  w  .  ja va 2s .  c  o m*/
        return parent.getChild(indexOfChild - 1);
    } catch (Exception e) {
        return null;
    }
}