Example #1
0
        private void addFillerWords()
        {
            HashSet hashSet = new HashSet(this.getGrammarNodes());

            Word[] interWordFillers = this.getInterWordFillers();
            if (interWordFillers.Length == 0)
            {
                return;
            }
            Iterator iterator = hashSet.iterator();

            while (iterator.hasNext())
            {
                GrammarNode grammarNode = (GrammarNode)iterator.next();
                if (!grammarNode.isEmpty() && !grammarNode.getWord().isFiller())
                {
                    GrammarNode grammarNode2 = grammarNode.splitNode(this.maxIdentity + 1);
                    this.add(grammarNode2);
                    GrammarNode grammarNode3 = this.createGrammarNode(false);
                    GrammarNode grammarNode4 = this.createGrammarNode(false);
                    grammarNode4.add(grammarNode3, 0f);
                    grammarNode4.add(grammarNode2, 0f);
                    grammarNode.add(grammarNode3, 0f);
                    Word[] array = interWordFillers;
                    int    num   = array.Length;
                    for (int i = 0; i < num; i++)
                    {
                        Word        word         = array[i];
                        GrammarNode grammarNode5 = this.createGrammarNode(this.maxIdentity + 1, word.getSpelling());
                        grammarNode3.add(grammarNode5, 0f);
                        grammarNode5.add(grammarNode4, 0f);
                    }
                }
            }
        }
Example #2
0
        private void addSilenceWords()
        {
            HashSet  hashSet  = new HashSet(this.getGrammarNodes());
            Iterator iterator = hashSet.iterator();

            while (iterator.hasNext())
            {
                GrammarNode grammarNode = (GrammarNode)iterator.next();
                if (!grammarNode.isEmpty() && !grammarNode.getWord().isFiller())
                {
                    GrammarNode grammarNode2 = this.createGrammarNode(this.maxIdentity + 1, this.dictionary.getSilenceWord().getSpelling());
                    GrammarNode grammarNode3 = grammarNode.splitNode(this.maxIdentity + 1);
                    this.add(grammarNode3);
                    grammarNode.add(grammarNode2, 0f);
                    grammarNode2.add(grammarNode3, 0f);
                    grammarNode2.add(grammarNode2, 0f);
                }
            }
        }
Example #3
0
        public virtual string getRandomSentence()
        {
            StringBuilder stringBuilder = new StringBuilder();
            GrammarNode   grammarNode   = this.getInitialNode();

            while (!grammarNode.isFinalNode())
            {
                if (!grammarNode.isEmpty())
                {
                    Word word = grammarNode.getWord();
                    if (!word.isFiller())
                    {
                        stringBuilder.append(word.getSpelling()).append(' ');
                    }
                }
                grammarNode = this.selectRandomSuccessor(grammarNode);
            }
            return(String.instancehelper_trim(stringBuilder.toString()));
        }
Example #4
0
        internal virtual string getGDLLabel(GrammarNode grammarNode)
        {
            string text = (!grammarNode.isEmpty()) ? grammarNode.getWord().getSpelling() : "";

            return(new StringBuilder().append('"').append(text).append('"').toString());
        }
Example #5
0
        protected internal override GrammarNode createGrammar()
        {
            this.languageModel.allocate();
            TimerPool.getTimer(this, "LMGrammar.create").start();
            GrammarNode grammarNode = null;

            if (this.languageModel.getMaxDepth() > 2)
            {
                [email protected]("Warning: LMGrammar  limited to bigrams");
            }
            ArrayList arrayList  = new ArrayList();
            Set       vocabulary = this.languageModel.getVocabulary();
            Iterator  iterator   = vocabulary.iterator();

            while (iterator.hasNext())
            {
                string      word         = (string)iterator.next();
                GrammarNode grammarNode2 = this.createGrammarNode(word);
                if (grammarNode2 != null && !grammarNode2.isEmpty())
                {
                    if (grammarNode2.getWord().equals(this.getDictionary().getSentenceStartWord()))
                    {
                        grammarNode = grammarNode2;
                    }
                    else if (grammarNode2.getWord().equals(this.getDictionary().getSentenceEndWord()))
                    {
                        grammarNode2.setFinalNode(true);
                    }
                    arrayList.add(grammarNode2);
                }
            }
            if (grammarNode == null)
            {
                string text = "No sentence start found in language model";

                throw new Error(text);
            }
            iterator = arrayList.iterator();
            while (iterator.hasNext())
            {
                GrammarNode grammarNode3 = (GrammarNode)iterator.next();
                if (!grammarNode3.isFinalNode())
                {
                    Iterator iterator2 = arrayList.iterator();
                    while (iterator2.hasNext())
                    {
                        GrammarNode grammarNode4 = (GrammarNode)iterator2.next();
                        string      spelling     = grammarNode3.getWord().getSpelling();
                        string      spelling2    = grammarNode4.getWord().getSpelling();
                        Word[]      words        = new Word[]
                        {
                            this.getDictionary().getWord(spelling),
                            this.getDictionary().getWord(spelling2)
                        };
                        float probability = this.languageModel.getProbability(new WordSequence(words));
                        grammarNode3.add(grammarNode4, probability);
                    }
                }
            }
            TimerPool.getTimer(this, "LMGrammar.create").stop();
            this.languageModel.deallocate();
            return(grammarNode);
        }