コード例 #1
0
        public virtual void RemoveArgument(ExtractionObject argToRemove, bool removeParent)
        {
            ICollection <ExtractionObject> thisEvent = new IdentityHashSet <ExtractionObject>();

            thisEvent.Add(argToRemove);
            RemoveArguments(thisEvent, removeParent);
        }
コード例 #2
0
        public virtual void RemoveArguments(ICollection <ExtractionObject> argsToRemove, bool removeParent)
        {
            IList <ExtractionObject> newArgs     = new List <ExtractionObject>();
            IList <string>           newArgNames = new List <string>();

            for (int i = 0; i < args.Count; i++)
            {
                ExtractionObject a = args[i];
                string           n = argNames[i];
                if (!argsToRemove.Contains(a))
                {
                    newArgs.Add(a);
                    newArgNames.Add(n);
                }
                else
                {
                    if (a is EventMention && removeParent)
                    {
                        ((EventMention)a).RemoveParent(this);
                    }
                }
            }
            args     = newArgs;
            argNames = newArgNames;
        }
コード例 #3
0
 public virtual void AddArg(ExtractionObject a, string an, bool discardSameArgDifferentName)
 {
     // only add if not already an argument
     for (int i = 0; i < GetArgs().Count; i++)
     {
         ExtractionObject myArg     = GetArg(i);
         string           myArgName = GetArgNames()[i];
         if (myArg == a)
         {
             if (myArgName.Equals(an))
             {
                 // safe to discard this arg: we already have it with the same name
                 return;
             }
             else
             {
                 logger.Info("Trying to add one argument: " + a + " with name " + an + " when this already exists with a different name: " + this + " in sentence: " + GetSentence().Get(typeof(CoreAnnotations.TextAnnotation)));
                 if (discardSameArgDifferentName)
                 {
                     return;
                 }
             }
         }
     }
     this.args.Add(a);
     this.argNames.Add(an);
     if (a is Edu.Stanford.Nlp.IE.Machinereading.Structure.EventMention)
     {
         ((Edu.Stanford.Nlp.IE.Machinereading.Structure.EventMention)a).AddParent(this);
     }
 }
コード例 #4
0
 public EventMention(string objectId, ICoreMap sentence, Span span, string type, string subtype, ExtractionObject anchor, IList <ExtractionObject> args, IList <string> argNames)
     : base(objectId, sentence, span, type, subtype, args, argNames)
 {
     // this is set if we're a subevent
     // we might have multiple parents for the same event (at least in the reader before sanity check 4)!
     this.anchor  = anchor;
     this.parents = new IdentityHashSet <ExtractionObject>();
     // set ourselves as the parent of any EventMentions in our args
     foreach (ExtractionObject arg in args)
     {
         if (arg is Edu.Stanford.Nlp.IE.Machinereading.Structure.EventMention)
         {
             ((Edu.Stanford.Nlp.IE.Machinereading.Structure.EventMention)arg).AddParent(this);
         }
     }
 }
コード例 #5
0
 /// <summary>Verifies if the two sets of arguments match</summary>
 /// <param name="inputArgs">List of arguments</param>
 public virtual bool ArgsMatch(IList <ExtractionObject> inputArgs)
 {
     if (inputArgs.Count != this.args.Count)
     {
         return(false);
     }
     for (int ind = 0; ind < this.args.Count; ind++)
     {
         ExtractionObject a1 = this.args[ind];
         ExtractionObject a2 = inputArgs[ind];
         if (!a1.Equals(a2))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #6
0
        public virtual void MergeEvent(Edu.Stanford.Nlp.IE.Machinereading.Structure.EventMention e, bool discardSameArgDifferentName)
        {
            // merge types if necessary
            string oldType = type;

            type = ExtractionObject.ConcatenateTypes(type, e.GetType());
            if (!type.Equals(oldType))
            {
                // This is not important: we use anchor types in the parser, not event types
                // This is done just for completeness of code
                logger.Fine("Type changed from " + oldType + " to " + type + " during check 3 merge.");
            }
            // add e's arguments
            for (int i = 0; i < e.GetArgs().Count; i++)
            {
                ExtractionObject a  = e.GetArg(i);
                string           an = e.GetArgNames()[i];
                // TODO: we might need more complex cycle detection than just contains()...
                if (a is Edu.Stanford.Nlp.IE.Machinereading.Structure.EventMention && ((Edu.Stanford.Nlp.IE.Machinereading.Structure.EventMention)a).Contains(this))
                {
                    logger.Info("Found event cycle during merge between e1 " + this + " and e2 " + e);
                }
                else
                {
                    // remove e from a's parents
                    if (a is Edu.Stanford.Nlp.IE.Machinereading.Structure.EventMention)
                    {
                        ((Edu.Stanford.Nlp.IE.Machinereading.Structure.EventMention)a).RemoveParent(e);
                    }
                    // add a as an arg to this
                    AddArg(a, an, discardSameArgDifferentName);
                }
            }
            // remove e's arguments. they are now attached to this, so we don't want them moved around during removeEvents
            e.ResetArguments();
            // remove e from its parent(s) to avoid using this argument in other merges of the parent
            e.RemoveFromParents();
        }
コード例 #7
0
 private static Edu.Stanford.Nlp.IE.Machinereading.Structure.RelationMention CreateUnrelatedRelation(RelationMentionFactory factory, string type, params ExtractionObject[] args)
 {
     return(factory.ConstructRelationMention(Edu.Stanford.Nlp.IE.Machinereading.Structure.RelationMention.MakeUniqueId(), args[0].GetSentence(), ExtractionObject.GetSpan(args), Edu.Stanford.Nlp.IE.Machinereading.Structure.RelationMention.Unrelated
                                             + type, null, Arrays.AsList(args), null));
 }
コード例 #8
0
 public virtual void AddArg(ExtractionObject a)
 {
     this.args.Add(a);
 }
コード例 #9
0
 public virtual void RemoveParent(ExtractionObject p)
 {
     parents.Remove(p);
 }