string JSGFActionsFromCapabilities(DeviceCapabilities caps, CMUSphinx_GrammarDict cgd) { string capsName = "<caps_" + caps.CapsAsIntString + ">"; if (caps_rules_jsgf.Keys.Contains(caps.Caps)) { return caps_rules_jsgf[caps.Caps]; } else { StringBuilder b = new StringBuilder(); cgd.JSGFRuleStart(capsName, b); List<string> capsAsString = caps.Actions; if (capsAsString == null || capsAsString.Count == 0) { cgd.JSGFRuleCancel(capsName, b); return null; } cgd.JSGFRuleAddChoicesStart(b, capsAsString); cgd.JSGFRuleAddChoicesEnd(b); cgd.JSGFRuleEnd(capsName, b); caps_rules_jsgf.Add(caps.Caps, capsName); } //return new SrgsRuleRef(r, "action"); return capsName; }
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; }
bool CreateNumberJSGF(string rulename, CMUSphinx_GrammarDict cgd) { List<string> digit_single = new List<string>(); digit_single.Add("one"); digit_single.Add("two"); digit_single.Add("three"); digit_single.Add("four"); digit_single.Add("five"); digit_single.Add("six"); digit_single.Add("seven"); digit_single.Add("eight"); digit_single.Add("nine"); List<string> digit_tens = new List<string>(); digit_tens.Add("twenty"); digit_tens.Add("thirty"); digit_tens.Add("fourty"); digit_tens.Add("fifty"); digit_tens.Add("sixty"); List<string> digit_special = new List<string>(); digit_special.Add("zero"); digit_special.Add("ten"); digit_special.Add("eleven"); digit_special.Add("twelve"); digit_special.Add("thirteen"); digit_special.Add("fourteen"); digit_special.Add("fifteen"); digit_special.Add("sixteen"); digit_special.Add("seventeen"); digit_special.Add("eighteen"); digit_special.Add("nineteen"); StringBuilder bld_twodigit = new StringBuilder(); cgd.JSGFRuleStart("<"+rulename+"_twodigit>", bld_twodigit); cgd.JSGFRuleAddChoicesStart(bld_twodigit, digit_tens); cgd.JSGFRuleAddChoicesEnd(bld_twodigit); cgd.JSGFRuleAddChoicesStart(bld_twodigit, digit_single); cgd.JSGFRuleAddChoicesEnd(bld_twodigit); cgd.JSGFRuleEnd("<"+rulename + "_twodigit>", bld_twodigit); StringBuilder bld_onedigit = new StringBuilder(); cgd.JSGFRuleStart("<"+rulename + "_onedigit>", bld_onedigit); cgd.JSGFRuleAddChoicesStart(bld_onedigit, digit_single); cgd.JSGFRuleAddChoicesMore(bld_onedigit, digit_tens); cgd.JSGFRuleAddChoicesMore(bld_onedigit, digit_special); cgd.JSGFRuleAddChoicesEnd(bld_onedigit); cgd.JSGFRuleEnd("<"+rulename + "_onedigit>", bld_onedigit); StringBuilder bld = new StringBuilder(); cgd.JSGFRuleStart("<"+rulename+">", bld); cgd.JSGFRuleAddChoicesStart(bld, new List<string>(new string[] { "<"+rulename + "_onedigit>", "<"+rulename + "_twodigit>" })); cgd.JSGFRuleAddChoicesEnd(bld); cgd.JSGFRuleEnd("<"+rulename+">", bld); return true; }
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; }
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; }