Exemplo n.º 1
0
        private void addForwardJumps(List <GrammarNode> wordGrammarNodes,
                                     GrammarNode branchNode, GrammarNode finalNode)
        {
            GrammarNode currNode = branchNode;

            for (int i = -1; i < wordGrammarNodes.Count; i++)
            {
                if (i > -1)
                {
                    currNode = wordGrammarNodes[i];
                }
                for (int j = i + 2; j < Math.Min(wordGrammarNodes.Count, i + numAllowedWordJumps + 1); j++)
                {
                    GrammarNode jumpNode = wordGrammarNodes[j];
                    currNode.add(
                        jumpNode,
                        logMath.linearToLog(forwardJumpProbability));
                }
            }
            for (int i = wordGrammarNodes.Count - numAllowedWordJumps - 1; i < wordGrammarNodes.Count - 1; i++)
            {
                int j = wordGrammarNodes.Count;
                currNode = wordGrammarNodes[i];
                currNode.add(finalNode, logMath.linearToLog((float)forwardJumpProbability * Math.Pow(Math.E, j - i)));
            }
        }
Exemplo n.º 2
0
        /*
         * (non-Javadoc)
         * We want a very strict grammar structure like the following:
         * InitialNode ----> KW1 ---> KW2 .... ---> KWn ---> FinalNode
         *   ↑________________________________________________|
         */
        protected override GrammarNode createGrammar()
        {
            string silence = Constants.SILENCE_SPELLING;

            initialNode = createGrammarNode(silence);
            finalNode   = createGrammarNode(silence);
            GrammarNode lastNode = createGrammarNode(silence);

            initialNode.add(lastNode, LogMath.getLogOne());
            lastNode.add(initialNode, LogMath.getLogOne());
            GrammarNode lastWordGrammarNode = initialNode;

            /*Iterator<string> iter = tokens.iterator();
             *      while(iter.hasNext()){
             *              GrammarNode currNode = createGrammarNode(iter.next());
             *              lastWordGrammarNode.add(currNode, logMath.getLogOne());
             *              lastWordGrammarNode = currNode;
             *
             *              // Parallel keyword topology
             *              //initialNode.add(currNode, logMath.getLogOne());
             *
             *              //currNode.add(finalNode, logMath.getLogOne());
             *      }*/
            foreach (var token in tokens)
            {
                GrammarNode currNode = createGrammarNode(token);
                lastWordGrammarNode.add(currNode, LogMath.getLogOne());
                lastWordGrammarNode = currNode;
            }
            lastWordGrammarNode.add(lastNode, LogMath.getLogOne());
            lastNode.add(finalNode, logMath.linearToLog(0.0001));
            finalNode.setFinalNode(true);
            return(initialNode);
        }
Exemplo n.º 3
0
        private JSGFGrammar.GrammarGraph processRuleSequence(JSGFRuleSequence jsgfruleSequence)
        {
            GrammarNode grammarNode  = null;
            GrammarNode grammarNode2 = null;

            this.logger.fine(new StringBuilder().append("parseRuleSequence: ").append(jsgfruleSequence).toString());
            List        rules        = jsgfruleSequence.getRules();
            GrammarNode grammarNode3 = null;

            for (int i = 0; i < rules.size(); i++)
            {
                JSGFRule rule = (JSGFRule)rules.get(i);
                JSGFGrammar.GrammarGraph grammarGraph = this.processRule(rule);
                if (i == 0)
                {
                    grammarNode = grammarGraph.getStartNode();
                }
                if (i == rules.size() - 1)
                {
                    grammarNode2 = grammarGraph.getEndNode();
                }
                if (i > 0)
                {
                    grammarNode3.add(grammarGraph.getStartNode(), 0f);
                }
                grammarNode3 = grammarGraph.getEndNode();
            }
            return(new JSGFGrammar.GrammarGraph(this, grammarNode, grammarNode2));
        }
Exemplo n.º 4
0
        private void createBaseGrammar(List <GrammarNode> wordGrammarNodes,
                                       GrammarNode branchNode, GrammarNode finalNode)
        {
            branchNode.add(wordGrammarNodes[0], LogMath.getLogOne());
            for (var i = 0; i < wordGrammarNodes.Count - 1; i++)
            {
                var currNode = wordGrammarNodes[i];
                var nextNode = wordGrammarNodes[i + 1];
                currNode.add(nextNode, LogMath.getLogOne());
            }
            var lastNode = wordGrammarNodes[wordGrammarNodes.Count - 1];

            lastNode.add(finalNode, LogMath.getLogOne());

            /*GrammarNode currNode = branchNode;
             * ListIterator<GrammarNode> iter = wordGrammarNodes.listIterator();
             * while (iter.hasNext()) {
             *  GrammarNode nextNode = iter.next();
             *  currNode.add(nextNode, logMath.getLogOne());
             *  currNode = nextNode;
             * }
             * currNode.add(finalNode, logMath.getLogOne());*/
        }