public static ReturnModel Handle(string text, MSCGJson son) { string[][] sentences = son.result; string[] originalSentences = text.Split(' '); int originIndex = 0; int wordIndex = 0; Word[][] postags = new Word[sentences.Length][]; List <Word> list; for (int i = 0; i < sentences.Length; ++i) { list = new List <Word>(); foreach (string j in sentences[i]) { if (!isMSCGSymbol(j)) { list.Add(new Word(originalSentences[originIndex], POSType(j), syllableIndices(originalSentences[originIndex]), Syllable.Syllabify(originalSentences[originIndex++]), wordIndex++)); } } postags[i] = list.ToArray(); } return(new ReturnModel(postags, GenerateHTML(postags, true))); }
public static async Task <ReturnModel> MSCSSuggestions(string text) { var client = new HttpClient(); // Request headers client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", Credentials.SubscriptionKey); var uri = "https://westus.api.cognitive.microsoft.com/linguistics/v1.0/analyze"; // Request body string analyzeText = text; byte[] byteData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(MSCG.GenerateRequest(analyzeText))); // "{ \"language\" : \"en\", \"analyzerIds\" : [\"4fa79af1-f22c-408d-98bb-b7d7aeef7f04\"], \"text\" : \"" + analyzeText + "\"}"); using (var content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync(uri, content); var contents = await response.Content.ReadAsStringAsync(); MSCGJson[] son = JsonConvert.DeserializeObject <MSCGJson[]>(contents); MSCGJson daughter = son[0]; return(Handle(text, daughter)); } }