public void StringFormatTest1()
        {
            var a = Variable.Random(StringDistribution.OneOf("World", "Universe"));
            var b = Variable.StringFormat("Hello {0}!!", a);

            var engine = new InferenceEngine();

            engine.Compiler.RecommendedQuality = QualityBand.Experimental;
            Test("a", engine.Infer <IDistribution <string> >(a), "World", "Universe");
            Test("b", engine.Infer <IDistribution <string> >(b), "Hello World!!", "Hello Universe!!");
            a.ObservedValue = "World";
            Test("b", engine.Infer <IDistribution <string> >(b), "Hello World!!");
            a.ClearObservedValue();
            b.ObservedValue = "Hello World!!";
            Test("a", engine.Infer <IDistribution <string> >(a), "World");

            var a2       = Variable.Random(WordString());
            var template = Variable.Random(WordStrings.WordPrefix() + StringDistribution.String("{0}") + WordStrings.WordSuffix());
            var b2       = Variable.StringFormat(template, a2);

            b2.ObservedValue = "Hello World!!";
            Test("t", engine.Infer <IDistribution <string> >(template), "Hello {0}!!", "{0}!!", "{0} World!!");
            Test("a2", engine.Infer <IDistribution <string> >(a2), "Hello", "World", "Hello World");
            a2.ObservedValue = "World";
            Test("t", engine.Infer <IDistribution <string> >(template), "Hello {0}!!");
        }
Exemple #2
0
        public void WordPrefix()
        {
            var wordPrefix = WordStrings.WordPrefix();

            StringInferenceTestUtilities.TestIfIncludes(wordPrefix, "hello ", string.Empty, "abc.");
            StringInferenceTestUtilities.TestIfExcludes(wordPrefix, "hello", "hello world", "1 2");
            Assert.Equal(wordPrefix.GetLogProb(string.Empty), wordPrefix.GetLogProb("hello "));
            Assert.Equal(wordPrefix.GetLogProb(string.Empty), wordPrefix.GetLogProb("hello world and people in it."));
        }