示例#1
0
        public async Task <TextAnalysisDocumentStore> ExtractKeyphrases(TextAnalysisDocumentStore S)
        {
            var R = await ExtractKeyPhrasesRaw(S);

            CopyDocumentInfo(S, R);
            return(R);
        }
示例#2
0
        public async Task <TextAnalysisDocumentStore> AnalyzeSentiment(TextAnalysisDocumentStore S)
        {
            var R = await AnalyzeSentimentRaw(S);

            CopyDocumentInfo(S, R);
            return(R);
        }
示例#3
0
        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);
        }
示例#4
0
        public static async Task <TextAnalysisDocumentStore> GetPhrasesforConversation()
        {
            TextAnalysisClient        client       = new TextAnalysisClient("d75051af54634a9e809edf8b2bf4e262");
            TextAnalysisDocumentStore SentResponse = await client.ExtractKeyphrases(fullConvHistory);

            return(SentResponse);
        }
示例#5
0
            public async Task AddSentance(string text, TextAnalysisDocumentStore fullhistory)
            {
                MessageCount++;
                Sentances.Add(text);
                if (Sentances.Count > 2)
                {
                    string merged = string.Empty;
                    foreach (string item in Sentances)
                    {
                        merged += " " + item;
                    }

                    TextAnalysisDocumentStore localStore = new TextAnalysisDocumentStore();
                    TextAnalysisDocument      doc        = new TextAnalysisDocument()
                    {
                        id = (localStore.documents.Count + 1).ToString(), text = merged
                    };
                    localStore.documents.Add(doc);
                    TextAnalysisClient client = new TextAnalysisClient("d75051af54634a9e809edf8b2bf4e262");
                    Sentances.Clear();
                    TextAnalysisDocumentStore SentResponse = await client.AnalyzeSentiment(localStore);

                    this.Sentiment = SentResponse.documents[0].score;
                    Graph.Add(ConversationState.GlobalTime++, Sentiment);
                    doc.id = (Convert.ToInt64(fullhistory.documents.Count) + 1).ToString();
                    fullhistory.documents.Add(doc);
                }
            }
示例#6
0
 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;
         }
     }
 }
示例#7
0
        public async void AddSentance(string text)
        {
            Sentances.Add(text);
            if (Sentances.Count > 2)
            {
                string merged = string.Empty;
                foreach (string item in Sentances)
                {
                    merged += " " + item;
                }

                TextAnalysisDocumentStore localStore = new TextAnalysisDocumentStore();
                localStore.documents.Add(new MediatorLib.TextAnalysisDocument()
                {
                    id = (localStore.documents.Count + 1).ToString(), text = merged
                });
                MediatorLib.TextAnalysisClient client = new MediatorLib.TextAnalysisClient("d75051af54634a9e809edf8b2bf4e262");
                Sentances.Clear();
                MediatorLib.TextAnalysisDocumentStore SentResponse = await client.AnalyzeSentiment(localStore);

                this.Sentiment = SentResponse.documents[0].score;
            }
        }
示例#8
0
        public async Task <TextAnalysisDocumentStore> ExtractKeyPhrasesRaw(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_keyphrases, content);

                var rstr = await response.Content.ReadAsStringAsync();

                res = Newtonsoft.Json.JsonConvert.DeserializeObject <TextAnalysisDocumentStore>(rstr);
            }
            return(res);
        }