Example #1
0
    public void ParseContextSetupReply(XmlReader reader)
    {
        // verify node is "context_setup_reply
        if (reader.Name == "context_setup_reply")
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "apiversion")
                {
                    csr.apiversion = reader.ReadElementContentAsString();
                    //UnityEngine.Debug.Log("apiversion=" + csr.apiversion);
                }
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "setup_request_status")
                {
                    csr.setup_request_status = reader.ReadElementContentAsInt();
                    //UnityEngine.Debug.Log("setup_request_status=" + csr.setup_request_status);
                }
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "context_uid")
                {
                    csr.context_uid = reader.ReadElementContentAsString();
					
#if SHOW_INIT
                    QuickInfoMsg msg = new QuickInfoMsg();
                    msg.title = "NLU STATUS";
                    msg.text = "NLU Initialized : " + CmdTime + " seconds";
                    msg.timeout = 2.0f;
                    QuickInfoDialog.GetInstance().PutMessage(msg);
#endif

                    Initialized = true;

                    //UnityEngine.Debug.Log("context_uid=" + csr.context_uid);
                }
            }
        }
    }
Example #2
0
    public void ParseUtteranceReply(XmlReader reader)
    {
        pur = new process_utterance_reply();

        // verify node is "context_setup_reply
        if (reader.Name == "process_utterance_reply")
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "utterance_request_status")
                {
                    pur.utterance_request_status = reader.ReadElementContentAsInt();
#if DEBUG_REPLY
                    UnityEngine.Debug.Log("utterance status=" + pur.utterance_request_status);
#endif
                    // report error
                    if (pur.utterance_request_status < 0 && errorCallback != null)
                    {
		                //'utterance_request_status' indicates if utterance process is final or NLU server starts 
		                // 0: OK. the 'match_record' list contains the simulation command(s) for the utterance
		                // 1: NLU server executes 'clarifying NLU sub-session' (see "SiTEL-SMS API Reqs & Specs" document)
		                //-1: cannot process utterance
		                //-2: MLU not ready for utterance processing
		                //-3: missing utterance text
                        string error="none";
                        switch (pur.utterance_request_status)
                        {
                            case -1:
                                error = "error -1: cannot process utterance";
                                break;
                            case -2:
                                error = "error -2: MLU not ready for utterance processing";
                                break;
                            case -3:
                                error = "error -3: missing utterance text";
                                break;
                        }
                        errorCallback(error);
                    }
                }
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "match_records")
                {
                    List<sim_command_param> parameters=null;
                    List<missing_sim_command_param> missing = null;
                    match_record record = null;

                    while (reader.Read())
                    {
#if DEBUG_REPLY
                        if (reader.NodeType == XmlNodeType.Element)
                            UnityEngine.Debug.Log("NODE_NAME=" + reader.Name + ", NODE_TYPE=" + reader.NodeType.ToString());
                        else if (reader.NodeType == XmlNodeType.EndElement)
                            UnityEngine.Debug.Log("NODE_END=" + reader.Name + ", NODE_TYPE=" + reader.NodeType.ToString());
                        else
                            UnityEngine.Debug.Log("NODE_TYPE=" + reader.NodeType.ToString());
#endif
                       
                        // match START element
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "match")
                        {
                            if (reader.IsEmptyElement == false)
                            {
                                record = new match_record();
                                if ( reader.MoveToAttribute("index") == false )
                                    UnityEngine.Debug.Log("CAN'T FIND INDEX!");
                                record.index = reader.ReadContentAsInt();
                                if ( reader.MoveToAttribute("sim_command") == false )
                                    UnityEngine.Debug.Log("CAN'T FIND SIM_COMMAND!");
                                record.sim_command = reader.ReadContentAsString();
                                if ( reader.MoveToAttribute("score") == false )
                                    UnityEngine.Debug.Log("CAN'T FIND SCORE!");
                                record.score = reader.ReadContentAsFloat();
                                if ( reader.MoveToAttribute("input") == false )
                                    UnityEngine.Debug.Log("CAN'T FIND INPUT!");
                                record.input = reader.ReadContentAsString();

#if DEBUG_REPLY
                                UnityEngine.Debug.Log("START MATCH : sim_command=" + record.sim_command);
#endif
                            }
                        }
                        // match END element
                        if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "match")
                        {
                            if (reader.IsEmptyElement == false)
                            {
#if DEBUG_REPLY
                                UnityEngine.Debug.Log("END MATCH");
#endif

                                pur.match_records.Add(record);

                                // do callback here, we have a valid match!!
                                if (utteranceCallback != null)
                                    utteranceCallback(record); 

                                record.Debug();
                            }
                        }
                        // sim command parameters
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "sim_command_params")
                        {
                            record.parameters = new List<sim_command_param>();

                            if (reader.IsEmptyElement == false)
                            {
#if DEBUG_REPLY
                                UnityEngine.Debug.Log("SIM_COMMAND_PARAMS");
#endif
                            }
                        }
                        // sc_param
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "sc_param")
                        {
                            sim_command_param sc_param = new sim_command_param();

                            if (reader.IsEmptyElement == false)
                            {
                                if (reader.MoveToAttribute("mandatory") == false)
                                    UnityEngine.Debug.Log("CAN'T FIND MANDATORY!");
                                sc_param.mandatory = reader.ReadContentAsString();
                                if ( reader.MoveToAttribute("name") == false )
                                    UnityEngine.Debug.Log("CAN'T FIND NAME!");
                                sc_param.name = reader.ReadContentAsString();
                                // value
                                reader.Read();
                                sc_param.value = reader.Value.Trim();
                                // add it
                                record.parameters.Add(sc_param);
    
                                sc_param.Debug();
                            }
                        }
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "missing_sim_command_params")
                        {
                            record.missing_parameters = new List<missing_sim_command_param>();

                            if (reader.IsEmptyElement == false)
                            {
#if DEBUG_REPLY
                                UnityEngine.Debug.Log("MISSING_SIM_COMMAND_PARAMS");
#endif
                            }
                        }
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "missing_sc_param") 
                        {
                            if (reader.IsEmptyElement == false)
                            {
                                missing_sim_command_param sc_param = new missing_sim_command_param();
#if DEBUG_REPLY
                                if (reader.MoveToAttribute("mandatory") == false)
                                    UnityEngine.Debug.Log("MISSING CAN'T FIND MANDATORY!");
                                sc_param.mandatory = reader.ReadContentAsString();
                                if (reader.MoveToAttribute("name") == false)
                                    UnityEngine.Debug.Log("MISSING CAN'T FIND NAME!");
#endif
                                sc_param.name = reader.ReadContentAsString();
                                record.missing_parameters.Add(sc_param);

                                sc_param.Debug();
                            }
                        }
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "readback")
                        {
                            if (reader.IsEmptyElement == false)
                            {
                                reader.Read();
                                record.readback = reader.Value.Trim();
#if DEBUG_REPLY
                                UnityEngine.Debug.Log("READBACK=<" + record.readback + ">");
#endif
                            }
                        }
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "feedback")
                        {
                            if (reader.IsEmptyElement == false)
                            {
                                reader.Read();
                                record.feedback = reader.Value.Trim();
#if DEBUG_REPLY
                                UnityEngine.Debug.Log("FEEDBACK=<" + record.feedback + ">");
#endif
                            }
                        }
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "command_subject")
                        {
                            if (reader.IsEmptyElement == false)
                            {
                                reader.Read();
                                record.command_subject = reader.Value.Trim();
#if DEBUG_REPLY
                                UnityEngine.Debug.Log("SUBJECT=<" + record.command_subject + ">");
#endif
                            }
                        }
                    }
                }
            }
        }
    }
Example #3
0
	protected virtual void LoadStatus (XmlReader reader) {
		reader.ReadToFollowing ("Status");
		reader.ReadToDescendant ("HP");
		HP = reader.ReadElementContentAsInt ();
	}