/// <summary>Predict a relation for each pair of entities in the sentence; including relations of type unrelated.</summary> /// <remarks> /// Predict a relation for each pair of entities in the sentence; including relations of type unrelated. /// This creates new RelationMention objects! /// </remarks> protected internal virtual IList <RelationMention> ExtractAllRelations(ICoreMap sentence) { IList <RelationMention> extractions = new List <RelationMention>(); IList <RelationMention> cands = null; if (createUnrelatedRelations) { // creates all possible relations between all entities in the sentence cands = AnnotationUtils.GetAllUnrelatedRelations(relationMentionFactory, sentence, false); } else { // just take the candidates produced by the reader (in KBP) cands = sentence.Get(typeof(MachineReadingAnnotations.RelationMentionsAnnotation)); if (cands == null) { cands = new List <RelationMention>(); } } // the actual classification takes place here! foreach (RelationMention rel in cands) { IDatum <string, string> testDatum = CreateDatum(rel); string label = ClassOf(testDatum, rel); ICounter <string> probs = ProbabilityOf(testDatum); double prob = probs.GetCount(label); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); if (logger.IsLoggable(Level.Info)) { JustificationOf(testDatum, pw, label); } logger.Info("Current sentence: " + AnnotationUtils.TokensAndNELabelsToString(rel.GetArg(0).GetSentence()) + "\n" + "Classifying relation: " + rel + "\n" + "JUSTIFICATION for label GOLD:" + rel.GetType() + " SYS:" + label + " (prob:" + prob + "):\n" + sw.ToString()); logger.Info("Justification done."); RelationMention relation = relationMentionFactory.ConstructRelationMention(rel.GetObjectId(), sentence, rel.GetExtent(), label, null, rel.GetArgs(), probs); extractions.Add(relation); if (!relation.GetType().Equals(rel.GetType())) { logger.Info("Classification: found different type " + relation.GetType() + " for relation: " + rel); logger.Info("The predicted relation is: " + relation); logger.Info("Current sentence: " + AnnotationUtils.TokensAndNELabelsToString(rel.GetArg(0).GetSentence())); } else { logger.Info("Classification: found similar type " + relation.GetType() + " for relation: " + rel); logger.Info("The predicted relation is: " + relation); logger.Info("Current sentence: " + AnnotationUtils.TokensAndNELabelsToString(rel.GetArg(0).GetSentence())); } } return(extractions); }