Beispiel #1
0
        /// <summary>
        /// Creates a DecisionTreeClassifier.exe from a decision tree, returning the file path of the new exe
        /// </summary>
        public static string CompileClassifier(TreeNode decisionTree)
        {
            var assemblyLocation  = Assembly.GetExecutingAssembly().Location;
            var assemblyDirectory = new FileInfo(assemblyLocation).DirectoryName ?? "";

            var classifierDir = Path.Combine(assemblyDirectory, "DecisionTreeClassifier");

            var projFullPath = Path.Combine(classifierDir, "DecisionTreeClassifier.csproj");
            var mainFullPath = Path.Combine(classifierDir, "Program.cs");

            ReplaceSerializedTreeLine(mainFullPath, decisionTree);

            // load up the classifier project
            var proj = new Project(projFullPath);

            // set project to compile special DecisionTree config
            proj.SetProperty("Configuration", "DecisionTree");

            // set the output path
            proj.SetProperty("DecisionTreeOutputPath", assemblyDirectory);

            // make a logger to catch possible build errors
            var logger = new SimpleBuildLogger();

            // if we failed to build the classifier, we're screwed
            if (!proj.Build(logger))
            {
                var sb = new StringBuilder();
                sb.AppendLine("***************************************");
                sb.AppendLine("**** Failed To Compile Classifier! ****");
                sb.AppendLine("***************************************");
                foreach (var error in logger.Errors)
                {
                    sb.AppendLine(error.Message + " " + error.File + ": " + error.LineNumber);
                }
                throw new Exception(sb.ToString());
            }

            // return the executable name
            var exeFileName = proj.GetProperty("AssemblyName").EvaluatedValue + ".exe";

            return(Path.Combine(assemblyDirectory, exeFileName));
        }
Beispiel #2
0
        /// <summary>
        /// Creates a DecisionTreeClassifier.exe from a decision tree, returning the file path of the new exe
        /// </summary>
        public static string CompileClassifier(TreeNode decisionTree)
        {
            var assemblyLocation = Assembly.GetExecutingAssembly().Location;
            var assemblyDirectory = new FileInfo(assemblyLocation).DirectoryName ?? "";

            var classifierDir = Path.Combine(assemblyDirectory, "DecisionTreeClassifier");

            var projFullPath = Path.Combine(classifierDir, "DecisionTreeClassifier.csproj");
            var mainFullPath = Path.Combine(classifierDir, "Program.cs");

            ReplaceSerializedTreeLine(mainFullPath, decisionTree);

            // load up the classifier project
            var proj = new Project(projFullPath);

            // set project to compile special DecisionTree config
            proj.SetProperty("Configuration", "DecisionTree");

            // set the output path
            proj.SetProperty("DecisionTreeOutputPath", assemblyDirectory);

            // make a logger to catch possible build errors
            var logger = new SimpleBuildLogger();

            // if we failed to build the classifier, we're screwed
            if (!proj.Build(logger))
            {
                var sb = new StringBuilder();
                sb.AppendLine("***************************************");
                sb.AppendLine("**** Failed To Compile Classifier! ****");
                sb.AppendLine("***************************************");
                foreach (var error in logger.Errors)
                {
                    sb.AppendLine(error.Message + " " + error.File + ": " + error.LineNumber);
                }
                throw new Exception(sb.ToString());
            }

            // return the executable name
            var exeFileName = proj.GetProperty("AssemblyName").EvaluatedValue + ".exe";
            return Path.Combine(assemblyDirectory, exeFileName);
        }