| 193 | } |
| 194 | |
| 195 | Parser* Parser::CreateParser(const char* filename, bool header, int num_features, int label_idx) { |
| 196 | const int n_read_line = 20; |
| 197 | auto lines = ReadKLineFromFile(filename, header, n_read_line); |
| 198 | int num_col = 0; |
| 199 | DataType type = GetDataType(lines, &num_col); |
| 200 | if (type == DataType::INVALID) { |
| 201 | Log::Fatal("Unknown format of training data."); |
| 202 | } |
| 203 | std::unique_ptr<Parser> ret; |
| 204 | if (type == DataType::LIBSVM) { |
| 205 | label_idx = GetLabelIdxForLibsvm(lines[0], num_features, label_idx); |
| 206 | ret.reset(new LibSVMParser(label_idx, num_col)); |
| 207 | } else if (type == DataType::TSV) { |
| 208 | label_idx = GetLabelIdxForTSV(lines[0], num_features, label_idx); |
| 209 | ret.reset(new TSVParser(label_idx, num_col)); |
| 210 | } else if (type == DataType::CSV) { |
| 211 | label_idx = GetLabelIdxForCSV(lines[0], num_features, label_idx); |
| 212 | ret.reset(new CSVParser(label_idx, num_col)); |
| 213 | } |
| 214 | |
| 215 | if (label_idx < 0) { |
| 216 | Log::Info("Data file %s doesn't contain a label column.", filename); |
| 217 | } |
| 218 | return ret.release(); |
| 219 | } |
| 220 | |
| 221 | } // namespace LightGBM |
nothing calls this directly
no test coverage detected