Example usage for edu.stanford.nlp.semgraph SemanticGraph getPathToRoot

List of usage examples for edu.stanford.nlp.semgraph SemanticGraph getPathToRoot

Introduction

In this page you can find the example usage for edu.stanford.nlp.semgraph SemanticGraph getPathToRoot.

Prototype

public List<IndexedWord> getPathToRoot(IndexedWord vertex) 

Source Link

Document

Find the path from the given node to a root.

Usage

From source file:sleventextraction.SLEntity.java

public SLEntity(AceMention m, CoreMap senCM, SemanticGraph senSG) {
    this();//from w  w  w.j ava2 s  . co  m
    isArg = m.isArg;
    argProb = m.argProb;
    role = m.role;
    if (m.getParent() instanceof AceJet.AceEntity) {
        this.entitytype = ((AceEntity) m.getParent()).type;
        this.entitysubtype = ((AceEntity) m.getParent()).subtype;
    } else if (m.getParent() instanceof AceJet.AceTimex) {
        this.entitytype = "";
        this.entitysubtype = "";
    } else if (m.getParent() instanceof AceJet.AceValue) {
        this.entitytype = ((AceValue) m.getParent()).type;
        this.entitysubtype = ((AceValue) m.getParent()).subtype;
    } else {
        this.entitytype = "";
        this.entitysubtype = "";
    }
    this.mentiontype = m.getType();

    System.arraycopy(m.roleProb, 0, roleProb, 0, m.roleProb.length);
    ground = m.ground;
    span = senCM;
    SemanticGraph totaldep = span.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);

    this.content = m.text.trim();
    if (m.text.charAt(0) == '\"') {
        this.content = m.text.substring(1).trim();
    }
    if ("s\nb".equals(this.content)) {
        this.content = "his brother";
    } else if (" f".equals(this.content)) {
        this.content = "foreign";
    } else if ("-l".equals(this.content)) {
        this.content = "US-led";
    } else if ("s a".equals(this.content)) {
        if (span.toString().contains("Arafat's administration")) {
            this.content = "Arafat's administration";
        } else if (span.toString().contains("bus attack")) {
            this.content = "bus attack";
        }
    } else if ("33-month".equals(this.content)) {
        this.content = "33-month-old";
    } else if ("U.S".equals(this.content)) {
        this.content = "U.S.";
    } else if ("four-day".equals(this.content)) {
        this.content = "four-day-old";
    } else if ("U.N".equals(this.content)) {
        this.content = "U.N.";
    } else if ("33-year".equals(this.content)) {
        this.content = "33-year-old";
    }
    Annotation document = ParseSentence(this.content);
    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);

    CoreMap cm = sentences.get(0);
    int pathlength = -1, imin = 1000;
    for (int i = 0; i < senCM.get(TokensAnnotation.class).size(); i++) {
        IndexedWord debug = new IndexedWord(senCM.get(TokensAnnotation.class).get(i));
        boolean canmatch = true;
        for (int j = 0; j < cm.get(TokensAnnotation.class).size(); j++) {
            IndexedWord iw = new IndexedWord(senCM.get(TokensAnnotation.class).get(i + j));
            IndexedWord shortiw = new IndexedWord(cm.get(TokensAnnotation.class).get(j));
            if (!iw.word().equals(shortiw.word())) {
                if (SLEventExtraction.overlap(iw.word(), shortiw.word()) <= 0
                        || Double.isNaN(SLEventExtraction.overlap(iw.word(), shortiw.word()))) {
                    canmatch = false;
                    break;
                }
            }
        }
        if (canmatch) {
            for (int j = 0; j < cm.get(TokensAnnotation.class).size(); j++) {
                IndexedWord iw = new IndexedWord(senCM.get(TokensAnnotation.class).get(i + j));
                this.ContentIws.add(iw);
                try {
                    pathlength = totaldep.getPathToRoot(iw).size();
                } catch (java.lang.IllegalArgumentException err) {
                    pathlength = 100;
                }
                if (imin > pathlength) {
                    imin = pathlength;
                    this.head = iw;
                }
            }
            break;
        }
    }
    if (this.head == null) {
        return;
    }
    this.predicate = totaldep.getParent(this.head);
    if (this.predicate == null) {
        this.predicate = this.head;
    } else {
        IndexedWord curr = head;
        dep = totaldep.getEdge(predicate, curr).getRelation().getShortName();
        if (totaldep.getEdge(predicate, curr).getRelation().getSpecific() != null) {
            dep += "_" + totaldep.getEdge(predicate, curr).getRelation().getSpecific();
        }
    }

}