/// <summary>This constructor is used to recreate a CorefMention following serialization.</summary> public CorefMention(Dictionaries.MentionType mentionType, Dictionaries.Number number, Dictionaries.Gender gender, Dictionaries.Animacy animacy, int startIndex, int endIndex, int headIndex, int corefClusterID, int mentionID, int sentNum, IntTuple position, string mentionSpan) { this.mentionType = mentionType; this.number = number; this.gender = gender; this.animacy = animacy; this.startIndex = startIndex; this.endIndex = endIndex; this.headIndex = headIndex; this.corefClusterID = corefClusterID; this.mentionID = mentionID; this.sentNum = sentNum; this.position = position; this.mentionSpan = mentionSpan; }
/// <summary>This constructor builds the external CorefMention class from the internal Mention.</summary> public CorefMention(Mention m, IntTuple pos) { mentionType = m.mentionType; number = m.number; gender = m.gender; animacy = m.animacy; startIndex = m.startIndex + 1; endIndex = m.endIndex + 1; headIndex = m.headIndex + 1; corefClusterID = m.corefClusterID; sentNum = m.sentNum + 1; mentionID = m.mentionID; mentionSpan = m.SpanToString(); // index starts from 1 position = new IntTuple(2); position.Set(0, pos.Get(0) + 1); position.Set(1, pos.Get(1) + 1); m.headWord.Set(typeof(CorefCoreAnnotations.CorefClusterIdAnnotation), corefClusterID); }
/// <summary>Loads the CorefChain objects from the serialized buffer.</summary> /// <param name="reader">the buffer</param> /// <returns>A map from cluster id to clusters</returns> /// <exception cref="System.IO.IOException"/> private static IDictionary <int, CorefChain> LoadCorefChains(BufferedReader reader) { string line = reader.ReadLine().Trim(); if (line.IsEmpty()) { return(null); } int clusterCount = System.Convert.ToInt32(line); IDictionary <int, CorefChain> chains = Generics.NewHashMap(); // read each cluster for (int c = 0; c < clusterCount; c++) { line = reader.ReadLine().Trim(); string[] bits = line.Split("\\s"); int cid = System.Convert.ToInt32(bits[0]); int mentionCount = System.Convert.ToInt32(bits[1]); IDictionary <IntPair, ICollection <CorefChain.CorefMention> > mentionMap = Generics.NewHashMap(); CorefChain.CorefMention representative = null; // read each mention in this cluster for (int m = 0; m < mentionCount; m++) { line = reader.ReadLine(); bits = line.Split("\\s"); IntPair key = new IntPair(System.Convert.ToInt32(bits[0]), System.Convert.ToInt32(bits[1])); bool rep = bits[2].Equals("1"); Dictionaries.MentionType mentionType = ParseMentionType(bits[3]); Dictionaries.Number number = ParseNumber(bits[4]); Dictionaries.Gender gender = ParseGender(bits[5]); Dictionaries.Animacy animacy = ParseAnimacy(bits[6]); int startIndex = System.Convert.ToInt32(bits[7]); int endIndex = System.Convert.ToInt32(bits[8]); int headIndex = System.Convert.ToInt32(bits[9]); int clusterID = System.Convert.ToInt32(bits[10]); int mentionID = System.Convert.ToInt32(bits[11]); int sentNum = System.Convert.ToInt32(bits[12]); int posLen = System.Convert.ToInt32(bits[13]); int[] posElems = new int[posLen]; for (int i = 0; i < posLen; i++) { posElems[i] = System.Convert.ToInt32(bits[14 + i]); } IntTuple position = new IntTuple(posElems); string span = UnescapeSpace(bits[14 + posLen]); CorefChain.CorefMention mention = new CorefChain.CorefMention(mentionType, number, gender, animacy, startIndex, endIndex, headIndex, clusterID, mentionID, sentNum, position, span); ICollection <CorefChain.CorefMention> mentionsWithThisHead = mentionMap[key]; if (mentionsWithThisHead == null) { mentionsWithThisHead = Generics.NewHashSet(); mentionMap[key] = mentionsWithThisHead; } mentionsWithThisHead.Add(mention); if (rep) { representative = mention; } } // construct the cluster CorefChain chain = new CorefChain(cid, mentionMap, representative); chains[cid] = chain; } reader.ReadLine(); return(chains); }