public JsonResult getToneAnalyzer(string text) { List <ToneAnalysis> finalData = new List <ToneAnalysis>(); if (!string.IsNullOrEmpty(text)) { ToneAnalysis data = WatsonToneAnalyzerHelper.PostDataAndGetResponse(text, "<UID>", "<PWD>"); finalData.Add(data); } return(Json(finalData, JsonRequestBehavior.AllowGet)); }
public ActionResult Custom(string customText) { List <ToneAnalysis> finalData = new List <ToneAnalysis>(); if (!string.IsNullOrEmpty(customText)) { ToneAnalysis data = WatsonToneAnalyzerHelper.PostDataAndGetResponse(customText, "539f5087-eae9-4cab-bf67-0c8902c7a163", "PjCjY8PqfaXs"); finalData.Add(data); } return(View(finalData)); }
public static List <ToneAnalysis> response(List <string> text) { List <ToneAnalysis> finalData = new List <ToneAnalysis>(); foreach (var item in text) { if (!string.IsNullOrEmpty(item)) { var regexCss = new Regex(@"(?></?\w+)(?>(?:[^>'""]+|'[^']*'|""[^""]*"")*)>", RegexOptions.Singleline | RegexOptions.IgnoreCase); var finalItem = regexCss.Replace(item, string.Empty); var newString = string.Join(" ", Regex.Split(finalItem, @"(?:\r\n|\n|\r|\t)")); StringBuilder sb = new StringBuilder(); char[] longChars = newString.ToCharArray(); int spaceCount = 0; //Using standard method with no library help for (int i = 0; i < longChars.Length; i++) { //If space then keep a count and move on until nonspace char is found if (longChars[i] == 32) { spaceCount++; continue; } //If more than one space then append a single space if (spaceCount > 1 && sb.Length > 0) { sb.Append(" "); } //Append the non space character sb.Append(longChars[i]); //Reset the space count spaceCount = 1; } ToneAnalysis data = WatsonToneAnalyzerHelper.PostDataAndGetResponse(sb.ToString(), "<UID>", "<PWD>"); finalData.Add(data); } } return(finalData); }