public void WordSuffix() { var wordSuffix = WordStrings.WordSuffix(); StringInferenceTestUtilities.TestIfIncludes(wordSuffix, " hello", string.Empty, ".abc"); StringInferenceTestUtilities.TestIfExcludes(wordSuffix, "hello", "hello world", "1 2"); Assert.Equal(wordSuffix.GetLogProb(string.Empty), wordSuffix.GetLogProb(" world")); Assert.Equal(wordSuffix.GetLogProb(string.Empty), wordSuffix.GetLogProb(". and that's it")); }
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}!!"); }