Пример #1
0
        private async void WitText_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                this.Focus();

                ProgressBar.IsIndeterminate = true;

                Wit wit = new Wit("CBP3OGVVJI23M5XAH7ARKOMDDSKB3HJV");

                WitResponse witResponse = await wit.CaptureTextIntent(WitText.Text);

                if (witResponse != null && witResponse.outcomes != null && witResponse.outcomes.Count > 0)
                {
                    WitIntent.Text = "Intent = " + witResponse.outcomes[0].intent;

                    if (witResponse.outcomes[0].entities.ContainsKey("datetime"))
                    {
                        List <WitDateTimeEntity> dateEntities = witResponse.outcomes[0].entities["datetime"].ToObject <List <WitDateTimeEntity> >();
                    }
                }
                else
                {
                    WitIntent.Text = "Intent not found";
                }

                ProgressBar.IsIndeterminate = false;
            }
        }
Пример #2
0
 private void OnValidate()
 {
     if (!wit)
     {
         wit = FindObjectOfType <Wit>();
     }
 }
Пример #3
0
        public WitService()
        {
            _actions = new WitActions();
            _actions["send"] = Send;
            _actions["time"] = TellTheTime;

            _witClient = new Wit("2PDIOI3QNKWLN5HQMSQLZJT4DYUSZ2RT", _actions)
            {
                WIT_API_VERSION = "20170307"
            };
        }
Пример #4
0
        static void Main(string[] args)
        {
            var actions = new WitActions();

            actions["send"] = Send;


            Wit wit = new Wit(accessToken: "<SERVER_ACCESS_TOKEN>", actions: actions);

            wit.Converse("session-id-01", "Hi!", new WitContext());
        }
Пример #5
0
        private void AffectURI(Uri baseAddress)
        {
            _baseAddress = baseAddress.AbsoluteUri;
            _builds      = BaseObjectApi <Builds> .CreateObject(this);

            _TestResults = BaseObjectApi <Test> .CreateObject(this);

            _VersionControl = BaseObjectApi <Versioncontrol> .CreateObject(this);

            _wit = BaseObjectApi <Wit> .CreateObject(this);

            _getComments = BaseObjectApi <GetComments> .CreateObject(this);
        }
Пример #6
0
        static async Task Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var wit = new Wit("COM3");

            Task.Run(() => wit.Print());

            await wit.Open();

            await wit.Start();

            Console.ReadKey();
        }
Пример #7
0
        public void Brain()
        {
            var actions = new WitActions();

            actions["send"] = Send;

            Wit client = new Wit(accessToken: accessToken, actions: actions);

            var    response = client.Message("hello dupa");
            string dupa     = String.Join("", response.Entities.Values);


            dynamic reply = response.Entities.Values;



            Console.WriteLine("Yay, got Wit.ai response: " + response.Entities.ToString());
        }
Пример #8
0
        public string Tokenise(string line)
        {
            // Create a new wit client to connect to wit.ai
            Wit client = new Wit(accessToken: ACCESS_TOKEN);

            // Get wit response
            var response = client.Message(line);


            string lex_chunk = string.Empty;

            // Reflects BIDMAS order of operations

            if (response.Entities.ContainsKey("identity"))
            {
                // Deal with identities
                string ident = (string)response.Entities["identity"][0]["value"];

                // Add to lex_chunk
                lex_chunk += ident;

                // Only do assignment if first character in the line is a variable, followed by equals
                if (line.Substring(0, 1) == ident && (line.Substring(1, 1) == "=" || line.Substring(1, 2) == " =" || line.Substring(1, 2) == " = "))
                {
                    lex_chunk += " = ";
                }
            }

            if (response.Entities.ContainsKey("divide"))
            {
                // Divide

                // Outputs x / y
                if (response.Entities["number"].Count > 0)
                {
                    if (response.Entities["number"].Count == 1)
                    {
                        lex_chunk += response.Entities["number"][0]["value"];
                        lex_chunk += " / ";
                        if (line.Substring(0, 1) == (string)response.Entities["identity"][0]["value"])
                        {
                            lex_chunk += response.Entities["identity"][1]["value"];
                        }
                        else
                        {
                            lex_chunk += response.Entities["identity"][0]["value"];
                        }
                    }
                    else
                    {
                        lex_chunk += response.Entities["number"][0]["value"];
                        lex_chunk += " / ";
                        lex_chunk += response.Entities["number"][1]["value"];
                    }
                }
                else
                {
                    lex_chunk += " / ";
                }
            }

            if (response.Entities.ContainsKey("multiply"))
            {
                // Multiply
                // output x * y
                if (response.Entities["number"].Count > 0)
                {
                    if (response.Entities["number"].Count == 1)
                    {
                        lex_chunk += response.Entities["number"][0]["value"];
                        lex_chunk += " * ";
                        if (line.Substring(0, 1) == (string)response.Entities["identity"][0]["value"])
                        {
                            lex_chunk += response.Entities["identity"][1]["value"];
                        }
                        else
                        {
                            lex_chunk += response.Entities["identity"][0]["value"];
                        }
                    }
                    else
                    {
                        lex_chunk += response.Entities["number"][0]["value"];
                        lex_chunk += " * ";
                        lex_chunk += response.Entities["number"][1]["value"];
                    }
                }
                else
                {
                    lex_chunk += " * ";
                }
            }

            if (response.Entities.ContainsKey("add"))
            {
                // Add
                // outpus x + y
                if (response.Entities["number"].Count > 0)
                {
                    if (response.Entities["number"].Count == 1)
                    {
                        lex_chunk += response.Entities["number"][0]["value"];
                        lex_chunk += " + ";
                        if (line.Substring(0, 1) == (string)response.Entities["identity"][0]["value"])
                        {
                            lex_chunk += response.Entities["identity"][1]["value"];
                        }
                        else
                        {
                            lex_chunk += response.Entities["identity"][0]["value"];
                        }
                    }
                    else
                    {
                        lex_chunk += response.Entities["number"][0]["value"];
                        lex_chunk += " + ";
                        lex_chunk += response.Entities["number"][1]["value"];
                    }
                }
                else
                {
                    lex_chunk += " + ";
                }
            }

            if (response.Entities.ContainsKey("subtract"))
            {
                // Subtract
                // outputs x - y
                if (response.Entities["number"].Count > 0)
                {
                    if (response.Entities["number"].Count == 1)
                    {
                        lex_chunk += response.Entities["number"][1]["value"];
                        lex_chunk += " - ";
                        if (line.Substring(0, 1) == (string)response.Entities["identity"][0]["value"])
                        {
                            lex_chunk += response.Entities["identity"][1]["value"];
                        }
                        else
                        {
                            lex_chunk += response.Entities["identity"][0]["value"];
                        }
                    }
                    else
                    {
                        lex_chunk += response.Entities["number"][1]["value"];
                        lex_chunk += " - ";
                        lex_chunk += response.Entities["number"][0]["value"];
                    }
                }
                else
                {
                    lex_chunk += " - ";
                }
            }

            if (response.Entities.ContainsKey("function"))
            {
                // Deal with functions
                var function_name = response.Entities["function"][0]["value"];
                lex_chunk  = lex_chunk.Insert(0, function_name + "(");
                lex_chunk += ")";
            }

            return(lex_chunk);
        }