/// <summary>
        /// Get list of all relations and non-relations between ArgForRelations in this sentence
        /// Use with care.
        /// </summary>
        /// <remarks>
        /// Get list of all relations and non-relations between ArgForRelations in this sentence
        /// Use with care. This is an expensive call due to getAllUnrelatedRelations, which creates all non-existing relations between all entity mentions
        /// </remarks>
        public virtual IList <RelationMention> GetAllRelations(RelationMentionFactory factory)
        {
            IList <RelationMention> allRelations = new List <RelationMention>(relationMentions);

            Sharpen.Collections.AddAll(allRelations, GetAllUnrelatedRelations(factory));
            return(allRelations);
        }
 /// <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));
 }
        /// <summary>
        /// Get list of all relations and non-relations between EntityMentions in this sentence
        /// Use with care.
        /// </summary>
        /// <remarks>
        /// Get list of all relations and non-relations between EntityMentions in this sentence
        /// Use with care. This is an expensive call due to getAllUnrelatedRelations, which creates all non-existing relations between all entity mentions
        /// </remarks>
        public static IList <RelationMention> GetAllRelations(RelationMentionFactory factory, ICoreMap sentence, bool createUnrelatedRelations)
        {
            IList <RelationMention> relationMentions = sentence.Get(typeof(MachineReadingAnnotations.RelationMentionsAnnotation));
            IList <RelationMention> allRelations     = new List <RelationMention>();

            if (relationMentions != null)
            {
                Sharpen.Collections.AddAll(allRelations, relationMentions);
            }
            if (createUnrelatedRelations)
            {
                Sharpen.Collections.AddAll(allRelations, GetAllUnrelatedRelations(factory, sentence, true));
            }
            return(allRelations);
        }
        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);
        }
 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));
 }
 public static Edu.Stanford.Nlp.IE.Machinereading.Structure.RelationMention CreateUnrelatedRelation(RelationMentionFactory factory, params ExtractionObject[] args)
 {
     return(CreateUnrelatedRelation(factory, string.Empty, args));
 }
 /// <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 static RelationMention GetRelation(RelationMentionFactory factory, ICoreMap sentence, params ExtractionObject[] args)
 {
     return(GetRelations(factory, sentence, args)[0]);
 }