public static void AddEntityMention(ICoreMap sentence, EntityMention arg) { IList <EntityMention> l = sentence.Get(typeof(MachineReadingAnnotations.EntityMentionsAnnotation)); if (l == null) { l = new List <EntityMention>(); sentence.Set(typeof(MachineReadingAnnotations.EntityMentionsAnnotation), l); } l.Add(arg); }
/// <param name="entity"> /// - identifier for entity, could be entity id or common string that /// all entity mentions of this entity share /// </param> /// <param name="em">- entity mention</param> public virtual void AddEntity(string entity, EntityMention em) { IList <EntityMention> mentions = this.entityToEntityMentions[entity]; if (mentions == null) { mentions = new List <EntityMention>(); this.entityToEntityMentions[entity] = mentions; } mentions.Add(em); }
public static IList <RelationMention> GetAllUnrelatedRelations(RelationMentionFactory factory, ICoreMap sentence, bool checkExisting) { IList <RelationMention> relationMentions = (checkExisting ? sentence.Get(typeof(MachineReadingAnnotations.RelationMentionsAnnotation)) : null); IList <EntityMention> entityMentions = sentence.Get(typeof(MachineReadingAnnotations.EntityMentionsAnnotation)); IList <RelationMention> nonRelations = new List <RelationMention>(); // // scan all possible arguments // if (entityMentions != null) { for (int i = 0; i < entityMentions.Count; i++) { for (int j = 0; j < entityMentions.Count; j++) { if (i == j) { continue; } EntityMention arg1 = entityMentions[i]; EntityMention arg2 = entityMentions[j]; bool match = false; if (relationMentions != null) { foreach (RelationMention rel in relationMentions) { if (rel.ArgsMatch(arg1, arg2)) { match = true; break; } } } if (match == false) { nonRelations.Add(RelationMention.CreateUnrelatedRelation(factory, arg1, arg2)); } } } } return(nonRelations); }
/// <summary>Find the right-most position of an argument's syntactic head</summary> public virtual int GetLastSyntacticHeadPosition() { int pos = int.MinValue; foreach (ExtractionObject obj in args) { if (obj is EntityMention) { EntityMention em = (EntityMention)obj; if (em.GetSyntacticHeadTokenPosition() > pos) { pos = em.GetSyntacticHeadTokenPosition(); } } } if (pos != int.MinValue) { return(pos); } return(-1); }
/// <summary> /// Replaces the arguments of this relations with equivalent mentions from the predictedMentions list /// This works only for arguments that are EntityMention! /// </summary> /// <param name="predictedMentions"/> public virtual bool ReplaceGoldArgsWithPredicted(IList <EntityMention> predictedMentions) { IList <ExtractionObject> newArgs = new List <ExtractionObject>(); foreach (ExtractionObject arg in args) { if (!(arg is EntityMention)) { continue; } EntityMention goldEnt = (EntityMention)arg; EntityMention newArg = null; foreach (EntityMention pred in predictedMentions) { if (goldEnt.TextEquals(pred)) { newArg = pred; break; } } if (newArg != null) { newArgs.Add(newArg); logger.Info("Replacing relation argument: [" + goldEnt + "] with predicted mention [" + newArg + "]"); } else { /* * logger.info("Failed to match relation argument: " + goldEnt); * return false; */ newArgs.Add(goldEnt); predictedMentions.Add(goldEnt); logger.Info("Failed to match relation argument, so keeping gold: " + goldEnt); } } this.args = newArgs; return(true); }
public virtual IList <RelationMention> GetAllUnrelatedRelations(RelationMentionFactory factory) { IList <RelationMention> nonRelations = new List <RelationMention>(); IList <RelationMention> allRelations = new List <RelationMention>(relationMentions); // // scan all possible arguments // for (int i = 0; i < GetEntityMentions().Count; i++) { for (int j = 0; j < GetEntityMentions().Count; j++) { if (i == j) { continue; } EntityMention arg1 = GetEntityMentions()[i]; EntityMention arg2 = GetEntityMentions()[j]; bool match = false; foreach (RelationMention rel in allRelations) { if (rel.ArgsMatch(arg1, arg2)) { match = true; break; } } if (!match) { RelationMention nonrel = RelationMention.CreateUnrelatedRelation(factory, arg1, arg2); nonRelations.Add(nonrel); allRelations.Add(nonrel); } } } return(nonRelations); }
public virtual void AddEntityMention(EntityMention arg) { this.entityMentions.Add(arg); }