private static ICollection <string> ExtractQuote(string text, ResponseItem item, string[] keywords) { var ret = new List <string>(); var splits = text.Split('"'); if (splits.Length == 1) { return(ret); } for (int i = 1; i < splits.Length; i += 2) { var quote = new ArquivoQuote { FullText = text, Quote = splits[i], Reference = item }; SetQuoteContext(splits, i, quote); if (EvaluateQuote(quote, keywords)) { ret.Add(quote.Quote); } } return(ret.Distinct().ToList()); }
public int CompareTo(ArquivoQuote other) { if (ReferenceEquals(this, other)) { return(0); } if (ReferenceEquals(null, other)) { return(1); } return(string.Compare(Quote, other.Quote, StringComparison.Ordinal)); }
private static void SetQuoteContext(string[] splits, int i, ArquivoQuote q) { q.PrevContext = q.PosContext = string.Empty; if (splits.Length == 0) { return; } if (i > 0) { q.PrevContext = splits[i - 1]; } if (i + 1 < splits.Length) { q.PosContext += splits[i + 1]; } }
private static bool EvaluateQuote(ArquivoQuote quote, string[] keywords) { var phraseStartIdx = quote.PrevContext.LastIndexOf(".", StringComparison.InvariantCulture); if (phraseStartIdx != -1) { quote.PrevContext = quote.PrevContext.Substring(phraseStartIdx, quote.PrevContext.Length - phraseStartIdx).ToLower(); } phraseStartIdx = quote.PosContext.IndexOf(".", StringComparison.InvariantCulture); if (phraseStartIdx != -1) { quote.PosContext = quote.PosContext.Substring(phraseStartIdx, quote.PosContext.Length - phraseStartIdx).ToLower(); } return(keywords.Any(k => quote.PrevContext.Contains(k) || quote.PosContext.Contains(k))); }
protected bool Equals(ArquivoQuote other) { return(string.Equals(Quote, other.Quote)); }