Beispiel #1
0
        public void AddGrammar(IGram gram)
        {
            Assert.IsTrue(gram.GetN() == N);
            NGram ngram = (NGram)gram;

            foreach (string key in ngram.Grammar.Keys)
            {
                if (Grammar.ContainsKey(key) == false)
                {
                    Grammar[key] = new UniGram();
                }

                Grammar[key].AddGrammar(ngram.Grammar[key]);
            }
        }
Beispiel #2
0
        public HierarchicalNGram(int n, float compiledMemoryUpdate)
        {
            Assert.IsTrue(compiledMemoryUpdate > 0);
            Assert.IsTrue(compiledMemoryUpdate < 1);
            Assert.IsTrue(n > 1);

            CompiledMemoryUpdate = compiledMemoryUpdate;
            N = n;

            Grammars    = new IGram[n];
            Grammars[0] = new UniGram();
            for (int grammarSize = 2; grammarSize <= n; ++grammarSize)
            {
                Grammars[grammarSize - 1] = new NGram(grammarSize);
            }
        }
Beispiel #3
0
        public static IGram InitGrammar(int n)
        {
            Assert.IsTrue(n >= 1);

            IGram gram;

            if (n == 1)
            {
                gram = new UniGram();
            }
            else
            {
                gram = new NGram(n);
            }

            return(gram);
        }