RunSQL() public static method

Runs the passed in SQL query on the database and returns a dataset of the results
public static RunSQL ( string sql ) : DataSet
sql string
return System.Data.DataSet
        public static SpeechRecognitionEngine Load_User_Grammar(SpeechRecognitionEngine oRecognizer)
        {
            //User

            List <string> userList  = new List <string>();
            DataSet       dsResults = new DataSet();

            try
            {
                //Load all users
                dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE base_type='PERSON'");
                for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++)
                {
                    userList.Add(dsResults.Tables[0].Rows[i][0].ToString());
                }
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar User Grammar 1: " + ex.Message, ex); }

            Choices userChoices = new Choices(userList.ToArray());
            Choices tempChoices = new Choices(new string[] { "this is", "I am" });

            try
            {
                GrammarBuilder    builder = new GrammarBuilder(tempChoices);
                SemanticResultKey srk     = new SemanticResultKey("PARAM1", userChoices);
                builder.Append(srk);
                Grammar gram = new Grammar(builder);
                gram.Name = "This is [OBJECT]";
                oRecognizer.LoadGrammar(gram);
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar User Grammar 2: " + ex.Message, ex); }
            return(oRecognizer);
        }
Example #2
0
 /// <summary>
 /// Object type Clone
 /// </summary>
 /// <param name="object_type_name">The name of the object type</param>
 public static void ObjectTypeClone(string NewObjectTypeName, string BaseObjectTypeName)
 {
     using (MySqlCommand command = new MySqlCommand())
     {
         //command.Parameters.Add(new MySqlParameter("@pexport_script", MySqlDbType.Text));
         //command.Parameters["@pexport_script"].Direction = System.Data.ParameterDirection.Output;
         OSAESql.RunSQL("CALL osae_sp_object_type_clone ('" + NewObjectTypeName.Replace("'", "''") + "','" + BaseObjectTypeName.Replace("'", "''") + "')");
     }
 }
        public static string GetQuestion()
        {
            DataSet dataset = new DataSet();

            dataset = OSAESql.RunSQL("CALL osae_sp_ai_get_question;'");
            if (dataset.Tables[0].Rows.Count > 0)
            {
                return(dataset.Tables[0].Rows[0][0].ToString());
            }
            else
            {
                return("");
            }
        }
Example #4
0
 /// <summary>
 /// Get all object names that start with a single word
 /// </summary>
 /// <param name="pattern"></param>
 /// <returns></returns>
 public static DataSet ObjectNamesStartingWith(string pattern)
 {
     using (MySqlCommand command = new MySqlCommand())
     {
         // DataSet dataset = new DataSet();
         // command.CommandText = "SELECT object_name FROM osae_object WHERE UPPER(object_name) LIKE '@Pattern%' ORDER BY Length(object_name) DESC";
         //  command.Parameters.AddWithValue("@Pattern", pattern.ToUpper());
         //  dataset = OSAESql.RunQuery(command);
         //  return dataset;
         DataSet dataset = new DataSet();
         //command.CommandText = "SELECT object_name FROM osae_object WHERE UPPER(object_name) LIKE '@Pattern%' ORDER BY Length(object_name) DESC";
         //command.Parameters.AddWithValue("@Pattern", pattern.ToUpper());
         dataset = OSAESql.RunSQL("SELECT object_name FROM osae_object WHERE (UPPER(object_name) LIKE UPPER('" + pattern.Replace("'", "''") + "%') OR UPPER(object_alias) LIKE UPPER('" + pattern.Replace("'", "''") + "%')) ORDER BY Length(object_name) DESC");
         return(dataset);
     }
 }
        public static string SearchForMeaning(string str, string ScriptParameter, string sUser)
        {
            DataSet dataset = new DataSet();

            dataset = OSAESql.RunSQL("SELECT pattern FROM osae_v_pattern_match WHERE `match`='" + str.Replace("'", "''") + "'");
            if (dataset.Tables[0].Rows.Count > 0)
            {
                //Since we have a match, lets execute the scripts
                OSAEScriptManager.RunPatternScript(dataset.Tables[0].Rows[0]["pattern"].ToString(), ScriptParameter, sUser);
                return(dataset.Tables[0].Rows[0]["pattern"].ToString());
            }
            else
            {
                return("Sorry!");
            }
        }
        public static SpeechRecognitionEngine Load_Direct_Grammar(SpeechRecognitionEngine oRecognizer)
        {
            List <string> grammerList = new List <string>();
            DataSet       dsResults   = new DataSet();
            Choices       myChoices   = new Choices();

            try
            {
                //Load all unique patterns with no place-holders into a single grammer, our main one.
                dsResults = OSAESql.RunSQL("SELECT `match` FROM osae_pattern_match WHERE UPPER(`match`) NOT LIKE '%[OBJECT]%' AND UPPER(`match`) NOT LIKE '%[STATE]%' AND UPPER(`match`) NOT LIKE '%[PRONOUN]%' ORDER BY `match`");
                //grammerList.Add(gWakePhrase);
                //grammerList.Add(gSleepPhrase);
                for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++)
                {
                    string sTemp = dsResults.Tables[0].Rows[i][0].ToString();

                    if (!string.IsNullOrEmpty(sTemp))
                    {
                        SemanticResultKey srk = new SemanticResultKey(sTemp, sTemp);
                        myChoices.Add(srk);
                    }
                }
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar Direct Grammar 1: " + ex.Message, ex); }
            try
            {
                GrammarBuilder builder = new GrammarBuilder(myChoices);
                Grammar        gram    = new Grammar(builder);
                gram.Name = "Direct Match";
                oRecognizer.LoadGrammar(gram);
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar Direct Grammar 2: " + ex.Message, ex); }

            return(oRecognizer);
        }
        public static string MatchPattern(string str)
        {
            string ScriptParameter = "";

            try
            {
                DataSet dataset = new DataSet();
                //command.CommandText = "SELECT pattern FROM osae_v_pattern WHERE `match`=@Name";
                //command.Parameters.AddWithValue("@Name", str);
                dataset = OSAESql.RunSQL("SELECT pattern FROM osae_v_pattern WHERE `match`='" + str + "'");

                if (dataset.Tables[0].Rows.Count > 0)
                {
                    //Since we have a match, lets execute the scripts
                    OSAEScriptManager.RunPatternScript(dataset.Tables[0].Rows[0]["pattern"].ToString(), "", "Jabber");
                    return(dataset.Tables[0].Rows[0]["pattern"].ToString());
                }
                else
                {
                    //Replace Words with place holders and retry the pattern match
                    //example  "Please turn the main light on" becomes "Please turn the [OBJECT] [STATE]"

                    //Step 1: Break the Input into an Array to Query the Words for DB matches
                    str = str.ToUpper();
                    string[] words = str.Split(' ');

                    DataSet dsObjects = new DataSet();
                    foreach (String word in words)
                    {
                        dsObjects = OSAE.Common.ObjectNamesStartingWith(word);
                        foreach (DataRow dr in dsObjects.Tables[0].Rows)
                        {
                            if (str.IndexOf(dr["object_name"].ToString()) > -1)
                            //return "Found " + dr["object_name"].ToString();
                            {
                                str              = str.Replace(dr["object_name"].ToString(), "[OBJECT]");
                                ScriptParameter += dr["object_name"].ToString();
                                //Here We have found our Object, so we need to look for an appropriate state afterwards
                                //So we are going to retrieve a state list and compare it to the remainder of the string

                                DataSet dsStates = new DataSet();
                                dsStates = OSAEObjectStateManager.ObjectStateListGet(dr["object_name"].ToString());
                                foreach (DataRow drState in dsStates.Tables[0].Rows)
                                {
                                    if (str.IndexOf(drState["state_label"].ToString().ToUpper()) > 0)
                                    {
                                        str              = str.Replace(drState["state_label"].ToString().ToUpper(), "[STATE]");
                                        ScriptParameter += ", " + drState["state_label"].ToString();

                                        //Now that we have replaced the Object and State, Lets check for a match again
                                        //DataSet dataset = new DataSet();
                                        //command.CommandText = "SELECT pattern FROM osae_v_pattern WHERE `match`=@Name";
                                        //command.Parameters.AddWithValue("@Name", str);
                                        //dataset = OSAESql.RunQuery(command);
                                        dataset = OSAESql.RunSQL("SELECT pattern FROM osae_v_pattern WHERE `match`='" + str + "'");
                                        if (dataset.Tables[0].Rows.Count > 0)
                                        {
                                            //return dataset.Tables[0].Rows[0]["pattern"].ToString();
                                            //Since we have a match, lets execute the scripts
                                            OSAEScriptManager.RunPatternScript(dataset.Tables[0].Rows[0]["pattern"].ToString(), ScriptParameter, "Jabber");
                                            return(dataset.Tables[0].Rows[0]["pattern"].ToString());
                                        }
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                    return(string.Empty);
                    //return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - MatchPattern error: " + ex.Message, true);
                return(string.Empty);
            }
        }
Example #8
0
        public static string MatchPattern(string str)
        {
            string ScriptParameter = "";

            try
            {
                str = str.TrimEnd('?', '.', '!');
                str = str.Replace(" 'S", "'S");
                str = str.Replace(" 's", "'s");
                DataSet dataset = new DataSet();
                //command.CommandText = "SELECT pattern FROM osae_v_pattern WHERE `match`=@Name";
                //command.Parameters.AddWithValue("@Name", str);
                dataset = OSAESql.RunSQL("SELECT pattern FROM osae_v_pattern_match WHERE `match`='" + str.Replace("'", "''") + "'");

                if (dataset.Tables[0].Rows.Count > 0)
                {
                    //Since we have a match, lets execute the scripts
                    OSAEScriptManager.RunPatternScript(dataset.Tables[0].Rows[0]["pattern"].ToString(), "", "Jabber");
                    return(dataset.Tables[0].Rows[0]["pattern"].ToString());
                }
                else
                {
                    //Replace Words with place holders and retry the pattern match
                    //example  "Please turn the main light on" becomes "Please turn the [OBJECT] [STATE]"

                    //Step 1: Break the Input into an Array to Query the Words for DB matches
                    str = str.ToUpper();

                    string[] words = str.Split(' ');

                    DataSet dsObjects = new DataSet();
                    foreach (String word in words)
                    {
                        dsObjects = OSAE.Common.ObjectNamesStartingWith(word.Replace("'S", ""));
                        foreach (DataRow dr in dsObjects.Tables[0].Rows)
                        {
                            if (str.IndexOf(dr["object_name"].ToString().ToUpper()) > -1)
                            //return "Found " + dr["object_name"].ToString();
                            {
                                str = str.Replace(dr["object_name"].ToString().ToUpper(), "[OBJECT]");
                                if (ScriptParameter.Length > 1)
                                {
                                    ScriptParameter = ScriptParameter + ",";
                                }
                                ScriptParameter += dr["object_name"].ToString();
                                //Determine if the Object is Possessive, which would be followed by a Property
                                if (str.ToUpper().IndexOf("[OBJECT]'S") > -1)
                                {
                                    //Here We have found our Possessive Object, so we need to look for an appropriate property afterwards
                                    //So we are going to retrieve a property list and compare it to the start of theremainder of the string

                                    DataSet dsProperties = new DataSet();
                                    dsProperties = OSAEObjectPropertyManager.ObjectPropertyListGet(dr["object_name"].ToString());
                                    foreach (DataRow drProperty in dsProperties.Tables[0].Rows)
                                    {
                                        //Here we need to break the string into words to avoid partial matches
                                        int    objectStartLoc = str.ToUpper().IndexOf("[OBJECT]'S");
                                        string strNewSearch   = str.Substring(objectStartLoc + 11);
                                        if (strNewSearch.ToUpper().IndexOf(drProperty["property_name"].ToString().ToUpper()) > -1)
                                        {
                                            str = str.Replace("[OBJECT]'S " + drProperty["property_name"].ToString().ToUpper(), "[OBJECT]'S [PROPERTY]");
                                            //str = str.Replace(drState["state_label"].ToString().ToUpper(), "[STATE]");
                                            ScriptParameter += "," + drProperty["property_name"].ToString();
                                        }
                                    }
                                }

                                //Here We have found our Object, so we need to look for an appropriate state afterwards
                                //So we are going to retrieve a state list and compare it to the remainder of the string
                                DataSet dsStates = new DataSet();
                                dsStates = OSAEObjectStateManager.ObjectStateListGet(dr["object_name"].ToString());
                                foreach (DataRow drState in dsStates.Tables[0].Rows)
                                {
                                    //Here we need to break the string into words to avoid partial matches
                                    string   replacementString = "";
                                    string[] wordArray         = str.Split(new Char[] { ' ' });
                                    foreach (string w in wordArray)
                                    {
                                        if (replacementString.Length > 1)
                                        {
                                            replacementString = replacementString + " ";
                                        }
                                        if (drState["state_label"].ToString().ToUpper() == w || drState["state_name"].ToString().ToUpper() == w)
                                        {
                                            replacementString = replacementString + "[STATE]";
                                            //str = str.Replace(drState["state_label"].ToString().ToUpper(), "[STATE]");
                                            ScriptParameter += "," + drState["state_name"].ToString();
                                        }
                                        else
                                        {
                                            replacementString = replacementString + w;
                                        }
                                    }
                                    //Now that we have replaced the Object and State, Lets check for a match again
                                    //DataSet dataset = new DataSet();
                                    //command.CommandText = "SELECT pattern FROM osae_v_pattern WHERE `match`=@Name";
                                    //command.Parameters.AddWithValue("@Name", str);
                                    //dataset = OSAESql.RunQuery(command);
                                    replacementString = replacementString.Replace(" 'S", "'S");
                                    dataset           = OSAESql.RunSQL("SELECT pattern FROM osae_v_pattern_match WHERE `match`='" + replacementString.Replace("'", "''") + "'");
                                    if (dataset.Tables[0].Rows.Count > 0)
                                    {
                                        //return dataset.Tables[0].Rows[0]["pattern"].ToString();
                                        //Since we have a match, lets execute the scripts
                                        OSAEScriptManager.RunPatternScript(dataset.Tables[0].Rows[0]["pattern"].ToString(), ScriptParameter, "Jabber");
                                        return(dataset.Tables[0].Rows[0]["pattern"].ToString());
                                    }
                                    //break;
                                }
                                //break;
                            }
                        }
                    }
                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - MatchPattern error: " + ex.Message, true);
                return(string.Empty);
            }
        }
        public static SpeechRecognitionEngine Load_Voice_Grammars(SpeechRecognitionEngine oRecognizer)
        {
            Choices nounPrecedentChoices = new Choices(new string[] { "a", "an", "the" });
            Choices pronounChoices       = new Choices(new string[] { "I", "you" });
            Choices possPronounChoices   = new Choices(new string[] { "my", "your" });
            Choices IsChoices            = new Choices(new string[] { "is", "am", "are" });
            Choices WhatWhoChoices       = new Choices(new string[] { "what is", "who is" });
            DataSet dsResults            = new DataSet();

            #region Build a List of all Objects AND Possessive Objects
            List <string> objectFullList       = new List <string>();
            List <string> objectPossessiveList = new List <string>();
            //Get All objects
            dsResults = OSAESql.RunSQL("SELECT object_name, CONCAT(object_name,'''s') AS possessive_name FROM osae_v_object_list_full");
            for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++)
            {
                string grammer           = dsResults.Tables[0].Rows[i][0].ToString();
                string possessivegrammer = dsResults.Tables[0].Rows[i][1].ToString();
                if (!string.IsNullOrEmpty(grammer))
                {
                    objectFullList.Add(grammer);
                }
                if (!string.IsNullOrEmpty(possessivegrammer))
                {
                    objectPossessiveList.Add(possessivegrammer);
                }
            }
            Choices objectFullChoices       = new Choices(objectFullList.ToArray());
            Choices objectPossessiveChoices = new Choices(objectPossessiveList.ToArray());
            #endregion

            #region Build a List of all Containers

            List <string> containerList = new List <string>();
            //Get All containers
            dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE container=1");
            foreach (DataRow dr in dsResults.Tables[0].Rows)
            {
                containerList.Add(dr[0].ToString());
            }
            Choices containerChoices = new Choices(containerList.ToArray());
            #endregion

            #region Build a List of all Object Types
            List <string> objectTypeList = new List <string>();
            dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type");
            foreach (DataRow dr in dsResults.Tables[0].Rows)
            {
                objectTypeList.Add(dr[0].ToString());
            }
            Choices objectTypeChoices = new Choices(objectTypeList.ToArray());
            #endregion

            //Choices are done, now write the grammars

            #region What is [OBJECT]'s [PROPERTY]
            //1 What/Who is my/your PROPERTY
            //2 What/Who is OBJECT's PROPERTY
            //3 What/Who is NP OBJECT's PROPERTY
            try {
                GrammarBuilder    gb1 = new GrammarBuilder(WhatWhoChoices);
                SemanticResultKey srk = new SemanticResultKey("PARAM1", possPronounChoices);
                gb1.Append(srk);
                GrammarBuilder gb2 = new GrammarBuilder(WhatWhoChoices);
                GrammarBuilder gb3 = new GrammarBuilder(WhatWhoChoices);
                gb3.Append(nounPrecedentChoices);

                List <string> propertyList = new List <string>();

                srk = new SemanticResultKey("PARAM1", objectPossessiveChoices);
                gb2.Append(srk);
                gb3.Append(srk);

                dsResults = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property");
                foreach (DataRow dr in dsResults.Tables[0].Rows)
                {
                    propertyList.Add(dr[0].ToString());
                }
                Choices propertyChoices = new Choices(propertyList.ToArray());

                srk = new SemanticResultKey("PARAM2", propertyChoices);
                gb1.Append(srk);
                Grammar g1 = new Grammar(gb1);
                g1.Name = "What is [OBJECT] [PROPERTY]";
                oRecognizer.LoadGrammar(g1);
                gb2.Append(srk);
                Grammar g2 = new Grammar(gb2);
                g2.Name = "What is [OBJECT] [PROPERTY]";
                oRecognizer.LoadGrammar(g2);

                gb3.Append(srk);
                Grammar g3 = new Grammar(gb3);
                g3.Name = "What is [OBJECT] [PROPERTY]";
                oRecognizer.LoadGrammar(g3);
            }

            catch (Exception ex)
            { throw new Exception("API.Grammar Voice Grammar, What is: " + ex.Message, ex); }

            #endregion

            //Too slow
            #region [Object] [State]

            /*
             * // 1 Are you STATE
             * // 2 Am I STATE
             * // 3 Is OBJECT STATE?
             * // 4 Is [NP] OBJECT STATE?
             *
             * // 5 You are STATE
             * // 6 I am STATE
             * // 7 OBJECT is STATE
             * // 8 [NP] OBJECT is STATE
             * GrammarBuilder gb1 = new GrammarBuilder("Are");
             * GrammarBuilder gb5 = new GrammarBuilder();
             * srk = new SemanticResultKey("PARAM1", "you");
             * gb1.Append(srk);
             * gb5.Append(srk);
             *
             * GrammarBuilder gb2 = new GrammarBuilder("Am");
             * GrammarBuilder gb6 = new GrammarBuilder();
             * srk = new SemanticResultKey("PARAM1", "I");
             * gb2.Append(srk);
             * gb6.Append(srk);
             *
             * //builder.Append(objectChoices);
             *
             * foreach (string ot in objectTypeList)
             * {
             * List<string> stateList = new List<string>();
             * GrammarBuilder gb3 = new GrammarBuilder("Is");
             * GrammarBuilder gb4 = new GrammarBuilder("Is");
             * gb4.Append(nounPrecedentChoices);
             *
             * GrammarBuilder gbNPObjectIsState = new GrammarBuilder(nounPrecedentChoices);
             *
             * //Get All objects of the current Object Type
             * List<string> objectList = new List<string>();
             * dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'");
             * foreach (DataRow dr in dsResults.Tables[0].Rows)
             * {
             * objectList.Add(dr[0].ToString());
             * }
             * if (objectList.Count > 0)  // Only bother with this object type if there are objects using it
             * {
             * Choices objectChoices = new Choices(objectList.ToArray());
             * srk = new SemanticResultKey("PARAM1", objectChoices);
             *
             * gb3.Append(srk);
             * gb4.Append(srk);
             * GrammarBuilder gbObjectIsState = new GrammarBuilder(srk);
             * gbNPObjectIsState.Append(srk);
             * gbObjectIsState.Append("is");
             * gbNPObjectIsState.Append("is");
             *
             * //Now the the appropriate states
             * dsResults = OSAESql.RunSQL("SELECT state_label FROM osae_v_object_type_state_list_full WHERE object_type='" + ot + "'");
             * foreach (DataRow dr in dsResults.Tables[0].Rows)
             * {
             *     stateList.Add(dr[0].ToString());
             * }
             * if (stateList.Count > 0)
             * {
             *     Choices stateChoices = new Choices(stateList.ToArray());
             *     srk = new SemanticResultKey("PARAM2", stateChoices);
             *     if (ot == "PERSON")
             *     {
             *         gb2.Append(srk);
             *         Grammar gAmIState = new Grammar(gb2);
             *         gAmIState.Name = "Is [OBJECT] [STATE]";
             *         oRecognizer.LoadGrammar(gAmIState);
             *
             *     }
             *     else if (ot == "SYSTEM")
             *     {
             *         gb1.Append(srk);
             *         Grammar g1 = new Grammar(gb1);
             *         g1.Name = "Is [OBJECT] [STATE]";
             *         oRecognizer.LoadGrammar(g1);
             *
             *         gb5.Append(srk);
             *         Grammar g5 = new Grammar(gb5);
             *         g5.Name = "Is [OBJECT] [STATE]";
             *         oRecognizer.LoadGrammar(g5);
             *     }
             *
             *     gb3.Append(srk);
             *     Grammar gIsObjectState = new Grammar(gb3);
             *     gIsObjectState.Name = "Is [OBJECT] [STATE]";
             *     oRecognizer.LoadGrammar(gIsObjectState);
             *
             *     gb4.Append(srk);
             *     Grammar gIsNPObjectState = new Grammar(gb4);
             *     gIsNPObjectState.Name = "[OBJECT] is [STATE]";
             *     oRecognizer.LoadGrammar(gIsNPObjectState);
             *
             *     gbObjectIsState.Append(srk);
             *     Grammar gObjectIsState = new Grammar(gbObjectIsState);
             *     gObjectIsState.Name = "[OBJECT] is [STATE]";
             *     oRecognizer.LoadGrammar(gObjectIsState);
             *
             *     gbNPObjectIsState.Append(srk);
             *     Grammar gNPObjectIsState = new Grammar(gbNPObjectIsState);
             *     gNPObjectIsState.Name = "[OBJECT] is [STATE]";
             *     oRecognizer.LoadGrammar(gNPObjectIsState);
             * }
             * }
             * }
             */
            #endregion

            #region New [Object] [State]
            // 1 [Am I/Are you] STATE
            // 2 Is OBJECT STATE?
            // 3 Is [NP] OBJECT STATE?

            // 4 [I am/You are] STATE
            // 5 OBJECT is STATE
            // 6 [NP] OBJECT is STATE
            // 7 OBJECT STATE
            try
            {
                GrammarBuilder    gb1 = new GrammarBuilder(IsChoices);
                GrammarBuilder    gb4 = new GrammarBuilder();
                SemanticResultKey srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb1.Append(srk);
                gb4.Append(srk);

                List <string>  stateList = new List <string>();
                GrammarBuilder gb2       = new GrammarBuilder("Is");
                GrammarBuilder gb3       = new GrammarBuilder("Is");
                gb3.Append(nounPrecedentChoices);

                GrammarBuilder gb6 = new GrammarBuilder(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM1", objectFullChoices);

                gb2.Append(srk);
                gb3.Append(srk);
                GrammarBuilder gb5 = new GrammarBuilder(srk);
                gb6.Append(srk);
                gb5.Append("is");
                gb6.Append("is");
                GrammarBuilder gb7 = new GrammarBuilder(srk);

                //Now the the appropriate states
                dsResults = OSAESql.RunSQL("SELECT DISTINCT state_label FROM osae_v_object_type_state_list_full WHERE state_label IS NOT NULL");
                foreach (DataRow dr in dsResults.Tables[0].Rows)
                {
                    stateList.Add(dr[0].ToString());
                }

                Choices stateChoices = new Choices(stateList.ToArray());
                srk = new SemanticResultKey("PARAM2", stateChoices);

                gb1.Append(srk);
                Grammar g1 = new Grammar(gb1);
                g1.Name = "Is [OBJECT] [STATE]";
                oRecognizer.LoadGrammar(g1);

                gb2.Append(srk);
                Grammar g2 = new Grammar(gb2);
                g2.Name = "Is [OBJECT] [STATE]";
                oRecognizer.LoadGrammar(g2);

                gb3.Append(srk);
                Grammar g3 = new Grammar(gb3);
                g3.Name = "Is [OBJECT] [STATE]";
                oRecognizer.LoadGrammar(g3);

                gb4.Append(srk);
                Grammar g4 = new Grammar(gb4);
                g4.Name = "Is [OBJECT] [STATE]";
                oRecognizer.LoadGrammar(g4);

                gb5.Append(srk);
                Grammar g5 = new Grammar(gb5);
                g5.Name = "[OBJECT] is [STATE]";
                oRecognizer.LoadGrammar(g5);

                gb6.Append(srk);
                Grammar g6 = new Grammar(gb6);
                g6.Name = "[OBJECT] is [STATE]";
                oRecognizer.LoadGrammar(g6);

                gb7.Append(srk);
                Grammar g7 = new Grammar(gb7);
                g7.Name = "[OBJECT] is [STATE]";
                oRecognizer.LoadGrammar(g7);
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar Voice Grammar, Object State: " + ex.Message, ex); }

            #endregion

            #region [Object] [Method] [Parameter]
            // 1 OBJECT STATE {PARAMETER}
            try
            {
                SemanticResultKey srk = new SemanticResultKey("PARAM1", objectFullChoices);
                GrammarBuilder    gb1 = new GrammarBuilder(srk);

                //Now the the appropriate method
                List <string> methodList = new List <string>();
                dsResults = OSAESql.RunSQL("SELECT DISTINCT method_label FROM osae_v_object_type_method_list_full WHERE method_label IS NOT NULL");
                foreach (DataRow dr in dsResults.Tables[0].Rows)
                {
                    methodList.Add(dr[0].ToString());
                }

                Choices methodChoices = new Choices(methodList.ToArray());
                srk = new SemanticResultKey("PARAM2", methodChoices);
                gb1.Append(srk);
                gb1.AppendDictation();
                Grammar g1 = new Grammar(gb1);
                g1.Name = "[OBJECT] [METHOD] [PARAMETER]";
                oRecognizer.LoadGrammar(g1);
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar Voice Grammar, Object Method Parameter: " + ex.Message, ex); }

            #endregion

            #region [OBJECT] [CONTAINER]
            // 1 OBJECT is in CONTAINER
            // 2 np OBJECT is in CONTAINER
            // 3 OBJECT is in np CONTAINER
            // 4 np OBJECT is in np CONTAINER
            // 5 I am/You are in CONTAINER
            // 6 I am/You are in np CONTAINER

            // 7 is OBJECT in CONTAINER
            // 8 is np OBJECT in CONTAINER
            // 9 is OBJECT in np CONTAINER
            // 10 is np OBJECT in np CONTAINER
            // 11 am I/are you in CONTAINER
            // 12 am I/are you in NP CONTAINER

            // 1 OBJECT is in CONTAINER
            try
            {
                GrammarBuilder    gb_GrammarBuilder = new GrammarBuilder();
                SemanticResultKey srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("is in");
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                Grammar g_Grammar = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 2 np OBJECT is in CONTAINER
                gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("is in");
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 3 OBJECT is in np CONTAINER
                gb_GrammarBuilder = new GrammarBuilder();
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("is in");
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 4 np OBJECT is in np CONTAINER
                gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("is in");
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 5 [I am/You are] in CONTAINER
                gb_GrammarBuilder = new GrammarBuilder();
                srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append(IsChoices);
                gb_GrammarBuilder.Append("in");
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 6 [I am/You are] am in np CONTAINER
                gb_GrammarBuilder = new GrammarBuilder();
                srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append(IsChoices);
                gb_GrammarBuilder.Append("in");
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);



                // 7 is OBJECT in CONTAINER
                gb_GrammarBuilder = new GrammarBuilder("is");
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("in");
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 8 is np OBJECT is in CONTAINER
                gb_GrammarBuilder = new GrammarBuilder("is");
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("in");
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 9 is OBJECT in np CONTAINER
                gb_GrammarBuilder = new GrammarBuilder("is");
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("in");
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 10 is np OBJECT in np CONTAINER
                gb_GrammarBuilder = new GrammarBuilder("is");
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("in");
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 11 [am I/are you] in CONTAINER
                gb_GrammarBuilder = new GrammarBuilder(IsChoices);
                srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("in");
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);

                // 12 [am I/are you] in NP CONTAINER
                gb_GrammarBuilder = new GrammarBuilder(IsChoices);
                srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append("in");
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM2", containerChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
                oRecognizer.LoadGrammar(g_Grammar);
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar Voice Grammar, Object Container: " + ex.Message, ex); }

            #endregion

            #region [OBJECT] [OBJECT TYPE]
            // 1 is OBJECT np OBJECT TYPE
            // 2 is np OBJECT np OBJECT TYPE
            // 3 am I/are you np OBJECT TYPE

            // is OBJECT np OBJECT TYPE
            try
            {
                GrammarBuilder    gb_GrammarBuilder = new GrammarBuilder("is");
                SemanticResultKey srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM2", objectTypeChoices);
                gb_GrammarBuilder.Append(srk);
                Grammar g_Grammar = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]";
                oRecognizer.LoadGrammar(g_Grammar);

                // is np OBJECT np OBJECT TYPE
                gb_GrammarBuilder = new GrammarBuilder("is");
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM2", objectTypeChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]";
                oRecognizer.LoadGrammar(g_Grammar);

                // [am I/are you] np OBJECT TYPE
                gb_GrammarBuilder = new GrammarBuilder(IsChoices);
                srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb_GrammarBuilder.Append(srk);
                gb_GrammarBuilder.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM2", objectTypeChoices);
                gb_GrammarBuilder.Append(srk);
                g_Grammar      = new Grammar(gb_GrammarBuilder);
                g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]";
                oRecognizer.LoadGrammar(g_Grammar);
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar Voice Grammar, Object ObjectType: " + ex.Message, ex); }

            #endregion

            #region Where/What is [OBJECT]
            //1 Where is OBJECT
            //2 Where is NP OBJECT
            //3 Where am I/You

            //4 What is OBJECT
            //5 What is NP OBJECT
            //6 What am I/You

            //Where is OBJECT
            try
            {
                GrammarBuilder    gb_Single = new GrammarBuilder("Where is");
                SemanticResultKey srk       = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_Single.Append(srk);
                Grammar g_Single = new Grammar(gb_Single);
                g_Single.Name = "Where is [OBJECT]";
                oRecognizer.LoadGrammar(g_Single);

                //Where is NP OBJECT
                gb_Single = new GrammarBuilder("Where is");
                gb_Single.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_Single.Append(srk);
                g_Single      = new Grammar(gb_Single);
                g_Single.Name = "Where is [OBJECT]";
                oRecognizer.LoadGrammar(g_Single);

                //Where am [I/you]
                gb_Single = new GrammarBuilder("Where");
                gb_Single.Append(IsChoices);
                srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb_Single.Append(srk);
                g_Single      = new Grammar(gb_Single);
                g_Single.Name = "Where is [OBJECT]";
                oRecognizer.LoadGrammar(g_Single);

                //What is OBJECT
                gb_Single = new GrammarBuilder("What is");
                srk       = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_Single.Append(srk);
                g_Single      = new Grammar(gb_Single);
                g_Single.Name = "What is [OBJECT]";
                oRecognizer.LoadGrammar(g_Single);

                // What is NP OBJECT
                gb_Single = new GrammarBuilder("What is");
                gb_Single.Append(nounPrecedentChoices);
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb_Single.Append(srk);
                g_Single      = new Grammar(gb_Single);
                g_Single.Name = "What is [OBJECT]";
                oRecognizer.LoadGrammar(g_Single);

                // What am [I/you]
                gb_Single = new GrammarBuilder("What");
                gb_Single.Append(IsChoices);
                srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb_Single.Append(srk);
                g_Single      = new Grammar(gb_Single);
                g_Single.Name = "What is [OBJECT]";
                oRecognizer.LoadGrammar(g_Single);
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar Voice Grammar, What Is Object:" + ex.Message, ex); }

            #endregion

            #region Who is [PRONOUN]
            //Who [am I/are you]
            try
            {
                GrammarBuilder gb_Single = new GrammarBuilder("Who");
                gb_Single.Append(IsChoices);
                SemanticResultKey srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb_Single.Append(srk);
                Grammar g_Single = new Grammar(gb_Single);
                g_Single.Name = "Who is [PERSON]";
                oRecognizer.LoadGrammar(g_Single);
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar Voice Grammar, Who Is:" + ex.Message, ex); }

            #endregion

            #region How is [PRONOUN]
            //1. How [am I/are you]
            //2. How is OBJECT

            try
            {
                GrammarBuilder gb1 = new GrammarBuilder("How");
                GrammarBuilder gb2 = new GrammarBuilder("How");
                gb1.Append(IsChoices);
                gb2.Append(IsChoices);
                SemanticResultKey srk = new SemanticResultKey("PARAM1", pronounChoices);
                gb1.Append(srk);
                srk = new SemanticResultKey("PARAM1", objectFullChoices);
                gb2.Append(srk);

                Grammar g1 = new Grammar(gb1);
                g1.Name = "How is [OBJECT]";
                oRecognizer.LoadGrammar(g1);
                Grammar g2 = new Grammar(gb2);
                g2.Name = "How is [OBJECT]";
                oRecognizer.LoadGrammar(g2);
            }
            catch (Exception ex)
            { throw new Exception("API.Grammar Voice Grammar, How Is Object:" + ex.Message, ex); }

            #endregion

            return(oRecognizer);
        }
        public static SpeechRecognitionEngine Load_Text_Only_Grammars(SpeechRecognitionEngine oRecognizer)
        {
            DataSet dsResults = new DataSet();

            #region Build a List of all Objects AND Possessive Objects
            List <string> objectFullList       = new List <string>();
            List <string> objectPossessiveList = new List <string>();
            //Get All objects
            dsResults = OSAESql.RunSQL("SELECT object_name, CONCAT(object_name,'''s') AS possessive_name FROM osae_v_object_list_full");
            for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++)
            {
                string grammer           = dsResults.Tables[0].Rows[i][0].ToString();
                string possessivegrammer = dsResults.Tables[0].Rows[i][1].ToString();
                if (!string.IsNullOrEmpty(grammer))
                {
                    objectFullList.Add(grammer);
                }
                if (!string.IsNullOrEmpty(possessivegrammer))
                {
                    objectPossessiveList.Add(possessivegrammer);
                }
            }
            Choices objectFullChoices       = new Choices(objectFullList.ToArray());
            Choices objectPossessiveChoices = new Choices(objectPossessiveList.ToArray());
            #endregion

            #region Build a List of all Object Types
            List <string> objectTypeList = new List <string>();
            dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type");
            foreach (DataRow dr in dsResults.Tables[0].Rows)
            {
                objectTypeList.Add(dr[0].ToString());
            }
            Choices objectTypeChoices = new Choices(objectTypeList.ToArray());
            #endregion

            #region [OBJECT]'s [PROPERTY] is [VALUE]
            //OBJECT's PROPERTY is [VALUE]

            foreach (string ot in objectTypeList)
            {
                List <string> objectList = new List <string>();

                GrammarBuilder gbObjectPropertyIs = new GrammarBuilder();

                //Get All objects of the current Object Type
                dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'");
                foreach (DataRow dr in dsResults.Tables[0].Rows)
                {
                    objectList.Add(dr[0].ToString());
                }
                if (objectList.Count > 0)  // Only bother with this object type if there are objects using it
                {
                    Choices           objectChoices = new Choices(objectList.ToArray());
                    SemanticResultKey srk           = new SemanticResultKey("PARAM1", objectChoices);
                    gbObjectPropertyIs.Append(srk);

                    //Now the the appropriate properties
                    DataSet dsPropType = OSAESql.RunSQL("SELECT DISTINCT(property_datatype),property_object_type FROM osae_v_object_type_property WHERE object_type='" + ot + "' ORDER BY property_datatype");
                    foreach (DataRow drType in dsPropType.Tables[0].Rows)
                    {
                        List <string> propertyList = new List <string>();
                        DataSet       dsPropName   = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='" + drType["property_datatype"].ToString() + "' ORDER BY property_datatype");
                        foreach (DataRow drName in dsPropName.Tables[0].Rows)
                        {
                            propertyList.Add(drName["property_name"].ToString());
                        }
                        Choices propertyChoices = new Choices(propertyList.ToArray());
                        if (drType["property_datatype"].ToString().ToUpper() == "STRING")
                        {
                            GrammarBuilder dictation = new GrammarBuilder();
                            dictation.AppendDictation();

                            srk = new SemanticResultKey("PARAM2", propertyChoices);
                            gbObjectPropertyIs.Append(srk);
                            gbObjectPropertyIs.Append("is");
                            gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", dictation));
                            Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
                            gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
                            oRecognizer.LoadGrammar(gObjectPropertyIs);
                        }
                        else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT")
                        {
                            srk = new SemanticResultKey("PARAM2", propertyChoices);
                            gbObjectPropertyIs.Append(srk);
                            gbObjectPropertyIs.Append("is");
                            gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", objectFullChoices));
                            Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
                            gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
                            oRecognizer.LoadGrammar(gObjectPropertyIs);
                        }
                        else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT TYPE")
                        {
                            List <string> propertyOTList   = new List <string>();
                            DataSet       dsPropObjectType = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + drType["property_object_type"].ToString() + "'");
                            foreach (DataRow drName in dsPropObjectType.Tables[0].Rows)
                            {
                                propertyOTList.Add(drName["object_name"].ToString());
                            }
                            Choices propertyOTChoices = new Choices(propertyOTList.ToArray());
                            srk = new SemanticResultKey("PARAM2", propertyChoices);
                            gbObjectPropertyIs.Append(srk);
                            gbObjectPropertyIs.Append("is");

                            gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", propertyOTChoices));
                            Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
                            gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
                            oRecognizer.LoadGrammar(gObjectPropertyIs);
                        }
                    }
                }
            }
            #endregion

            return(oRecognizer);
        }
Example #11
0
        public static SpeechRecognitionEngine Load_Object_State_Grammar(SpeechRecognitionEngine oRecognizer)
        {
            DataSet dsResults = new DataSet();

            Choices nounPrecedentChoices = new Choices(new string[] { "a", "an", "the" });

            #region Build a List of all Object Types
            List <string> objectTypeList = new List <string>();
            dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type");
            foreach (DataRow dr in dsResults.Tables[0].Rows)
            {
                objectTypeList.Add(dr[0].ToString());
            }
            Choices objectTypeChoices = new Choices(objectTypeList.ToArray());
            #endregion

            #region [Object] [State]
            // 1 Are you STATE
            // 2 Am I STATE
            // 3 Is OBJECT STATE?
            // 4 Is [NP] OBJECT STATE?

            // 5 You are STATE
            // 6 I am STATE
            // 7 OBJECT is STATE
            // 8 [NP] OBJECT is STATE
            GrammarBuilder    gb1 = new GrammarBuilder("Are");
            GrammarBuilder    gb5 = new GrammarBuilder();
            SemanticResultKey srk = new SemanticResultKey("PARAM1", "you");
            gb1.Append(srk);
            gb5.Append(srk);

            GrammarBuilder gb2 = new GrammarBuilder("Am I");
            GrammarBuilder gb6 = new GrammarBuilder();
            srk = new SemanticResultKey("PARAM1", "I");
            gb2.Append(srk);
            gb6.Append(srk);

            //builder.Append(objectChoices);

            foreach (string ot in objectTypeList)
            {
                List <string>  stateList = new List <string>();
                GrammarBuilder gb3       = new GrammarBuilder("Is");
                GrammarBuilder gb4       = new GrammarBuilder("Is");
                gb4.Append(nounPrecedentChoices);

                GrammarBuilder gbNPObjectIsState = new GrammarBuilder(nounPrecedentChoices);

                //Get All objects of the current Object Type
                List <string> objectList = new List <string>();
                dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'");
                foreach (DataRow dr in dsResults.Tables[0].Rows)
                {
                    objectList.Add(dr[0].ToString());
                }
                if (objectList.Count > 0)  // Only bother with this object type if there are objects using it
                {
                    Choices objectChoices = new Choices(objectList.ToArray());
                    srk = new SemanticResultKey("PARAM1", objectChoices);

                    gb3.Append(srk);
                    gb4.Append(srk);
                    GrammarBuilder gbObjectIsState = new GrammarBuilder(srk);
                    gbNPObjectIsState.Append(srk);
                    gbObjectIsState.Append("is");
                    gbNPObjectIsState.Append("is");

                    //Now the the appropriate states
                    dsResults = OSAESql.RunSQL("SELECT state_name FROM osae_v_object_type_state_list_full WHERE object_type='" + ot + "'");
                    foreach (DataRow dr in dsResults.Tables[0].Rows)
                    {
                        stateList.Add(dr[0].ToString());
                    }
                    if (stateList.Count > 0)
                    {
                        Choices stateChoices = new Choices(stateList.ToArray());
                        srk = new SemanticResultKey("PARAM2", stateChoices);
                        if (ot == "PERSON")
                        {
                            gb2.Append(srk);
                            Grammar gAmIState = new Grammar(gb2);
                            gAmIState.Name = "Is [OBJECT] [STATE]";
                            oRecognizer.LoadGrammar(gAmIState);
                        }
                        else if (ot == "SYSTEM")
                        {
                            gb1.Append(srk);
                            Grammar g1 = new Grammar(gb1);
                            g1.Name = "Is [OBJECT] [STATE]";
                            oRecognizer.LoadGrammar(g1);

                            gb5.Append(srk);
                            Grammar g5 = new Grammar(gb5);
                            g5.Name = "Is [OBJECT] [STATE]";
                            oRecognizer.LoadGrammar(g5);
                        }

                        gb3.Append(srk);
                        Grammar gIsObjectState = new Grammar(gb3);
                        gIsObjectState.Name = "Is [OBJECT] [STATE]";
                        oRecognizer.LoadGrammar(gIsObjectState);

                        gb4.Append(srk);
                        Grammar gIsNPObjectState = new Grammar(gb4);
                        gIsNPObjectState.Name = "[OBJECT] is [STATE]";
                        oRecognizer.LoadGrammar(gIsNPObjectState);

                        gbObjectIsState.Append(srk);
                        Grammar gObjectIsState = new Grammar(gbObjectIsState);
                        gObjectIsState.Name = "[OBJECT] is [STATE]";
                        oRecognizer.LoadGrammar(gObjectIsState);

                        gbNPObjectIsState.Append(srk);
                        Grammar gNPObjectIsState = new Grammar(gbNPObjectIsState);
                        gNPObjectIsState.Name = "[OBJECT] is [STATE]";
                        oRecognizer.LoadGrammar(gNPObjectIsState);
                    }
                }
            }
            #endregion
            return(oRecognizer);
        }
Example #12
0
        public static SpeechRecognitionEngine Load_OSA_Grammar(SpeechRecognitionEngine oRecognizer)
        {
            oRecognizer = Load_Object_State_Grammar(oRecognizer);

            Choices nounPrecedentChoices = new Choices(new string[] { "a", "an", "the" });
            DataSet dsResults            = new DataSet();

            #region Build a List of all Objects

            List <string> objectFullList = new List <string>();
            //Get All objects
            dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full");
            for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++)
            {
                string grammer = dsResults.Tables[0].Rows[i][0].ToString();
                if (!string.IsNullOrEmpty(grammer))
                {
                    objectFullList.Add(grammer);
                }
            }
            Choices objectFullChoices = new Choices(objectFullList.ToArray());
            #endregion

            #region Build a List of all Possessive Objects

            List <string> objectPossessiveList = new List <string>();
            //Get All objects
            dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') AS object_name FROM osae_v_object_list_full");
            //dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object ORDER BY object_name");
            for (int i = 0; i < dsResults.Tables[0].Rows.Count; i++)
            {
                string grammer = dsResults.Tables[0].Rows[i][0].ToString();
                if (!string.IsNullOrEmpty(grammer))
                {
                    objectPossessiveList.Add(grammer);
                }
            }
            Choices objectPossessiveChoices = new Choices(objectPossessiveList.ToArray());
            #endregion

            #region Build a List of all Containers

            List <string> containerList = new List <string>();
            //Get All containers
            dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE container=1");
            foreach (DataRow dr in dsResults.Tables[0].Rows)
            {
                containerList.Add(dr[0].ToString());
            }
            Choices containerChoices = new Choices(containerList.ToArray());
            #endregion

            #region Build a List of all Object Types
            List <string> objectTypeList = new List <string>();
            dsResults = OSAESql.RunSQL("SELECT DISTINCT(object_type) FROM osae_v_object_list_full ORDER BY object_type");
            foreach (DataRow dr in dsResults.Tables[0].Rows)
            {
                objectTypeList.Add(dr[0].ToString());
            }
            Choices objectTypeChoices = new Choices(objectTypeList.ToArray());
            #endregion


            #region What is [OBJECT]'s [PROPERTY]
            //What is OBJECT's PROPERTY
            //What is NP OBJECT's PROPERTY
            //What is my PROPERTY
            //What is your PROPERTY

            GrammarBuilder    gbWhatIsMyProperty = new GrammarBuilder("What is");
            SemanticResultKey srk = new SemanticResultKey("PARAM1", "my");
            gbWhatIsMyProperty.Append(srk);
            GrammarBuilder gbWhatIsYourProperty = new GrammarBuilder("What is");
            srk = new SemanticResultKey("PARAM1", "your");
            gbWhatIsYourProperty.Append(srk);

            foreach (string ot in objectTypeList)
            {
                GrammarBuilder gbWhatIsObjectProperty   = new GrammarBuilder("What is");
                GrammarBuilder gbWhatIsNPObjectProperty = new GrammarBuilder("What is");
                gbWhatIsNPObjectProperty.Append(nounPrecedentChoices);

                List <string> objectList   = new List <string>();
                List <string> propertyList = new List <string>();

                //Get All objects of the current Object Type
                dsResults = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'");
                foreach (DataRow dr in dsResults.Tables[0].Rows)
                {
                    objectList.Add(dr[0].ToString());
                }
                if (objectList.Count > 0)  // Only bother with this object type if there are objects using it
                {
                    Choices objectChoices = new Choices(objectList.ToArray());
                    srk = new SemanticResultKey("PARAM1", objectChoices);
                    gbWhatIsObjectProperty.Append(srk);
                    gbWhatIsNPObjectProperty.Append(srk);

                    //Now the the appropriate properties
                    dsResults = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND (property_datatype != 'Object Type' OR property_object_type != 'PERSON')");
                    foreach (DataRow dr in dsResults.Tables[0].Rows)
                    {
                        propertyList.Add(dr[0].ToString());
                    }
                    if (propertyList.Count > 0)
                    {
                        Choices propertyChoices = new Choices(propertyList.ToArray());
                        srk = new SemanticResultKey("PARAM2", propertyChoices);
                        if (ot == "PERSON")
                        {
                            gbWhatIsMyProperty.Append(srk);
                            Grammar gWhatIsMyProperty = new Grammar(gbWhatIsMyProperty);
                            gWhatIsMyProperty.Name = "What is [OBJECT] [PROPERTY]";
                            oRecognizer.LoadGrammar(gWhatIsMyProperty);
                        }
                        else if (ot == "SYSTEM")
                        {
                            gbWhatIsYourProperty.Append(srk);
                            Grammar gWhatIsYourProperty = new Grammar(gbWhatIsYourProperty);
                            gWhatIsYourProperty.Name = "What is [OBJECT] [PROPERTY]";
                            oRecognizer.LoadGrammar(gWhatIsYourProperty);
                        }
                        gbWhatIsObjectProperty.Append(srk);
                        Grammar gWhatIsObjectProperty = new Grammar(gbWhatIsObjectProperty);
                        gWhatIsObjectProperty.Name = "What is [OBJECT] [PROPERTY]";
                        oRecognizer.LoadGrammar(gWhatIsObjectProperty);

                        gbWhatIsNPObjectProperty.Append(srk);
                        Grammar gWhatIsNPObjectProperty = new Grammar(gbWhatIsNPObjectProperty);
                        gWhatIsNPObjectProperty.Name = "What is [OBJECT] [PROPERTY]";
                        oRecognizer.LoadGrammar(gWhatIsNPObjectProperty);
                    }
                }
            }
            #endregion

            #region Who is [OBJECT]'s [PROPERTY]
            //Who is OBJECT's PROPERTY
            //Who is NP OBJECT's PROPERTY
            //Who is my PROPERTY
            //Who is your PROPERTY

            GrammarBuilder gbWhoIsMyProperty = new GrammarBuilder("Who is");
            srk = new SemanticResultKey("PARAM1", "my");
            gbWhoIsMyProperty.Append(srk);
            GrammarBuilder gbWhoIsYourProperty = new GrammarBuilder("Who is");
            srk = new SemanticResultKey("PARAM1", "your");
            gbWhoIsYourProperty.Append(srk);

            foreach (string ot in objectTypeList)
            {
                GrammarBuilder gbWhoIsObjectProperty   = new GrammarBuilder("Who is");
                GrammarBuilder gbWhoIsNPObjectProperty = new GrammarBuilder("Who is");
                gbWhoIsNPObjectProperty.Append(nounPrecedentChoices);

                List <string> objectList   = new List <string>();
                List <string> propertyList = new List <string>();

                //Get All objects of the current Object Type
                dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'");
                foreach (DataRow dr in dsResults.Tables[0].Rows)
                {
                    objectList.Add(dr[0].ToString());
                }
                if (objectList.Count > 0)  // Only bother with this object type if there are objects using it
                {
                    Choices objectChoices = new Choices(objectList.ToArray());
                    srk = new SemanticResultKey("PARAM1", objectChoices);
                    gbWhoIsObjectProperty.Append(srk);
                    gbWhoIsNPObjectProperty.Append(srk);

                    //Now the the appropriate properties
                    dsResults = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='Object Type' AND property_object_type='PERSON'");
                    foreach (DataRow dr in dsResults.Tables[0].Rows)
                    {
                        propertyList.Add(dr[0].ToString());
                    }
                    if (propertyList.Count > 0)
                    {
                        Choices propertyChoices = new Choices(propertyList.ToArray());
                        srk = new SemanticResultKey("PARAM2", propertyChoices);
                        if (ot == "PERSON")
                        {
                            gbWhoIsMyProperty.Append(srk);
                            Grammar gWhoIsMyProperty = new Grammar(gbWhoIsMyProperty);
                            gWhoIsMyProperty.Name = "What is [OBJECT] [PROPERTY]";
                            oRecognizer.LoadGrammar(gWhoIsMyProperty);
                        }
                        else if (ot == "SYSTEM")
                        {
                            gbWhoIsYourProperty.Append(srk);
                            Grammar gWhoIsYourProperty = new Grammar(gbWhoIsYourProperty);
                            gWhoIsYourProperty.Name = "What is [OBJECT] [PROPERTY]";
                            oRecognizer.LoadGrammar(gWhoIsYourProperty);
                        }

                        gbWhoIsObjectProperty.Append(srk);
                        Grammar gWhoIsObjectProperty = new Grammar(gbWhoIsObjectProperty);
                        gWhoIsObjectProperty.Name = "What is [OBJECT] [PROPERTY]";
                        oRecognizer.LoadGrammar(gWhoIsObjectProperty);

                        gbWhoIsNPObjectProperty.Append(srk);
                        Grammar gWhoIsNPObjectProperty = new Grammar(gbWhoIsNPObjectProperty);
                        gWhoIsNPObjectProperty.Name = "What is [OBJECT] [PROPERTY]";
                        oRecognizer.LoadGrammar(gWhoIsNPObjectProperty);
                    }
                }
            }
            #endregion

            #region [OBJECT]'s [PROPERTY] is [VALUE]
            //OBJECT's PROPERTY is [VALUE]

            foreach (string ot in objectTypeList)
            {
                List <string> objectList = new List <string>();


                GrammarBuilder gbObjectPropertyIs = new GrammarBuilder();

                //Get All objects of the current Object Type
                dsResults = OSAESql.RunSQL("SELECT CONCAT(object_name,'''s') as object_name FROM osae_v_object_list_full WHERE object_type='" + ot + "'");
                foreach (DataRow dr in dsResults.Tables[0].Rows)
                {
                    objectList.Add(dr[0].ToString());
                }
                if (objectList.Count > 0)  // Only bother with this object type if there are objects using it
                {
                    Choices objectChoices = new Choices(objectList.ToArray());
                    srk = new SemanticResultKey("PARAM1", objectChoices);
                    gbObjectPropertyIs.Append(srk);

                    //Now the the appropriate properties
                    DataSet dsPropType = OSAESql.RunSQL("SELECT DISTINCT(property_datatype),property_object_type FROM osae_v_object_type_property WHERE object_type='" + ot + "' ORDER BY property_datatype");
                    foreach (DataRow drType in dsPropType.Tables[0].Rows)
                    {
                        List <string> propertyList = new List <string>();
                        DataSet       dsPropName   = OSAESql.RunSQL("SELECT DISTINCT(property_name) FROM osae_v_object_type_property WHERE object_type='" + ot + "' AND property_datatype='" + drType["property_datatype"].ToString() + "' ORDER BY property_datatype");
                        foreach (DataRow drName in dsPropName.Tables[0].Rows)
                        {
                            propertyList.Add(drName["property_name"].ToString());
                        }
                        Choices propertyChoices = new Choices(propertyList.ToArray());
                        if (drType["property_datatype"].ToString().ToUpper() == "STRING")
                        {
                            GrammarBuilder dictation = new GrammarBuilder();
                            dictation.AppendDictation();

                            srk = new SemanticResultKey("PARAM2", propertyChoices);
                            gbObjectPropertyIs.Append(srk);
                            gbObjectPropertyIs.Append("is");
                            gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", dictation));
                            Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
                            gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
                            oRecognizer.LoadGrammar(gObjectPropertyIs);
                        }
                        else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT")
                        {
                            srk = new SemanticResultKey("PARAM2", propertyChoices);
                            gbObjectPropertyIs.Append(srk);
                            gbObjectPropertyIs.Append("is");
                            gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", objectFullChoices));
                            Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
                            gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
                            oRecognizer.LoadGrammar(gObjectPropertyIs);
                        }
                        else if (drType["property_datatype"].ToString().ToUpper() == "OBJECT TYPE")
                        {
                            List <string> propertyOTList   = new List <string>();
                            DataSet       dsPropObjectType = OSAESql.RunSQL("SELECT object_name FROM osae_v_object_list_full WHERE object_type='" + drType["property_object_type"].ToString() + "'");
                            foreach (DataRow drName in dsPropObjectType.Tables[0].Rows)
                            {
                                propertyOTList.Add(drName["object_name"].ToString());
                            }
                            Choices propertyOTChoices = new Choices(propertyOTList.ToArray());
                            srk = new SemanticResultKey("PARAM2", propertyChoices);
                            gbObjectPropertyIs.Append(srk);
                            gbObjectPropertyIs.Append("is");

                            gbObjectPropertyIs.Append(new SemanticResultKey("PARAM3", propertyOTChoices));
                            Grammar gObjectPropertyIs = new Grammar(gbObjectPropertyIs);
                            gObjectPropertyIs.Name = "[OBJECT] [PROPERTY] is [VALUE]";
                            oRecognizer.LoadGrammar(gObjectPropertyIs);
                        }
                    }
                }
            }
            #endregion

            #region [OBJECT] [CONTAINER]
            // OBJECT is in CONTAINER
            // np OBJECT is in CONTAINER
            // OBJECT is in np CONTAINER
            // np OBJECT is in np CONTAINER
            // I am in CONTAINER
            // I am in np CONTAINER
            // You are in CONTAINER
            // You are in np CONTAINER


            // is OBJECT in CONTAINER
            // is np OBJECT is in CONTAINER
            // is OBJECT in np CONTAINER
            // is np OBJECT in np CONTAINER
            // am I in CONTAINER
            // am I in NP CONTAINER
            // are you in CONTAINER
            // are you in np CONTAINER

            // OBJECT is in CONTAINER
            GrammarBuilder gb_GrammarBuilder = new GrammarBuilder();
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("is in");
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            Grammar g_Grammar = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // np OBJECT is in CONTAINER
            gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("is in");
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // OBJECT is in np CONTAINER
            gb_GrammarBuilder = new GrammarBuilder();
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("is in");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // np OBJECT is in np CONTAINER
            gb_GrammarBuilder = new GrammarBuilder(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("is in");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // I am in CONTAINER
            gb_GrammarBuilder = new GrammarBuilder();
            srk = new SemanticResultKey("PARAM1", "I");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("am in");
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // I am in np CONTAINER
            gb_GrammarBuilder = new GrammarBuilder();
            srk = new SemanticResultKey("PARAM1", "I");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("am in");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // You are in CONTAINER
            gb_GrammarBuilder = new GrammarBuilder();
            srk = new SemanticResultKey("PARAM1", "you");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("are in");
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // You are in np CONTAINER
            gb_GrammarBuilder = new GrammarBuilder();
            srk = new SemanticResultKey("PARAM1", "you");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("are in");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "[OBJECT] is in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // is OBJECT in CONTAINER
            gb_GrammarBuilder = new GrammarBuilder("is");
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("in");
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // is np OBJECT is in CONTAINER
            gb_GrammarBuilder = new GrammarBuilder("is");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("in");
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // is OBJECT in np CONTAINER
            gb_GrammarBuilder = new GrammarBuilder("is");
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("is in");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // is np OBJECT in np CONTAINER
            gb_GrammarBuilder = new GrammarBuilder("is");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("in");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // am I in CONTAINER
            gb_GrammarBuilder = new GrammarBuilder("Am");
            srk = new SemanticResultKey("PARAM1", "I");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("in");
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // am I in NP CONTAINER
            gb_GrammarBuilder = new GrammarBuilder("Am");
            srk = new SemanticResultKey("PARAM1", "I");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("in");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // are you in CONTAINER
            gb_GrammarBuilder = new GrammarBuilder("Are");
            srk = new SemanticResultKey("PARAM1", "you");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("in");
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);

            // are you in np CONTAINER
            gb_GrammarBuilder = new GrammarBuilder("Are");
            srk = new SemanticResultKey("PARAM1", "you");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append("in");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", containerChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] in [CONTAINER]";
            oRecognizer.LoadGrammar(g_Grammar);
            #endregion

            #region [OBJECT] [OBJECT TYPE]
            // is OBJECT np OBJECT TYPE
            // is np OBJECT np OBJECT TYPE
            // am I np OBJECT TYPE
            // are you np OBJECT TYPE

            // is OBJECT np OBJECT TYPE
            gb_GrammarBuilder = new GrammarBuilder("is");
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", objectTypeChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]";
            oRecognizer.LoadGrammar(g_Grammar);

            // is np OBJECT np OBJECT TYPE
            gb_GrammarBuilder = new GrammarBuilder("is");
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", objectTypeChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]";
            oRecognizer.LoadGrammar(g_Grammar);

            // am I np OBJECT TYPE
            gb_GrammarBuilder = new GrammarBuilder("am");
            srk = new SemanticResultKey("PARAM1", "I");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", objectTypeChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]";
            oRecognizer.LoadGrammar(g_Grammar);

            // are you np OBJECT TYPE
            gb_GrammarBuilder = new GrammarBuilder("are");
            srk = new SemanticResultKey("PARAM1", "you");
            gb_GrammarBuilder.Append(srk);
            gb_GrammarBuilder.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM2", objectTypeChoices);
            gb_GrammarBuilder.Append(srk);
            g_Grammar      = new Grammar(gb_GrammarBuilder);
            g_Grammar.Name = "Is [OBJECT] [OBJECT TYPE]";
            oRecognizer.LoadGrammar(g_Grammar);
            #endregion

            #region Where/What is [OBJECT]
            //Where is OBJECT
            //Where is NP OBJECT
            //Where am I
            //Where are You

            //What is OBJECT
            //What is NP OBJECT
            //What am I
            //What are You

            //Where is OBJECT
            GrammarBuilder gb_Single = new GrammarBuilder("Where is");
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_Single.Append(srk);
            Grammar g_Single = new Grammar(gb_Single);
            g_Single.Name = "Where is [OBJECT]";
            oRecognizer.LoadGrammar(g_Single);

            //Where is NP OBJECT
            gb_Single = new GrammarBuilder("Where is");
            gb_Single.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_Single.Append(srk);
            g_Single      = new Grammar(gb_Single);
            g_Single.Name = "Where is [OBJECT]";
            oRecognizer.LoadGrammar(g_Single);

            //Where am I
            gb_Single = new GrammarBuilder("Where am");
            srk       = new SemanticResultKey("PARAM1", "I");
            gb_Single.Append(srk);
            g_Single      = new Grammar(gb_Single);
            g_Single.Name = "Where is [OBJECT]";
            oRecognizer.LoadGrammar(g_Single);

            //Where are you
            gb_Single = new GrammarBuilder("Where are");
            srk       = new SemanticResultKey("PARAM1", "you");
            gb_Single.Append(srk);
            g_Single      = new Grammar(gb_Single);
            g_Single.Name = "Where is [OBJECT]";
            oRecognizer.LoadGrammar(g_Single);


            //What is OBJECT
            gb_Single = new GrammarBuilder("What is");
            srk       = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_Single.Append(srk);
            g_Single      = new Grammar(gb_Single);
            g_Single.Name = "What is [OBJECT]";
            oRecognizer.LoadGrammar(g_Single);

            //What is NP OBJECT
            gb_Single = new GrammarBuilder("What is");
            gb_Single.Append(nounPrecedentChoices);
            srk = new SemanticResultKey("PARAM1", objectFullChoices);
            gb_Single.Append(srk);
            g_Single      = new Grammar(gb_Single);
            g_Single.Name = "What is [OBJECT]";
            oRecognizer.LoadGrammar(g_Single);

            //What am I
            gb_Single = new GrammarBuilder("What am");
            srk       = new SemanticResultKey("PARAM1", "I");
            gb_Single.Append(srk);
            g_Single      = new Grammar(gb_Single);
            g_Single.Name = "What is [OBJECT]";
            oRecognizer.LoadGrammar(g_Single);

            //What are you
            gb_Single = new GrammarBuilder("What are");
            srk       = new SemanticResultKey("PARAM1", "you");
            gb_Single.Append(srk);
            g_Single      = new Grammar(gb_Single);
            g_Single.Name = "What is [OBJECT]";
            oRecognizer.LoadGrammar(g_Single);
            #endregion

            #region Who is [PRONOUN]
            //Who am I
            //Who are you

            //Who am I
            gb_Single = new GrammarBuilder("Who am");
            srk       = new SemanticResultKey("PARAM1", "I");
            gb_Single.Append(srk);
            g_Single      = new Grammar(gb_Single);
            g_Single.Name = "Who is [PERSON]";
            oRecognizer.LoadGrammar(g_Single);

            //Who are you
            gb_Single = new GrammarBuilder("Who are");
            srk       = new SemanticResultKey("PARAM1", "you");
            gb_Single.Append(srk);
            g_Single      = new Grammar(gb_Single);
            g_Single.Name = "Who is [PERSON]";
            oRecognizer.LoadGrammar(g_Single);
            #endregion

            return(oRecognizer);
        }