static void Main(string[] args) { var grammar = Helper.LoadGrammar("Annagrammer.syntax.grammar", true, typeof(StringOfLetters), typeof(Semantics)); if (grammar != null) { var specification = ShouldConvert.Given(grammar).To(new StringOfLetters("Hallo"), new StringOfLetters("aHllo")); var result = Helper.LearnDeductive(grammar, specification, "learning.log.xml"); if (result.RealizedPrograms != null) { Console.WriteLine("No program found!"); } else { // TODO for ranking, define a feature // for now, iterate over the programms without score or other features. int i = 0; foreach (var program in result.RealizedPrograms) { Console.WriteLine($"[{i}]: {program}"); i++; } // TODO programm auf neuen Input anwenden. } } }
private static void LoadAndTestSubstrings() { var grammar = LoadGrammar("ProseSample.Substrings.grammar"); if (grammar == null) { return; } StringRegion prose = new StringRegion("Microsoft Program Synthesis using Examples SDK", Semantics.Tokens); StringRegion sdk = prose.Slice(prose.End - 3, prose.End); Spec spec = ShouldConvert.Given(grammar).To(prose, sdk); Learn(grammar, spec, new Substrings.RankingScore(grammar), new Substrings.WitnessFunctions(grammar)); TestFlashFillBenchmark(grammar, "emails"); }
private static void LoadAndTestSubstrings() { var grammar = LoadGrammar("ProseSample.Substrings.grammar", CompilerReference.FromAssemblyFiles(typeof(StringRegion).GetTypeInfo().Assembly, typeof(Substrings.Semantics).GetTypeInfo().Assembly, typeof(Record).GetTypeInfo().Assembly)); if (grammar == null) { return; } StringRegion prose = new StringRegion("Microsoft Program Synthesis using Examples SDK", Token.Tokens); StringRegion sdk = prose.Slice(prose.End - 3, prose.End); Spec spec = ShouldConvert.Given(grammar).To(prose, sdk); Learn(grammar, spec, new Substrings.RankingScore(grammar), new Substrings.WitnessFunctions(grammar)); TestFlashFillBenchmark(grammar, "emails"); }
private static void testLearning(Grammar grammar) { var inputList = new[] { "Hello", "World!!!!!!", "Eureka!!", "oh!!" }; var outputLists = new String[][] { new [] { "oh!!", "Hello", "Eureka!!", "World!!!!!!" }, new [] { "Eureka!!", "oh!!", "Hello", "World!!!!!!" }, new [] { "Hello", "oh!!", "World!!!!!!", "Eureka!!" }, new [] { "Eureka!!", "oh!!", "World!!!!!!", "Hello" }, new [] { "Hello", "oh!!", "Eureka!!", "World!!!!!!" }, new [] { "Hello", "Eureka!!", "oh!!", "World!!!!!!" }, }; foreach (var outputList in outputLists) { Spec spec = ShouldConvert.Given(grammar).To(inputList, outputList); Learn(grammar, spec, new SortKeySynthesis.Learning.RankingScore(grammar), new SortKeySynthesis.Learning.Learners(grammar)); } }
static void Main() { var grammar = Helper.LoadGrammar("HelloWorld.syntax.grammar", true, typeof(HelloWorld.semantic.Semantics), typeof(System.Text.RegularExpressions.Regex)); var Spec = ShouldConvert.Given(grammar).To("Hello World", "He").To("hello World", "Wo"); var program = Helper.LearnDeductively(grammar, Spec, new WitnessFunctions(grammar), "learning_ded.log.xml"); if (program.IsEmpty) { Console.WriteLine("Could not learn any program."); return; } /*var programs = Helper.Learn(grammar, ShouldConvert.Given(grammar).To("Hello World", "Wo"), "learning.log.xml"); //LearnProgram(grammar); * var bestPrograms = Helper.RankPrograms(programs, 10, new MyFeature(grammar)); * * var scorer = new MyFeature(grammar); * var funcCounter = new FunctionCounter(grammar); * foreach (var p in bestPrograms) * { * Console.WriteLine($"[Score: {p.GetFeatureValue(scorer):F3}, Function calls: {p.GetFeatureValue(funcCounter)}] {p}"); * } * * var bestProgram = bestPrograms.First(); * * if (bestProgram != null) * { * Console.WriteLine("Execute the first realized Program on some more input:"); * var input = "Dies ist ein Test"; * var output = (string)Helper.ExecuteOn(bestProgram, input); * Console.WriteLine($"{input} -> {output}"); * } * else * { * Console.WriteLine("No programm found"); * }*/ }
private static void LoadAndTestSubstrings() { var grammar = LoadGrammar("ProseSample.Substrings.grammar"); if (grammar == null) { return; } ProgramNode p = grammar.ParseAST(@"SubStr(v, PosPair(AbsPos(v, -4), AbsPos(v, -1)))", ASTSerializationFormat.HumanReadable); StringRegion prose = StringRegion.Create("Microsoft Program Synthesis using Examples SDK"); State input = State.Create(grammar.InputSymbol, prose); Console.WriteLine(p.Invoke(input)); StringRegion sdk = prose.Slice(prose.End - 3, prose.End); Spec spec = ShouldConvert.Given(grammar).To(prose, sdk); Learn(grammar, spec); TestFlashFillBenchmark(grammar, "emails"); }
private static void LoadAndTestSubstrings() { var grammar = LoadGrammar("ProseSample.Substrings.grammar"); if (grammar == null) { return; } ProgramNode p = ProgramNode.Parse(@"SubStr(v, PosPair(AbsPos(v, -4), AbsPos(v, -1)))", grammar, ASTSerializationFormat.HumanReadable); StringRegion data = RegionLearner.CreateStringRegion("Microsoft PROSE SDK"); State input = State.Create(grammar.InputSymbol, data); Console.WriteLine(p.Invoke(input)); StringRegion sdk = data.Slice(data.End - 3, data.End); Spec spec = ShouldConvert.Given(grammar).To(data, sdk); Learn(grammar, spec, new Substrings.RankingScore(grammar), new Substrings.WitnessFunctions(grammar)); TestTextTransformationBenchmark(grammar, "emails"); }