| 1024 | |
| 1025 | |
| 1026 | table_index_t CsvTable::flagInconsistentData(table_index_t column) { |
| 1027 | std::vector<enum CellContentType> types; |
| 1028 | std::map<enum CellContentType, table_index_t> type_distribution; |
| 1029 | table_index_t ROWS = getNumberRows(); |
| 1030 | |
| 1031 | // Guess type of each cell |
| 1032 | for( table_index_t r = 0; r < ROWS; ++r ) { |
| 1033 | enum CellContentType my_type = guessContentType(getCell(r, column)); |
| 1034 | types.push_back(my_type); |
| 1035 | auto it = type_distribution.find(my_type); |
| 1036 | if( it != type_distribution.end() ) { |
| 1037 | ++it->second; |
| 1038 | } else { |
| 1039 | type_distribution.emplace(my_type, 1); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | // Find most popular type |
| 1044 | enum CellContentType best_guess = CellContentType::CELL_ANY; |
| 1045 | table_index_t num_cells_with_best_guess = 0; |
| 1046 | for( auto it = type_distribution.begin(); it != type_distribution.end(); ++it ) { |
| 1047 | if( it->second > num_cells_with_best_guess ) { |
| 1048 | best_guess = it->first; |
| 1049 | num_cells_with_best_guess = it->second; |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | // Flag rows that are different than the best guess |
| 1054 | table_index_t count_flagged_rows = 0; |
| 1055 | for( table_index_t r = 0; r < ROWS; ++r ) { |
| 1056 | if( types.at(r) != best_guess ) { |
| 1057 | flagRow(r, true); |
| 1058 | ++count_flagged_rows; |
| 1059 | } |
| 1060 | } |
| 1061 | return count_flagged_rows; |
| 1062 | } |
| 1063 | |
| 1064 | |
| 1065 | enum CsvTable::CellContentType CsvTable::guessContentType(std::string content) { |