Example usage for edu.stanford.nlp.ling IndexedWord tag

List of usage examples for edu.stanford.nlp.ling IndexedWord tag

Introduction

In this page you can find the example usage for edu.stanford.nlp.ling IndexedWord tag.

Prototype

@Override
    public String tag() 

Source Link

Usage

From source file:ca.ualberta.exemplar.core.ArgumentExtraction.java

License:Open Source License

public void extractArgumentsTemplateC(CoreMap sentence, SemanticGraph dependencies,
        List<IndexedWord> relationalWords, RelationInstance instance) {

    //Dependencies where the relation is the governor
    {// w w w . j av a 2 s . c o m
        SemgrexMatcher matcher = patternC1.matcher(dependencies);
        while (matcher.find()) {
            IndexedWord rel = matcher.getNode("rel");
            IndexedWord arg = matcher.getNode("arg");
            String dep = matcher.getRelnString("dep");
            dep = ">" + dep;

            if (relationalWords.contains(rel)) {
                //System.out.println("ARG: " + getOriginalText(arg) + " ("+dep+", " + arg.ner() +")");
                String argumentType = rel.tag().substring(0, 2) + dep;
                Argument argument = getEntityFromHead(arg, sentence, dependencies, argumentType);
                instance.addArgument(argument);
            }
        }
    }

    // Dependencies where the entity is the governor
    {
        SemgrexMatcher matcher = patternC2.matcher(dependencies);
        while (matcher.find()) {
            IndexedWord rel = matcher.getNode("rel");
            IndexedWord arg = matcher.getNode("arg");
            String dep = matcher.getRelnString("dep");
            dep = "<" + dep;

            if (relationalWords.contains(rel)) {
                //System.out.println("ARG: " + getOriginalText(arg) + " ("+dep+", " + arg.ner() +")");
                String argumentType = rel.tag().substring(0, 2) + dep;
                Argument argument = getEntityFromHead(arg, sentence, dependencies, argumentType);
                instance.addArgument(argument);
            }
        }
    }

    assignArgumentTypesTemplateC(instance);
}

From source file:ca.ualberta.exemplar.core.ArgumentExtraction.java

License:Open Source License

public void extractArgumentsTemplateB(CoreMap sentence, SemanticGraph dependencies,
        List<IndexedWord> relationalWords, RelationInstance instance) {

    //Dependencies where the relation is the governor
    {//from ww w  . j  av a 2s  .  com
        SemgrexMatcher matcher = patternB1.matcher(dependencies);
        while (matcher.find()) {
            IndexedWord rel = matcher.getNode("rel");
            IndexedWord arg = matcher.getNode("arg");
            String dep = matcher.getRelnString("dep");
            dep = ">" + dep;

            if (relationalWords.contains(rel)) {
                //System.out.println("ARG: " + getOriginalText(arg) + " ("+dep+", " + arg.ner() +")");
                String argumentType = rel.tag().substring(0, 2) + dep;
                Argument argument = getEntityFromHead(arg, sentence, dependencies, argumentType);
                instance.addArgument(argument);
            }
        }
    }

    // Dependencies where the entity is the governor
    {
        SemgrexMatcher matcher = patternB2.matcher(dependencies);
        while (matcher.find()) {
            IndexedWord rel = matcher.getNode("rel");
            IndexedWord arg = matcher.getNode("arg");
            String dep = matcher.getRelnString("dep");
            dep = "<" + dep;

            if (relationalWords.contains(rel)) {
                //System.out.println("ARG: " + getOriginalText(arg) + " ("+dep+", " + arg.ner() +")");
                String argumentType = rel.tag().substring(0, 2) + dep;
                Argument argument = getEntityFromHead(arg, sentence, dependencies, argumentType);
                instance.addArgument(argument);
            }
        }
    }

    assignArgumentTypesTemplateB(instance);

}

From source file:ca.ualberta.exemplar.core.ArgumentExtraction.java

License:Open Source License

