Пример #1
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);
        }
Пример #2
0
        //@Override
        protected override GrammarNode createGrammar()
        {
            //logger.info("Creating Grammar");
            initialNode = createGrammarNode(Constants.SILENCE_SPELLING);
            finalNode   = createGrammarNode(Constants.SILENCE_SPELLING);
            finalNode.setFinalNode(true);
            GrammarNode branchNode = createGrammarNode(false);

            List <GrammarNode> wordGrammarNodes = new List <GrammarNode>();
            int end = tokens.Count;

            //logger.info("Creating Grammar nodes");
            foreach (var word in tokens.Take(end))
            {
                GrammarNode wordNode = createGrammarNode(word.toLowerCase());
                wordGrammarNodes.Add(wordNode);
            }
            //logger.info("Done creating grammar node");

            // now connect all the GrammarNodes together
            initialNode.add(branchNode, LogMath.getLogOne());

            createBaseGrammar(wordGrammarNodes, branchNode, finalNode);

            if (modelDeletions)
            {
                addForwardJumps(wordGrammarNodes, branchNode, finalNode);
            }
            if (modelBackwardJumps)
            {
                addBackwardJumps(wordGrammarNodes, branchNode, finalNode);
            }
            if (modelRepetitions)
            {
                addSelfLoops(wordGrammarNodes);
            }
            //logger.info("Done making Grammar");
            //initialNode.dumpDot("./graph.dot");
            return(initialNode);
        }
Пример #3
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());*/
        }