public async Task Summarize() { TextAnalysisClient Client = new TextAnalysisClient(Config.TextAnalysisApiKey); string fname = @"Data\wap.txt"; StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; var file = await InstallationFolder.GetFileAsync(fname); var stream = await file.OpenReadAsync(); var sr = new StreamReader(stream.AsStreamForRead()); int b = 0; // BOOK int c = 0; // Chapter int p = 0; // Paragraph StringBuilder sb = new StringBuilder(); TextAnalysisDocumentStore Store = new TextAnalysisDocumentStore(); while (!sr.EndOfStream) { var s = await sr.ReadLineAsync(); if (s.Contains("BOOK")) { b++; c = 0; if (b > 2) { break; } continue; } if (s.Contains("CHAPTER")) { if (sb.Length > 20) { var key = $"b{b}c{c}p{p}"; Store.documents.Add(new TextAnalysisDocument(key, "en", sb.ToString())); } sb.Clear(); if (Store.documents.Count > 0) { var R = await Client.ExtractKeyphrases(Store); StringBuilder z = new StringBuilder(); z.AppendLine($"CHAPTER {c}"); foreach (var d in R.documents) { z.AppendLine(string.Join(",", d.keyPhrases)); } Summary.Text += z.ToString(); } Store.documents.Clear(); c++; p = 0; continue; } if (s.Trim().Equals(string.Empty)) { if (sb.Length > 20) { var key = $"b{b}c{c}p{p}"; if (Store.documents.Count > 0 && Store.documents.Last().text.Length + sb.ToString().Length < 5000) { System.Diagnostics.Debug.WriteLine($"Last {Store.documents.Last().text.Length}, sb {sb.Length}"); Store.documents.Last().text += "\n\r" + sb.ToString(); } else { Store.documents.Add(new TextAnalysisDocument(key, "en", sb.ToString())); } } sb.Clear(); p++; continue; } sb.AppendLine(s); } }