Example #1
0
        internal virtual string getGDLColor(GrammarNode grammarNode)
        {
            string result = "grey";

            if (grammarNode.isFinalNode())
            {
                result = "red";
            }
            else if (!grammarNode.isEmpty())
            {
                result = "green";
            }
            return(result);
        }
Example #2
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 #3
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);
        }