public void extractArgumentsTemplateA(CoreMap sentence, SemanticGraph dependencies,
        List<IndexedWord> relationalWords, RelationInstance instance) {

    //Dependencies where the relation is the governor
    {/*www  . j a  v  a2 s. c o m*/
        SemgrexMatcher matcher = patternA1.matcher(dependencies);
        while (matcher.find()) {
            IndexedWord rel = matcher.getNode("rel");
            IndexedWord arg = matcher.getNode("arg");
            String dep = matcher.getRelnString("dep");
            dep = ">" + dep;

            if (relationalWords.contains(rel)) {
                //System.out.println("ARG: " + getOriginalText(arg) + " ("+dep+", " + arg.ner() +")");
                String argumentType = rel.tag().substring(0, 2) + dep;
                Argument argument = getEntityFromHead(arg, sentence, dependencies, argumentType);
                instance.addArgument(argument);
            }
        }
    }

    // Dependencies where the entity is the governor
    {
        SemgrexMatcher matcher = patternA2.matcher(dependencies);
        while (matcher.find()) {
            IndexedWord rel = matcher.getNode("rel");
            IndexedWord arg = matcher.getNode("arg");
            String dep = matcher.getRelnString("dep");
            dep = "<" + dep;

            if (relationalWords.contains(rel)) {
                //System.out.println("ARG: " + getOriginalText(arg) + " ("+dep+", " + arg.ner() +")");
                String argumentType = rel.tag().substring(0, 2) + dep;
                Argument argument = getEntityFromHead(arg, sentence, dependencies, argumentType);
                instance.addArgument(argument);
            }
        }
    }

    assignArgumentTypesTemplateA(instance);

}

From source file:count_dep.Count_dep.java

public LinkedList<Event> GetEvents(SemanticGraph dependencies, CoreMap sentence) {
    LinkedList<Event> res = new LinkedList<>();
    LinkedList<IndexedWord> roots = new LinkedList<>();
    List<CoreLabel> words = sentence.get(TokensAnnotation.class);
    List<GrammaticalRelation> senserel = new LinkedList<>();
    senserel.add(GrammaticalRelation.valueOf("nsubj"));
    senserel.add(GrammaticalRelation.valueOf("dobj"));
    for (CoreLabel word : words) {
        if (word.tag().length() >= 2
                && ("VB".equals(word.tag().substring(0, 2)) || "NN".equals(word.tag().substring(0, 2)))) {
            IndexedWord iword = new IndexedWord(word);
            roots.add(iword);/* w w w  .j  a v a 2 s  .  c o  m*/
        }
    }
    for (IndexedWord word : roots) {
        Event e = new Event();
        e.trigger = word.word();
        try {
            Set<IndexedWord> children = dependencies.getChildren(word);
            children.stream().forEach((iw) -> {
                e.arguments.add(new EventArgument(iw.word(), ""));
            });
            if (dependencies.inDegree(word) > 0) {
                IndexedWord parent = dependencies.getParent(word);
                if (parent.tag().length() >= 2 && "VB".equals(parent.tag().substring(0, 2))) {
                    Set<IndexedWord> children1 = dependencies.getChildrenWithRelns(parent, senserel);
                    children1.remove(word);
                    children1.stream().forEach((iw) -> {
                        e.arguments.add(new EventArgument(iw.word(), ""));
                    });
                } else {
                    e.arguments.add(new EventArgument(dependencies.getParent(word).word(), ""));
                }
            }
        } catch (java.lang.IllegalArgumentException error) {
            continue;
        }
        res.add(e);
    }
    return res;
}

From source file:eu.ubipol.opinionmining.nlp_engine.Sentence.java

License:Open Source License

protected Sentence(SemanticGraph dependencies, int indexStart, DatabaseAdapter adp, int beginPosition) {
    IndexedWord rootWord = dependencies.getFirstRoot();
    sentenceRoot = new Token(rootWord.originalText(), rootWord.lemma(), rootWord.tag(), null, null,
            rootWord.index() + indexStart, rootWord.beginPosition(), rootWord.endPosition(), adp,
            beginPosition);/*from   ww  w  . j a  v a 2  s  .  co  m*/
    addChildTokens(sentenceRoot, rootWord, dependencies, indexStart, adp, beginPosition);
    sentenceRoot.transferScores();
    if (sentenceRoot.isAKeyword())
        sentenceRoot.addAspectScore(sentenceRoot.getScore(), sentenceRoot.getWeight(),
                sentenceRoot.getAspect());
    indexStart += dependencies.size();
}

From source file:eu.ubipol.opinionmining.nlp_engine.Sentence.java

License:Open Source License

private void addChildTokens(Token rootToken, IndexedWord currentRoot, SemanticGraph dependencies,
        int indexStart, DatabaseAdapter adp, int beginPosition) {
    for (IndexedWord child : dependencies.getChildren(currentRoot)) {
        Token childToken = new Token(child.originalText(), child.lemma(), child.tag(), rootToken,
                dependencies.getEdge(currentRoot, child).toString(), child.index() + indexStart,
                child.beginPosition(), child.endPosition(), adp, beginPosition);
        rootToken.addChildToken(childToken);
        addChildTokens(childToken, child, dependencies, indexStart, adp, beginPosition);
    }/*from   w  w  w.j a  v  a 2 s  .com*/
}

