Skip to content

Commit c955ae9

Browse files
authored
printing escaped chars + bug (dotnet#212)
1 parent abf6f0d commit c955ae9

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/mlnet/Templates/Console/MLCodeGen.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Microsoft.ML.CLI.Templates.Console
1111
{
1212
using System.Linq;
1313
using System.Text;
14+
using System.Text.RegularExpressions;
1415
using System.Collections.Generic;
1516
using Microsoft.ML.CLI.Utilities;
1617
using System;
@@ -77,7 +78,7 @@ private static ITransformer BuildTrainEvaluateAndSaveModel(MLContext mlContext)
7778
hasHeader : ");
7879
this.Write(this.ToStringHelper.ToStringWithCulture(HasHeader.ToString().ToLowerInvariant()));
7980
this.Write(",\r\n separatorChar : \'");
80-
this.Write(this.ToStringHelper.ToStringWithCulture(Separator));
81+
this.Write(this.ToStringHelper.ToStringWithCulture(Regex.Escape(Separator.ToString())));
8182
this.Write("\',\r\n allowQuotedStrings : ");
8283
this.Write(this.ToStringHelper.ToStringWithCulture(AllowQuoting.ToString().ToLowerInvariant()));
8384
this.Write(",\r\n trimWhitespace : ");
@@ -91,7 +92,7 @@ private static ITransformer BuildTrainEvaluateAndSaveModel(MLContext mlContext)
9192
" hasHeader : ");
9293
this.Write(this.ToStringHelper.ToStringWithCulture(HasHeader.ToString().ToLowerInvariant()));
9394
this.Write(",\r\n separatorChar : \'");
94-
this.Write(this.ToStringHelper.ToStringWithCulture(Separator));
95+
this.Write(this.ToStringHelper.ToStringWithCulture(Regex.Escape(Separator.ToString())));
9596
this.Write("\',\r\n allowQuotedStrings : ");
9697
this.Write(this.ToStringHelper.ToStringWithCulture(AllowQuoting.ToString().ToLowerInvariant()));
9798
this.Write(",\r\n trimWhitespace : ");
@@ -110,6 +111,9 @@ private static ITransformer BuildTrainEvaluateAndSaveModel(MLContext mlContext)
110111
{ Write("\r\n .Append(");
111112
}
112113
Write("mlContext.Transforms."+Transforms[i]);
114+
if(i>0)
115+
{ Write(")");
116+
}
113117
}
114118
this.Write(";\r\n");
115119
}
@@ -196,7 +200,7 @@ private static void TestSinglePrediction(MLContext mlContext)
196200
hasHeader : ");
197201
this.Write(this.ToStringHelper.ToStringWithCulture(HasHeader.ToString().ToLowerInvariant()));
198202
this.Write(",\r\n separatorChar : \'");
199-
this.Write(this.ToStringHelper.ToStringWithCulture(Separator));
203+
this.Write(this.ToStringHelper.ToStringWithCulture(Regex.Escape(Separator.ToString())));
200204
this.Write("\',\r\n allowQuotedStrings : ");
201205
this.Write(this.ToStringHelper.ToStringWithCulture(AllowQuoting.ToString().ToLowerInvariant()));
202206
this.Write(",\r\n trimWhitespace : ");

src/mlnet/Templates/Console/MLCodeGen.tt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<#@ assembly name="System.Core" #>
33
<#@ import namespace="System.Linq" #>
44
<#@ import namespace="System.Text" #>
5+
<#@ import namespace="System.Text.RegularExpressions" #>
56
<#@ import namespace="System.Collections.Generic" #>
67
<#@ import namespace="Microsoft.ML.CLI.Utilities" #>
78
// Licensed to the .NET Foundation under one or more agreements.
@@ -51,15 +52,15 @@ namespace <#= Namespace #>
5152
IDataView trainingDataView = mlContext.Data.ReadFromTextFile<SampleObservation>(
5253
path: TrainDataPath,
5354
hasHeader : <#= HasHeader.ToString().ToLowerInvariant() #>,
54-
separatorChar : '<#= Separator #>',
55+
separatorChar : '<#= Regex.Escape(Separator.ToString()) #>',
5556
allowQuotedStrings : <#= AllowQuoting.ToString().ToLowerInvariant() #>,
5657
trimWhitespace : <#= TrimWhiteSpace.ToString().ToLowerInvariant() #> ,
5758
supportSparse : <#= AllowSparse.ToString().ToLowerInvariant() #>);
5859
<# if(!string.IsNullOrEmpty(TestPath)){ #>
5960
IDataView testDataView = mlContext.Data.ReadFromTextFile<SampleObservation>(
6061
path: TestDataPath,
6162
hasHeader : <#= HasHeader.ToString().ToLowerInvariant() #>,
62-
separatorChar : '<#= Separator #>',
63+
separatorChar : '<#= Regex.Escape(Separator.ToString()) #>',
6364
allowQuotedStrings : <#= AllowQuoting.ToString().ToLowerInvariant() #>,
6465
trimWhitespace : <#= TrimWhiteSpace.ToString().ToLowerInvariant() #> ,
6566
supportSparse : <#= AllowSparse.ToString().ToLowerInvariant() #>);
@@ -73,6 +74,9 @@ namespace <#= Namespace #>
7374
{ Write("\r\n .Append(");
7475
}
7576
Write("mlContext.Transforms."+Transforms[i]);
77+
if(i>0)
78+
{ Write(")");
79+
}
7680
}#>;
7781
<#}#>
7882

@@ -132,7 +136,7 @@ else{#>
132136
IDataView trainingDataView = mlContext.Data.ReadFromTextFile<SampleObservation>(
133137
path: TrainDataPath,
134138
hasHeader : <#= HasHeader.ToString().ToLowerInvariant() #>,
135-
separatorChar : '<#= Separator #>',
139+
separatorChar : '<#= Regex.Escape(Separator.ToString()) #>',
136140
allowQuotedStrings : <#= AllowQuoting.ToString().ToLowerInvariant() #>,
137141
trimWhitespace : <#= TrimWhiteSpace.ToString().ToLowerInvariant() #> ,
138142
supportSparse : <#= AllowSparse.ToString().ToLowerInvariant() #>);

0 commit comments

Comments
 (0)