예제 #1
0
        /// <summary>
        /// Removes the specified mention to an entity in the specified discourse model or creates a new entity for the mention.
        /// </summary>
        /// <param name="mention">
        /// The mention to resolve.
        /// </param>
        /// <param name="discourseModel">
        /// The discourse model of existing entities.
        /// </param>
        protected internal virtual void Resolve(MentionContext mention, DiscourseModel discourseModel)
        {
            //System.err.println("AbstractLinker.resolve: "+mode+"("+econtext.id+") "+econtext.toText());
            bool validEntity = true;             // true if we should add this entity to the dm
            bool canResolve  = false;

            for (int currentResolver = 0; currentResolver < mResolvers.Length; currentResolver++)
            {
                if (mResolvers[currentResolver].CanResolve(mention))
                {
                    if (mMode == LinkerMode.Test)
                    {
                        mEntities[currentResolver] = mResolvers[currentResolver].Resolve(mention, discourseModel);
                        canResolve = true;
                    }
                    else if (mMode == LinkerMode.Train)
                    {
                        mEntities[currentResolver] = mResolvers[currentResolver].Retain(mention, discourseModel);
                        if (currentResolver + 1 != mResolvers.Length)
                        {
                            canResolve = true;
                        }
                    }
                    else if (mMode == LinkerMode.Eval)
                    {
                        mEntities[currentResolver] = mResolvers[currentResolver].Retain(mention, discourseModel);
                        //DiscourseEntity rde = resolvers[ri].resolve(mention, discourseModel);
                        //eval.update(rde == entities[ri], ri, entities[ri], rde);
                    }
                    else
                    {
                        System.Console.Error.WriteLine("AbstractLinker.Unknown mode: " + mMode);
                    }
                    if (currentResolver == mSingularPronounIndex && mEntities[currentResolver] == null)
                    {
                        validEntity = false;
                    }
                }
                else
                {
                    mEntities[currentResolver] = null;
                }
            }
            if (!canResolve && mRemoveUnresolvedMentions)
            {
                //System.err.println("No resolver for: "+econtext.toText()+ " head="+econtext.headTokenText+" "+econtext.headTokenTag);
                validEntity = false;
            }
            DiscourseEntity discourseEntity = CheckForMerges(discourseModel, mEntities);

            if (validEntity)
            {
                UpdateExtent(discourseModel, mention, discourseEntity, mUseDiscourseModel);
            }
        }
예제 #2
0
        /// <summary>
        /// Removes the specified mention to an entity in the specified discourse model or creates a new entity for the mention.
        /// </summary>
        /// <param name="mention">
        /// The mention to resolve.
        /// </param>
        /// <param name="discourseModel">
        /// The discourse model of existing entities.
        /// </param>
        protected internal virtual void Resolve(MentionContext mention, DiscourseModel discourseModel)
        {
            var validEntity = true;             // true if we should add this entity to the dm
            var canResolve  = false;

            for (var currentResolver = 0; currentResolver < mResolvers.Length; currentResolver++)
            {
                if (mResolvers[currentResolver].CanResolve(mention))
                {
                    if (mMode == LinkerMode.Test)
                    {
                        mEntities[currentResolver] = mResolvers[currentResolver].Resolve(mention, discourseModel);
                        canResolve = true;
                    }
                    else if (mMode == LinkerMode.Train)
                    {
                        mEntities[currentResolver] = mResolvers[currentResolver].Retain(mention, discourseModel);
                        if (currentResolver + 1 != mResolvers.Length)
                        {
                            canResolve = true;
                        }
                    }
                    else if (mMode == LinkerMode.Eval)
                    {
                        mEntities[currentResolver] = mResolvers[currentResolver].Retain(mention, discourseModel);
                        //DiscourseEntity rde = resolvers[ri].resolve(mention, discourseModel);
                        //eval.update(rde == entities[ri], ri, entities[ri], rde);
                    }
                    else
                    {
                        Console.Error.WriteLine("AbstractLinker.Unknown mode: " + mMode);
                    }
                    if (currentResolver == mSingularPronounIndex && mEntities[currentResolver] == null)
                    {
                        validEntity = false;
                    }
                }
                else
                {
                    mEntities[currentResolver] = null;
                }
            }
            if (!canResolve && mRemoveUnresolvedMentions)
            {
                validEntity = false;
            }
            var discourseEntity = CheckForMerges(discourseModel, mEntities);

            if (validEntity)
            {
                UpdateExtent(discourseModel, mention, discourseEntity, mUseDiscourseModel);
            }
        }
