Skip to content

Commit a52849c

Browse files
committed
removed ReadFile, only kept MlContext ReadFromTextFile
1 parent d90c116 commit a52849c

33 files changed

+70
-85
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/FeatureContributionCalculationTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static void FeatureContributionCalculationTransform_Regression()
1919

2020
// Step 1: Read the data as an IDataView.
2121
// First, we define the reader: specify the data columns and where to find them in the text file.
22-
var reader = mlContext.Data.TextReader(
22+
var reader = mlContext.Data.CreateTextReader(
2323
columns: new[]
2424
{
2525
new TextLoader.Column("MedianHomeValue", DataKind.R4, 0),

docs/samples/Microsoft.ML.Samples/Dynamic/FeatureSelectionTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void FeatureSelectionTransform()
3131

3232
// First, we define the reader: specify the data columns and where to find them in the text file. Notice that we combine entries from
3333
// all the feature columns into entries of a vector of a single column named "Features".
34-
var reader = ml.Data.TextReader(
34+
var reader = ml.Data.CreateTextReader(
3535
columns: new[]
3636
{
3737
new TextLoader.Column("Label", DataKind.BL, 0),

docs/samples/Microsoft.ML.Samples/Dynamic/GeneralizedAdditiveModels.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static void RunExample()
1919

2020
// Step 1: Read the data as an IDataView.
2121
// First, we define the reader: specify the data columns and where to find them in the text file.
22-
var reader = mlContext.Data.TextReader(
22+
var reader = mlContext.Data.CreateTextReader(
2323
columns: new[]
2424
{
2525
new TextLoader.Column("MedianHomeValue", DataKind.R4, 0),

docs/samples/Microsoft.ML.Samples/Dynamic/PermutationFeatureImportance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void PFI_Regression()
2222
// First, we define the reader: specify the data columns and where to find them in the text file.
2323
// The data file is composed of rows of data, with each row having 11 numerical columns
2424
// separated by whitespace.
25-
var reader = mlContext.Data.TextReader(
25+
var reader = mlContext.Data.CreateTextReader(
2626
columns: new[]
2727
{
2828
// Read the first column (indexed by 0) in the data file as an R4 (float)

docs/samples/Microsoft.ML.Samples/Dynamic/SDCA.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void SDCA_BinaryClassification()
2424

2525
// Step 1: Read the data as an IDataView.
2626
// First, we define the reader: specify the data columns and where to find them in the text file.
27-
var reader = mlContext.Data.TextReader(
27+
var reader = mlContext.Data.CreateTextReader(
2828
columns: new[]
2929
{
3030
new TextLoader.Column("Sentiment", DataKind.BL, 0),

src/Microsoft.ML.Data/DataLoadSave/Text/TextLoader.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,26 +1316,6 @@ internal static IDataLoader Create(IHostEnvironment env, ModelLoadContext ctx, I
13161316
internal static IDataLoader Create(IHostEnvironment env, Arguments args, IMultiStreamSource files)
13171317
=> (IDataLoader)new TextLoader(env, args, files).Read(files);
13181318

1319-
/// <summary>
1320-
/// Creates a <see cref="TextLoader"/> and uses it to read a specified file.
1321-
/// </summary>
1322-
/// <param name="env">The environment to use.</param>
1323-
/// <param name="columns">Defines a mapping between input columns in the file and IDataView columns.</param>
1324-
/// <param name="hasHeader">Whether the file has a header.</param>
1325-
/// <param name="separatorChar"> The character used as separator between data points in a row. By default the tab character is used as separator.</param>
1326-
/// <param name="fileSource">Specifies a file from which to read.</param>
1327-
public static IDataView ReadFile(IHostEnvironment env, IMultiStreamSource fileSource, Column[] columns, bool hasHeader = false, char separatorChar = '\t')
1328-
=> new TextLoader(env, columns, hasHeader, separatorChar, fileSource).Read(fileSource);
1329-
1330-
/// <summary>
1331-
/// Loads a text file into an <see cref="IDataView"/>. Supports basic mapping from input columns to IDataView columns.
1332-
/// </summary>
1333-
/// <param name="env">The environment to use.</param>
1334-
/// <param name="fileSource">Specifies a file from which to read.</param>
1335-
/// <param name="args">Defines the settings of the load operation.</param>
1336-
public static IDataView ReadFile(IHostEnvironment env, IMultiStreamSource fileSource, Arguments args = null)
1337-
=> new TextLoader(env, args, fileSource).Read(fileSource);
1338-
13391319
public void Save(ModelSaveContext ctx)
13401320
{
13411321
_host.CheckValue(ctx, nameof(ctx));

src/Microsoft.ML.Data/DataLoadSave/Text/TextLoaderSaverCatalog.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static class TextLoaderSaverCatalog
2121
/// <param name="hasHeader">Whether the file has a header.</param>
2222
/// <param name="separatorChar">The character used as separator between data points in a row. By default the tab character is used as separator.</param>
2323
/// <param name="dataSample">The optional location of a data sample.</param>
24-
public static TextLoader TextReader(this DataOperations catalog,
24+
public static TextLoader CreateTextReader(this DataOperations catalog,
2525
Column[] columns, bool hasHeader = false, char separatorChar = '\t', IMultiStreamSource dataSample = null)
2626
=> new TextLoader(CatalogUtils.GetEnvironment(catalog), columns, hasHeader, separatorChar, dataSample);
2727

@@ -31,7 +31,7 @@ public static TextLoader TextReader(this DataOperations catalog,
3131
/// <param name="catalog">The catalog.</param>
3232
/// <param name="args">Defines the settings of the load operation.</param>
3333
/// <param name="dataSample">Allows to expose items that can be used for reading.</param>
34-
public static TextLoader TextReader(this DataOperations catalog, Arguments args, IMultiStreamSource dataSample = null)
34+
public static TextLoader CreateTextReader(this DataOperations catalog, Arguments args, IMultiStreamSource dataSample = null)
3535
=> new TextLoader(CatalogUtils.GetEnvironment(catalog), args, dataSample);
3636

3737
/// <summary>
@@ -62,7 +62,7 @@ public static IDataView ReadFromTextFile(this DataOperations catalog,
6262
/// <param name="catalog">The catalog.</param>
6363
/// <param name="path">Specifies a file from which to read.</param>
6464
/// <param name="args">Defines the settings of the load operation.</param>
65-
public static IDataView ReadFromTextFile(this DataOperations catalog, string path, Arguments args)
65+
public static IDataView ReadFromTextFile(this DataOperations catalog, string path, Arguments args = null)
6666
{
6767
Contracts.CheckNonEmpty(path, nameof(path));
6868

src/Microsoft.ML.Data/Transforms/ValueToKeyMappingTransformer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,10 @@ private static TermMap CreateFileTermMap(IHostEnvironment env, IChannel ch, stri
483483
"{0} should not be specified when default loader is TextLoader. Ignoring {0}={1}",
484484
nameof(Arguments.TermsColumn), src);
485485
}
486-
termData = TextLoader.ReadFile(env, fileSource,
487-
columns: new[] { new TextLoader.Column("Term", DataKind.TX, 0) }
488-
);
486+
termData = new TextLoader(env,
487+
columns: new[] { new TextLoader.Column("Term", DataKind.TX, 0) },
488+
dataSample: fileSource)
489+
.Read(fileSource);
489490
src = "Term";
490491
autoConvert = true;
491492
}

src/Microsoft.ML.Data/Utilities/ModelFileUtils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ public static IEnumerable<KeyValuePair<ColumnRole, string>> LoadRoleMappingsOrNu
283283
{
284284
// REVIEW: Should really validate the schema here, and consider
285285
// ignoring this stream if it isn't as expected.
286-
var loader = TextLoader.ReadFile(env, new RepositoryStreamWrapper(rep, DirTrainingInfo, RoleMappingFile));
286+
var loader = new TextLoader(env, dataSample: new RepositoryStreamWrapper(rep, DirTrainingInfo, RoleMappingFile))
287+
.Read(new RepositoryStreamWrapper(rep, DirTrainingInfo, RoleMappingFile));
287288

288289
using (var cursor = loader.GetRowCursor(c => true))
289290
{

src/Microsoft.ML.Transforms/TermLookupTransformer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,14 @@ private static IComponentFactory<IMultiStreamSource, IDataLoader> GetLoaderFacto
361361
ulong max = ulong.MinValue;
362362
try
363363
{
364-
var data = TextLoader.ReadFile(host, new MultiFileSource(filename), new[]
364+
var data = new TextLoader(host, new[]
365365
{
366366
new TextLoader.Column("Term", DataKind.TX, 0),
367367
new TextLoader.Column("Value", DataKind.TX, 1)
368-
});
368+
},
369+
dataSample: new MultiFileSource(filename)
370+
).Read(new MultiFileSource(filename));
371+
369372
using (var cursor = data.GetRowCursor(c => true))
370373
{
371374
var getTerm = cursor.GetGetter<ReadOnlyMemory<char>>(0);

0 commit comments

Comments
 (0)