예제 #1
0
        /// <summary>
        /// Run analysis of a program on the given path.
        /// </summary>
        /// <param name="programName"></param>
        /// <param name="path"></param>
        /// <param name="mightBeFolder"></param>
        /// <returns></returns>
        public static AnalysisResult <OutputType> Analyze <OutputType>(string programName, string path, bool verbose, bool mightBeFolder)
        {
            // TODO: proposal: Method just like this which just gives a "learning/evaluation result" back, packed with the example selection technique and a sequence of analysis results spun together with some information on which samples were used
            var result    = new AnalysisResult <OutputType>();
            var wasFolder = false;

            if (mightBeFolder)
            {
                var tuple = IfPathIsFolderRunOnFolder(programName, path, verbose, Analyze <OutputType>);
                result.FurtherResults = tuple.Item1;
                wasFolder             = tuple.Item2;
            }
            result.ProgramName = programName;
            result.Path        = path;

            if (!wasFolder)
            {
                if (typeof(OutputType) == typeof(string))
                {
                    var program = AnalysisProgram <RegionAnalysisSession, string> .LoadAnalysisProgram(programName);

                    program.ApplyToFile(path, (AnalysisResult <string>)(object) result, verbose);
                }

                if (typeof(OutputType) == typeof(string[]))
                {
                    var program = AnalysisProgram <SequenceAnalysisSession, string[]> .LoadAnalysisProgram(programName);

                    program.ApplyToFile(path, (AnalysisResult <string[]>)(object) result, verbose);
                }

                // TODO get desired output from somewhere
                result.DesiredOutput = result.Output;
                result.Successful    = result.DesiredOutput.Equals(result.Output);
            }
            else
            {
                result.Successful = true;
            }

            return(result);
        }
예제 #2
0
        public static EvaluationResult <OutputType> Evaluate <OutputType>(string programName, ExampleSelection exampleSelection)
        {
            var result = new EvaluationResult <OutputType>();

            result.ExampleSelection = exampleSelection;
            result.ProgramName      = programName;
            if (typeof(OutputType) == typeof(string))
            {
                var program = AnalysisProgram <RegionAnalysisSession, string> .LoadAnalysisProgram(programName);

                return((EvaluationResult <OutputType>)(object) program.Evaluate(exampleSelection, (EvaluationResult <string>)(object) result));
            }
            if (typeof(OutputType) == typeof(string[]))
            {
                var program = AnalysisProgram <SequenceAnalysisSession, string[]> .LoadAnalysisProgram(programName);

                return((EvaluationResult <OutputType>)(object) program.Evaluate(exampleSelection, (EvaluationResult <string[]>)(object) result));
            }
            return(result);
        }