Ejemplo n.º 1
0
        public void NoSamples()
        {
            var words = new string[0];

            NgramModel <string, char> model = NgramModel <string, char> .Train(2, words, w => w, new MaxLikelihoodSmoother <string, char>());

            Assert.That(model.GetProbability('a', new Ngram <char>("l")), Is.EqualTo(0));
            Assert.That(model.GetProbability('l', new Ngram <char>("l")), Is.EqualTo(0));
            Assert.That(model.GetProbability('e', new Ngram <char>("l")), Is.EqualTo(0));
            Assert.That(model.GetProbability('t', new Ngram <char>("l")), Is.EqualTo(0));
        }
Ejemplo n.º 2
0
        public void Ngrams()
        {
            var words = new[] { "#call#", "#stall#", "#hello#", "#the#", "#a#", "#test#", "#income#", "#unproduce#" };

            NgramModel <string, char>[] models = NgramModel <string, char> .TrainAll(10, words, w => w, () => new MaxLikelihoodSmoother <string, char>()).ToArray();

            Assert.That(models[0].Ngrams.Count, Is.EqualTo(16));
            Assert.That(models[1].Ngrams.Count, Is.EqualTo(36));
            Assert.That(models[7].Ngrams.Count, Is.EqualTo(5));
            Assert.That(models[8].Ngrams.Count, Is.EqualTo(3));
            Assert.That(models[9].Ngrams.Count, Is.EqualTo(2));
        }
Ejemplo n.º 3
0
        public void GetProbabilityRightToLeft()
        {
            var words = new[] { "#call#", "#stall#", "#hello#", "#the#", "#a#", "#test#", "#income#", "#unproduce#" };

            NgramModel <string, char> model = NgramModel <string, char> .Train(2, words, w => w, Direction.RightToLeft, new MaxLikelihoodSmoother <string, char>());

            Assert.That(model.GetProbability('a', new Ngram <char>("l")), Is.EqualTo(0.333).Within(0.001));
            Assert.That(model.GetProbability('l', new Ngram <char>("l")), Is.EqualTo(0.5));
            Assert.That(model.GetProbability('e', new Ngram <char>("l")), Is.EqualTo(0.166).Within(0.001));
            Assert.That(model.GetProbability('t', new Ngram <char>("l")), Is.EqualTo(0.0));

            Assert.That(model.GetProbability('c', new Ngram <char>("a")), Is.EqualTo(0.333).Within(0.001));
            Assert.That(model.GetProbability('t', new Ngram <char>("a")), Is.EqualTo(0.333).Within(0.001));
            Assert.That(model.GetProbability('#', new Ngram <char>("a")), Is.EqualTo(0.333).Within(0.001));
            Assert.That(model.GetProbability('l', new Ngram <char>("a")), Is.EqualTo(0.0));
        }