Beispiel #1
0
        public CMUSphinx_GrammarDict CreateGrammarDoc_JSGF()
        {
            if (currentCMUSphinxDoc != null) return currentCMUSphinxDoc;
            CMUSphinx_GrammarDict ret = new CMUSphinx_GrammarDict();
            ret.GrammarName = GetName();

            StringBuilder bld = new StringBuilder();
            ret.JSGFRuleStart("<ISAWAKE>", bld);
            ret.JSGFRuleAddChoicesStart(bld, new List<string>(new string[] { "i'm awake", "turn off the alarm", "i am awake" }));
            ret.JSGFRuleAddChoicesEnd(bld);
            ret.JSGFRuleEnd("<ISAWAKE>", bld);

            ret.JSGFRuleStart("<ROOT>", bld);
            ret.JSGFRuleAddToken(bld, "Holly");
            ret.JSGFRuleAddToken(bld, "<ISAWAKE>");
            ret.JSGFRuleAddToken(bld, "please");
            ret.JSGFRuleEnd("<ROOT>", bld);

            ret.JSGFSetRootRule("<ROOT>");

            ret.BuildJSGFGrammarAndDict();

            currentCMUSphinxDoc = ret;
            return ret;
        }
Beispiel #2
0
        public CMUSphinx_GrammarDict CreateGrammarDoc_JSGF()
        {
            if (currentCMUDoc != null) return currentCMUDoc;
            caps_rules_jsgf = new Dictionary<EDeviceCapabilities, string>();
            CMUSphinx_GrammarDict ret = new CMUSphinx_GrammarDict();
            ret.GrammarName = GetName();
            StringBuilder bld = new StringBuilder();
            StringBuilder actionItemLocs = new StringBuilder();

            ret.JSGFRuleStart("<ACTIONITEMLOCS>", actionItemLocs);
            List<string> actionItemLocation_choices = new List<string>();
            foreach (Room rm in ListRooms())
            {
                if (rm.Name == "") continue;
                Dictionary<string, string> actionsPerDevice = new Dictionary<string, string>();
                foreach (Device d in rm.ListDevices())
                {
                    string caps_ruleref = JSGFActionsFromCapabilities(d.Capabilities, ret);
                    if (caps_ruleref == null) continue;
                    string cl = SoundsLike.Get(d.Class, false);
                    if (cl != "" && !actionsPerDevice.ContainsKey(cl))
                    {
                        actionsPerDevice.Add(cl, caps_ruleref);
                    }
                    if (d.FriendlyName != "")
                    {
                        if (!actionsPerDevice.ContainsKey(d.FriendlyName))
                            actionsPerDevice.Add(d.FriendlyName, caps_ruleref);
                    }
                }
                //actionsperdevice.Value + actionsperdevice.Key+room
                if (actionsPerDevice.Count == 0) continue; //nothing in the room
                StringBuilder bld_ail_gb = new StringBuilder();
                string name_ail_gb = "<"+AudioRecog_SAPI.SrgsCleanupID(rm.Name + "__ail")+">";
                ret.JSGFRuleStart(name_ail_gb, bld_ail_gb);

                List<string> action_items = new List<string>();
                bool action_items_valid = false;
                foreach (string item in actionsPerDevice.Keys)
                {
                    if (item == "") continue;
                    StringBuilder bld_ai_gb = new StringBuilder();
                    string name_ai_gb = "<" + AudioRecog_SAPI.SrgsCleanupID(rm.Name + "_" + item) + ">";

                    ret.JSGFRuleStart(name_ai_gb, bld_ai_gb);
                    ret.JSGFRuleAddToken(bld_ai_gb, actionsPerDevice[item]);
                    ret.JSGFRuleAddToken(bld_ai_gb, item);
                    ret.JSGFRuleEnd(name_ai_gb, bld_ai_gb);

                    action_items.Add(name_ai_gb);
                    action_items_valid = true;
                }
                if (!action_items_valid)
                {
                    ret.JSGFRuleCancel(name_ail_gb, bld_ail_gb);
                    continue;
                }
                ret.JSGFRuleAddChoicesStart(bld_ail_gb, action_items);
                ret.JSGFRuleAddChoicesEnd(bld_ail_gb);
                if (rm != CurrentLocation)
                {
                    ret.JSGFRuleAddToken(bld_ail_gb, "in the " + rm.Name);
                    ret.JSGFRuleUnaryOp(bld_ail_gb, true, false);
                }
                else
                {
                    ret.JSGFRuleAddChoicesStart(bld_ail_gb, new List<string>(new string[] { "in the " + rm.Name, "here" }));
                    ret.JSGFRuleAddChoicesEnd(bld_ail_gb);
                    ret.JSGFRuleUnaryOp(bld_ail_gb, true, false);
                }
                ret.JSGFRuleEnd(name_ail_gb, bld_ail_gb);
                actionItemLocation_choices.Add(name_ail_gb);
            }
            ret.JSGFRuleAddChoicesStart(actionItemLocs, actionItemLocation_choices);
            ret.JSGFRuleAddChoicesEnd(actionItemLocs);
            ret.JSGFRuleEnd("<ACTIONITEMLOCS>", actionItemLocs);

            ret.JSGFRuleStart("<ROOT>", bld);
            ret.JSGFRuleAddToken(bld, "Holly");
            ret.JSGFRuleAddToken(bld, "<ACTIONITEMLOCS>");
            ret.JSGFRuleAddToken(bld, "please");
            ret.JSGFRuleEnd("<ROOT>", bld);

            ret.JSGFSetRootRule("<ROOT>");

            ret.BuildJSGFGrammarAndDict();

            currentCMUDoc = ret;
            return ret;
        }
