public virtual DiscourseEntity Retain(Mention.MentionContext mention, DiscourseModel discourseModel) { int entityIndex = 0; if (mention.Id == -1) { return(null); } for (; entityIndex < discourseModel.EntityCount; entityIndex++) { DiscourseEntity currentDiscourseEntity = discourseModel.GetEntity(entityIndex); Mention.MentionContext candidateExtentContext = currentDiscourseEntity.LastExtent; if (candidateExtentContext.Id == mention.Id) { Distances.Add(entityIndex); return(currentDiscourseEntity); } } return(null); }
public virtual DiscourseEntity Retain(Mention.MentionContext mention, DiscourseModel discourseModel) { int entityIndex = 0; if (mention.Id == -1) { return(null); } for (; entityIndex < discourseModel.EntityCount; entityIndex++) { DiscourseEntity currentDiscourseEntity = discourseModel.GetEntity(entityIndex); Mention.MentionContext candidateExtentContext = currentDiscourseEntity.LastExtent; if (candidateExtentContext.Id == mention.Id) { Distances.Add(entityIndex); return(currentDiscourseEntity); } } //System.err.println("AbstractResolver.Retain: non-referring entity with id: "+ec.toText()+" id="+ec.id); return(null); }
public override DiscourseEntity Retain(Mention.MentionContext mention, DiscourseModel discourseModel) { //System.err.println(this+".retain("+ec+") "+mode); if (mResolverMode == ResolverMode.Train) { DiscourseEntity discourseEntity = null; bool referentFound = false; bool hasReferentialCandidate = false; bool nonReferentFound = false; for (int entityIndex = 0; entityIndex < GetNumberEntitiesBack(discourseModel); entityIndex++) { DiscourseEntity currentDiscourseEntity = discourseModel.GetEntity(entityIndex); Mention.MentionContext entityMention = currentDiscourseEntity.LastExtent; if (IsOutOfRange(mention, currentDiscourseEntity)) { if (mention.Id != -1 && !referentFound) { //System.err.println("retain: Referent out of range: "+ec.toText()+" "+ec.parse.getSpan()); } break; } if (IsExcluded(mention, currentDiscourseEntity)) { if (ShowExclusions) { if (mention.Id != -1 && entityMention.Id == mention.Id) { System.Console.Error.WriteLine(this + ".retain: Referent excluded: (" + mention.Id + ") " + mention.ToText() + " " + mention.IndexSpan + " -> (" + entityMention.Id + ") " + entityMention.ToText() + " " + entityMention.Span + " " + this); } } } else { hasReferentialCandidate = true; bool useAsDifferentExample = defaultReferent(currentDiscourseEntity); //if (!sampleSelection || (mention.getId() != -1 && entityMention.getId() == mention.getId()) || (!nonReferentFound && useAsDifferentExample)) { List <string> features = GetFeatures(mention, currentDiscourseEntity); //add Event to Model if (mDebugOn) { System.Console.Error.WriteLine(this + ".retain: " + mention.Id + " " + mention.ToText() + " -> " + entityMention.Id + " " + currentDiscourseEntity); } if (mention.Id != -1 && entityMention.Id == mention.Id) { referentFound = true; mEvents.Add(new SharpEntropy.TrainingEvent(Same, features.ToArray())); discourseEntity = currentDiscourseEntity; //System.err.println("MaxentResolver.retain: resolved at "+ei); Distances.Add(entityIndex); } else if (!mPairedSampleSelection || (!nonReferentFound && useAsDifferentExample)) { nonReferentFound = true; mEvents.Add(new SharpEntropy.TrainingEvent(Diff, features.ToArray())); } //} } if (mPairedSampleSelection && referentFound && nonReferentFound) { break; } if (mPreferFirstReferent && referentFound) { break; } } // doesn't refer to anything if (hasReferentialCandidate) { mNonReferentialResolver.AddEvent(mention); } return(discourseEntity); } else { return(base.Retain(mention, discourseModel)); } }
public override DiscourseEntity Resolve(Mention.MentionContext expression, DiscourseModel discourseModel) { DiscourseEntity discourseEntity; int entityIndex = 0; double nonReferentialProbability = mNonReferentialResolver.GetNonReferentialProbability(expression); if (mDebugOn) { System.Console.Error.WriteLine(this.ToString() + ".resolve: " + expression.ToText() + " -> " + "null " + nonReferentialProbability); } for (; entityIndex < GetNumberEntitiesBack(discourseModel); entityIndex++) { discourseEntity = discourseModel.GetEntity(entityIndex); if (IsOutOfRange(expression, discourseEntity)) { break; } if (IsExcluded(expression, discourseEntity)) { mCandidateProbabilities[entityIndex] = 0; if (mDebugOn) { System.Console.Error.WriteLine("excluded " + this.ToString() + ".resolve: " + expression.ToText() + " -> " + discourseEntity + " " + mCandidateProbabilities[entityIndex]); } } else { string[] features = GetFeatures(expression, discourseEntity).ToArray(); try { mCandidateProbabilities[entityIndex] = mModel.Evaluate(features)[mSameIndex]; } catch (System.IndexOutOfRangeException e) { mCandidateProbabilities[entityIndex] = 0; } if (mDebugOn) { System.Console.Error.WriteLine(this + ".resolve: " + expression.ToText() + " -> " + discourseEntity + " (" + expression.GetGender() + "," + discourseEntity.Gender + ") " + mCandidateProbabilities[entityIndex] + " " + string.Join(",", features)); //SupportClass.CollectionToString(lfeatures)); } } if (mPreferFirstReferent && mCandidateProbabilities[entityIndex] > nonReferentialProbability) { entityIndex++; //update for nonRef assignment break; } } mCandidateProbabilities[entityIndex] = nonReferentialProbability; // find max int maximumCandidateIndex = 0; for (int currentCandidate = 1; currentCandidate <= entityIndex; currentCandidate++) { if (mCandidateProbabilities[currentCandidate] > mCandidateProbabilities[maximumCandidateIndex]) { maximumCandidateIndex = currentCandidate; } } if (maximumCandidateIndex == entityIndex) { // no referent return(null); } else { discourseEntity = discourseModel.GetEntity(maximumCandidateIndex); return(discourseEntity); } }
public virtual DiscourseEntity Retain(Mention.MentionContext mention, DiscourseModel discourseModel) { int entityIndex = 0; if (mention.Id == - 1) { return null; } for (; entityIndex < discourseModel.EntityCount; entityIndex++) { DiscourseEntity currentDiscourseEntity = discourseModel.GetEntity(entityIndex); Mention.MentionContext candidateExtentContext = currentDiscourseEntity.LastExtent; if (candidateExtentContext.Id == mention.Id) { Distances.Add(entityIndex); return currentDiscourseEntity; } } //System.err.println("AbstractResolver.Retain: non-referring entity with id: "+ec.toText()+" id="+ec.id); return null; }
public override DiscourseEntity Retain(Mention.MentionContext mention, DiscourseModel discourseModel) { //System.err.println(this+".retain("+ec+") "+mode); if (mResolverMode == ResolverMode.Train) { DiscourseEntity discourseEntity = null; bool referentFound = false; bool hasReferentialCandidate = false; bool nonReferentFound = false; for (int entityIndex = 0; entityIndex < GetNumberEntitiesBack(discourseModel); entityIndex++) { DiscourseEntity currentDiscourseEntity = discourseModel.GetEntity(entityIndex); Mention.MentionContext entityMention = currentDiscourseEntity.LastExtent; if (IsOutOfRange(mention, currentDiscourseEntity)) { if (mention.Id != -1 && !referentFound) { //System.err.println("retain: Referent out of range: "+ec.toText()+" "+ec.parse.getSpan()); } break; } if (IsExcluded(mention, currentDiscourseEntity)) { if (ShowExclusions) { if (mention.Id != - 1 && entityMention.Id == mention.Id) { System.Console.Error.WriteLine(this + ".retain: Referent excluded: (" + mention.Id + ") " + mention.ToText() + " " + mention.IndexSpan + " -> (" + entityMention.Id + ") " + entityMention.ToText() + " " + entityMention.Span + " " + this); } } } else { hasReferentialCandidate = true; bool useAsDifferentExample = defaultReferent(currentDiscourseEntity); //if (!sampleSelection || (mention.getId() != -1 && entityMention.getId() == mention.getId()) || (!nonReferentFound && useAsDifferentExample)) { List<string> features = GetFeatures(mention, currentDiscourseEntity); //add Event to Model if (mDebugOn) { System.Console.Error.WriteLine(this + ".retain: " + mention.Id + " " + mention.ToText() + " -> " + entityMention.Id + " " + currentDiscourseEntity); } if (mention.Id != - 1 && entityMention.Id == mention.Id) { referentFound = true; mEvents.Add(new SharpEntropy.TrainingEvent(Same, features.ToArray())); discourseEntity = currentDiscourseEntity; //System.err.println("MaxentResolver.retain: resolved at "+ei); Distances.Add(entityIndex); } else if (!mPairedSampleSelection || (!nonReferentFound && useAsDifferentExample)) { nonReferentFound = true; mEvents.Add(new SharpEntropy.TrainingEvent(Diff, features.ToArray())); } //} } if (mPairedSampleSelection && referentFound && nonReferentFound) { break; } if (mPreferFirstReferent && referentFound) { break; } } // doesn't refer to anything if (hasReferentialCandidate) { mNonReferentialResolver.AddEvent(mention); } return discourseEntity; } else { return base.Retain(mention, discourseModel); } }
public override DiscourseEntity Resolve(Mention.MentionContext expression, DiscourseModel discourseModel) { DiscourseEntity discourseEntity; int entityIndex = 0; double nonReferentialProbability = mNonReferentialResolver.GetNonReferentialProbability(expression); if (mDebugOn) { System.Console.Error.WriteLine(this.ToString() + ".resolve: " + expression.ToText() + " -> " + "null " + nonReferentialProbability); } for (; entityIndex < GetNumberEntitiesBack(discourseModel); entityIndex++) { discourseEntity = discourseModel.GetEntity(entityIndex); if (IsOutOfRange(expression, discourseEntity)) { break; } if (IsExcluded(expression, discourseEntity)) { mCandidateProbabilities[entityIndex] = 0; if (mDebugOn) { System.Console.Error.WriteLine("excluded " + this.ToString() + ".resolve: " + expression.ToText() + " -> " + discourseEntity + " " + mCandidateProbabilities[entityIndex]); } } else { string[] features = GetFeatures(expression, discourseEntity).ToArray(); try { mCandidateProbabilities[entityIndex] = mModel.Evaluate(features)[mSameIndex]; } catch (System.IndexOutOfRangeException e) { mCandidateProbabilities[entityIndex] = 0; } if (mDebugOn) { System.Console.Error.WriteLine(this + ".resolve: " + expression.ToText() + " -> " + discourseEntity + " (" + expression.GetGender() + "," + discourseEntity.Gender + ") " + mCandidateProbabilities[entityIndex] + " " + string.Join(",", features)); //SupportClass.CollectionToString(lfeatures)); } } if (mPreferFirstReferent && mCandidateProbabilities[entityIndex] > nonReferentialProbability) { entityIndex++; //update for nonRef assignment break; } } mCandidateProbabilities[entityIndex] = nonReferentialProbability; // find max int maximumCandidateIndex = 0; for (int currentCandidate = 1; currentCandidate <= entityIndex; currentCandidate++) { if (mCandidateProbabilities[currentCandidate] > mCandidateProbabilities[maximumCandidateIndex]) { maximumCandidateIndex = currentCandidate; } } if (maximumCandidateIndex == entityIndex) { // no referent return null; } else { discourseEntity = discourseModel.GetEntity(maximumCandidateIndex); return discourseEntity; } }
public override DiscourseEntity Retain(Mention.MentionContext mention, DiscourseModel discourseModel) { if (_resolverMode == ResolverMode.Train) { DiscourseEntity discourseEntity = null; var referentFound = false; var hasReferentialCandidate = false; var nonReferentFound = false; for (var entityIndex = 0; entityIndex < GetNumberEntitiesBack(discourseModel); entityIndex++) { var currentDiscourseEntity = discourseModel.GetEntity(entityIndex); var entityMention = currentDiscourseEntity.LastExtent; if (IsOutOfRange(mention, currentDiscourseEntity)) { break; } if (IsExcluded(mention, currentDiscourseEntity)) { if (ShowExclusions) { if (mention.Id != -1 && entityMention.Id == mention.Id) { Console.Error.WriteLine(this + ".retain: Referent excluded: (" + mention.Id + ") " + mention.ToText() + " " + mention.IndexSpan + " -> (" + entityMention.Id + ") " + entityMention.ToText() + " " + entityMention.Span + " " + this); } } } else { hasReferentialCandidate = true; var useAsDifferentExample = defaultReferent(currentDiscourseEntity); //if (!sampleSelection || (mention.getId() != -1 && entityMention.getId() == mention.getId()) || (!nonReferentFound && useAsDifferentExample)) { var features = GetFeatures(mention, currentDiscourseEntity); //add Event to Model if (DebugOn) { Console.Error.WriteLine(this + ".retain: " + mention.Id + " " + mention.ToText() + " -> " + entityMention.Id + " " + currentDiscourseEntity); } if (mention.Id != -1 && entityMention.Id == mention.Id) { referentFound = true; _events.Add(new SharpEntropy.TrainingEvent(Same, features.ToArray())); discourseEntity = currentDiscourseEntity; Distances.Add(entityIndex); } else if (!PairedSampleSelection || (!nonReferentFound && useAsDifferentExample)) { nonReferentFound = true; _events.Add(new SharpEntropy.TrainingEvent(Diff, features.ToArray())); } //} } if (PairedSampleSelection && referentFound && nonReferentFound) { break; } if (PreferFirstReferent && referentFound) { break; } } // doesn't refer to anything if (hasReferentialCandidate) { NonReferentialResolver.AddEvent(mention); } return(discourseEntity); } else { return(base.Retain(mention, discourseModel)); } }
public virtual DiscourseEntity Retain(Mention.MentionContext mention, DiscourseModel discourseModel) { int entityIndex = 0; if (mention.Id == - 1) { return null; } for (; entityIndex < discourseModel.EntityCount; entityIndex++) { DiscourseEntity currentDiscourseEntity = discourseModel.GetEntity(entityIndex); Mention.MentionContext candidateExtentContext = currentDiscourseEntity.LastExtent; if (candidateExtentContext.Id == mention.Id) { Distances.Add(entityIndex); return currentDiscourseEntity; } } return null; }