コード例 #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));
        }
コード例 #2
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));
        }