Search in sources :

Example 61 with Mention

use of edu.stanford.nlp.coref.data.Mention in project CoreNLP by stanfordnlp.

the class ProtobufAnnotationSerializer method loadSentenceMentions.

protected void loadSentenceMentions(CoreNLPProtos.Sentence proto, CoreMap sentence) {
    // add all Mentions for this sentence
    if (proto.getHasCorefMentionsAnnotation()) {
        sentence.set(CorefMentionsAnnotation.class, new ArrayList<>());
    }
    if (proto.getMentionsForCorefList().size() != 0) {
        HashMap<Integer, Mention> idToMention = new HashMap<>();
        List<Mention> sentenceMentions = sentence.get(CorefMentionsAnnotation.class);
        // initial set up of all mentions
        for (CoreNLPProtos.Mention protoMention : proto.getMentionsForCorefList()) {
            Mention m = fromProtoNoTokens(protoMention);
            sentenceMentions.add(m);
            idToMention.put(m.mentionID, m);
        }
        // populate sets of Mentions for each Mention
        for (CoreNLPProtos.Mention protoMention : proto.getMentionsForCorefList()) {
            Mention m = idToMention.get(protoMention.getMentionID());
            if (protoMention.getAppositionsList().size() != 0) {
                m.appositions = new HashSet<>();
                m.appositions.addAll(protoMention.getAppositionsList().stream().map(idToMention::get).collect(Collectors.toList()));
            }
            if (protoMention.getPredicateNominativesList().size() != 0) {
                m.predicateNominatives = new HashSet<>();
                m.predicateNominatives.addAll(protoMention.getPredicateNominativesList().stream().map(idToMention::get).collect(Collectors.toList()));
            }
            if (protoMention.getRelativePronounsList().size() != 0) {
                m.relativePronouns = new HashSet<>();
                m.relativePronouns.addAll(protoMention.getRelativePronounsList().stream().map(idToMention::get).collect(Collectors.toList()));
            }
            if (protoMention.getListMembersList().size() != 0) {
                m.listMembers = new HashSet<>();
                m.listMembers.addAll(protoMention.getListMembersList().stream().map(idToMention::get).collect(Collectors.toList()));
            }
            if (protoMention.getBelongToListsList().size() != 0) {
                m.belongToLists = new HashSet<>();
                m.belongToLists.addAll(protoMention.getBelongToListsList().stream().map(idToMention::get).collect(Collectors.toList()));
            }
        }
    }
}
Also used : RelationMention(edu.stanford.nlp.ie.machinereading.structure.RelationMention) Mention(edu.stanford.nlp.coref.data.Mention) EntityMention(edu.stanford.nlp.ie.machinereading.structure.EntityMention)

Example 62 with Mention

use of edu.stanford.nlp.coref.data.Mention in project CoreNLP by stanfordnlp.

the class ProtobufAnnotationSerializer method fromProtoNoTokens.

private Mention fromProtoNoTokens(CoreNLPProtos.Mention protoMention) {
    Mention returnMention = new Mention();
    // set enums
    if (protoMention.getMentionType() != null && !protoMention.getMentionType().equals("")) {
        returnMention.mentionType = Dictionaries.MentionType.valueOf(protoMention.getMentionType());
    }
    if (protoMention.getNumber() != null && !protoMention.getNumber().equals("")) {
        returnMention.number = Dictionaries.Number.valueOf(protoMention.getNumber());
    }
    if (protoMention.getGender() != null && !protoMention.getGender().equals("")) {
        returnMention.gender = Dictionaries.Gender.valueOf(protoMention.getGender());
    }
    if (protoMention.getAnimacy() != null && !protoMention.getAnimacy().equals("")) {
        returnMention.animacy = Dictionaries.Animacy.valueOf(protoMention.getAnimacy());
    }
    if (protoMention.getPerson() != null && !protoMention.getPerson().equals("")) {
        returnMention.person = Dictionaries.Person.valueOf(protoMention.getPerson());
    }
    // TO DO: if the original Mention had "" for this field it will be lost, should deal with this problem
    if (!protoMention.getHeadString().equals("")) {
        returnMention.headString = protoMention.getHeadString();
    }
    // TO DO: if the original Mention had "" for this field it will be lost, should deal with this problem
    if (!protoMention.getNerString().equals("")) {
        returnMention.nerString = protoMention.getNerString();
    }
    returnMention.startIndex = protoMention.getStartIndex();
    returnMention.endIndex = protoMention.getEndIndex();
    returnMention.headIndex = protoMention.getHeadIndex();
    returnMention.mentionID = protoMention.getMentionID();
    returnMention.originalRef = protoMention.getOriginalRef();
    returnMention.goldCorefClusterID = protoMention.getGoldCorefClusterID();
    returnMention.corefClusterID = protoMention.getCorefClusterID();
    returnMention.mentionNum = protoMention.getMentionNum();
    returnMention.sentNum = protoMention.getSentNum();
    returnMention.utter = protoMention.getUtter();
    returnMention.paragraph = protoMention.getParagraph();
    returnMention.isSubject = protoMention.getIsSubject();
    returnMention.isDirectObject = protoMention.getIsDirectObject();
    returnMention.isIndirectObject = protoMention.getIsIndirectObject();
    returnMention.isPrepositionObject = protoMention.getIsPrepositionObject();
    returnMention.hasTwin = protoMention.getHasTwin();
    returnMention.generic = protoMention.getGeneric();
    returnMention.isSingleton = protoMention.getIsSingleton();
    // handle the sets of Strings
    if (protoMention.getDependentsCount() != 0) {
        returnMention.dependents = new HashSet<>();
        returnMention.dependents.addAll(protoMention.getDependentsList());
    }
    if (protoMention.getPreprocessedTermsCount() != 0) {
        returnMention.preprocessedTerms = new ArrayList<>();
        returnMention.preprocessedTerms.addAll(protoMention.getPreprocessedTermsList());
    }
    return returnMention;
}
Also used : RelationMention(edu.stanford.nlp.ie.machinereading.structure.RelationMention) Mention(edu.stanford.nlp.coref.data.Mention) EntityMention(edu.stanford.nlp.ie.machinereading.structure.EntityMention)

Aggregations

Mention (edu.stanford.nlp.coref.data.Mention)62 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)27 CoreLabel (edu.stanford.nlp.ling.CoreLabel)27 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)21 ArrayList (java.util.ArrayList)20 TreeCoreAnnotations (edu.stanford.nlp.trees.TreeCoreAnnotations)17 CoreMap (edu.stanford.nlp.util.CoreMap)17 List (java.util.List)15 Tree (edu.stanford.nlp.trees.Tree)14 IntPair (edu.stanford.nlp.util.IntPair)14 CorefCluster (edu.stanford.nlp.coref.data.CorefCluster)12 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)10 ClassicCounter (edu.stanford.nlp.stats.ClassicCounter)9 EntityMention (edu.stanford.nlp.ie.machinereading.structure.EntityMention)7 RelationMention (edu.stanford.nlp.ie.machinereading.structure.RelationMention)7 ParserConstraint (edu.stanford.nlp.parser.common.ParserConstraint)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)6 Map (java.util.Map)6