Exemple #1
0
        /// <summary>
        /// Always use this method to construct RelationMentions
        /// Other factories that inherit from this (e.g., NFLRelationFactory) may override this
        /// </summary>
        /// <param name="objectId"/>
        /// <param name="sentence"/>
        /// <param name="span"/>
        /// <param name="type"/>
        /// <param name="subtype"/>
        /// <param name="args"/>
        /// <param name="probs"/>
        public virtual RelationMention ConstructRelationMention(string objectId, ICoreMap sentence, Span span, string type, string subtype, IList <ExtractionObject> args, ICounter <string> probs)
        {
            RelationMention relation = new RelationMention(objectId, sentence, span, type, subtype, args);

            relation.SetTypeProbabilities(probs);
            return(relation);
        }
        public virtual void AddRelation(string relation, RelationMention rm)
        {
            IList <RelationMention> mentions = this.relationToRelationMentions[relation];

            if (mentions == null)
            {
                mentions = new List <RelationMention>();
                this.relationToRelationMentions[relation] = mentions;
            }
            mentions.Add(rm);
        }
 /// <summary>Return the relation that holds between the given entities.</summary>
 /// <remarks>
 /// Return the relation that holds between the given entities.
 /// Return a relation of type UNRELATED if this sentence contains no relation between the entities.
 /// </remarks>
 public virtual RelationMention GetRelation(RelationMentionFactory factory, params ExtractionObject[] args)
 {
     foreach (RelationMention rel in relationMentions)
     {
         if (rel.ArgsMatch(args))
         {
             return(rel);
         }
     }
     return(RelationMention.CreateUnrelatedRelation(factory, args));
 }
        public static void AddRelationMention(ICoreMap sentence, RelationMention arg)
        {
            IList <RelationMention> l = sentence.Get(typeof(MachineReadingAnnotations.RelationMentionsAnnotation));

            if (l == null)
            {
                l = new List <RelationMention>();
                sentence.Set(typeof(MachineReadingAnnotations.RelationMentionsAnnotation), l);
            }
            l.Add(arg);
        }
        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>Return all the relations that holds between the given entities.</summary>
        /// <remarks>
        /// Return all the relations that holds between the given entities.
        /// Returns a list containing a relation of type UNRELATED if this sentence contains no relation between the entities.
        /// </remarks>
        public static IList <RelationMention> GetRelations(RelationMentionFactory factory, ICoreMap sentence, params ExtractionObject[] args)
        {
            IList <RelationMention> relationMentions         = sentence.Get(typeof(MachineReadingAnnotations.RelationMentionsAnnotation));
            IList <RelationMention> matchingRelationMentions = new List <RelationMention>();

            if (relationMentions != null)
            {
                foreach (RelationMention rel in relationMentions)
                {
                    if (rel.ArgsMatch(args))
                    {
                        matchingRelationMentions.Add(rel);
                    }
                }
            }
            if (matchingRelationMentions.Count == 0)
            {
                matchingRelationMentions.Add(RelationMention.CreateUnrelatedRelation(factory, args));
            }
            return(matchingRelationMentions);
        }
        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 AddRelationMention(RelationMention rel)
 {
     relationMentions.Add(rel);
 }