Beispiel #3
0
        public CMUSphinx_GrammarDict CreateGrammarDoc_JSGF()
        {
            if (currentJSGFDoc != null) return currentJSGFDoc;
            CMUSphinx_GrammarDict ret = new CMUSphinx_GrammarDict();
            ret.GrammarName = GetName();
            StringBuilder bld = new StringBuilder();

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

            //numbers
            CreateNumberJSGF("NUMS", ret);

            //TV Shows
            if (mTVShows == null)
            {
                mTVShows = ListTVShows();
            }
            if (mTVShows == null) return null;
            List<string> tvShowNames = new List<string>();
            foreach (XBMCProto.TVShow s in mTVShows)
            {
                string temps = CleanString(s.label);
                temps = temps.Trim();
                if (temps == "" || s.tvshowid < 1) continue;
                tvShowNames.Add(temps);
            }

            string tvshow_name = "<TVSHOW>";
            StringBuilder tvshow_bld = new StringBuilder();
            ret.JSGFRuleStart(tvshow_name, tvshow_bld);
            ret.JSGFRuleAddChoicesStart(tvshow_bld, new List<string>(new string[]{ "play show", "resume show"}));
            ret.JSGFRuleAddChoicesEnd(tvshow_bld);
            ret.JSGFRuleAddChoicesStart(tvshow_bld, tvShowNames);
            ret.JSGFRuleAddChoicesEnd(tvshow_bld);
            ret.JSGFRuleAddToken(tvshow_bld, "SEASON");
            ret.JSGFRuleAddToken(tvshow_bld, "<NUMS>");
            ret.JSGFRuleAddToken(tvshow_bld, "EPISODE");
            ret.JSGFRuleAddToken(tvshow_bld, "<NUMS>");
            ret.JSGFRuleEnd(tvshow_name, tvshow_bld);

            ops.Add(tvshow_name);

            //Movies
            if (mMovies == null)
            {
                mMovies = ListMovies();
            }
            if (mMovies == null) return null;
            List<string> movieNames = new List<string>();
            foreach (XBMCProto.Movie m in mMovies)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.movieid < 1) continue;
                movieNames.Add(temps);
            }

            string movie_name = "<MOVIE>";
            StringBuilder movie_bld = new StringBuilder();
            ret.JSGFRuleStart(movie_name, movie_bld);
            ret.JSGFRuleAddChoicesStart(movie_bld, new List<string>(new string[] { "play movie", "resume movie" }));
            ret.JSGFRuleAddChoicesEnd(movie_bld);
            ret.JSGFRuleAddChoicesStart(movie_bld, movieNames);
            ret.JSGFRuleAddChoicesEnd(movie_bld);
            ret.JSGFRuleEnd(movie_name, movie_bld);

            ops.Add(movie_name);

            //Music Genres
            SrgsOneOf audioGenres = new SrgsOneOf();
            if (mGenres == null)
            {
                mGenres = ListAudioGenres();
            }
            if (mGenres == null) return null;
            List<string> genreNames = new List<string>();
            foreach (XBMCProto.Genre m in mGenres)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.genreid < 1) continue;
                genreNames.Add(temps + " music");
            }

            string audiogenre_name = "<AUDIOGENRE>";
            StringBuilder audiogenre_bld = new StringBuilder();
            ret.JSGFRuleStart(audiogenre_name, audiogenre_bld);
            ret.JSGFRuleAddToken(audiogenre_bld, "play me some");
            ret.JSGFRuleAddChoicesStart(audiogenre_bld, genreNames);
            ret.JSGFRuleAddChoicesEnd(audiogenre_bld);
            ret.JSGFRuleEnd(audiogenre_name, audiogenre_bld);

            ops.Add(audiogenre_name);

            //Other
            ops.Add("stop media");
            ops.Add("pause media");
            ops.Add("resume media");

            StringBuilder bld_ops= new StringBuilder();
            ret.JSGFRuleStart("<OPS>", bld_ops);
            ret.JSGFRuleAddChoicesStart(bld_ops, ops);
            ret.JSGFRuleAddChoicesEnd(bld_ops);
            ret.JSGFRuleEnd("<OPS>", bld_ops);

            ret.JSGFRuleStart("<ROOT>", bld);
            ret.JSGFRuleAddToken(bld, "Holly");
            ret.JSGFRuleAddToken(bld, "<OPS>");
            ret.JSGFRuleAddToken(bld, "please");
            ret.JSGFRuleEnd("<ROOT>", bld);

            ret.JSGFSetRootRule("<ROOT>");

            ret.BuildJSGFGrammarAndDict();
            currentJSGFDoc = ret;
            return ret;
        }