9#include "opennn_strings.h"
18Index count_tokens(
string& str,
const char& separator)
22 Index tokens_count = 0;
26 string::size_type last_pos = str.find_first_not_of(separator, 0);
30 string::size_type pos = str.find_first_of(separator, last_pos);
32 while(string::npos != pos || string::npos != last_pos)
40 last_pos = str.find_first_not_of(separator, pos);
44 pos = str.find_first_of(separator, last_pos);
51Index count_tokens(
const string& s,
const char& c)
53 return static_cast<Index
>(count(s.begin(), s.end(), c) + 1);
61Tensor<string, 1> get_tokens(
const string& str,
const char& separator)
65 const Index tokens_number = count_tokens(str, separator);
67 Tensor<string, 1> tokens(tokens_number);
71 string::size_type lastPos = str.find_first_not_of(separator, 0);
78 string::size_type pos = str.find_first_of(separator, lastPos);
80 while(string::npos != pos || string::npos != lastPos)
82 if((lastPos-old_pos != 1) && index!= 0)
93 tokens[index] = str.substr(lastPos, pos - lastPos);
100 lastPos = str.find_first_not_of(separator, pos);
104 pos = str.find_first_of(separator, lastPos);
117void fill_tokens(
const string& str,
const char& separator, Tensor<string, 1>& tokens)
119 tokens.setConstant(
"");
123 string::size_type last_position = str.find_first_not_of(separator, 0);
125 string::size_type position = str.find_first_of(separator, last_position);
134 while(string::npos != position || string::npos != last_position)
138 if((last_position-old_pos != 1) && index!= 0)
149 tokens[index] = str.substr(last_position, position - last_position);
156 last_position = str.find_first_not_of(separator, position);
160 position = str.find_first_of(separator, last_position);
169Tensor<type, 1> to_type_vector(
const string& str,
const char& separator)
171 const Tensor<string, 1> tokens = get_tokens(str, separator);
173 const Index tokens_size = tokens.dimension(0);
175 Tensor<type, 1> type_vector(tokens_size);
177 for(Index i = 0; i < tokens_size; i++)
185 type_vector(i) = type(stof(buffer.str()));
187 catch(
const logic_error&)
189 type_vector(i) =
static_cast<type
>(nan(
""));
200bool is_numeric_string(
const string& str)
202 string::size_type index;
204 istringstream iss(str.data());
212 if(!iss)
return false;
220 if(index == str.size() || (str.find(
"%") != string::npos && index+1 == str.size()))
229 catch(
const exception&)
239bool is_constant_string(
const Tensor<string, 1>& str)
241 const string str0 = str[0];
244 for(
int i = 1; i < str.size(); i++)
247 if(str1.compare(str0) != 0)
256bool is_constant_numeric(
const Tensor<type, 1>& str)
258 const type a0 = str[0];
260 for(
int i = 1; i < str.size(); i++)
262 if(
abs(str[i]-a0) > type(1e-3) ||
isnan(str[i]) ||
isnan(a0))
return false;
272bool is_date_time_string(
const string& str)
274 if(is_numeric_string(str))
return false;
276 const string format_1 =
"(201[0-9]|202[0-9]|19[0-9][0-9])+[-|/|.](0[1-9]|1[0-2])+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])+[:]([0-5][0-9])";
277 const string format_2 =
"(201[0-9]|202[0-9]|19[0-9][0-9])+[-|/|.](0[1-9]|1[0-2])+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])";
278 const string format_3 =
"(201[0-9]|202[0-9]|19[0-9][0-9])+[-|/|.](0[1-9]|1[0-2])+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])";
279 const string format_4 =
"(0[1-9]|1[0-9]|2[0-9]|3[0-1])+[-|\\s|/|.](0[1-9]|1[0-2])+[-|\\s|/|.](200[0-9]|201[0-9]|202[0-9]|19[0-9][0-9])+[,| ||-]([0-1][0-9]|2[0-3]|[0-9])+[:]([0-5][0-9])+[:]([0-5][0-9])";
280 const string format_5 =
"(0[1-9]|1[0-9]|2[0-9]|3[0-1])+[-|\\s|/|.](0[1-9]|1[0-2])+[-|\\s|/|.](200[0-9]|201[0-9]|202[0-9]|19[0-9][0-9])+[,| ||-]([0-1][0-9]|2[0-3]|[0-9])+[:]([0-5][0-9])";
281 const string format_6 =
"(0[1-9]|1[0-9]|2[0-9]|3[0-1])+[-|\\s|/|.](0[1-9]|1[0-2])+[-|\\s|/|.](200[0-9]|201[0-9]|202[0-9]|19[0-9][0-9])";
282 const string format_7 =
"(201[0-9]|202[0-9]|19[0-9][0-9])+[-|/|.]([Jj]an(?:uary)?|[Ff]eb(?:ruary)?|[Mm]ar(?:ch)?|[Aa]pr(?:il)?|[Mm]ay|[Jj]un(?:e)?|[Jj]ul(?:y)|[Aa]ug(?:gust)?|[Ss]ep(?:tember)?|[Oo]ct(?:ober)?|[Nn]ov(?:ember)?|[Dd]ec(?:ember)?)+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])+[:]([0-5][0-9])";
283 const string format_8 =
"(201[0-9]|202[0-9]|19[0-9][0-9])+[-|/|.]([Jj]an(?:uary)?|[Ff]eb(?:ruary)?|[Mm]ar(?:ch)?|[Aa]pr(?:il)?|[Mm]ay|[Jj]un(?:e)?|[Jj]ul(?:y)|[Aa]ug(?:gust)?|[Ss]ep(?:tember)?|[Oo]ct(?:ober)?|[Nn]ov(?:ember)?|[Dd]ec(?:ember)?)+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])";
284 const string format_9 =
"(201[0-9]|202[0-9]|19[0-9][0-9])+[-|/|.]([Jj]an(?:uary)?|[Ff]eb(?:ruary)?|[Mm]ar(?:ch)?|[Aa]pr(?:il)?|[Mm]ay|[Jj]un(?:e)?|[Jj]ul(?:y)|[Aa]ug(?:gust)?|[Ss]ep(?:tember)?|[Oo]ct(?:ober)?|[Nn]ov(?:ember)?|[Dd]ec(?:ember)?)+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])";
285 const string format_10 =
"([Jj]an(?:uary)?|[Ff]eb(?:ruary)?|[Mm]ar(?:ch)?|[Aa]pr(?:il)?|[Mm]ay|[Jj]un(?:e)?|[Jj]ul(?:y)|[Aa]ug(?:gust)?|[Ss]ep(?:tember)?|[Oo]ct(?:ober)?|[Nn]ov(?:ember)?|[Dd]ec(?:ember)?)+ (0[1-9]|1[0-9]|2[0-9]|3[0-1])+[| ][,|.| ](201[0-9]|202[0-9]|19[0-9][0-9])";
286 const string format_11 =
"(20[0-9][0-9]|19[0-9][0-9])+[-|/|.](0[1-9]|1[0-2])";
287 const string format_12 =
"([0-2][0-9])+[:]([0-5][0-9])+[:]([0-5][0-9])";
288 const string format_13 =
"([1-9]|0[1-9]|1[0-2])+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[-|/|.](201[0-9]|202[0-9]|19[0-9][0-9])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])+[:]([0-5][0-9])+[,| ||-][AP]M";
290 const regex regular_expression(format_1 +
"|" + format_2 +
"|" + format_3 +
"|" + format_4 +
"|" + format_5 +
"|" + format_6 +
"|" + format_7 +
"|" + format_8
291 +
"|" + format_9 +
"|" + format_10 +
"|" + format_11 +
"|" + format_12 +
"|" + format_13);
293 if(regex_match(str, regular_expression))
308time_t date_to_timestamp(
const string& date,
const Index& gmt)
310 struct tm time_structure;
314 const regex months(
"([Jj]an(?:uary)?)|([Ff]eb(?:ruary)?)|([Mm]ar(?:ch)?)|([Aa]pr(?:il)?)|([Mm]ay)|([Jj]un(?:e)?)|([Jj]ul(?:y)?)"
315 "|([Aa]ug(?:gust)?)|([Ss]ep(?:tember)?)|([Oo]ct(?:ober)?)|([Nn]ov(?:ember)?)|([Dd]ec(?:ember)?)");
319 const string format_1 =
"(201[0-9]|202[0-9]|200[0-9]|19[0-9][0-9])+[-|/|.](0[1-9]|1[0-2])+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])+[:]([0-5][0-9])";
320 const string format_2 =
"(201[0-9]|202[0-9]|200[0-9]|19[0-9][0-9])+[-|/|.](0[1-9]|1[0-2])+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])";
321 const string format_3 =
"(201[0-9]|202[0-9]|200[0-9]|19[0-9][0-9])+[-|/|.](0[1-9]|1[0-2])+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])";
322 const string format_4 =
"(0[1-9]|1[0-9]|2[0-9]|3[0-1])+[-|\\s|/|.](0[1-9]|1[0-2])+[-|\\s|/|.](200[0-9]|201[0-9]|202[0-9]|19[0-9][0-9])+[,| ||-]([0-1][0-9]|2[0-3]|[0-9])+[:]([0-5][0-9])+[:]([0-5][0-9])";
323 const string format_5 =
"(0[1-9]|1[0-9]|2[0-9]|3[0-1])+[-|\\s|/|.](0[1-9]|1[0-2])+[-|\\s|/|.](200[0-9]|201[0-9]|202[0-9]|19[0-9][0-9])+[,| ||-]([0-1][0-9]|2[0-3]|[0-9])+[:]([0-5][0-9])";
324 const string format_6 =
"(0[1-9]|1[0-9]|2[0-9]|3[0-1])+[-|\\s|/|.](0[1-9]|1[0-2])+[-|\\s|/|.](200[0-9]|201[0-9]|202[0-9]|19[0-9][0-9])";
325 const string format_7 =
"(201[0-9]|202[0-9]|200[0-9]|19[0-9][0-9])+[-|/|.]([Jj]an(?:uary)?|[Ff]eb(?:ruary)?|[Mm]ar(?:ch)?|[Aa]pr(?:il)?|[Mm]ay|[Jj]un(?:e)?|[Jj]ul(?:y)|[Aa]ug(?:gust)?|[Ss]ep(?:tember)?|[Oo]ct(?:ober)?|[Nn]ov(?:ember)?|[Dd]ec(?:ember)?)+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])+[:]([0-5][0-9])";
326 const string format_8 =
"(201[0-9]|202[0-9]|200[0-9]|19[0-9][0-9])+[-|/|.]([Jj]an(?:uary)?|[Ff]eb(?:ruary)?|[Mm]ar(?:ch)?|[Aa]pr(?:il)?|[Mm]ay|[Jj]un(?:e)?|[Jj]ul(?:y)|[Aa]ug(?:gust)?|[Ss]ep(?:tember)?|[Oo]ct(?:ober)?|[Nn]ov(?:ember)?|[Dd]ec(?:ember)?)+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])";
327 const string format_9 =
"(201[0-9]|202[0-9]|200[0-9]|19[0-9][0-9])+[-|/|.]([Jj]an(?:uary)?|[Ff]eb(?:ruary)?|[Mm]ar(?:ch)?|[Aa]pr(?:il)?|[Mm]ay|[Jj]un(?:e)?|[Jj]ul(?:y)|[Aa]ug(?:gust)?|[Ss]ep(?:tember)?|[Oo]ct(?:ober)?|[Nn]ov(?:ember)?|[Dd]ec(?:ember)?)+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])";
328 const string format_10 =
"([Jj]an(?:uary)?|[Ff]eb(?:ruary)?|[Mm]ar(?:ch)?|[Aa]pr(?:il)?|[Mm]ay|[Jj]un(?:e)?|[Jj]ul(?:y)|[Aa]ug(?:gust)?|[Ss]ep(?:tember)?|[Oo]ct(?:ober)?|[Nn]ov(?:ember)?|[Dd]ec(?:ember)?)+ (0[1-9]|1[0-9]|2[0-9]|3[0-1])+[| ][,|.| ](201[0-9]|202[0-9]|19[0-9][0-9])";
329 const string format_11 =
"(20[0-9][0-9]|19[0-9][0-9])+[-|/|.](0[1-9]|1[0-2])";
330 const string format_12 =
"([0-2][0-9])+[:]([0-5][0-9])+[:]([0-5][0-9])";
331 const string format_13 =
"([1-9]|0[1-9]|1[0-2])+[-|/|.](0[1-9]|1[0-9]|2[0-9]|3[0-1])+[-|/|.](201[0-9]|202[0-9]|19[0-9][0-9])+[,| ||-]([0-1][0-9]|2[0-3])+[:]([0-5][0-9])+[:]([0-5][0-9])+[,| ||-][AP]M";
332 const string format_14 =
"(201[0-9]|202[0-9]|200[0-9]|19[0-9][0-9])";
334 const regex regular_expression(format_1 +
"|" + format_2 +
"|" + format_3 +
"|" + format_4 +
"|" + format_5 +
"|" + format_6 +
"|" + format_7 +
"|" + format_8
335 +
"|" + format_9 +
"|" + format_10 +
"|" + format_11 +
"|" + format_12 +
"|" + format_13 +
"|" + format_14);
337 regex_search(date, matchs, regular_expression);
341 if(stoi(matchs[1].str()) < 1970)
343 ostringstream buffer;
345 buffer <<
"OpenNN Exception: DataSet Class.\n"
346 <<
"time_t date_to_timestamp(const string&) method.\n"
347 <<
"Cannot convert dates below 1970.\n";
349 throw logic_error(buffer.str());
354 time_structure.tm_year = stoi(matchs[1].str())-1900;
355 time_structure.tm_mon = stoi(matchs[2].str())-1;
356 time_structure.tm_mday = stoi(matchs[3].str());
357 time_structure.tm_hour = stoi(matchs[4].str()) -
static_cast<int>(gmt);
358 time_structure.tm_min = stoi(matchs[5].str());
359 time_structure.tm_sec = stoi(matchs[6].str());
362 else if(matchs[7] !=
"")
364 if(stoi(matchs[7].str()) < 1970)
366 ostringstream buffer;
368 buffer <<
"OpenNN Exception: DataSet Class.\n"
369 <<
"time_t date_to_timestamp(const string&) method.\n"
370 <<
"Cannot convert dates below 1970.\n";
372 throw logic_error(buffer.str());
376 time_structure.tm_year = stoi(matchs[7].str())-1900;
377 time_structure.tm_mon = stoi(matchs[8].str())-1;
378 time_structure.tm_mday = stoi(matchs[9].str());
379 time_structure.tm_hour = stoi(matchs[10].str()) -
static_cast<int>(gmt);
380 time_structure.tm_min = stoi(matchs[11].str());
381 time_structure.tm_sec = 0;
384 else if(matchs[12] !=
"")
386 if(stoi(matchs[12].str()) < 1970)
388 ostringstream buffer;
390 buffer <<
"OpenNN Exception: DataSet Class.\n"
391 <<
"time_t date_to_timestamp(const string&) method.\n"
392 <<
"Cannot convert dates below 1970.\n";
394 throw logic_error(buffer.str());
398 time_structure.tm_year = stoi(matchs[12].str())-1900;
399 time_structure.tm_mon = stoi(matchs[13].str())-1;
400 time_structure.tm_mday = stoi(matchs[14].str());
401 time_structure.tm_hour = 0;
402 time_structure.tm_min = 0;
403 time_structure.tm_sec = 0;
406 else if(matchs[15] !=
"")
408 if(stoi(matchs[17].str()) < 1970)
410 ostringstream buffer;
412 buffer <<
"OpenNN Exception: DataSet Class.\n"
413 <<
"time_t date_to_timestamp(const string&) method.\n"
414 <<
"Cannot convert dates below 1970.\n";
416 throw logic_error(buffer.str());
420 time_structure.tm_year = stoi(matchs[17].str())-1900;
421 time_structure.tm_mon = stoi(matchs[16].str())-1;
422 time_structure.tm_mday = stoi(matchs[15].str());
423 time_structure.tm_hour = stoi(matchs[18].str()) -
static_cast<int>(gmt);
424 time_structure.tm_min = stoi(matchs[19].str());
425 time_structure.tm_sec = stoi(matchs[20].str());
428 else if(matchs[21] !=
"")
430 if(stoi(matchs[23].str()) < 1970)
432 ostringstream buffer;
434 buffer <<
"OpenNN Exception: DataSet Class.\n"
435 <<
"time_t date_to_timestamp(const string&) method.\n"
436 <<
"Cannot convert dates below 1970.\n";
438 throw logic_error(buffer.str());
442 time_structure.tm_year = stoi(matchs[23].str())-1900;
443 time_structure.tm_mon = stoi(matchs[22].str())-1;
444 time_structure.tm_mday = stoi(matchs[21].str());
445 time_structure.tm_hour = stoi(matchs[24].str()) -
static_cast<int>(gmt);
446 time_structure.tm_min = stoi(matchs[25].str());
447 time_structure.tm_sec = 0;
450 else if(matchs[26] !=
"")
452 if(stoi(matchs[28].str()) < 1970)
454 ostringstream buffer;
456 buffer <<
"OpenNN Exception: DataSet Class.\n"
457 <<
"time_t date_to_timestamp(const string&) method.\n"
458 <<
"Cannot convert dates below 1970.\n";
460 throw logic_error(buffer.str());
464 time_structure.tm_year = stoi(matchs[28].str())-1900;
465 time_structure.tm_mon = stoi(matchs[27].str())-1;
466 time_structure.tm_mday = stoi(matchs[26].str());
467 time_structure.tm_hour = 0;
468 time_structure.tm_min = 0;
469 time_structure.tm_sec = 0;
472 else if(matchs[29] !=
"")
474 if(stoi(matchs[29].str()) < 1970)
476 ostringstream buffer;
478 buffer <<
"OpenNN Exception: DataSet Class.\n"
479 <<
"time_t date_to_timestamp(const string&) method.\n"
480 <<
"Cannot convert dates below 1970.\n";
482 throw logic_error(buffer.str());
486 regex_search(date, month, months);
488 Index month_number = 0;
492 for(Index i = 1; i < 13; i++)
494 if(month[
static_cast<size_t>(i)] !=
"") month_number = i;
498 time_structure.tm_year = stoi(matchs[29].str())-1900;
499 time_structure.tm_mon =
static_cast<int>(month_number) - 1;
500 time_structure.tm_mday = stoi(matchs[31].str());
501 time_structure.tm_hour = stoi(matchs[32].str()) -
static_cast<int>(gmt);
502 time_structure.tm_min = stoi(matchs[33].str());
503 time_structure.tm_sec = stoi(matchs[34].str());
506 else if(matchs[35] !=
"")
508 if(stoi(matchs[35].str()) < 1970)
510 ostringstream buffer;
512 buffer <<
"OpenNN Exception: DataSet Class.\n"
513 <<
"time_t date_to_timestamp(const string&) method.\n"
514 <<
"Cannot convert dates below 1970.\n";
516 throw logic_error(buffer.str());
520 regex_search(date, month, months);
522 Index month_number = 0;
525 for(Index i =1 ; i<13 ; i++)
527 if(month[
static_cast<size_t>(i)] !=
"") month_number = i;
531 time_structure.tm_year = stoi(matchs[35].str())-1900;
532 time_structure.tm_mon =
static_cast<int>(month_number) - 1;
533 time_structure.tm_mday = stoi(matchs[37].str());
534 time_structure.tm_hour = stoi(matchs[38].str())-
static_cast<int>(gmt);
535 time_structure.tm_min = stoi(matchs[39].str());
536 time_structure.tm_sec = 0;
539 else if(matchs[40] !=
"")
541 if(stoi(matchs[40].str()) < 1970)
543 ostringstream buffer;
545 buffer <<
"OpenNN Exception: DataSet Class.\n"
546 <<
"time_t date_to_timestamp(const string&) method.\n"
547 <<
"Cannot convert dates below 1970.\n";
549 throw logic_error(buffer.str());
553 regex_search(date, month, months);
555 Index month_number = 0;
558 for(Index i =1 ; i<13 ; i++)
560 if(month[
static_cast<size_t>(i)] !=
"") month_number = i;
564 time_structure.tm_year = stoi(matchs[40].str())-1900;
565 time_structure.tm_mon =
static_cast<int>(month_number)-1;
566 time_structure.tm_mday = stoi(matchs[42].str())-
static_cast<int>(gmt);
567 time_structure.tm_hour = 0;
568 time_structure.tm_min = 0;
569 time_structure.tm_sec = 0;
572 else if(matchs[43] !=
"")
574 if(stoi(matchs[45].str()) < 1970)
576 ostringstream buffer;
578 buffer <<
"OpenNN Exception: DataSet Class.\n"
579 <<
"time_t date_to_timestamp(const string&) method.\n"
580 <<
"Cannot convert dates below 1970.\n";
582 throw logic_error(buffer.str());
586 regex_search(date,month,months);
588 Index month_number = 0;
592 for(Index i =1 ; i<13 ; i++)
594 if(month[
static_cast<size_t>(i)] !=
"") month_number = i;
598 time_structure.tm_year = stoi(matchs[45].str())-1900;
599 time_structure.tm_mon =
static_cast<int>(month_number)-1;
600 time_structure.tm_mday = stoi(matchs[44].str());
601 time_structure.tm_hour = 0;
602 time_structure.tm_min = 0;
603 time_structure.tm_sec = 0;
606 else if(matchs[46] !=
"")
608 if(stoi(matchs[46].str()) < 1970)
610 ostringstream buffer;
612 buffer <<
"OpenNN Exception: DataSet Class.\n"
613 <<
"time_t date_to_timestamp(const string&) method.\n"
614 <<
"Cannot convert dates below 1970.\n";
616 throw logic_error(buffer.str());
620 time_structure.tm_year = stoi(matchs[46].str())-1900;
621 time_structure.tm_mon = stoi(matchs[47].str())-1;
622 time_structure.tm_mday = 1;
623 time_structure.tm_hour = 0;
624 time_structure.tm_min = 0;
625 time_structure.tm_sec = 0;
628 else if(matchs[48] !=
"")
630 time_structure.tm_year = 70;
631 time_structure.tm_mon = 0;
632 time_structure.tm_mday = 1;
633 time_structure.tm_hour = stoi(matchs[48].str());
634 time_structure.tm_min = stoi(matchs[49].str());
635 time_structure.tm_sec = stoi(matchs[50].str());
637 else if(matchs[51] !=
"")
639 time_structure.tm_year = stoi(matchs[53].str())-1900;
640 time_structure.tm_mon = stoi(matchs[51].str());
641 time_structure.tm_mday = stoi(matchs[52].str());
642 time_structure.tm_min = stoi(matchs[55].str());
643 time_structure.tm_sec = stoi(matchs[56].str());
644 if(matchs[57].str()==
"PM"){
645 time_structure.tm_hour = stoi(matchs[54].str())+12;
648 time_structure.tm_hour = stoi(matchs[54].str());
651 else if(matchs[57] !=
"")
653 time_structure.tm_year = stoi(matchs[57].str())-1900;
654 time_structure.tm_mon = 0;
655 time_structure.tm_mday = 1;
656 time_structure.tm_hour = 0;
657 time_structure.tm_min = 0;
658 time_structure.tm_sec = 0;
660 return mktime(&time_structure);
662 else if(is_numeric_string(date)){
666 ostringstream buffer;
668 buffer <<
"OpenNN Exception: DataSet Class.\n"
669 <<
"time_t date_to_timestamp(const string&) method.\n"
670 <<
"Date format (" << date <<
") is not implemented.\n";
672 throw logic_error(buffer.str());
675 if(is_numeric_string(date))
677 time_t time_t_date = stoi(date);
682 return mktime(&time_structure);
691bool contains_substring(
const string& str,
const string& sub_str)
693 if(str.find(sub_str) != string::npos)
705void trim(
string& str)
709 str.erase(0, str.find_first_not_of(
' '));
710 str.erase(0, str.find_first_not_of(
'\t'));
714 str.erase(str.find_last_not_of(
' ') + 1);
715 str.erase(str.find_last_not_of(
'\t') + 1);
719void erase(
string& s,
const char& c)
721 s.erase(remove(s.begin(), s.end(), c), s.end());
729string get_trimmed(
const string& str)
735 output.erase(0, output.find_first_not_of(
' '));
739 output.erase(output.find_last_not_of(
' ') + 1);
749string prepend(
const string& pre,
const string& str)
751 ostringstream buffer;
753 buffer << pre << str;
762bool is_numeric_string_vector(
const Tensor<string, 1>& v)
764 for(Index i = 0; i < v.size(); i++)
766 if(!is_numeric_string(v[i]))
return false;
773bool has_numbers(
const Tensor<string, 1>& v)
775 for(Index i = 0; i < v.size(); i++)
777 if(is_numeric_string(v[i]))
return true;
784bool has_strings(
const Tensor<string, 1>& v)
786 for(Index i = 0; i < v.size(); i++)
788 if(!is_numeric_string(v[i]))
return true;
797bool is_not_numeric(
const Tensor<string, 1>& v)
799 for(Index i = 0; i < v.size(); i++)
801 if(is_numeric_string(v[i]))
return false;
811bool is_mixed(
const Tensor<string, 1>& v)
813 unsigned count_numeric = 0;
814 unsigned count_not_numeric = 0;
816 for(Index i = 0; i < v.size(); i++)
818 if(is_numeric_string(v[i]))
828 if(count_numeric > 0 && count_not_numeric > 0)
843void replace_substring(Tensor<string, 1>& vector,
const string& find_what,
const string& replace_with)
845 const Index size = vector.dimension(0);
847 for(Index i = 0; i < size; i++)
851 while((position = vector(i).find(find_what, position)) != string::npos)
853 vector(i).replace(position, find_what.length(), replace_with);
855 position += replace_with.length();
861void replace(
string& source,
const string& find_what,
const string& replace_with)
865 while((position = source.find(find_what, position)) != string::npos)
867 source.replace(position, find_what.length(), replace_with);
869 position += replace_with.length();
HALF_CONSTEXPR half abs(half arg)
HALF_CONSTEXPR bool isnan(half arg)