MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
StandardQueryTextFile.cs
1using MyCaffe.basecode;
2using System;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8
9namespace MyCaffe.db.stream
10{
15 {
16 string m_strPath;
17 string[] m_rgstrFiles;
18 int m_nFileIdx = 0;
19
24 public StandardQueryTextFile(string strParam = null)
25 {
26 if (strParam != null)
27 {
28 strParam = ParamPacker.UnPack(strParam);
29 PropertySet ps = new PropertySet(strParam);
30 m_strPath = ps.GetProperty("FilePath");
31 }
32 }
33
38 {
39 get { return CUSTOM_QUERY_TYPE.BYTE; }
40 }
41
45 public string Name
46 {
47 get { return "StdTextFileQuery"; }
48 }
49
53 public int FieldCount
54 {
55 get { return 1; } // data
56 }
57
63 public IXCustomQuery Clone(string strParam)
64 {
65 return new StandardQueryTextFile(strParam);
66 }
67
71 public void Close()
72 {
73 m_rgstrFiles = null;
74 m_nFileIdx = 0;
75 }
76
80 public void Open()
81 {
82 string[] rgstrFiles = Directory.GetFiles(m_strPath);
83 m_nFileIdx = 0;
84
85 List<string> rgstr = new List<string>();
86
87 for (int i = 0; i < rgstrFiles.Length; i++)
88 {
89 FileInfo fi = new FileInfo(rgstrFiles[i]);
90
91 if (fi.Extension.ToLower() == ".txt")
92 rgstr.Add(rgstrFiles[i]);
93 }
94
95 m_rgstrFiles = rgstr.ToArray();
96
97 if (m_rgstrFiles.Length == 0)
98 throw new Exception("The CustomTextQuery could not find any text (*.txt) files to load.");
99 }
100
108 public double[] QueryByTime(DateTime dt, TimeSpan ts, int nCount)
109 {
110 throw new NotImplementedException();
111 }
112
117 public byte[] QueryBytes()
118 {
119 if (m_nFileIdx == m_rgstrFiles.Length)
120 return null;
121
122 using (StreamReader sr = new StreamReader(m_rgstrFiles[m_nFileIdx]))
123 {
124 m_nFileIdx++;
125 return Encoding.ASCII.GetBytes(sr.ReadToEnd());
126 }
127 }
128
133 public List<double[]> QueryRealD()
134 {
135 throw new NotImplementedException();
136 }
137
142 public List<float[]> QueryRealF()
143 {
144 throw new NotImplementedException();
145 }
146
151 public Dictionary<string, float> QueryInfo()
152 {
153 return null;
154 }
155
160 public List<int> GetQuerySize()
161 {
162 if (m_nFileIdx == m_rgstrFiles.Length)
163 return null;
164
165 List<int> rgSize = new List<int>();
166
167 rgSize.Add(1);
168 rgSize.Add(1);
169
170 FileInfo fi = new FileInfo(m_rgstrFiles[m_nFileIdx]);
171 rgSize.Add((int)fi.Length);
172
173 return rgSize;
174 }
175
179 public void Reset()
180 {
181 m_nFileIdx = 0;
182 }
183
190 public byte[] ConvertOutput(float[] rg, out string strType)
191 {
192 using (MemoryStream ms = new MemoryStream())
193 {
194 strType = "String";
195
196 for (int i = 0; i < rg.Length; i++)
197 {
198 int nVal = (int)Convert.ChangeType(rg[i], typeof(int));
199 char ch = (char)nVal;
200 ms.WriteByte((byte)ch);
201 }
202
203 ms.WriteByte(0);
204
205 return ms.ToArray();
206 }
207 }
208 }
209}
Specifies a key-value pair of properties.
Definition: PropertySet.cs:16
string GetProperty(string strName, bool bThrowExceptions=true)
Returns a property as a string value.
Definition: PropertySet.cs:146
The ParamPacker is use to pack and unpack parameters sent to each custom query.
Definition: Interfaces.cs:246
static string UnPack(string str)
Unpack the custom query parameters.
Definition: Interfaces.cs:263
The StandardQueryTextFile provides queries that read text (*.txt) files residing in a given directory...
CUSTOM_QUERY_TYPE QueryType
Returns the QUERY_TYPE of BYTE.
IXCustomQuery Clone(string strParam)
Clone the custom query returning a new copy.
List< int > GetQuerySize()
The GetQuerySize method returns the size of the query as {1,1,filesize}.
void Reset()
Reset the file index to the first file.
StandardQueryTextFile(string strParam=null)
The constructor.
double[] QueryByTime(DateTime dt, TimeSpan ts, int nCount)
The QueryByTime method is not implemented for this custom query.
byte[] QueryBytes()
The QueryBytes method returns the bytes of the next file in the directory.
byte[] ConvertOutput(float[] rg, out string strType)
Converts the output values into the native type used by the CustomQuery.
Dictionary< string, float > QueryInfo()
The Query information returns information about the data queried such as header information.
int FieldCount
Returns the field count of 1.
string Name
Returns the custom query name 'StdTextFileQuery'.
List< float[]> QueryRealF()
The QueryRealF method is not implemented for this custom query.
List< double[]> QueryRealD()
The QueryRealD method is not implemented for this custom query.
void Open()
Open the custom query. The query must be opened before calling QueryBytes.
The custom query interface defines the functions implemented by each Custom Query object used to spec...
Definition: Interfaces.cs:168
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.db.stream namespace contains all data streaming related classes.
CUSTOM_QUERY_TYPE
Defines the custom query type to use.
Definition: Interfaces.cs:134
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12