public static void SendQuestionNonsenseRequest(OffensivenessModelRequest offensivenessModel)
        {
            if (connections.ContainsKey("NLP") && connections["NLP"] != null && connections["NLP"].State == WebSocketState.Open && offensivenessModel != null)
            {
                String json = JsonSerializer.Serialize(offensivenessModel);

                connections["NLP"].SendAsync(new ArraySegment <byte>(usedEncoding.GetBytes(json), 0, json.Length), WebSocketMessageType.Text, true, CancellationToken.None);
            }
            else
            {
                taskQueue.Enqueue(new NLPTask <OffensivenessModelRequest>(offensivenessModel, SendQuestionNonsenseRequest));
            }
        }
        private void SendAnswerOffenseRequest(NewAnswerNonsenseCheck newAnswerNonsenseCheck)
        {
            var temp = new OffensivenessModelRequest(newAnswerNonsenseCheck);

            if (connections.ContainsKey("NLP") && connections["NLP"] != null && connections["NLP"].State == WebSocketState.Open && temp != null)
            {
                String json = JsonSerializer.Serialize(temp);

                connections["NLP"].SendAsync(new ArraySegment <byte>(usedEncoding.GetBytes(json), 0, json.Length), WebSocketMessageType.Text, true, CancellationToken.None);
            }
            else
            {
                taskQueue.Enqueue(new NLPTask <NewAnswerNonsenseCheck>(newAnswerNonsenseCheck, SendAnswerOffenseRequest));
            }
        }
        internal static void CheckIfQuestionIsNonsense(ChatbotNewQuestionModel chatbotNewQuestionModel)
        {
            var temp = new OffensivenessModelRequest(chatbotNewQuestionModel);

            if (connections.ContainsKey("NLP") && connections["NLP"] != null && connections["NLP"].State == WebSocketState.Open && temp != null)
            {
                String json = JsonSerializer.Serialize(temp);

                connections["NLP"].SendAsync(new ArraySegment <byte>(usedEncoding.GetBytes(json), 0, json.Length), WebSocketMessageType.Text, true, CancellationToken.None);
            }
            else
            {
                taskQueue.Enqueue(new NLPTask <ChatbotNewQuestionModel>(chatbotNewQuestionModel, CheckIfQuestionIsNonsense));
            }
        }
        internal static void SendTestToNLP()
        {
            if (connections.ContainsKey("NLP") && connections["NLP"] != null && connections["NLP"].State == WebSocketState.Open)
            {
                OffensivenessModelRequest omr = new OffensivenessModelRequest();
                omr.msg_id      = 65;
                omr.question    = "It's f*****g snowing!";
                omr.question_id = 25;
                omr.action      = "ESTIMATE_OFFENSIVENESS".ToLower();

                String json = JsonSerializer.Serialize(omr);

                connections["NLP"].SendAsync(new ArraySegment <byte>(usedEncoding.GetBytes(json), 0, json.Length), WebSocketMessageType.Text, true, CancellationToken.None);
            }
        }
예제 #5
0
        public IHttpActionResult GetTestQuestion()
        {
            OffensivenessModelRequest[] actions   = new OffensivenessModelRequest[1];
            OffensivenessModelRequest   nLPAction = new OffensivenessModelRequest();

            nLPAction.action      = DEFAULT_ACTION;
            nLPAction.question_id = -1;
            nLPAction.question    = "ROSES ARE RED, VIOLETS ARE BLUE, GANDALF IS A WIZARD, NOW FLY YOU FOOL!";
            nLPAction.msg_id      = -1;

            if (nLPAction == null)
            {
                return(NotFound());
            }
            actions[0] = nLPAction;
            return(Ok(actions));
        }
 /// <summary>
 /// Send a message to the NLP Controller to process the given answer and check if the contents are nonsone or not.
 ///
 /// </summary>
 /// <param name="result"></param>
 private void SendAnswerToNLPForNonsense(OffensivenessModelRequest result)
 {
     NLPWebSocketController.SendQuestionNonsenseRequest(result);
 }