Exemple #1
0
        public bool FixItSelf(Mistake mistake, Dictionary <string, long> tests)
        {
            //var unparser = new Unparser();

            //PythonAst ast = null;
            //try
            //{
            //    ast = ASTHelper.ParseContent(mistake.before);
            //    var cleanCode = unparser.Unparse(NodeWrapper.Wrap(ast));
            //    mistake.before = cleanCode;
            //    ast = ASTHelper.ParseContent(cleanCode);

            //    var astAfter = NodeWrapper.Wrap(ASTHelper.ParseContent(mistake.after));
            //    var cleanedAfter = unparser.Unparse(astAfter);
            //    mistake.after = cleanedAfter;
            //}
            //catch (Exception e)
            //{
            //    Console.Error.WriteLine(e.Message);
            //    return false;
            //}
            //var input = State.Create(grammar.Value.InputSymbol, NodeWrapper.Wrap(ast));
            //var program = LearnProgram(mistake, input);
            //if (program == null) return false;

            //var fixedCode = TryFix(tests, program, input, unparser);
            //if (fixedCode != null)
            //{
            //    return true;
            //}
            return(false);
        }
Exemple #2
0
        public ProgramNode LearnProgram(List <Mistake> list, Mistake next)
        {
            var mistakes = (list.Any()) ?  new List <Mistake>()
            {
                list.First(), next
            } :
            new List <Mistake>()
            {
                next
            };

            if (LearnProgram(mistakes) != null)
            {
                mistakes = (list.Count > 30) ? new List <Mistake>(list.GetRange(0, 30))
                {
                    next
                }:
                new List <Mistake>(list)
                {
                    next
                };
                return(LearnProgram(mistakes));
            }
            return(null);
        }
Exemple #3
0
        public ProgramNode LearnProgram(Mistake mistake, State input)
        {
            //var examples = new Dictionary<State, object>();

            //var astAfter = NodeWrapper.Wrap(ASTHelper.ParseContent(mistake.after));
            //examples.Add(input, astAfter);

            //var spec = new ExampleSpec(examples);
            //var prose = new SynthesisEngine(grammar.Value);
            //var learned = prose.LearnGrammarTopK(spec, "Score", k: 1);
            //return learned.Any() ? learned.First() : null;
            throw new NotImplementedException();
        }
Exemple #4
0
        private bool TryInParallel(Mistake mistake, Dictionary <string, long> tests, ProgramNode program, State input)
        {
            var  unparser  = new Unparser();
            bool isFixed   = false;
            var  fixedCode = TryFix(tests, program, input, unparser);

            if (fixedCode != null)
            {
                mistake.UsedFix          = program.ToString();
                mistake.SynthesizedAfter = fixedCode;
                isFixed = true;
            }
            return(isFixed);
        }
Exemple #5
0
        //public SubmissionFixer Create(Tuple<string, string> example,
        //    string ranking, int numberOftransformations, string pathToGrammar, string pathToLib)
        //{
        //    var unparser = new Unparser();
        //    var before = unparser.Unparse(NodeWrapper.Wrap(ASTHelper.ParseContent(example.Item1)));
        //    var after = unparser.Unparse(NodeWrapper.Wrap(ASTHelper.ParseContent(example.Item1)));
        //    var mistake = new Mistake() { before = before, after = after };
        //    var list = new List<Mistake>() { mistake };
        //    var queue = new ConcurrentQueue<Tuple<List<Mistake>, ProgramNode>>();
        //    //if ranking is specific, we add more weight for expressions that contains parent context
        //    RankingScore.ScoreForContext = ranking.Equals("specific") ? 100 : -100;
        //    var transformations = LearnPrograms(list, numberOftransformations);

        //    return new SubmissionFixer(queue);
        //}

        public bool Fix(Mistake mistake, Dictionary <string, long> tests, bool leaveOneOut = true)
        {
            //PythonAst ast = null;
            //ast = ASTHelper.ParseContent(mistake.before);
            //var input = State.Create(grammar.Value.InputSymbol, NodeWrapper.Wrap(ast));
            //var unparser = new Unparser();

            //foreach (var tuple in _classification)
            //{
            //    var belongs = false;
            //    foreach (var mistake1 in tuple.Item1)
            //    {
            //        if (mistake.Equals(mistake1))
            //            belongs = true;
            //    }
            //    if (belongs && leaveOneOut)
            //    {
            //        var listWithoutCurrentMistake = tuple.Item1.Where(e => !e.Equals(mistake));
            //        if (!listWithoutCurrentMistake.Any()) return false;
            //        var program = LearnProgram(listWithoutCurrentMistake.ToList());
            //        if (program == null) return false;

            //        var fixedCode = TryFix(tests, program, input, unparser);
            //        if (fixedCode != null)
            //        {
            //            mistake.UsedFix = program.ToString();
            //            mistake.SynthesizedAfter = fixedCode;
            //            return true;
            //        }
            //    }
            //    else
            //    {
            //        var fixedCode = TryFix(tests, tuple.Item2, input, unparser);
            //        if (fixedCode != null)
            //        {
            //            mistake.UsedFix = tuple.Item2.ToString();
            //            mistake.SynthesizedAfter = fixedCode;
            //            return true;
            //        }
            //    }
            //}
            return(false);
        }
Exemple #6
0
 protected bool Equals(Mistake other)
 {
     return(string.Equals(diff, other.diff) && string.Equals(before, other.before) && string.Equals(after, other.after));
 }