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;
 }
示例#2
0
        // Update incompatibles for two clusters that are about to be merged
        public virtual void MergeIncompatibles(CorefCluster to, CorefCluster from)
        {
            IList <Pair <Pair <int, int>, Pair <int, int> > > replacements = new List <Pair <Pair <int, int>, Pair <int, int> > >();

            foreach (Pair <int, int> p in incompatibleClusters)
            {
                int other = null;
                if (p.first == from.clusterID)
                {
                    other = p.second;
                }
                else
                {
                    if (p.second == from.clusterID)
                    {
                        other = p.first;
                    }
                }
                if (other != null && other != to.clusterID)
                {
                    int cid1 = System.Math.Min(other, to.clusterID);
                    int cid2 = System.Math.Max(other, to.clusterID);
                    replacements.Add(Pair.MakePair(p, Pair.MakePair(cid1, cid2)));
                }
            }
            foreach (Pair <Pair <int, int>, Pair <int, int> > r in replacements)
            {
                incompatibleClusters.Remove(r.first.First(), r.first.Second());
                incompatibleClusters.Add(r.second.First(), r.second.Second());
            }
        }
示例#3
0
        public virtual bool IsIncompatible(CorefCluster c1, CorefCluster c2)
        {
            // Was any of the pairs of mentions marked as incompatible
            int cid1 = System.Math.Min(c1.clusterID, c2.clusterID);
            int cid2 = System.Math.Max(c1.clusterID, c2.clusterID);

            return(incompatibleClusters.Contains(cid1, cid2));
        }
示例#4
0
 /// <summary>Extract gold coref cluster information.</summary>
 public virtual void ExtractGoldCorefClusters()
 {
     goldCorefClusters = Generics.NewHashMap();
     foreach (IList <Mention> mentions in goldOrderedMentionsBySentence)
     {
         foreach (Mention m in mentions)
         {
             int id = m.goldCorefClusterID;
             if (id == -1)
             {
                 throw new Exception("No gold info");
             }
             CorefCluster c = goldCorefClusters[id];
             if (c == null)
             {
                 c = new CorefCluster(id);
                 goldCorefClusters[id] = c;
             }
             c.corefMentions.Add(m);
         }
     }
 }
示例#5
0
        public virtual void MergeAcronymCache(CorefCluster to, CorefCluster from)
        {
            TwoDimensionalSet <int, int> replacements = TwoDimensionalSet.HashSet();

            foreach (int first in acronymCache.FirstKeySet())
            {
                foreach (int second in acronymCache.Get(first).Keys)
                {
                    if (acronymCache.Get(first, second))
                    {
                        int other = null;
                        if (first == from.clusterID)
                        {
                            other = second;
                        }
                        else
                        {
                            if (second == from.clusterID)
                            {
                                other = first;
                            }
                        }
                        if (other != null && other != to.clusterID)
                        {
                            int cid1 = System.Math.Min(other, to.clusterID);
                            int cid2 = System.Math.Max(other, to.clusterID);
                            replacements.Add(cid1, cid2);
                        }
                    }
                }
            }
            foreach (int first_1 in replacements.FirstKeySet())
            {
                foreach (int second in replacements.SecondKeySet(first_1))
                {
                    acronymCache.Put(first_1, second, true);
                }
            }
        }