public CorefChain(CorefCluster c, IDictionary <Mention, IntTuple> positions) { chainID = c.clusterID; // Collect mentions mentions = new List <CorefChain.CorefMention>(); mentionMap = Generics.NewHashMap(); CorefChain.CorefMention represents = null; foreach (Mention m in c.GetCorefMentions()) { CorefChain.CorefMention men = new CorefChain.CorefMention(m, positions[m]); mentions.Add(men); } mentions.Sort(new CorefChain.CorefMentionComparator()); // Find representative mention foreach (CorefChain.CorefMention men_1 in mentions) { IntPair position = new IntPair(men_1.sentNum, men_1.headIndex); if (!mentionMap.Contains(position)) { mentionMap[position] = Generics.NewHashSet <CorefChain.CorefMention>(); } mentionMap[position].Add(men_1); if (men_1.MoreRepresentativeThan(represents)) { represents = men_1; } } representative = represents; }
/// <summary>Delete a mention from this coreference chain.</summary> /// <param name="m">The mention to delete.</param> public virtual void DeleteMention(CorefChain.CorefMention m) { this.mentions.Remove(m); IntPair position = new IntPair(m.sentNum, m.headIndex); Sharpen.Collections.Remove(this.mentionMap, position); }
public override bool Equals(object aThat) { if (this == aThat) { return(true); } if (!(aThat is CorefChain.CorefMention)) { return(false); } CorefChain.CorefMention that = (CorefChain.CorefMention)aThat; if (mentionType != that.mentionType) { return(false); } if (number != that.number) { return(false); } if (gender != that.gender) { return(false); } if (animacy != that.animacy) { return(false); } if (startIndex != that.startIndex) { return(false); } if (endIndex != that.endIndex) { return(false); } if (headIndex != that.headIndex) { return(false); } if (corefClusterID != that.corefClusterID) { return(false); } if (mentionID != that.mentionID) { return(false); } if (sentNum != that.sentNum) { return(false); } if (!position.Equals(that.position)) { return(false); } // we ignore MentionSpan as it is constructed from the tokens // the mention is a span of, so if we know those spans are the // same, we should be able to ignore the actual text return(true); }
// return "(sentence:" + sentNum + ", startIndex:" + startIndex + "-endIndex:" + endIndex + ")"; private bool MoreRepresentativeThan(CorefChain.CorefMention m) { if (m == null) { return(true); } if (mentionType != m.mentionType) { return((mentionType == Dictionaries.MentionType.Proper) || (mentionType == Dictionaries.MentionType.Nominal && m.mentionType == Dictionaries.MentionType.Pronominal)); } else { // First, check length if (headIndex - startIndex > m.headIndex - m.startIndex) { return(true); } if (headIndex - startIndex < m.headIndex - m.startIndex) { return(false); } if (endIndex - startIndex > m.endIndex - m.startIndex) { return(true); } if (endIndex - startIndex < m.endIndex - m.startIndex) { return(false); } // Now check relative position if (sentNum < m.sentNum) { return(true); } if (sentNum > m.sentNum) { return(false); } if (headIndex < m.headIndex) { return(true); } if (headIndex > m.headIndex) { return(false); } if (startIndex < m.startIndex) { return(true); } if (startIndex > m.startIndex) { return(false); } // At this point they're equal... return(false); } }
/// <summary>Constructor required by CustomAnnotationSerializer</summary> public CorefChain(int cid, IDictionary <IntPair, ICollection <CorefChain.CorefMention> > mentionMap, CorefChain.CorefMention representative) { this.chainID = cid; this.representative = representative; this.mentionMap = mentionMap; this.mentions = new List <CorefChain.CorefMention>(); foreach (ICollection <CorefChain.CorefMention> ms in mentionMap.Values) { foreach (CorefChain.CorefMention m in ms) { this.mentions.Add(m); } } mentions.Sort(new CorefChain.CorefMentionComparator()); }