From source file:main.java.spatialrelex.markup.SpatialElement.java

public static SpatialElement setSpatialElementFeatures(Doc document, SpatialElement se) {
    IndexedWord iw = document.startOffsetIndexedWord.get(se.start);
    se.lemmaText = iw.lemma();// ww  w. j  a v  a 2  s.  c o m
    se.startToken = iw.index();
    se.endToken = iw.index();
    int i = se.start + 1;
    while (i < se.end) {
        if (!document.startOffsetIndexedWord.containsKey(i)) {
            i++;
            continue;
        }

        iw = document.startOffsetIndexedWord.get(i);
        se.endToken = iw.index();
        se.lemmaText += " " + iw.lemma();
        if (iw.tag().contains("NN")) {
            se.generalInquirerCategories = GeneralInquirer
                    .getGeneralInquirerCategories(se.generalInquirerCategories, iw.value().toLowerCase());
            se = WordNet.setWordNetSynsetsAndHypernyms(se, iw.tag(), "NN");
        } else if (iw.tag().contains("VB")) {
            se.verbNetClasses = VerbNet.getVerbNetClasses(se.verbNetClasses, iw.value().toLowerCase());
            se = WordNet.setWordNetSynsetsAndHypernyms(se, iw.tag(), "VB");
        }
        List<String> tokenSRLs = document.startOffsetSRLRoles.get(i);
        i++;

        if (tokenSRLs == null)
            continue;
        for (String tokenSRL : tokenSRLs) {
            if (se.srls.contains(tokenSRL))
                continue;
            se.srls.add(tokenSRL);
        }
    }

    return se;
}

From source file:semRewrite.datesandnumber.DateAndNumbersGeneration.java

License:Open Source License

/** ***************************************************************
 *///  ww  w  . j  ava 2s.c om
private String lemmatizeWord(IndexedWord measuredEntity) {

    String value = measuredEntity.value();
    if (!measuredEntity.tag().equals("NNP") || !measuredEntity.tag().equals("NNPS")) {
        value = measuredEntity.lemma();
    }
    return value;
}

From source file:semRewrite.datesandnumber.DatesAndDuration.java

License:Open Source License

/** ***************************************************************
   *///from  ww w.  j  a  v  a2s. c  o m
public void generateDurationSumoTerms(IndexedWord tempParent, Utilities utilities,
        semRewrite.datesandnumber.DateInfo startDateInfo, DateInfo endDateInfo) {

    if (tempParent != null) {
        if (Utilities.VerbTags.contains(tempParent.tag())) {
            utilities.sumoTerms.add("StartTime(" + tempParent.value() + "-" + tempParent.index() + "," + "time-"
                    + startDateInfo.getTimeCount() + ")");
            utilities.sumoTerms.add("EndTime(" + tempParent.value() + "-" + tempParent.index() + "," + "time-"
                    + endDateInfo.getTimeCount() + ")");

        }
        if (Utilities.nounTags.contains(tempParent.tag())) {
            if (tempParent.ner().equals("PERSON")) {
                utilities.sumoTerms.add("BirthDate(" + tempParent.value() + "-" + tempParent.index() + ","
                        + "time-" + startDateInfo.getTimeCount() + ")");
                utilities.sumoTerms.add("DeathDate(" + tempParent.value() + "-" + tempParent.index() + ","
                        + "time-" + endDateInfo.getTimeCount() + ")");
            } else {
                utilities.sumoTerms.add("StartTime(" + tempParent.value() + "-" + tempParent.index() + ","
                        + "time-" + startDateInfo.getTimeCount() + ")");
                utilities.sumoTerms.add("EndTime(" + tempParent.value() + "-" + tempParent.index() + ","
                        + "time-" + endDateInfo.getTimeCount() + ")");
            }
        }
        startDateInfo.setDurationFlag(true);
        endDateInfo.setDurationFlag(true);
    }
}

From source file:semRewrite.datesandnumber.DatesAndDuration.java

License:Open Source License

/** ***************************************************************
   *///from  w ww  .  ja  v  a  2 s.  co m
public IndexedWord getAssociatedWord(Utilities utilities, IndexedWord tempParent) {

    while (!tempParent.equals(utilities.StanfordDependencies.getFirstRoot())) {
        tempParent = utilities.StanfordDependencies.getParent(tempParent);
        if (Utilities.VerbTags.contains(tempParent.tag()) || Utilities.nounTags.contains(tempParent.tag())) {
            break;
        }
    }
    return tempParent;
}