/// <summary> /// Creates a new entity based on the specified mention and its specified gender and number properties. /// </summary> /// <param name="mention"> /// The first mention of this entity. /// </param> /// <param name="gender"> /// The gender of this entity. /// </param> /// <param name="genderProbability"> /// The probability that the specified gender is correct. /// </param> /// <param name="number"> /// The number for this entity. /// </param> /// <param name="numberProbability"> /// The probability that the specified number is correct. /// </param> public DiscourseEntity(Mention.MentionContext mention, Similarity.GenderEnum gender, double genderProbability, Similarity.NumberEnum number, double numberProbability) : base(mention) { mGender = gender; mGenderProbability = genderProbability; mNumber = number; mNumberProbability = numberProbability; }
/// <summary> /// Creates a new entity based on the specified mention. /// </summary> /// <param name="mention"> /// The first mention of this entity. /// </param> public DiscourseEntity(Mention.MentionContext mention) : base(mention) { Gender = Similarity.GenderEnum.Unknown; Number = Similarity.NumberEnum.Unknown; }
protected internal override Number ComputeNumber(Mention.MentionContext mention) { return(mCompatibilityModel.ComputeNumber(mention)); }
protected internal abstract Number ComputeNumber(MentionContext mention);
protected internal abstract Gender ComputeGender(MentionContext mention);
public virtual MentionContext[] ConstructMentionContexts(Mention.Mention[] mentions) { if (mentions == null) { throw new ArgumentNullException("mentions"); } int mentionInSentenceIndex = -1; int mentionsInSentenceCount = -1; int previousSentenceIndex = -1; var contexts = new MentionContext[mentions.Length]; for (int mentionIndex = 0, mentionCount = mentions.Length; mentionIndex < mentionCount; mentionIndex++) { IParse mentionParse = mentions[mentionIndex].Parse; if (mentionParse == null) { 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); 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; }
/// <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); } } }
/// <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) { 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) { validEntity = false; } DiscourseEntity discourseEntity = CheckForMerges(discourseModel, mEntities); if (validEntity) { UpdateExtent(discourseModel, mention, discourseEntity, mUseDiscourseModel); } }
/// <summary> /// Adds the specified mention to this discourse element. /// </summary> /// <param name="mention"> /// The mention to be added. /// </param> public virtual void AddMention(Mention.MentionContext mention) { mExtents.Add(mention); mLastExtent = mention; }
/// <summary> /// Creates a new discourse element which contains the specified mention. /// </summary> /// <param name="mention"> /// The mention which begins this discourse element. /// </param> protected DiscourseElement(Mention.MentionContext mention) { mExtents = new List <Mention.MentionContext>(1); mLastExtent = mention; mExtents.Add(mention); }
/// <summary> /// Creates a new discourse element which contains the specified mention. /// </summary> /// <param name="mention"> /// The mention which begins this discourse element. /// </param> protected DiscourseElement(Mention.MentionContext mention) { mExtents = new List<Mention.MentionContext>(1); mLastExtent = mention; mExtents.Add(mention); }
/// <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); }