private void Print(List <ExperimentsGenerator.Sweep> candidates, IChannel ch, StreamWriter sw = null) { for (int i = 0; i < candidates.Count; i++) { var experiment = candidates[i]; string rsp = null; // If there is a sweeper section, build a sweep command, otherwise just format the pattern to rsp. if (experiment.TrainerSweeper.Parameters.Count > 0) { rsp = $" {SweepCommand.LoadName} evaluator=Local{{ pattern= {{{experiment.Pattern.ToStringRep(_mode, _dataFile, _testFile)}}} outfolder={_outputDataFolder} }} {experiment.TrainerSweeper.ToStringRep(_sweeper)}"; } else { rsp = experiment.Pattern.ToStringRep(_mode, _dataFile, _testFile, Path.Combine(_outputDataFolder, $"{i}_{experiment.Pattern.Learner.LoadableClassInfo.LoadNames[0]}.out")); } ch.Info(rsp); if (sw != null) { sw.WriteLine(rsp); } else { // Print everything in its file indented. using (var swr = new StreamWriter(Path.Combine(_rspsOutFolder, $"Experiment_{i:0000}.rsp"))) swr.WriteLine(CmdIndenter.GetIndentedCommandLine(rsp)); } } }
private void WriteSchemaAsComment(TextWriter writer, string str) { writer.WriteLine("#@ TextLoader{"); foreach (string line in CmdIndenter.GetIndentedCommandLine(str).Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries)) { writer.WriteLine("#@ " + line); } writer.WriteLine("#@ }"); }
internal void Run() { string text = GetResText("Microsoft.ML.RunTests.CmdLine.IndenterTestInput.txt"); string outName = "CmdIndenterOutput.txt"; string outPath = DeleteOutputPath("CmdLine", outName); using (var writer = File.CreateText(outPath)) { var wrt = new IndentedTextWriter(writer, " "); // Individual scripts are separated by $ int count = 0; int ichLim = 0; int lineLim = 1; while (ichLim < text.Length) { int ichMin = ichLim; int lineMin = lineLim; while (ichLim < text.Length && text[ichLim] != '$') { if (text[ichLim] == '\n') { lineLim++; } ichLim++; } while (ichMin < ichLim && char.IsWhiteSpace(text[ichMin])) { if (text[ichMin] == '\n') { lineMin++; } ichMin++; } if (ichMin < ichLim) { // Process the script. count++; string scriptName = string.Format("Script {0}, lines {1} to {2}", count, lineMin, lineLim); wrt.WriteLine("===== Start {0} =====", scriptName); string input = text.Substring(ichMin, ichLim - ichMin); try { wrt.WriteLine(CmdIndenter.GetIndentedCommandLine(input)); } catch (Exception ex) { if (!ex.IsMarked()) { wrt.WriteLine("Unknown Exception!"); } wrt.WriteLine("Exception: {0}", ex.Message); } wrt.WriteLine("===== End {0} =====", scriptName); } // Skip the $ ichLim++; } } CheckEquality("CmdLine", outName); Done(); }