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()));
}
}
}
}
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;
}
Aggregations