public void SemanticWebTest3b() { var prop0 = Variable.Random(NamePrior()); var dateStrings = Variable.Observed(new[] { "6 May 1953", "May 6, 1953" }); var dateFormat = Variable.DiscreteUniform(dateStrings.Range); var prop1 = ArrayIndex(dateStrings, dateFormat); var template = Variable.Random(StringDistribution.String("{0}") + WordStrings.WordMiddle() + StringDistribution.String("{1}")); var text = Variable.StringFormat(template, prop0, prop1); text.ObservedValue = "Tony Blair was born on May 6, 1953"; var engine = new InferenceEngine(); engine.Compiler.RecommendedQuality = QualityBand.Experimental; engine.NumberOfIterations = 1; var prop0Dist = engine.Infer <StringDistribution>(prop0); var prop1Dist = engine.Infer <StringDistribution>(prop1); var templateDist = engine.Infer <StringDistribution>(template); var dateFormatDist = engine.Infer <Discrete>(dateFormat); StringInferenceTestUtilities.TestProbability(prop0Dist, 1.0, "Tony Blair"); StringInferenceTestUtilities.TestProbability(prop1Dist, 1.0, "May 6, 1953"); StringInferenceTestUtilities.TestProbability(templateDist, 1.0, "{0} was born on {1}"); //Assert.AreEqual(1.0, dateFormatDist[1]); // TODO: fix me }
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}!!"); }
public void SemanticWebTest3() { // Simplified name model var prop0 = Variable.Random(NamePrior()).Named("prop0"); // Simplified date model any string ending in a digit var prop1 = Variable.Random( StringDistribution.Char(DiscreteChar.Digit()) + StringDistribution.Any() + StringDistribution.Char(DiscreteChar.Digit())) .Named("prop1"); var template = Variable.Random(StringDistribution.String("{0}") + WordStrings.WordMiddle() + StringDistribution.String("{1}")) .Named("template"); var text = Variable.StringFormat(template, prop0, prop1).Named("text"); text.ObservedValue = "Tony Blair was born on 6 May 1953"; var engine = new InferenceEngine(); engine.Compiler.RecommendedQuality = QualityBand.Experimental; engine.NumberOfIterations = 1; var prop0Dist = engine.Infer <StringDistribution>(prop0); var prop1Dist = engine.Infer <StringDistribution>(prop1); var templateDist = engine.Infer <StringDistribution>(template); StringInferenceTestUtilities.TestProbability(prop0Dist, 1.0, "Tony Blair"); StringInferenceTestUtilities.TestProbability(prop1Dist, 0.5, "1953", "6 May 1953"); StringInferenceTestUtilities.TestProbability(templateDist, 0.5, "{0} was born on {1}", "{0} was born on 6 May {1}"); }
public void WordMiddleLimitedLength() { const double Eps = 1e-6; var wordMiddleLimitedLength1 = WordStrings.WordMiddle(3, 5); StringInferenceTestUtilities.TestIfIncludes(wordMiddleLimitedLength1, " h w ", ". ab.", "..."); StringInferenceTestUtilities.TestIfExcludes( wordMiddleLimitedLength1, "hello", " w", "hi ", "1 2", ".", "..", " hello world ", string.Empty); Assert.Equal(wordMiddleLimitedLength1.GetLogProb(" h w "), wordMiddleLimitedLength1.GetLogProb(" h "), Eps); var wordMiddleLimitedLength2 = WordStrings.WordMiddle(1, 5); StringInferenceTestUtilities.TestIfIncludes(wordMiddleLimitedLength2, " ", " h w ", ". ab.", "..."); StringInferenceTestUtilities.TestIfExcludes(wordMiddleLimitedLength2, "hello", " w", "hi ", "1 2", " hello world ", string.Empty); Assert.Equal(wordMiddleLimitedLength2.GetLogProb("."), wordMiddleLimitedLength2.GetLogProb(" h "), Eps); var wordMiddleLimitedLength3 = WordStrings.WordMiddle(1, 2); StringInferenceTestUtilities.TestIfIncludes(wordMiddleLimitedLength3, " ", " ."); StringInferenceTestUtilities.TestIfExcludes(wordMiddleLimitedLength3, "hw", " w", "h ", "12", " hello world ", string.Empty); Assert.Equal(wordMiddleLimitedLength3.GetLogProb("."), wordMiddleLimitedLength3.GetLogProb(".."), Eps); }
public BaseApiBuilder(WordTemplater wordTemplater, SDProject sdProject, WordStrings wordStrings, string docLanguage) { _wordTemplater = wordTemplater; _sdProject = sdProject; _wordStrings = wordStrings; _docLanguage = docLanguage; }
public BaseApiBuilder(WordTemplater wordTemplater, SDProject sdProject, WordStrings wordStrings, string docLanguage) { _wordTemplater = wordTemplater; _sdProject = sdProject; _wordStrings = wordStrings; _docLanguage = docLanguage; }
public void WordMiddle() { var wordMiddle = WordStrings.WordMiddle(); StringInferenceTestUtilities.TestIfIncludes(wordMiddle, " hello world ", ". abc.", ". abc. def gh. ", " ", ".."); StringInferenceTestUtilities.TestIfExcludes(wordMiddle, "hello", " world", "hi ", "1 2", string.Empty); Assert.Equal(wordMiddle.GetLogProb(" "), wordMiddle.GetLogProb(" world ")); }
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 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.")); }
public DocBuilder(SDProject sdProject, WordStrings wordStrings, string docLanguage, string outputPath) { _sdProject = sdProject; _wordStrings = wordStrings; _docLanguage = docLanguage; _outputPath = outputPath; _templatePath = Helper.EnsureCopy( Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "templates", "sharpDox.docx"), Path.Combine(outputPath, "tmp")); _wordTemplater = new WordTemplater(_templatePath); _apiBuilder = new ApiBuilder(_wordTemplater, _sdProject, _wordStrings, _docLanguage, outputPath); _articleBuilder = new ArticleBuilder(_wordTemplater, _sdProject, _apiBuilder); }
public DocBuilder(SDProject sdProject, WordStrings wordStrings, string docLanguage, string outputPath) { _sdProject = sdProject; _wordStrings = wordStrings; _docLanguage = docLanguage; _outputPath = outputPath; _templatePath = Helper.EnsureCopy( Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "templates", "sharpDox.docx"), Path.Combine(outputPath, "tmp")); _wordTemplater = new WordTemplater(_templatePath); _apiBuilder = new ApiBuilder(_wordTemplater, _sdProject, _wordStrings, _docLanguage, outputPath); _articleBuilder = new ArticleBuilder(_wordTemplater, _sdProject, _apiBuilder); }
public TypeBuilder(WordTemplater wordTemplater, SDProject sdProject, WordStrings wordStrings, string docLanguage, string outputPath) : base(wordTemplater, sdProject, wordStrings, docLanguage) { _outputPath = outputPath; }
public ApiBuilder(WordTemplater wordTemplater, SDProject sdProject, WordStrings wordStrings, string docLanguage, string outputPath) : base(wordTemplater, sdProject, wordStrings, docLanguage) { _namespaceBuilder = new NamespaceBuilder(wordTemplater, sdProject, wordStrings, docLanguage, outputPath); }
public TypeBuilder(WordTemplater wordTemplater, SDProject sdProject, WordStrings wordStrings, string docLanguage, string outputPath) : base(wordTemplater, sdProject, wordStrings, docLanguage) { _outputPath = outputPath; }
public NamespaceBuilder(WordTemplater wordTemplater, SDProject sdProject, WordStrings wordStrings, string docLanguage, string outputPath) : base(wordTemplater, sdProject, wordStrings, docLanguage) { _typeBuilder = new TypeBuilder(wordTemplater, sdProject, wordStrings, docLanguage, outputPath); }