public static PrefixSpec WitnessLinesMap(GrammarRule rule, int parameter, PrefixSpec spec) { var linesExamples = new Dictionary <State, IEnumerable <object> >(); foreach (State input in spec.ProvidedInputs) { var document = ((StringRegion)input[rule.Grammar.InputSymbol]); var selectionPrefix = spec.Examples[input].Cast <StringRegion>(); var linesContainingSelection = new List <StringRegion>(); foreach (StringRegion example in selectionPrefix) { var startLine = GetLine(document, example.Start); var endLine = GetLine(document, example.End); if (startLine == null || endLine == null || startLine != endLine) { return(null); } linesContainingSelection.Add(startLine); } linesExamples[input] = linesContainingSelection; } return(new PrefixSpec(linesExamples)); }
private static void TestExtractionBenchmark(Grammar grammar, string benchmark) { StringRegion document; List<StringRegion> examples = LoadBenchmark($"benchmarks/{benchmark}.txt", out document); var input = State.Create(grammar.InputSymbol, document); var spec = new PrefixSpec(input, examples); ProgramNode program = Learn(grammar, spec); string[] output = program.Invoke(input).ToEnumerable().Select(s => ((StringRegion) s).Value).ToArray(); WriteColored(ConsoleColor.DarkCyan, output.DumpCollection(openDelim: "", closeDelim: "", separator: "\n")); }
private static void TestExtractionBenchmark(Grammar grammar, string benchmark) { StringRegion document; List <StringRegion> examples = LoadBenchmark($"benchmarks/{benchmark}.txt", out document); var input = State.Create(grammar.InputSymbol, document); var spec = new PrefixSpec(input, examples); ProgramNode program = Learn(grammar, spec); string[] output = program.Invoke(input).ToEnumerable().Select(s => ((StringRegion)s).Value).ToArray(); WriteColored(ConsoleColor.DarkCyan, output.DumpCollection(openDelim: "", closeDelim: "", separator: "\n")); }
public static PrefixSpec WitnessLinesMap(GrammarRule rule, int parameter, PrefixSpec spec) { var linesExamples = new Dictionary<State, IEnumerable<object>>(); foreach (State input in spec.ProvidedInputs) { var document = ((StringRegion) input[rule.Grammar.InputSymbol]); var selectionPrefix = spec.Examples[input].Cast<StringRegion>(); var linesContainingSelection = new List<StringRegion>(); foreach (StringRegion example in selectionPrefix) { var startLine = GetLine(document, example.Start); var endLine = GetLine(document, example.End); if (startLine == null || endLine == null || startLine != endLine) return null; linesContainingSelection.Add(startLine); } linesExamples[input] = linesContainingSelection; } return new PrefixSpec(linesExamples); }