/// <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); } }
public virtual DiscourseEntity[] GetEntitiesFromMentions(Mention.Mention[] mentions) { MentionContext[] extentContexts = ConstructMentionContexts(mentions); var discourseModel = new DiscourseModel(); for (int extentIndex = 0; extentIndex < extentContexts.Length; extentIndex++) { Resolve(extentContexts[extentIndex], discourseModel); } return(discourseModel.Entities); }
/// <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); } }
public virtual DiscourseEntity[] GetEntitiesFromMentions(Mention.Mention[] mentions) { MentionContext[] extentContexts = ConstructMentionContexts(mentions); DiscourseModel discourseModel = new DiscourseModel(); for (int extentIndex = 0; extentIndex < extentContexts.Length; extentIndex++) { //System.err.println(ei+" "+extentContexts[ei].toText()); Resolve(extentContexts[extentIndex], discourseModel); } return(discourseModel.Entities); }
/// <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); }
protected internal virtual DiscourseEntity CheckForMerges(DiscourseModel discourseModel, DiscourseEntity[] discourseEntities) { DiscourseEntity firstDiscourseEntity = discourseEntities[0]; for (int discourseEntityIndex = 1; discourseEntityIndex < discourseEntities.Length; discourseEntityIndex++) { DiscourseEntity secondDiscourseEntity = discourseEntities[discourseEntityIndex]; //temporary variable if (secondDiscourseEntity != null) { if (firstDiscourseEntity != null && firstDiscourseEntity != secondDiscourseEntity) { discourseModel.MergeEntities(firstDiscourseEntity, secondDiscourseEntity, 1); } else { firstDiscourseEntity = secondDiscourseEntity; } } } return(firstDiscourseEntity); }
/// <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); } } }
public virtual DiscourseEntity[] GetEntitiesFromMentions(Mention.Mention[] mentions) { MentionContext[] extentContexts = ConstructMentionContexts(mentions); var discourseModel = new DiscourseModel(); for (int extentIndex = 0; extentIndex < extentContexts.Length; extentIndex++) { Resolve(extentContexts[extentIndex], discourseModel); } return discourseModel.Entities; }
protected internal virtual DiscourseEntity CheckForMerges(DiscourseModel discourseModel, DiscourseEntity[] discourseEntities) { DiscourseEntity firstDiscourseEntity = discourseEntities[0]; for (int discourseEntityIndex = 1; discourseEntityIndex < discourseEntities.Length; discourseEntityIndex++) { DiscourseEntity secondDiscourseEntity = discourseEntities[discourseEntityIndex]; //temporary variable if (secondDiscourseEntity != null) { if (firstDiscourseEntity != null && firstDiscourseEntity != secondDiscourseEntity) { discourseModel.MergeEntities(firstDiscourseEntity, secondDiscourseEntity, 1); } else { firstDiscourseEntity = secondDiscourseEntity; } } } return firstDiscourseEntity; }
/// <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> /// 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); }
public virtual DiscourseEntity[] GetEntitiesFromMentions(Mention.Mention[] mentions) { MentionContext[] extentContexts = ConstructMentionContexts(mentions); DiscourseModel discourseModel = new DiscourseModel(); for (int extentIndex = 0; extentIndex < extentContexts.Length; extentIndex++) { //System.err.println(ei+" "+extentContexts[ei].toText()); Resolve(extentContexts[extentIndex], discourseModel); } return discourseModel.Entities; }