Beispiel #1
0
 /// <summary>Extract the relations in this clause.</summary>
 /// <seealso cref="EntailmentsFromClause(SentenceFragment)"/>
 /// <seealso cref="RelationsInFragments(System.Collections.Generic.ICollection{E})"/>
 public virtual IList <RelationTriple> RelationsInClause(SentenceFragment clause)
 {
     return(RelationsInFragments(EntailmentsFromClause(clause)));
 }
Beispiel #2
0
 /// <summary>Returns the possible relation triple in this sentence fragment.</summary>
 /// <seealso cref="RelationInFragment(SentenceFragment, Edu.Stanford.Nlp.Util.ICoreMap)"/>
 public virtual Optional <RelationTriple> RelationInFragment(SentenceFragment fragment)
 {
     return(segmenter.Segment(fragment.parseTree, Optional.Of(fragment.score), consumeAll));
 }
Beispiel #3
0
 /// <summary>Returns the possible relation triple in this sentence fragment.</summary>
 /// <param name="fragment">The sentence fragment to try to extract relations from.</param>
 /// <param name="sentence">The containing sentence for the fragment.</param>
 /// <returns>
 /// A relation triple if we could find one; otherwise,
 /// <see cref="Java.Util.Optional{T}.Empty{T}()"/>
 /// .
 /// </returns>
 private Optional <RelationTriple> RelationInFragment(SentenceFragment fragment, ICoreMap sentence)
 {
     return(segmenter.Segment(fragment.parseTree, Optional.Of(fragment.score), consumeAll));
 }
Beispiel #4
0
 /// <summary>Returns all of the entailed shortened clauses (as per natural logic) from the given clause.</summary>
 /// <remarks>
 /// Returns all of the entailed shortened clauses (as per natural logic) from the given clause.
 /// This runs the forward entailment component of the OpenIE system only.
 /// It is usually chained together with the clause splitting component:
 /// <see cref="ClausesInSentence(Edu.Stanford.Nlp.Util.ICoreMap)"/>
 /// .
 /// </remarks>
 /// <param name="clause">The premise clause, as a sentence fragment in itself.</param>
 /// <returns>A list of entailed clauses.</returns>
 public virtual IList <SentenceFragment> EntailmentsFromClause(SentenceFragment clause)
 {
     if (clause.parseTree.IsEmpty())
     {
         return(Java.Util.Collections.EmptyList());
     }
     else
     {
         // Get the forward entailments
         IList <SentenceFragment> list = new List <SentenceFragment>();
         if (entailmentsPerSentence > 0)
         {
             Sharpen.Collections.AddAll(list, forwardEntailer.Apply(clause.parseTree, true).Search().Stream().Map(null).Collect(Collectors.ToList()));
         }
         list.Add(clause);
         // A special case for adjective entailments
         IList <SentenceFragment> adjFragments = new List <SentenceFragment>();
         SemgrexMatcher           matcher      = adjectivePattern.Matcher(clause.parseTree);
         while (matcher.Find())
         {
             // (get nodes)
             IndexedWord subj = matcher.GetNode("subj");
             IndexedWord be   = matcher.GetNode("be");
             IndexedWord adj  = matcher.GetNode("adj");
             IndexedWord obj  = matcher.GetNode("obj");
             IndexedWord pobj = matcher.GetNode("pobj");
             string      prep = matcher.GetRelnString("prep");
             // (if the adjective, or any earlier adjective, is privative, then all bets are off)
             foreach (SemanticGraphEdge edge in clause.parseTree.OutgoingEdgeIterable(obj))
             {
                 if ("amod".Equals(edge.GetRelation().ToString()) && edge.GetDependent().Index() <= adj.Index() && Edu.Stanford.Nlp.Naturalli.Util.PrivativeAdjectives.Contains(edge.GetDependent().Word().ToLower()))
                 {
                     goto OUTER_continue;
                 }
             }
             // (create the core tree)
             SemanticGraph tree = new SemanticGraph();
             tree.AddRoot(adj);
             tree.AddVertex(subj);
             tree.AddVertex(be);
             tree.AddEdge(adj, be, GrammaticalRelation.ValueOf(Language.English, "cop"), double.NegativeInfinity, false);
             tree.AddEdge(adj, subj, GrammaticalRelation.ValueOf(Language.English, "nsubj"), double.NegativeInfinity, false);
             // (add pp attachment, if it existed)
             if (pobj != null)
             {
                 System.Diagnostics.Debug.Assert(prep != null);
                 tree.AddEdge(adj, pobj, GrammaticalRelation.ValueOf(Language.English, prep), double.NegativeInfinity, false);
             }
             // (check for monotonicity)
             if (adj.Get(typeof(NaturalLogicAnnotations.PolarityAnnotation)).IsUpwards() && be.Get(typeof(NaturalLogicAnnotations.PolarityAnnotation)).IsUpwards())
             {
                 // (add tree)
                 adjFragments.Add(new SentenceFragment(tree, clause.assumedTruth, false));
             }
             OUTER_continue :;
         }
         OUTER_break :;
         Sharpen.Collections.AddAll(list, adjFragments);
         return(list);
     }
 }