public static async Task <IActionResult> WhatDidYouSay( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Functions with Fabian Text Analyisi Cog Svcs about to begin..."); IncomingText input = GetTextInfo(req); ITextAnalyticsClient client = new TextAnalyticsClient(new ApiKeyServiceClientCredentials()) { Endpoint = "https://eastus2.api.cognitive.microsoft.com" }; if (string.IsNullOrWhiteSpace(input.Text)) { return(new BadRequestObjectResult("Please pass an image URL on the query string or in the request body")); } else { SentimentBatchResult result = client.SentimentAsync( new MultiLanguageBatchInput( new List <MultiLanguageInput>() { new MultiLanguageInput(input.Language, input.Id, input.Text), })).Result; var outputItem = JsonConvert.SerializeObject(result.Documents[0].Score); log.LogInformation($"Evauated Sentiment of thet text: \"{input.Text}\" is: {outputItem}"); return(new OkObjectResult($"{outputItem}")); } }
private static void SendMessage(SenderObjectRelation senderObjectRelation) { Application.Current.Dispatcher.Invoke(delegate { if (senderObjectRelation.Group == null) { if (!MessageCollection.ContainsKey(senderObjectRelation.SenderId)) { MessageCollection.Add(senderObjectRelation.SenderId, new ObservableCollection <Message>()); } User friend = Friends.SingleOrDefault(f => f.Id == senderObjectRelation.SenderId); MessageCollection[senderObjectRelation.SenderId].Add((Message)senderObjectRelation.Data); IncomingText?.Invoke(senderObjectRelation); } else { Group group = Group.groups.SingleOrDefault(g => g.Id == senderObjectRelation.DestinationId); User friend = Friends.SingleOrDefault(f => f.Id == senderObjectRelation.SenderId); if (friend == null) { friend = new User(senderObjectRelation.SenderId); } group.Messages.Add(new Message(friend, senderObjectRelation.Data.ToString(), DateTime.Now)); IncomingText?.Invoke(senderObjectRelation, group); } }); }
private async Task <bool> HandleIncomingText(IncomingText message) { Debug.WriteLine($"{userName}: Received -> {message.Text}"); await HubContext.Clients.Group($"{Context.Parent.Path.Name}/{Context.Self.Path.Name}").SendAsync("IncomingMessage", message.Text, message.SenderName, message.Region); return(true); }
private async Task <bool> HandleIncomingText(IncomingText message) { await HubContext .Clients .Group($"{Context.Parent.Path.Name}/{Context.Self.Path.Name}") .SendAsync("IncomingMessage", message.Text, message.SenderName, message.Region); return(true); }
//No longer needed as i am using the native SDK Client /* * public static async Task<Quote[]> GetTextAnalysisResults(string txtPayload) * { * * string textUrlBase = Environment.GetEnvironmentVariable("TextCognitiveServicesUrlBase"); * string keyText = Environment.GetEnvironmentVariable("TextCognitiveServicesKey1"); * * string reqParams = "?returnFaceLandmarks=true&returnFaceAttributes=emotion"; * * var client = new HttpClient(); * client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", keyText); * * //var json = "{\"url\":\"" + $"{txtPayload}" + "\"}"; * var json = "{\"documents\": [{\"language\": \"en\", \"id\": \"1\",\"text\": \"" + $"{txtPayload}" + "\"}}]"; * * HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, textUrlBase); * request.Content = new StringContent(json, * Encoding.UTF8, * "application/json"); * * var resp = await client.SendAsync(request); * var jsonResponse = await resp.Content.ReadAsStringAsync(); * * * var quotes = JsonConvert.DeserializeObject<Quote[]>(jsonResponse); * * return quotes; * * } */ public static IncomingText GetTextInfo(HttpRequest req) { string txtInfo = req.Query["Text"]; string requestBody = new StreamReader(req.Body).ReadToEnd(); dynamic data = JsonConvert.DeserializeObject <IncomingText>(requestBody); if (string.IsNullOrWhiteSpace(txtInfo)) { return(data); } else { //the below is used to allow the GET method which only takes the raw text to conform //or cast to a IncomingText object. Be aware this hard codes English as the language txtInfo = "{\"Language\": \"en\", \"Id\": \"1\",\"Text\": \"" + $"{txtInfo}" + "\"}"; IncomingText txtData = JsonConvert.DeserializeObject <IncomingText>(txtInfo); return(txtData); } }
/* * private static double StringCompare(string a, string b) * { * if (a == b) * { * return 100; * } * if ((a.Length == 0) || (b.Length == 0)) * { * return 0; * } * double maxLen = a.Length > b.Length ? a.Length : b.Length; * var minLen = a.Length < b.Length ? a.Length : b.Length; * var sameCharAtIndex = 0; * for (var i = 0; i < minLen; i++) * { * if (a[i] == b[i]) * { * sameCharAtIndex++; * } * } * return sameCharAtIndex/maxLen*100; * } */ private static void CreateMenu() { Config = MainMenu.AddMenu("Chat Translator", "Config"); TranslatorMenu = Config.AddSubMenu("Translator", "Translator"); IncomingText = Config.AddSubMenu("IncomingText", "IncomingText"); OutgoingText = Config.AddSubMenu("OutgoingText", "OutgoingText"); Position = Config.AddSubMenu("Position", "Position"); Logger = Config.AddSubMenu("Logger", "Logger"); CopyPaste = Config.AddSubMenu("Paste", "Paste"); #region Translator Menu TranslatorMenu.Add("Check", new KeyBind("Check", true, KeyBind.BindTypes.HoldActive, 32)); #endregion #region Incoming Text Menu IncomingText.AddLabel("From: "); var incomingFrom = IncomingText.Add("From", new Slider("From: ", 0, 0, 63)); incomingFrom.DisplayName = FromArrayMenu[incomingFrom.CurrentValue]; incomingFrom.OnValueChange += delegate(ValueBase <int> sender, ValueBase <int> .ValueChangeArgs changeArgs) { sender.DisplayName = FromArrayMenu[changeArgs.NewValue]; }; IncomingText.AddLabel("To: "); var incomingTo = IncomingText.Add("To", new Slider("To: ", 0, 0, 62)); incomingTo.DisplayName = ToArrayMenu[incomingFrom.CurrentValue]; incomingTo.OnValueChange += delegate(ValueBase <int> sender, ValueBase <int> .ValueChangeArgs changeArgs) { sender.DisplayName = ToArrayMenu[changeArgs.NewValue]; }; IncomingText.Add("ShowInChat", new CheckBox("Show in chat", false)); IncomingText.Add("Enabled", new CheckBox("Enabled")); #endregion #region Outgoing Text Menu OutgoingText.AddLabel("From: "); var outgoingFrom = OutgoingText.Add("OutFrom", new Slider("From: ", 0, 0, 63)); outgoingFrom.DisplayName = FromArrayMenu[outgoingFrom.CurrentValue]; outgoingFrom.OnValueChange += delegate(ValueBase <int> sender, ValueBase <int> .ValueChangeArgs changeArgs) { sender.DisplayName = FromArrayMenu[changeArgs.NewValue]; }; OutgoingText.AddLabel("To: "); var outgoingTo = OutgoingText.Add("OutTo", new Slider("To: ", 0, 0, 62)); outgoingTo.DisplayName = ToArrayMenu[outgoingTo.CurrentValue]; outgoingTo.OnValueChange += delegate(ValueBase <int> sender, ValueBase <int> .ValueChangeArgs changeArgs) { sender.DisplayName = ToArrayMenu[changeArgs.NewValue]; }; OutgoingText.Add("EnabledOut", new CheckBox("Enabled", false)); #endregion #region Position Position.Add("Horizontal", new Slider("Horizontal", 15, 1, 2000)); Position.Add("Vertical", new Slider("Vertical", 500, 1, 2000)); Position.Add("AutoShow", new CheckBox("Show on message")); Position.Add("Duration", new Slider("Duration", 3000, 1000, 8000)); #endregion #region Logger Logger.Add("EnabledLog", new CheckBox("Enable")); #endregion #region Copy Paste CopyPaste.Add("Paste", new KeyBind("Paste", false, KeyBind.BindTypes.PressToggle, 'P')); CopyPaste.Add("PasteForAll", new KeyBind("Paste for all", false, KeyBind.BindTypes.PressToggle, 'O')); CopyPaste.Add("Delay", new Slider("Spam delay", 2000, 0, 2000)); CopyPaste.Add("DisablePaste", new CheckBox("Disable this section")); Config.AddLabel("You can use your own API key"); Config.AddLabel( "AppData\\Roaming\\EloBuddy\\yandexApiKey.txt, copy into the first line \"trnsl.1.1.201...\""); #endregion }