Exemple #1
0
        /// <summary>
        /// including an example where nothing should be extracted, e.g. because the desired information is not present
        /// </summary>
        /// <param name="inputPath">the path to the example file</param>
        /// <returns></returns>
        public override AnalysisSession <string> AddCompletelyNegativeExample(string inputPath)
        {
            var inputRegion = AnalysisUtil.RegionFromFile(inputPath);

            session.Constraints.Add(new RegionNegativeExample(inputRegion, inputRegion));
            return(this);
        }
Exemple #2
0
        public override AnalysisSession <string> AddExample(ExampleData <string> exampleData)
        {
            var inputRegion = AnalysisUtil.RegionFromFile(exampleData.InputPath);
            var startIndex  = inputRegion.S.IndexOf(exampleData.Output, StringComparison.Ordinal);

            Console.WriteLine(exampleData.InputPath);
            var outputRegion = inputRegion.Slice((uint)startIndex, (uint)(startIndex) + ((uint)exampleData.Output.Length));

            session.Constraints.Add(new RegionExample(inputRegion, outputRegion));

            return(this);
        }
Exemple #3
0
        /// <summary>
        /// Analyze the file in <param name="inputPath"></param> using a program learned new from the currently present exampleset.
        /// </summary>
        /// <returns>The extraction result.</returns>
        public override AnalysisResult <string> Analyze(string inputPath, AnalysisResult <string> result, bool verbose)
        {
            ConsolePrinter consolePrinter = new ConsolePrinter(verbose);

            var inputRegion = AnalysisUtil.RegionFromFile(inputPath);

            result.TestInputLineCount = AnalysisUtil.BuildlogLineCount(inputPath);

            consolePrinter.WriteLine("Starting to learn program");
            Stopwatch learningStopwatch = Stopwatch.StartNew();

            RegionProgram topRankedProgram = session.Learn();

            learningStopwatch.Stop();
            consolePrinter.WriteLine("Learning took " + learningStopwatch.Elapsed);
            result.LearningDuration = learningStopwatch.Elapsed;
            result.TestInputPath    = inputPath;

            if (topRankedProgram == null)
            {
                consolePrinter.WriteLine("no program found");
                result.Successful = false;
                result.Output     = "no program found";
                return(result);
            }

            consolePrinter.WriteLine("Learned Program:");
            consolePrinter.WriteLine(topRankedProgram);
            consolePrinter.WriteLine("");
            result.LearnedProgram = topRankedProgram.ToString();

            consolePrinter.WriteLine("Starting to apply program");
            Stopwatch applyingStopwatch = Stopwatch.StartNew();

            StringRegion output = topRankedProgram.Run(inputRegion);

            applyingStopwatch.Stop();
            consolePrinter.WriteLine("Applying took " + applyingStopwatch.Elapsed);
            result.ApplicationDuration = applyingStopwatch.Elapsed;

            if (output == null)
            {
                result.Successful = false;
                result.Output     = "no extraction found for this input";
                return(result);
            }

            result.Successful = true;
            result.Output     = output?.Value;
            return(result);
        }
Exemple #4
0
        public override AnalysisResult <string[]> Analyze(string inputPath, AnalysisResult <string[]> result, bool verbose)
        {
            var             inputRegion      = AnalysisUtil.RegionFromFile(inputPath);
            SequenceProgram topRankedProgram = session.Learn();

            if (topRankedProgram == null)
            {
                Console.Error.WriteLine("no program found");
                return(null);
            }
            List <StringRegion> output = topRankedProgram.Run(inputRegion).ToList();

            result.Output = output.Select(o => o.Value).ToArray();
            return(result);
        }
Exemple #5
0
        public override AnalysisSession <string[]> AddExample(ExampleData <string[]> exampleData)
        {
            var inputRegion = AnalysisUtil.RegionFromFile(exampleData.InputPath);
            List <StringRegion> outputRegions = new List <StringRegion>();

            foreach (string output in exampleData.Output)
            {
                var startIndex   = inputRegion.S.IndexOf(output, StringComparison.Ordinal);
                var outputRegion = inputRegion.Slice((uint)startIndex, (uint)(startIndex + output.Length));
                outputRegions.Add(outputRegion);
            }

            session.Constraints.Add(new SequenceExample(inputRegion, outputRegions));

            return(this);
        }
Exemple #6
0
 public override AnalysisSession <string> AddInput(string inputPath)
 {
     session.Inputs.Add(new[] { AnalysisUtil.RegionFromFile(inputPath) });
     return(this);
 }