예제 #3
0
        public virtual MentionContext[] ConstructMentionContexts(Mention.Mention[] mentions)
        {
            if (mentions == null)
            {
                throw new ArgumentNullException("mentions");
            }

            int mentionInSentenceIndex  = -1;
            int mentionsInSentenceCount = -1;
            int previousSentenceIndex   = -1;

            MentionContext[] contexts = new MentionContext[mentions.Length];
            for (int mentionIndex = 0, mentionCount = mentions.Length; mentionIndex < mentionCount; mentionIndex++)
            {
                IParse mentionParse = mentions[mentionIndex].Parse;
                //System.err.println("AbstractLinker.constructMentionContexts: mentionParse="+mentionParse);
                if (mentionParse == null)
                {
                    System.Console.Error.WriteLine("no parse for " + mentions[mentionIndex]);
                }
                int sentenceIndex = mentionParse.SentenceNumber;
                if (sentenceIndex != previousSentenceIndex)
                {
                    mentionInSentenceIndex  = 0;
                    previousSentenceIndex   = sentenceIndex;
                    mentionsInSentenceCount = 0;
                    for (int currentMentionInSentence = mentionIndex; currentMentionInSentence < mentions.Length; currentMentionInSentence++)
                    {
                        if (sentenceIndex != mentions[currentMentionInSentence].Parse.SentenceNumber)
                        {
                            break;
                        }
                        mentionsInSentenceCount++;
                    }
                }
                contexts[mentionIndex] = new MentionContext(mentions[mentionIndex], mentionInSentenceIndex, mentionsInSentenceCount, mentionIndex, sentenceIndex, HeadFinder);
                //System.err.println("AbstractLinker.constructMentionContexts: mi="+mi+" sn="+mentionParse.getSentenceNumber()+" extent="+mentions[mi]+" parse="+mentionParse.getSpan()+" mc="+contexts[mi].toText());
                contexts[mentionIndex].Id = mentions[mentionIndex].Id;
                mentionInSentenceIndex++;
                if (mMode != LinkerMode.Sim)
                {
                    Gender gender = ComputeGender(contexts[mentionIndex]);
                    contexts[mentionIndex].SetGender(gender.Type, gender.Confidence);
                    Number number = ComputeNumber(contexts[mentionIndex]);
                    contexts[mentionIndex].SetNumber(number.Type, number.Confidence);
                }
            }
            return(contexts);
        }
예제 #4
0
        public virtual MentionContext[] ConstructMentionContexts(Mention.Mention[] mentions)
        {
            if (mentions == null)
            {
                throw new ArgumentNullException("mentions");
            }

            var mentionInSentenceIndex  = -1;
            var mentionsInSentenceCount = -1;
            var previousSentenceIndex   = -1;
            var contexts = new MentionContext[mentions.Length];

            for (int mentionIndex = 0, mentionCount = mentions.Length; mentionIndex < mentionCount; mentionIndex++)
            {
                var mentionParse = mentions[mentionIndex].Parse;
                if (mentionParse == null)
                {
                    Console.Error.WriteLine("no parse for " + mentions[mentionIndex]);
                }
                var sentenceIndex = mentionParse.SentenceNumber;
                if (sentenceIndex != previousSentenceIndex)
                {
                    mentionInSentenceIndex  = 0;
                    previousSentenceIndex   = sentenceIndex;
                    mentionsInSentenceCount = 0;
                    for (var currentMentionInSentence = mentionIndex; currentMentionInSentence < mentions.Length; currentMentionInSentence++)
                    {
                        if (sentenceIndex != mentions[currentMentionInSentence].Parse.SentenceNumber)
                        {
                            break;
                        }
                        mentionsInSentenceCount++;
                    }
                }
                contexts[mentionIndex]    = new MentionContext(mentions[mentionIndex], mentionInSentenceIndex, mentionsInSentenceCount, mentionIndex, sentenceIndex, HeadFinder);
                contexts[mentionIndex].Id = mentions[mentionIndex].Id;
                mentionInSentenceIndex++;
                if (mMode != LinkerMode.Sim)
                {
                    var gender = ComputeGender(contexts[mentionIndex]);
                    contexts[mentionIndex].SetGender(gender.Type, gender.Confidence);
                    var number = ComputeNumber(contexts[mentionIndex]);
                    contexts[mentionIndex].SetNumber(number.Type, number.Confidence);
                }
            }
            return(contexts);
        }
