-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileTypeInferenceFileTypeInference.cs
More file actions
88 lines (79 loc) · 2.54 KB
/
Copy pathFileTypeInferenceFileTypeInference.cs
File metadata and controls
88 lines (79 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
namespace nyoka_Client
{
public static class FileTypeInference
{
public class FileTypeInferenceError : System.Exception
{
public FileTypeInferenceError(string message)
: base(message)
{
}
}
public static readonly string[] codeFileExtensions = {"py", "ipynb", "r", "jar", "mon"};
public static readonly string[] modelFileExtensions = {"pmml", "h5", "pb", "pbtxt", "onnx"};
public static readonly string[] dataFileExtensions = {"json", "csv", "png", "jpg", "jpeg", "zip","txt","md", "webp"};
private static string getLowerCaseFileExtension(string fileName)
{
string[] splitByDot = fileName.Split('.');
if (splitByDot.Length < 2)
{
throw new FileTypeInferenceError($"File name {fileName} has no extension");
}
string extension = splitByDot[splitByDot.Length - 1];
if (extension.Trim().Length == 0)
{
throw new FileTypeInferenceError($"Empty file extension {extension}");
}
return extension.Trim().ToLower();
}
public static bool isCodeFileName(string fileName)
{
string extension = getLowerCaseFileExtension(fileName);
switch(extension)
{
case "py":
case "ipynb":
case "r":
case "jar":
case "mon":
return true;
default:
return false;
}
}
public static bool isModelFileName(string fileName)
{
string extension = getLowerCaseFileExtension(fileName);
switch(extension)
{
case "pmml":
case "h5":
case "pb":
case "pbtxt":
case "onnx" :
return true;
default:
return false;
}
}
public static bool isDataFileName(string fileName)
{
string extension = getLowerCaseFileExtension(fileName);
switch(extension)
{
case "json":
case "csv":
case "png":
case "jpg":
case "jpeg":
case "zip":
case "txt":
case "md":
case "webp":
return true;
default:
return false;
}
}
}
}