//select nearest mention to the left if: the quote is ending a paragraph. public virtual void ParagraphEndQuoteClosestBefore(Annotation doc) { IList <CoreLabel> tokens = doc.Get(typeof(CoreAnnotations.TokensAnnotation)); IList <ICoreMap> quotes = doc.Get(typeof(CoreAnnotations.QuotationsAnnotation)); foreach (ICoreMap quote in quotes) { if (quote.Get(typeof(QuoteAttributionAnnotator.MentionAnnotation)) != null) { continue; } Pair <int, int> range = QuoteAttributionUtils.GetRemainderInSentence(doc, quote); if (range == null) { continue; } //search for mentions in the first run Pair <List <string>, List <Pair <int, int> > > namesAndNameIndices = ScanForNames(range); List <string> names = namesAndNameIndices.first; int quoteBeginTokenIndex = quote.Get(typeof(CoreAnnotations.TokenBeginAnnotation)); bool isBefore = range.second.Equals(quoteBeginTokenIndex - 1); //check if the range is preceding the quote or after it. int quoteParagraph = QuoteAttributionUtils.GetQuoteParagraphIndex(doc, quote); int quoteIndex = quote.Get(typeof(CoreAnnotations.QuotationIndexAnnotation)); bool isOnlyQuoteInParagraph = true; if (quoteIndex > 0) { ICoreMap prevQuote = quotes[quoteIndex - 1]; int prevQuoteParagraph = QuoteAttributionUtils.GetQuoteParagraphIndex(doc, prevQuote); if (prevQuoteParagraph == quoteParagraph) { isOnlyQuoteInParagraph = false; } } if (quoteIndex < quotes.Count - 1) { ICoreMap nextQuote = quotes[quoteIndex + 1]; int nextQuoteParagraph = QuoteAttributionUtils.GetQuoteParagraphIndex(doc, nextQuote); if (nextQuoteParagraph == quoteParagraph) { isOnlyQuoteInParagraph = false; } } if (isBefore && tokens[range.second].Word().Equals(",") && isOnlyQuoteInParagraph) { Sieve.MentionData closestMention = FindClosestMentionInSpanBackward(range); if (closestMention != null && !closestMention.type.Equals("animate noun")) { FillInMention(quote, closestMention, sieveName); } } } }
protected internal virtual ICollection <Person> GetNamesInParagraph(ICoreMap quote) { //iterate forwards and backwards to look for quotes in the same paragraph, and add all the names present in them to the list. IList <ICoreMap> quotes = doc.Get(typeof(CoreAnnotations.QuotationsAnnotation)); IList <ICoreMap> sentences = doc.Get(typeof(CoreAnnotations.SentencesAnnotation)); IList <string> quoteNames = new List <string>(); int quoteParagraph = QuoteAttributionUtils.GetQuoteParagraphIndex(doc, quote); int quoteIndex = quote.Get(typeof(CoreAnnotations.QuotationIndexAnnotation)); for (int i = quoteIndex; i >= 0; i--) { ICoreMap currQuote = quotes[i]; int currQuoteParagraph = QuoteAttributionUtils.GetQuoteParagraphIndex(doc, currQuote); if (currQuoteParagraph == quoteParagraph) { Sharpen.Collections.AddAll(quoteNames, ScanForNames(new Pair <int, int>(currQuote.Get(typeof(CoreAnnotations.TokenBeginAnnotation)), currQuote.Get(typeof(CoreAnnotations.TokenEndAnnotation)))).first); } else { break; } } for (int i_1 = quoteIndex + 1; i_1 < quotes.Count; i_1++) { ICoreMap currQuote = quotes[i_1]; int currQuoteParagraph = QuoteAttributionUtils.GetQuoteParagraphIndex(doc, currQuote); if (currQuoteParagraph == quoteParagraph) { Sharpen.Collections.AddAll(quoteNames, ScanForNames(new Pair <int, int>(currQuote.Get(typeof(CoreAnnotations.TokenBeginAnnotation)), currQuote.Get(typeof(CoreAnnotations.TokenEndAnnotation)))).first); } else { break; } } ICollection <Person> namesInParagraph = new HashSet <Person>(); foreach (string name in quoteNames) { foreach (Person p in characterMap[name]) { namesInParagraph.Add(p); } } return(namesInParagraph); }