예제 #5
0
 /// <summary>
 /// Updates the specified discourse model with the specified mention as coreferent with the specified entity.
 /// </summary>
 /// <param name="discourseModel">
 /// The discourse model
 /// </param>
 /// <param name="mention">
 /// The mention to be added to the specified entity.
 /// </param>
 /// <param name="entity">
 /// The entity which is mentioned by the specified mention.
 /// </param>
 /// <param name="useDiscourseModel">
 /// Whether the mentions should be kept as an entiy or simply co-indexed.
 /// </param>
 protected internal virtual void UpdateExtent(DiscourseModel discourseModel, MentionContext mention, DiscourseEntity entity, bool useDiscourseModel)
 {
     if (useDiscourseModel)
     {
         if (entity != null)
         {
             //System.err.println("AbstractLinker.updateExtent: addingExtent:
             // "+econtext.toText());
             if (entity.GenderProbability < mention.GenderProbability)
             {
                 entity.Gender            = mention.GetGender();
                 entity.GenderProbability = mention.GenderProbability;
             }
             if (entity.NumberProbability < mention.NumberProbability)
             {
                 entity.Number            = mention.GetNumber();
                 entity.NumberProbability = mention.NumberProbability;
             }
             entity.AddMention(mention);
             discourseModel.MentionEntity(entity);
         }
         else
         {
             //System.err.println("AbstractLinker.updateExtent: creatingExtent:
             // "+econtext.toText()+" "+econtext.gender+" "+econtext.number);
             entity = new DiscourseEntity(mention, mention.GetGender(), mention.GenderProbability, mention.GetNumber(), mention.NumberProbability);
             discourseModel.AddEntity(entity);
         }
     }
     else
     {
         if (entity != null)
         {
             DiscourseEntity newEntity = new DiscourseEntity(mention, mention.GetGender(), mention.GenderProbability, mention.GetNumber(), mention.NumberProbability);
             discourseModel.AddEntity(newEntity);
             newEntity.Id = entity.Id;
         }
         else
         {
             DiscourseEntity newEntity = new DiscourseEntity(mention, mention.GetGender(), mention.GenderProbability, mention.GetNumber(), mention.NumberProbability);
             discourseModel.AddEntity(newEntity);
         }
     }
     //System.err.println(de1);
 }
예제 #6
0
 public CorefParse(CoreferencerTool outerInstance, IList <Parse> parses, DiscourseEntity[] entities)
 {
     this.outerInstance = outerInstance;
     this.parses        = parses;
     parseMap           = new Dictionary <Parse, int?>();
     for (int ei = 0, en = entities.Length; ei < en; ei++)
     {
         if (entities[ei].NumMentions > 1)
         {
             for (IEnumerator <MentionContext> mi = entities[ei].Mentions; mi.MoveNext();)
             {
                 MentionContext mc           = mi.Current;
                 Parse          mentionParse = ((DefaultParse)mc.Parse).Parse;
                 parseMap[mentionParse] = ei + 1;
             }
         }
     }
 }
예제 #7
0
 /// <summary>
 /// Updates the specified discourse model with the specified mention as coreferent with the specified entity.
 /// </summary>
 /// <param name="discourseModel">
 /// The discourse model
 /// </param>
 /// <param name="mention">
 /// The mention to be added to the specified entity.
 /// </param>
 /// <param name="entity">
 /// The entity which is mentioned by the specified mention.
 /// </param>
 /// <param name="useDiscourseModel">
 /// Whether the mentions should be kept as an entiy or simply co-indexed.
 /// </param>
 protected internal virtual void UpdateExtent(DiscourseModel discourseModel, MentionContext mention, DiscourseEntity entity, bool useDiscourseModel)
 {
     if (useDiscourseModel)
     {
         if (entity != null)
         {
             if (entity.GenderProbability < mention.GenderProbability)
             {
                 entity.Gender            = mention.GetGender();
                 entity.GenderProbability = mention.GenderProbability;
             }
             if (entity.NumberProbability < mention.NumberProbability)
             {
                 entity.Number            = mention.GetNumber();
                 entity.NumberProbability = mention.NumberProbability;
             }
             entity.AddMention(mention);
             discourseModel.MentionEntity(entity);
         }
         else
         {
             entity = new DiscourseEntity(mention, mention.GetGender(), mention.GenderProbability, mention.GetNumber(), mention.NumberProbability);
             discourseModel.AddEntity(entity);
         }
     }
     else
     {
         if (entity != null)
         {
             var newEntity = new DiscourseEntity(mention, mention.GetGender(), mention.GenderProbability, mention.GetNumber(), mention.NumberProbability);
             discourseModel.AddEntity(newEntity);
             newEntity.Id = entity.Id;
         }
         else
         {
             var newEntity = new DiscourseEntity(mention, mention.GetGender(), mention.GenderProbability, mention.GetNumber(), mention.NumberProbability);
             discourseModel.AddEntity(newEntity);
         }
     }
 }
예제 #8
0
 protected internal abstract Number ComputeNumber(MentionContext mention);
예제 #9
0
 protected internal abstract Gender ComputeGender(MentionContext mention);
예제 #10
0
 protected internal override Number ComputeNumber(MentionContext mention)
 {
     return(mCompatibilityModel.ComputeNumber(mention));
 }