Search in sources :

Example 1 with AbstractCoreLabel

use of edu.stanford.nlp.ling.AbstractCoreLabel in project CoreNLP by stanfordnlp.

the class Mention method getContextHelper.

private static List<String> getContextHelper(List<? extends AbstractCoreLabel> words) {
    List<List<AbstractCoreLabel>> namedEntities = Generics.newArrayList();
    List<AbstractCoreLabel> ne = Generics.newArrayList();
    String previousNEType = "";
    int previousNEIndex = -1;
    for (int i = 0; i < words.size(); i++) {
        AbstractCoreLabel word = words.get(i);
        if (!word.ner().equals("O")) {
            if (!word.ner().equals(previousNEType) || previousNEIndex != i - 1) {
                ne = Generics.newArrayList();
                namedEntities.add(ne);
            }
            ne.add(word);
            previousNEType = word.ner();
            previousNEIndex = i;
        }
    }
    List<String> neStrings = new ArrayList<>();
    Set<String> hs = Generics.newHashSet();
    for (List<AbstractCoreLabel> namedEntity : namedEntities) {
        String ne_str = StringUtils.joinWords(namedEntity, " ");
        hs.add(ne_str);
    }
    neStrings.addAll(hs);
    return neStrings;
}
Also used : AbstractCoreLabel(edu.stanford.nlp.ling.AbstractCoreLabel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with AbstractCoreLabel

use of edu.stanford.nlp.ling.AbstractCoreLabel in project CoreNLP by stanfordnlp.

the class Mention method getPattern.

public String getPattern(List<AbstractCoreLabel> pTokens) {
    ArrayList<String> phrase_string = new ArrayList<>();
    String ne = "";
    for (AbstractCoreLabel token : pTokens) {
        if (token.index() == headWord.index()) {
            phrase_string.add(token.lemma());
            ne = "";
        } else if ((token.lemma().equals("and") || StringUtils.isPunct(token.lemma())) && pTokens.size() > pTokens.indexOf(token) + 1 && pTokens.indexOf(token) > 0 && pTokens.get(pTokens.indexOf(token) + 1).ner().equals(pTokens.get(pTokens.indexOf(token) - 1).ner())) {
        } else if (token.index() == headWord.index() - 1 && token.ner().equals(nerString)) {
            phrase_string.add(token.lemma());
            ne = "";
        } else if (!token.ner().equals("O")) {
            if (!token.ner().equals(ne)) {
                ne = token.ner();
                phrase_string.add("<" + ne + ">");
            }
        } else {
            phrase_string.add(token.lemma());
            ne = "";
        }
    }
    return StringUtils.join(phrase_string);
}
Also used : AbstractCoreLabel(edu.stanford.nlp.ling.AbstractCoreLabel) ArrayList(java.util.ArrayList)

Example 3 with AbstractCoreLabel

use of edu.stanford.nlp.ling.AbstractCoreLabel in project CoreNLP by stanfordnlp.

the class Mention method getPattern.

public String getPattern(List<AbstractCoreLabel> pTokens) {
    ArrayList<String> phrase_string = new ArrayList<>();
    String ne = "";
    for (AbstractCoreLabel token : pTokens) {
        if (token.index() == headWord.index()) {
            phrase_string.add(token.lemma());
            ne = "";
        } else if ((token.lemma().equals("and") || StringUtils.isPunct(token.lemma())) && pTokens.size() > pTokens.indexOf(token) + 1 && pTokens.indexOf(token) > 0 && pTokens.get(pTokens.indexOf(token) + 1).ner().equals(pTokens.get(pTokens.indexOf(token) - 1).ner())) {
        } else if (token.index() == headWord.index() - 1 && token.ner().equals(nerString)) {
            phrase_string.add(token.lemma());
            ne = "";
        } else if (!token.ner().equals("O")) {
            if (!token.ner().equals(ne)) {
                ne = token.ner();
                phrase_string.add("<" + ne + ">");
            }
        } else {
            phrase_string.add(token.lemma());
            ne = "";
        }
    }
    return StringUtils.join(phrase_string);
}
Also used : AbstractCoreLabel(edu.stanford.nlp.ling.AbstractCoreLabel) ArrayList(java.util.ArrayList)

Example 4 with AbstractCoreLabel

use of edu.stanford.nlp.ling.AbstractCoreLabel in project CoreNLP by stanfordnlp.

the class Mention method getContextHelper.

private static List<String> getContextHelper(List<? extends AbstractCoreLabel> words) {
    List<List<AbstractCoreLabel>> namedEntities = Generics.newArrayList();
    List<AbstractCoreLabel> ne = Generics.newArrayList();
    String previousNEType = "";
    int previousNEIndex = -1;
    for (int i = 0; i < words.size(); i++) {
        AbstractCoreLabel word = words.get(i);
        if (!word.ner().equals("O")) {
            if (!word.ner().equals(previousNEType) || previousNEIndex != i - 1) {
                ne = Generics.newArrayList();
                namedEntities.add(ne);
            }
            ne.add(word);
            previousNEType = word.ner();
            previousNEIndex = i;
        }
    }
    List<String> neStrings = new ArrayList<>();
    Set<String> hs = Generics.newHashSet();
    for (List<AbstractCoreLabel> namedEntity : namedEntities) {
        String ne_str = StringUtils.joinWords(namedEntity, " ");
        hs.add(ne_str);
    }
    neStrings.addAll(hs);
    return neStrings;
}
Also used : AbstractCoreLabel(edu.stanford.nlp.ling.AbstractCoreLabel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

AbstractCoreLabel (edu.stanford.nlp.ling.AbstractCoreLabel)4 ArrayList (java.util.ArrayList)4 List (java.util.List)2