示例#1
0
        bool RecurseForwardsAndFinalise(CMUSphinx_FSGState n)
        {
            //check for loops
            if(!doneStates.Add(n)) return true;

            n.StateID = nextStateID++;

            //Calculate Probabilities
            int nOut = 0;
            foreach (CMUSphinx_FSGTransition t in n.TransitionsOut)
            {
                //nOut += t.To.EquivalentCount;
                nOut += t.Count;
            }
            foreach (CMUSphinx_FSGTransition t in n.TransitionsOut)
            {
                //t.Probability = ((float)1.0 * t.To.EquivalentCount) / nOut;
                t.Probability = ((float)1.0 * t.Count) / nOut;
                outTransitions.Add(t);
                RecurseForwardsAndFinalise(t.To);
            }

            return true;
        }
示例#2
0
文件: World.cs 项目: kingtut666/holly
 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;
 }
示例#3
0
 bool OptimiseBackwards(CMUSphinx_FSGState n)
 {
     //TODO: equivalent if graph to the endNode is the same
     return false;
 }
示例#4
0
 bool OptimiseForwards(CMUSphinx_FSGState n)
 {
     //TODO: equivalent if the previous state was the same and the transition string was the same
     return false;
 }
示例#5
0
        public bool FSGLinkStates(CMUSphinx_FSGState from, CMUSphinx_FSGState to, string onString)
        {
            //need to split and uppercase the onString
            CMUSphinx_FSGState tempFrom = from;
            onString = onString.ToUpper();
            string[] toks = onString.Split(new Char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            int i = 0;
            for (i = 0; i < toks.Length - 1; i++)
            {
                _AddToWordList(toks[i]);
                tempFrom = FSGTransitionToNewState(tempFrom, toks[i]);
            }

            string endTok;
            if (toks.Length <= i) endTok = "";
            else endTok = toks[i];

                _AddToWordList(endTok);
                CMUSphinx_FSGTransition tr = new CMUSphinx_FSGTransition(tempFrom, to, endTok);
                if (tr != null) return true;

            return false;
        }
示例#6
0
 public CMUSphinx_FSGState FSGTransitionToNewState(CMUSphinx_FSGState from, string onString)
 {
     CMUSphinx_FSGState ret = new CMUSphinx_FSGState(-1);
     allFSGNodes.Add(ret);
     FSGLinkStates(from, ret, onString);
     return ret;
 }
示例#7
0
 public CMUSphinx_FSGState FSGCreateOrphanState()
 {
     CMUSphinx_FSGState ret = new CMUSphinx_FSGState(-1);
     allFSGNodes.Add(ret);
     return ret;
 }
示例#8
0
 public CMUSphinx_FSGState FSGGroupStates(CMUSphinx_FSGState State1, CMUSphinx_FSGState State2)
 {
     if (State1 == null || State2 == null) return null;
     State2.EquivalentTo = State1;
     return State1;
 }
示例#9
0
 public CMUSphinx_FSGState FSGCreate(string name)
 {
     GrammarName = name;
     allFSGNodes = new HashSet<CMUSphinx_FSGState>();
     rootFSGNode = new CMUSphinx_FSGState(-1);
     allFSGNodes.Add(rootFSGNode);
     endFSGNode = new CMUSphinx_FSGState(-1);
     allFSGNodes.Add(endFSGNode);
     return rootFSGNode;
 }
示例#10
0
        public bool BuildFSGGrammarAndDict()
        {
            //0) Insert blank entry leading to endNode - get crashes without this
            CMUSphinx_FSGState tempState = new CMUSphinx_FSGState(-1);
            allFSGNodes.Add(tempState);
            FSGLinkStates(endFSGNode, tempState, "");
            endFSGNode = tempState;

            //1) Optimise graph
            //optimise graph, check for loose ends, be careful of loops
            // states are equivalent if the previous state was the same and the transition string was the same
            //             or if graph to the endNode is the same
            //1a) Equiv lookforward
            OptimiseForwards(rootFSGNode);
            //1b) Equiv lookback
            OptimiseBackwards(endFSGNode.TransitionsIn[0].From);
            //1c) Remove equivalents
            RemoveEquivalents();

            //2) Number and count states, set probs, and compile list of transitions (out only)
            outTransitions = new HashSet<CMUSphinx_FSGTransition>();
            nextStateID = 0;
            doneStates = new HashSet<CMUSphinx_FSGState>(); //loop protection
            RecurseForwardsAndFinalise(rootFSGNode);

            //3) create output file header
            StringBuilder b = new StringBuilder();
            b.AppendLine("FSG_BEGIN <"+GrammarName+">");
            b.AppendLine("NUM_STATES " + nextStateID.ToString());
            b.AppendLine("START_STATE " + rootFSGNode.StateID.ToString());
            b.AppendLine("FINAL_STATE " + endFSGNode.StateID.ToString());

            //4) Dump transitions
            foreach (CMUSphinx_FSGTransition t in outTransitions)
            {
                b.AppendFormat("TRANSITION {0} {1} {2} {3}{4}",
                    t.From.StateID, t.To.StateID, t.Probability, t.OnString, Environment.NewLine);
            }

            //5)Footer and close out
            b.AppendLine("FSG_END");
            Grammar = b.ToString();
            GrammarType = "FSG";
            _validGrammar = true;
            return _BuildDict();
        }
示例#11
0
 public CMUSphinx_FSGTransition(CMUSphinx_FSGState from, CMUSphinx_FSGState to, string on)
 {
     From = from;
     To = to;
     OnString = on;
     from.TransitionsOut.Add(this);
     to.TransitionsIn.Add(this);
     Probability = 1.0f;
     Count = 1;
 }
示例#12
0
 public CMUSphinx_FSGState(int stateID)
 {
     StateID = stateID;
     TransitionsOut = new List<CMUSphinx_FSGTransition>();
     TransitionsIn = new List<CMUSphinx_FSGTransition>();
     EquivalentTo = null;
     EquivalentCount = 1;
 }
示例#13
0
文件: XBMC.cs 项目: kingtut666/holly
        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;
        }