public virtual Pair <string, double> Classify(KBPRelationExtractor.KBPInput input) { // Annotate Sentence ICoreMap sentenceAsMap = input.sentence.AsCoreMap(null); IList <CoreLabel> tokens = sentenceAsMap.Get(typeof(CoreAnnotations.TokensAnnotation)); // Annotate where the subject is foreach (int i in input.subjectSpan) { tokens[i].Set(typeof(KBPTokensregexExtractor.Subject), "true"); if ("O".Equals(tokens[i].Ner())) { tokens[i].SetNER(input.subjectType.name); } } // Annotate where the object is foreach (int i_1 in input.objectSpan) { tokens[i_1].Set(typeof(KBPTokensregexExtractor.Object), "true"); if ("O".Equals(tokens[i_1].Ner())) { tokens[i_1].SetNER(input.objectType.name); } } // Run Rules foreach (KBPRelationExtractor.RelationType rel in KBPRelationExtractor.RelationType.Values()) { if (rules.Contains(rel) && rel.entityType == input.subjectType && rel.validNamedEntityLabels.Contains(input.objectType)) { CoreMapExpressionExtractor extractor = rules[rel]; IList <MatchedExpression> extractions = extractor.ExtractExpressions(sentenceAsMap); if (extractions != null && extractions.Count > 0) { MatchedExpression best = MatchedExpression.GetBestMatched(extractions, MatchedExpression.ExprWeightScorer); // Un-Annotate Sentence foreach (CoreLabel token in tokens) { token.Remove(typeof(KBPTokensregexExtractor.Subject)); token.Remove(typeof(KBPTokensregexExtractor.Object)); } return(Pair.MakePair(rel.canonicalName, best.GetWeight())); } } } // Un-Annotate Sentence foreach (CoreLabel token_1 in tokens) { token_1.Remove(typeof(KBPTokensregexExtractor.Subject)); token_1.Remove(typeof(KBPTokensregexExtractor.Object)); } return(Pair.MakePair(KBPRelationExtractorConstants.NoRelation, 1.0)); }
public TimeExpression(MatchedExpression expr) : base(expr) { }