ArffBase.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // ArffBase.h
  2. #ifndef __ARFFBASE_H__
  3. #define __ARFFBASE_H__
  4. #include "AttributeTypes.h"
  5. #include <memory>
  6. #include <vector>
  7. #include <iterator>
  8. using namespace std;
  9. typedef vector<vector<double>> arffData;
  10. class ArffBase
  11. {
  12. public:
  13. ArffBase();
  14. ArffBase(const char* filename);
  15. ~ArffBase();
  16. bool Load(const char *filename);
  17. void Save(const char *filename);
  18. void AddRow(vector<double> row);
  19. ///< Adds the provided row at the end of the data
  20. void AddColumn(string attName, string type);
  21. ///< Adds a new column at the end and initializes the new column data to 0. The string type
  22. ///< is either "integer", "numeric" or nominal. For nominal attributes provide
  23. ///< the possible values within curly braces (ex. "{val1,val2}").
  24. vector<double>& operator[](const int index);
  25. ///< Returns an entry (a row) of the ARFF data.
  26. void SetRelation(string relation);
  27. string GetRelation() const;
  28. bool GetMetadata(const string& key, string& value) const;
  29. bool SetMetadata(const string &key, const string &value);
  30. ///< This function returns always true.
  31. bool GetAttMapping(const int &attIndex, vector<string>& values) const;
  32. bool GetAttMapping(const string &attName, vector<string>& values) const;
  33. ///< The values are the strings of the mapping to the doubles
  34. ///< in the data.
  35. bool GetAttIndex(const string &attName, int &index) const;
  36. void Size(int &rows, int &columns) const;
  37. ///< \p rows represents number of data rows in the ARFF file and
  38. ///< \p columns represents the number of attributes.
  39. arffData::const_iterator cbegin() const;
  40. arffData::const_iterator cend() const;
  41. arffData::iterator begin();
  42. arffData::iterator end();
  43. private:
  44. void ProcessArffLine(string& line);
  45. void ProcessMetadata(vector<string>& metaLine);
  46. void ProcessAttribute(vector<string>& attLine);
  47. void ProcessComment(string& comLine);
  48. void ProcessData(string& dataLine);
  49. unique_ptr<AttributeType> AttributeFactory(string attName, string type);
  50. bool CompareStrings(string first, string second) const;
  51. ///< Case insensitive string comparison.
  52. vector<unique_ptr<AttributeType>> m_vpAttributes;
  53. map<string, string> m_mMetadata;
  54. vector<string> m_vComments;
  55. arffData m_data;
  56. string m_relation;
  57. bool m_dataReached;
  58. };
  59. #endif /*__ARFFBASE_H__*/