public async Task <double> AnalyzeSentiment(string text, string lang = "en") { var T = new TextAnalysisDocumentStore(new TextAnalysisDocument("id", lang, text)); var R = await AnalyzeSentimentRaw(T); return(R.documents[0].score); }
public async Task <TextAnalysisDocumentStore> ExtractKeyphrases(TextAnalysisDocumentStore S) { var R = await ExtractKeyPhrasesRaw(S); CopyDocumentInfo(S, R); return(R); }
public async Task <TextAnalysisDocumentStore> AnalyzeSentiment(TextAnalysisDocumentStore S) { var R = await AnalyzeSentimentRaw(S); CopyDocumentInfo(S, R); return(R); }
public double AnalyzeSentiment(string text, string lang = "en") { var T = new TextAnalysisDocumentStore(new TextAnalysisDocument("id", lang, text)); var R = AnalyzeSentiment(T); return(R.documents[0].score); }
public TextAnalysisDocumentStore AnalyzeSentiment(TextAnalysisDocumentStore S) { TextAnalysisDocumentStore res = new TextAnalysisDocumentStore(); foreach (var d in S.documents) { var doc = new TextAnalysisDocument(d.id, d.language, d.text); doc.score = Analyze(d.text); res.documents.Add(doc); } return(res); }
private static void CopyDocumentInfo(TextAnalysisDocumentStore S, TextAnalysisDocumentStore R) { for (int i = 0; i < R.documents.Count; i++) { var t = (from x in S.documents where x.id == R.documents[i].id select x).FirstOrDefault(); if (t != null) { R.documents[i].text = t.text; R.documents[i].language = t.language; } } }
public async Task <TextAnalysisDocumentStore> AnalyzeSentimentRaw(TextAnalysisDocumentStore S) { var client = new HttpClient(); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", api_key); HttpResponseMessage response; var s = Newtonsoft.Json.JsonConvert.SerializeObject(S); byte[] byteData = Encoding.UTF8.GetBytes(s); TextAnalysisDocumentStore res; using (var content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response = await client.PostAsync(api_uri_sentiment, content); var rstr = await response.Content.ReadAsStringAsync(); res = Newtonsoft.Json.JsonConvert.DeserializeObject <TextAnalysisDocumentStore>(rstr); } return(res); }