Example usage for edu.stanford.nlp.trees ModCollinsHeadFinder ModCollinsHeadFinder

List of usage examples for edu.stanford.nlp.trees ModCollinsHeadFinder ModCollinsHeadFinder

Introduction

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

Prototype

public ModCollinsHeadFinder() 

Source Link

Usage

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

License:Apache License

public String computePredicationType(Mention np) {
    String predType = null;/*from  w w w.jav a2s .  co  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.coref.mentions.Mention.java

License:Apache License

public String computePredicationAttr(Mention np) {
    String predAttr = null;//from www  . ja v  a  2s .co m
    Tree mentionTree = np.getHighestProjection();
    Tree sentenceTree = np.getSentenceTree();
    Tree parentNode = null;
    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) {
        if (parentNode.children()[1].children()[0].headTerminal(new ModCollinsHeadFinder()).toString()
                .equals("is")
                || parentNode.children()[1].children()[0].headTerminal(new ModCollinsHeadFinder()).toString()
                        .equals("are")
                || parentNode.children()[1].children()[0].headTerminal(new ModCollinsHeadFinder()).toString()
                        .equals("was")
                || parentNode.children()[1].children()[0].headTerminal(new ModCollinsHeadFinder()).toString()
                        .equals("were")) {
            if (!(parentNode.children()[1].children()[1] == null)) {// &&
                if (parentNode.children()[1].children()[1].label().toString().equals("ADJP")) {
                    predAttr = parentNode.children()[1].children()[1].headTerminal(new ModCollinsHeadFinder())
                            .toString();
                    // System.out.println("ATTR!!! " + predAttr);
                } else if (parentNode.children()[1].children()[1].label().toString().equals("NP")
                        && parentNode.children()[1].children()[1].headPreTerminal(new ModCollinsHeadFinder())
                                .label().toString().equals("JJS")) {
                    predAttr = parentNode.children()[1].children()[1].headTerminal(new ModCollinsHeadFinder())
                            .toString();
                    // System.out.println("ATTR!!! " + predAttr);
                }
            }
        }
    }
    return predAttr;
}

From source file:elkfed.expletives.EF_Tree.java

License:Apache License

public static Tree tree_pred(Tree node) {
    LabelFactory lf = new StringLabelFactory();
    Tree result = new LabeledScoredTreeNode();
    result.setLabel(lf.newLabel(node.value() + "-PRD"));
    if (node.value().equals("PP") && node.children().length == 2 && node.children()[0].value().equals("IN")) {
        Tree[] dtrs = new Tree[2];
        dtrs[0] = node.children()[0];/*from   ww w. j  a va2 s  .  co  m*/
        dtrs[1] = node.children()[1].headPreTerminal(new ModCollinsHeadFinder());
        result.setChildren(dtrs);
    }
    Tree[] dtrs = new Tree[1];
    dtrs[0] = node.headPreTerminal(new ModCollinsHeadFinder());
    result.setChildren(dtrs);
    return result;
}

From source file:elkfed.mmax.importer.DetermineMinSpan.java

License:Apache License

/** adds min_ids and min_span attributes so that
 *  BART's chunk-based coref resolution works
 *//*from  ww  w.  ja v a  2  s  . co  m*/
public static void addMinSpan(int start, Tree tree, IMarkable tag, List<String> tokens) {
    List<Tree> leaves = tree.getLeaves();
    Tree startNode;
    Tree endNode;
    try {
        startNode = leaves.get(tag.getLeftmostDiscoursePosition() - start);
        endNode = leaves.get(tag.getRightmostDiscoursePosition() - start);
        if (".".equals(endNode.parent(tree).value())) {
            //System.err.println("Sentence-final dot in "+
            //        tokens.subList(tag.start, tag.end + 1)+ "removed.");
            endNode = leaves.get(tag.getRightmostDiscoursePosition() - start - 1);
        }
    } catch (IndexOutOfBoundsException ex) {
        System.out.format("indices not found: %d,%d in %s [wanted: %s] [ctx: %s]",
                tag.getLeftmostDiscoursePosition() - start, tag.getRightmostDiscoursePosition() - start, leaves,
                tokens.subList(tag.getLeftmostDiscoursePosition(), tag.getRightmostDiscoursePosition() + 1),
                tokens.subList(start, tag.getLeftmostDiscoursePosition()));
        throw ex;
    }

    Tree parentNode = startNode;
    while (parentNode != null && !parentNode.dominates(endNode)) {
        parentNode = parentNode.parent(tree);
    }

    if (parentNode == null) {
        System.err.println("Could not match tree (1)");
        return;
    }

    if (startNode.leftCharEdge(tree) != parentNode.leftCharEdge(tree)
            || endNode.rightCharEdge(tree) != parentNode.rightCharEdge(tree)) {
        System.err.println("Could not match tree (2)");
        return;
    }

    Tree oldParent = parentNode;
    ModCollinsHeadFinder hf = new ModCollinsHeadFinder();
    // use the head finder to narrow down the span.
    // stop if (a) the head is no longer an NP or
    // (b) the NP is a conjunction
    go_up: while (true) {
        for (Tree t : parentNode.getChildrenAsList()) {
            if (t.value().equals("CC")) {
                break go_up;
            }
        }
        Tree headDtr = hf.determineHead(parentNode);
        if (headDtr == null || !headDtr.value().equals("NP")) {
            break;
        }
        parentNode = headDtr;
    }
    if (parentNode != oldParent) {
        List<Tree> newLeaves = parentNode.getLeaves();
        int newStart = start + find_same(leaves, newLeaves.get(0));
        int newEnd = newStart + newLeaves.size() - 1;
        if (newStart <= tag.getLeftmostDiscoursePosition()) {
            if (tag.getLeftmostDiscoursePosition() - newStart > 1) {
                System.err.println("NP node is too big:" + parentNode.toString() + " wanted:" + tokens
                        .subList(tag.getLeftmostDiscoursePosition(), tag.getRightmostDiscoursePosition() + 1)
                        + " in: " + tree);
                return;
            }
            for (int i = newStart - start; i < tag.getLeftmostDiscoursePosition() - start; i++) {
                System.err.println("additional prefix in syntax:" + leaves.get(i));
            }
            // switch NP boundary and tag boundary
            // (even [Connie Cheung]) => min_words="Connie Cheung"
            int tmp = tag.getLeftmostDiscoursePosition();
            tag.adjustSpan(newStart, tag.getRightmostDiscoursePosition());
            newStart = tmp;
        }
        assert newEnd <= tag.getRightmostDiscoursePosition();
        // this relies on MiniDiscourse's default word numbering
        // which is ugly but should generally work...
        if (newStart == newEnd) {
            tag.setAttributeValue("min_ids", "word_" + (newStart + 1));
        } else {
            tag.setAttributeValue("min_ids", String.format("word_%d..word_%d", newStart + 1, newEnd + 1));
        }
        StringBuffer buf = new StringBuffer();
        for (Tree t : newLeaves) {
            buf.append(t.toString().toLowerCase());
            buf.append(' ');
        }
        buf.setLength(buf.length() - 1);
        tag.setAttributeValue("min_words", buf.toString());
    }
}

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

License:Apache License

private ModCollinsHeadFinder getHeadFinder() {
    if (_headFinder == null)
        _headFinder = new ModCollinsHeadFinder();
    return _headFinder;
}