public static void AnalyzeEverything(List <BoardOrder> orders) { var client = LanguageServiceClient.Create(); var responses = new List <AnnotateTextResponse>(); var truncatedOrders = new List <BoardOrder>(); //Truncate orders with text exceeding the size limit. foreach (var order in orders.ToList()) { if (order.Text.Length > 60000) { var splitText = order.Text.SplitByLength(60000); foreach (var text in splitText) { truncatedOrders.Add(new BoardOrder() { Path = order.Path, Text = text, }); } orders.Remove(order); continue; } } orders.AddRange(truncatedOrders); // Get text from each order and run through the api foreach (var order in orders) { var response = client.AnnotateText(new Document() { //Removed new lines to get better output Content = order.Text.Replace("\r\n", " "), Type = Document.Types.Type.PlainText }, new Features() { ExtractSyntax = true, ExtractDocumentSentiment = true, ExtractEntities = true, ExtractEntitySentiment = true, ClassifyText = true }); order.SetResponse(response); } // save response NLPDatabase.SaveResponses(orders, _connString); return; }
public static void Main(string[] args) { // Before running through Google NLP api, I stored the board order text in a database in the board order table referenced in the db calls //Get order text and anazlyze var orders = NLPDatabase.GetBoardOrdersText(_connString); // Run through Google NLP api, save response in database in a Google table AnalyzeEverything(orders); ////Write sentences to output file //var responses = NLPDatabase.GetResponses( _connString); //responses = responses.Where(r => !r.Path.Contains("Sexual")).ToList(); //ExtractSentences(responses, _spath); Console.Write("\nPress any key to continue..."); Console.ReadKey(); }