Exemplo n.º 1
0
            public void InitParser()
            {
                NLUIOClient nluIO = gameObject.GetComponent <NLUIOClient>();

                if (nluIO == null)
                {
                    _parser = new SimpleParser();
                }
                else   // I think that using the IO handlers is what's expected here
                {
                    _parser = new PythonJSONParser();
                    _parser.InitParserService(nluIO);
                }
            }
Exemplo n.º 2
0
            string route            = ""; // Don't expect to be setting it anytime soon

            public void InitParserService(NLUIOClient nluIO = null)
            {
                //Look, the SimpleParser doesn't do anything here either
                nluIOClient = nluIO;
            }
Exemplo n.º 3
0
            /// <summary>
            /// In this method, we actually invoke a request to the outside server
            /// </summary>
            public override IEnumerator AsyncRequest(string jsonPayload, string method, string url, string success, string error)
            {
                if (!url.StartsWith("http"))
                {
                    url = "http://" + url;
                }
                UnityWebRequest webRequest;

                Debug.Log("Payload is: " + jsonPayload);

                if (jsonPayload != "0")
                {
                    var form = new WWWForm();
                    form.AddField("sentence", jsonPayload); // IMPORTANT: Assumes there is a form with THIS PARICULAR NAME OF FIELD
                    webRequest = UnityWebRequest.Post(url, form);
                }
                else
                {
                    // Only really handles the initialization step, to see if the server is, in fact, real
                    webRequest = new UnityWebRequest(url + route, method); // route is specific page as directed by server
                    var payloadBytes = string.IsNullOrEmpty(jsonPayload)
                        ? Encoding.UTF8.GetBytes("{}")
                        : Encoding.UTF8.GetBytes(jsonPayload);

                    UploadHandler upload = new UploadHandlerRaw(payloadBytes);
                    webRequest.uploadHandler   = upload;
                    webRequest.downloadHandler = new DownloadHandlerBuffer();
                    webRequest.SetRequestHeader("Content-Type", "application/json");
                }

                webRequest.SendWebRequest();
                int count = 0;                                    // Try several times before failing

                while (count < 20)                                // 2 seconds max is good? Probably.
                {
                    yield return(new WaitForSeconds((float)0.1)); // Totally sufficient

                    if (webRequest.isNetworkError || webRequest.isHttpError)
                    {
                        Debug.LogWarning("Some sort of network error: " + webRequest.error + " from " + url);
                    }
                    else
                    {
                        // Show results as text
                        if (webRequest.downloadHandler.text != "")
                        {
                            last_read = webRequest.downloadHandler.text;
                            //BroadcastMessage("LookForNewParse"); // Tell something, in JointGestureDemo for instance, to grab the result
                            if (webRequest.downloadHandler.text != "connected")
                            {
                                SingleAgentInteraction sai = GameObject.FindObjectOfType <SingleAgentInteraction>();
                                sai.SendMessage("LookForNewParse");
                            }
                            else
                            {
                                // Blatantly janky
                                NLUIOClient parent = GameObject.FindObjectOfType <NLUIOClient>();
                                parent.nlurestclient = this; // Ew, disgusting
                            }

                            Debug.Log("Server took " + count * 0.1 + " seconds");
                            POST_okay(count * 0.1); // Parameter literally means nothing here.
                            break;
                        }
                    }
                    count++;
                }
                if (count >= 20)
                {
                    Debug.LogWarning("Server took 2+ seconds ");
                }
            }
Exemplo n.º 4
0
            //public void InitParserService(NLUServerHandler nlu = null) {
            //	// do nothing
            //}

            public void InitParserService(NLUIOClient nluIO)
            {
                throw new System.NotImplementedException();
            }