public CMUSphinx_GrammarDict CreateGrammarDoc_FSG() { if (currentCMUDoc != null) return currentCMUDoc; caps_rules_fsg = new Dictionary<EDeviceCapabilities,Tuple<CMUSphinx_FSGState,CMUSphinx_FSGState>>(); CMUSphinx_GrammarDict ret = new CMUSphinx_GrammarDict(); ret.GrammarName = GetName(); CMUSphinx_FSGState root = ret.FSGCreate(GetName()); CMUSphinx_FSGState holly = ret.FSGTransitionToNewState(root, "Holly"); // HOLLY <ACTION> (<DEVICECLASS> [(<ROOM> | HERE)] | <DEVICENAME> ) PLEASE //only add to this list if the action only has a single output, "Please" CMUSphinx_FSGState preSinglePlease = ret.FSGCreateOrphanState(); CMUSphinx_FSGState postSinglePlease = ret.FSGCreateOrphanState(); ret.FSGLinkStates(preSinglePlease, postSinglePlease, "please"); foreach (Room rm in ListRooms()) { if (rm.Name == "") continue; CMUSphinx_FSGState actionDevicePreRoom = null; foreach (Device d in rm.ListDevices()) { CMUSphinx_FSGState startAction = null, endAction = null; bool caps_valid = FSGActionsFromCapabilities(d.Capabilities, ret, ref startAction, ref endAction); if (!caps_valid) continue; ret.FSGGroupStates(holly, startAction); //Action immediately follows Holly string cl = SoundsLike.Get(d.Class, false); if (cl != "") { if(actionDevicePreRoom == null) actionDevicePreRoom = ret.FSGCreateOrphanState(); ret.FSGLinkStates(startAction, actionDevicePreRoom, cl); } if (d.FriendlyName != "") { ret.FSGLinkStates(endAction, preSinglePlease, d.FriendlyName); } } if (actionDevicePreRoom == null) continue; //no device classes in room if (rm != CurrentLocation) { ret.FSGLinkStates(actionDevicePreRoom, preSinglePlease, "in the "+rm.Name); } else { ret.FSGLinkStates(actionDevicePreRoom, preSinglePlease, "in the " + rm.Name); ret.FSGLinkStates(actionDevicePreRoom, preSinglePlease, "here"); } ret.FSGLinkStates(actionDevicePreRoom, postSinglePlease, "please"); } ret.FSGGroupStates(ret.FSGGetEndState(), postSinglePlease); ret.BuildFSGGrammarAndDict(); currentCMUDoc = ret; return ret; }
bool FSGActionsFromCapabilities(DeviceCapabilities caps, CMUSphinx_GrammarDict cgd, ref CMUSphinx_FSGState startState, ref CMUSphinx_FSGState endState) { string capsName = "<caps_" + caps.CapsAsIntString + ">"; if (caps_rules_fsg.Keys.Contains(caps.Caps)) { startState = caps_rules_fsg[caps.Caps].Item1; endState = caps_rules_fsg[caps.Caps].Item2; return true; } List<string> capsAsString = caps.Actions; if (capsAsString == null || capsAsString.Count == 0) { startState = null; endState = null; return false; } CMUSphinx_FSGState start = cgd.FSGCreateOrphanState(); CMUSphinx_FSGState end = cgd.FSGCreateOrphanState(); foreach (string s in capsAsString) { cgd.FSGLinkStates(start, end, s); } caps_rules_fsg.Add(caps.Caps, new Tuple<CMUSphinx_FSGState,CMUSphinx_FSGState>(start, end)); startState = start; endState = end; //return new SrgsRuleRef(r, "action"); return true; }
CMUSphinx_FSGState CreateNumberFSG(CMUSphinx_FSGState startState, CMUSphinx_GrammarDict cgd) { CMUSphinx_FSGState start_special = cgd.FSGCreateOrphanState(); CMUSphinx_FSGState start_digits = cgd.FSGCreateOrphanState(); CMUSphinx_FSGState start_tens = cgd.FSGCreateOrphanState(); CMUSphinx_FSGState end = cgd.FSGCreateOrphanState(); CMUSphinx_FSGState end_tens = cgd.FSGCreateOrphanState(); //fillers cgd.FSGLinkStates(startState, start_digits, ""); cgd.FSGLinkStates(startState, start_special, ""); cgd.FSGLinkStates(startState, start_tens, ""); //digits cgd.FSGLinkStates(start_digits, end, "one"); cgd.FSGLinkStates(start_digits, end, "two"); cgd.FSGLinkStates(start_digits, end, "seven"); //TODO //specials cgd.FSGLinkStates(start_special, end, "ten"); cgd.FSGLinkStates(start_special, end, "eleven"); cgd.FSGLinkStates(start_special, end, "twelve"); //TODO: Finish these //tens cgd.FSGLinkStates(start_tens, end_tens, "twenty"); cgd.FSGLinkStates(start_tens, end_tens, "thirty"); //TODO: Finish the tens cgd.FSGLinkStates(end_tens, start_digits, ""); cgd.FSGLinkStates(end_tens, end, ""); return end; }