public async Task <Option <RichFormatting> > Answer(Request request) { try { var rich = new RichFormatting(); var paragraphs = ReadParagraphs(path); if (paragraphs != null) { await paragraphs.Where(paragraph => paragraph.Contains(request.QueryText)).ForEachAsync(paragraph => { var text = new TextParagraph( StringExt.HighlightWords(paragraph, request.QueryText) .Select(p => new Text(p.text, emphasis: p.highlight))); rich.Paragraphs.Add(text); }); return(Option.Some(rich)); } } catch (FileNotFoundException) { var text = "This data source looks for a custom_notes.txt file in the data directory. Currently no such file exists."; var rich = new RichFormatting( EnumerableExt.OfSingle( new TextParagraph( EnumerableExt.OfSingle( new Text(text))))); return(Option.Some(rich)); } return(Option.None <RichFormatting>()); }
public Task <Option <RichFormatting> > Answer(Request request, CancellationToken token) { var rich = new RichFormatting(); var sentences = be.SearchByJapaneseText(request.QueryText); foreach (var sentence in sentences.OrderBy(s => s.JapaneseSentence.Length).Take(20)) { var paragraph = new TextParagraph(); foreach (var part in StringExt.HighlightWords(sentence.JapaneseSentence, request.QueryText)) { paragraph.Content.Add(new Text(part.text, part.highlight)); } paragraph.Content.Add(new Text(sentence.EnglishSentence)); rich.Paragraphs.Add(paragraph); } if (rich.Paragraphs.Count != 0) { return(Task.FromResult(Option.Some(rich))); } return(Task.FromResult(Option.None <RichFormatting>())); }
public async Task <Option <RichFormatting> > Answer(Request request, CancellationToken token) { var rich = new RichFormatting(); var sentences = jesc.SearchByJapaneseTextAsync(request.QueryText); foreach (var sentence in (await sentences.Take(100).ToListAsync(token)).OrderByDescending(s => s.JapaneseSentence.Length).Take(20)) { var paragraph = new TextParagraph(); foreach (var(text, highlight) in StringExt.HighlightWords(sentence.JapaneseSentence, request.QueryText)) { paragraph.Content.Add(new Text(text, highlight)); } paragraph.Content.Add(new Text(sentence.EnglishSentence)); rich.Paragraphs.Add(paragraph); } if (rich.Paragraphs.Count != 0) { return(Option.Some(rich)); } return(Option.None <RichFormatting>()); }