TextIoUtils#
Currently, this API is unsupported in Python
-
class TextIoUtils#
Utilities for operations on text.
Public Static Functions
-
static bool parseCsvLine(std::vector<std::string> &res, std::istream &stream, char delimiter = ',')#
Parses the next line of the given csv text into a vector of strings, using the given delimiter.
Returns true if a line has been read and false otherwise (when reaching EOF, for example).
- Parameters:
res – The resulting vector of strings will be stored here.
stream – A stream to the CSV file.
delimiter – The CSV delimiter
-
static bool parseCsvLine(std::vector<double> &res, std::istream &stream, char delimiter = ',')#
Parses the next line of the given csv text into a vector of doubles, using the given delimiter.
Returns true if a line has been read and false otherwise (when reaching EOF, for example).
- Parameters:
res – The resulting vector of doubles will be stored here.
stream – A stream to the CSV file.
delimiter – The CSV delimiter
- Throws:
runtime_error – If one of the read values couldn’t be converted to a double.
-
static bool parseCsvLine(std::vector<int> &res, std::istream &stream, char delimiter = ',')#
Parses the next line of the given csv text into a vector of integers, using the given delimiter.
Returns true if a line has been read and false otherwise (when reaching EOF, for example).
- Parameters:
res – The resulting vector of integers will be stored here.
stream – A stream to the CSV file.
delimiter – The CSV delimiter
- Throws:
runtime_error – If one of the read values couldn’t be converted to an integer.
-
static DoubleTensor readMatrixFromCsvFile(const std::string &filePath, bool ignoreFirstRow = false)#
Reads a matrix from a CSV file.
Returns the result as a 2D DoubleTensor.
- Parameters:
filePath – Path to legal CSV file to read from.
ignoreFirstRow – If true, assumes the first row is column names and ignores it.
-
static DoubleTensor readMatrixFromCsvStream(std::istream &stream, bool ignoreFirstRow = false)#
Reads a matrix from a stream containing the content of a CSV file.
Returns the result as a 2D DoubleTensor.
- Parameters:
stream – Stream containing the content of a legal CSV file to read from.
ignoreFirstRow – If true, assumes the first row is column names and ignores it.
-
static void writeMatrixToCsv(const DoubleTensor &dt, const std::string &filePath)#
Writes the content of “dt” to a CSV file.
The shape of “dt” must be 2D.
- Parameters:
dt – The DoubleTensor to write.
filePath – Path to CSV file to write to.
-
static void writeMatrixToCsv(const DoubleTensor &dt, std::ostream &out)#
Writes the content of “dt” as CSV to a stream.
The shape of “dt” must be 2D.
- Parameters:
dt – The DoubleTensor to write.
out – Stream to write to.
-
static std::shared_ptr<std::istream> getCsvMatrixStream(const DoubleTensor &dt)#
Returns a stream containing “dt” DoubleTensor as CSV.
The shape of “dt” must be 2D.
- Parameters:
dt – The DoubleTeensor to write into a stream.
-
static void removeWhiteSpaces(std::string &str)#
Removes whitespace charecters from “str”.
- Parameters:
str – To remove whitespaces from.
-
static char readNextNonWhiteSpace(std::istream &stream)#
Reads the next non whitespace charecter from the given stream.
Returns the read charecter.
- Parameters:
stream – The stream to read from.
-
static char readNextNonWhiteSpace(std::istream &stream, char expected)#
Reads the next non whitespace charecter from the given stream, and verifies it is equal to the given expected charecter.
If verifcation passes, returns the read charecter. Otherwise, throws runtime_error().
- Parameters:
stream – The stream to read from.
expected – The expected charecter to be read.
- Throws:
invalid_argument – If the read charecter is different than the given expected charecter.
-
static bool parseCsvLine(std::vector<std::string> &res, std::istream &stream, char delimiter = ',')#