Skip to content

Commit 25f8c5b

Browse files
authored
Removed references to "raw.githubusercontent" download links (#4955)
1 parent c1e422d commit 25f8c5b

File tree

9 files changed

+32603
-43
lines changed

9 files changed

+32603
-43
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/OrdinaryLeastSquaresAdvanced.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Example()
1818
// Downloading a regression dataset from
1919
// github.com/dotnet/machinelearning
2020
string dataFile = Microsoft.ML.SamplesUtils.DatasetUtils
21-
.DownloadHousingRegressionDataset();
21+
.GetHousingRegressionDataset();
2222

2323
// Create a new ML context, for ML.NET operations. It can be used for
2424
// exception tracking and logging, as well as the source of randomness.

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/OrdinaryLeastSquaresWithOptionsAdvanced.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Example()
1818
{
1919
// Downloading a regression dataset from
2020
// github.com/dotnet/machinelearning
21-
string dataFile = DatasetUtils.DownloadHousingRegressionDataset();
21+
string dataFile = DatasetUtils.GetHousingRegressionDataset();
2222

2323
// Create a new ML context, for ML.NET operations. It can be used for
2424
// exception tracking and logging, as well as the source of randomness.

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/ConvertToGrayScale.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Example()
2222
// folder will be created, containing 4 images, and a .tsv file
2323
// enumerating the images.
2424
var imagesDataFile = Microsoft.ML.SamplesUtils.DatasetUtils
25-
.DownloadImages();
25+
.GetSampleImages();
2626

2727
// Preview of the content of the images.tsv file
2828
//

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/DnnFeaturizeImage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static void Example()
1919
// folder will be created, containing 4 images, and a .tsv file
2020
// enumerating the images.
2121
var imagesDataFile = Microsoft.ML.SamplesUtils.DatasetUtils
22-
.DownloadImages();
22+
.GetSampleImages();
2323

2424
// Preview of the content of the images.tsv file, which lists the images
2525
// to operate on

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/ExtractPixels.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void Example()
2424
// folder will be created, containing 4 images, and a .tsv file
2525
// enumerating the images.
2626
var imagesDataFile = Microsoft.ML.SamplesUtils.DatasetUtils
27-
.DownloadImages();
27+
.GetSampleImages();
2828

2929
// Preview of the content of the images.tsv file
3030
//

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/LoadImages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void Example()
2121
// folder will be created, containing 4 images, and a .tsv file
2222
// enumerating the images.
2323
var imagesDataFile = Microsoft.ML.SamplesUtils.DatasetUtils
24-
.DownloadImages();
24+
.GetSampleImages();
2525

2626
// Preview of the content of the images.tsv file
2727
//

docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/ResizeImages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void Example()
2121
// folder will be created, containing 4 images, and a .tsv file
2222
// enumerating the images.
2323
var imagesDataFile = Microsoft.ML.SamplesUtils.DatasetUtils
24-
.DownloadImages();
24+
.GetSampleImages();
2525

2626
// Preview of the content of the images.tsv file
2727
//

src/Microsoft.ML.SamplesUtils/SamplesDatasetUtils.cs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,35 @@ namespace Microsoft.ML.SamplesUtils
1212
{
1313
public static class DatasetUtils
1414
{
15-
/// <summary>
16-
/// Downloads the housing dataset from the ML.NET repo.
17-
/// </summary>
18-
public static string DownloadHousingRegressionDataset()
15+
public static string GetFilePathFromDataDirectory(string fileName)
1916
{
20-
var fileName = "housing.txt";
21-
if (!File.Exists(fileName))
22-
Download("https://raw.githubusercontent.com/dotnet/machinelearning/024bd4452e1d3660214c757237a19d6123f951ca/test/data/housing.txt", fileName);
23-
return fileName;
17+
#if NETFRAMEWORK
18+
string directory = AppDomain.CurrentDomain.BaseDirectory;
19+
#else
20+
string directory = AppContext.BaseDirectory;
21+
#endif
22+
23+
while (!Directory.Exists(Path.Combine(directory, ".git")) && directory != null)
24+
{
25+
directory = Directory.GetParent(directory).FullName;
26+
}
27+
28+
if (directory == null)
29+
{
30+
throw new DirectoryNotFoundException("Could not find the ML.NET repository");
31+
}
32+
return Path.Combine(directory, "test", "data", fileName);
2433
}
2534

35+
/// <summary>
36+
/// Returns the path to the housing dataset from the ML.NET repo.
37+
/// </summary>
38+
public static string GetHousingRegressionDataset() => GetFilePathFromDataDirectory("housing.txt");
39+
2640
public static IDataView LoadHousingRegressionDataset(MLContext mlContext)
2741
{
28-
// Download the file
29-
string dataFile = DownloadHousingRegressionDataset();
42+
// Obtains the path to the file
43+
string dataFile = GetHousingRegressionDataset();
3044

3145
// Define the columns to load
3246
var loader = mlContext.Data.CreateTextLoader(
@@ -55,13 +69,12 @@ public static IDataView LoadHousingRegressionDataset(MLContext mlContext)
5569
}
5670

5771
/// <summary>
58-
/// Downloads the adult dataset from the ML.NET repo.
72+
/// Returns the path to the adult dataset from the ML.NET repo.
5973
/// </summary>
60-
public static string DownloadAdultDataset()
61-
=> Download("https://raw.githubusercontent.com/dotnet/machinelearning/244a8c2ac832657af282aa312d568211698790aa/test/data/adult.train", "adult.txt");
74+
public static string GetAdultDataset() => GetFilePathFromDataDirectory("adult.txt");
6275

6376
/// <summary>
64-
/// Downloads the Adult UCI dataset and featurizes it to be suitable for classification tasks.
77+
/// Returns the path to the Adult UCI dataset and featurizes it to be suitable for classification tasks.
6578
/// </summary>
6679
/// <param name="mlContext"><see cref="MLContext"/> used for data loading and processing.</param>
6780
/// <returns>Featurized dataset.</returns>
@@ -70,8 +83,8 @@ public static string DownloadAdultDataset()
7083
/// </remarks>
7184
public static IDataView LoadFeaturizedAdultDataset(MLContext mlContext)
7285
{
73-
// Download the file
74-
string dataFile = DownloadAdultDataset();
86+
// Obtains the path to the file
87+
string dataFile = GetAdultDataset();
7588

7689
// Define the columns to load
7790
var loader = mlContext.Data.CreateTextLoader(
@@ -120,30 +133,14 @@ public static IDataView LoadFeaturizedAdultDataset(MLContext mlContext)
120133
}
121134

122135
/// <summary>
123-
/// Downloads the breast cancer dataset from the ML.NET repo.
136+
/// Returns the path to the breast cancer dataset from the ML.NET repo.
124137
/// </summary>
125-
public static string DownloadBreastCancerDataset()
126-
=> Download("https://raw.githubusercontent.com/dotnet/machinelearning/76cb2cdf5cc8b6c88ca44b8969153836e589df04/test/data/breast-cancer.txt", "breast-cancer.txt");
138+
public static string GetBreastCancerDataset() => GetFilePathFromDataDirectory("breast-cancer.txt");
127139

128140
/// <summary>
129-
/// Downloads 4 images, and a tsv file with their names from the dotnet/machinelearning repo.
141+
/// Returns the path to 4 sample images, and a tsv file with their names from the dotnet/machinelearning repo.
130142
/// </summary>
131-
public static string DownloadImages()
132-
{
133-
string path = "images";
134-
135-
var dirInfo = Directory.CreateDirectory(path);
136-
137-
string pathEscaped = $"{path}{Path.DirectorySeparatorChar}";
138-
139-
Download("https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/banana.jpg", $"{pathEscaped}banana.jpg");
140-
Download("https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/hotdog.jpg", $"{pathEscaped}hotdog.jpg");
141-
Download("https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/images.tsv", $"{pathEscaped}images.tsv");
142-
Download("https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/tomato.bmp", $"{pathEscaped}tomato.bmp");
143-
Download("https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/tomato.jpg", $"{pathEscaped}tomato.jpg");
144-
145-
return $"{path}{Path.DirectorySeparatorChar}images.tsv";
146-
}
143+
public static string GetSampleImages() => GetFilePathFromDataDirectory("images/images.tsv");
147144

148145
/// <summary>
149146
/// Downloads sentiment_model from the dotnet/machinelearning-testdata repo.

0 commit comments

Comments
 (0)