22 #ifndef __DATA_SOURCE_DICTIONARY_H__
23 #define __DATA_SOURCE_DICTIONARY_H__
28 #include "services/internal/buffer.h"
29 #include "data_management/features/defines.h"
30 #include "data_management/data/data_dictionary.h"
34 namespace data_management
44 class CategoricalFeatureDictionary :
public std::map<std::string, std::pair<int, int> > { };
45 typedef services::SharedPtr<CategoricalFeatureDictionary> CategoricalFeatureDictionaryPtr;
51 class DataSourceFeature :
public SerializationIface
54 NumericTableFeature ntFeature;
58 CategoricalFeatureDictionary *cat_dict;
72 DataSourceFeature(
const DataSourceFeature &other)
80 DataSourceFeature &operator= (
const DataSourceFeature &other)
86 virtual ~DataSourceFeature()
88 if (_catDictPtr.get() != cat_dict)
97 services::String getFeatureName()
const
99 return services::String(name);
106 CategoricalFeatureDictionary *getCategoricalDictionary()
110 cat_dict =
new CategoricalFeatureDictionary();
111 _catDictPtr = CategoricalFeatureDictionaryPtr(cat_dict);
117 void setCategoricalDictionary(
const CategoricalFeatureDictionaryPtr &dictionary)
119 if (_catDictPtr.get() != cat_dict)
122 _catDictPtr = dictionary;
123 cat_dict = dictionary.get();
130 void setFeatureName(
const services::String &featureName)
133 synchRawAndStringNames();
143 ntFeature.setType<T>();
147 services::Status serializeImpl(InputDataArchive *arch) DAAL_C11_OVERRIDE
149 return serialImpl<InputDataArchive, false>(arch);
153 services::Status deserializeImpl(
const OutputDataArchive *arch) DAAL_C11_OVERRIDE
155 return serialImpl<const OutputDataArchive, true>(arch);
159 template<
typename Archive,
bool onDeserialize>
160 services::Status serialImpl( Archive *arch )
162 services::Status status;
164 arch->setObj(&ntFeature);
165 arch->set(name_length);
171 _name = services::String(name_length);
172 synchRawAndStringNames();
176 arch->set(name, name_length);
178 const int categoricalFeatureDictionaryFlag = (cat_dict != 0);
179 arch->set(categoricalFeatureDictionaryFlag);
181 if (categoricalFeatureDictionaryFlag)
186 getCategoricalDictionary();
191 size_t size = cat_dict->size();
196 const size_t initialBuffSize = 10;
197 services::internal::Buffer<char> buff(initialBuffSize, &status);
198 DAAL_CHECK_STATUS_VAR(status);
200 for (
size_t i = 0; i < size; i++)
202 size_t catNameLen = 0;
206 arch->set(catNameLen);
207 if (catNameLen > buff.size())
209 DAAL_CHECK_STATUS( status, buff.reallocate(catNameLen) );
211 arch->set(buff.data(), catNameLen);
215 (*cat_dict)[ std::string(buff.data(), catNameLen) ] = std::pair<int,int>(catV1, catV2);
220 typedef CategoricalFeatureDictionary::iterator it_type;
222 for (it_type it=cat_dict->begin(); it != cat_dict->end(); it++)
224 const std::string & catName = it->first;
225 size_t catNameLen = catName.size();
226 int catV1 = it->second.first;
227 int catV2 = it->second.second;
229 arch->set(catNameLen);
230 arch->set(catName.c_str(), catNameLen);
239 _catDictPtr = CategoricalFeatureDictionaryPtr();
245 virtual int getSerializationTag() const DAAL_C11_OVERRIDE
247 return SERIALIZATION_DATAFEATURE_NT_ID;
250 features::IndexNumType getIndexType()
const
252 return ntFeature.indexType;
256 DataSourceFeature &assign(
const DataSourceFeature& other)
259 _catDictPtr = other._catDictPtr;
260 ntFeature = other.ntFeature;
261 cat_dict = other.cat_dict;
263 if (other.name == other._name.c_str())
265 synchRawAndStringNames();
270 name_length = other.name_length;
276 void synchRawAndStringNames()
278 name_length = _name.length();
279 name =
const_cast<char *
>(_name.c_str());
283 services::String _name;
284 CategoricalFeatureDictionaryPtr _catDictPtr;
287 typedef Dictionary<DataSourceFeature, SERIALIZATION_DATADICTIONARY_DS_ID> DataSourceDictionary;
288 typedef services::SharedPtr<DataSourceDictionary> DataSourceDictionaryPtr;
293 using interface1::CategoricalFeatureDictionary;
294 using interface1::CategoricalFeatureDictionaryPtr;
295 using interface1::DataSourceFeature;
296 using interface1::DataSourceDictionary;
297 using interface1::DataSourceDictionaryPtr;
daal
Definition: algorithm_base_common.h:31
daal::data_management::interface1::DataSourceFeature::setFeatureName
void setFeatureName(const services::String &featureName)
Definition: data_source_dictionary.h:130
daal::data_management::interface1::DataSourceFeature::setType
void setType()
Definition: data_source_dictionary.h:141
daal::data_management::interface1::DataSourceFeature::getFeatureName
services::String getFeatureName() const
Definition: data_source_dictionary.h:97
daal::data_management::interface1::DataSourceFeature
Data structure that describes the Data Source feature.
Definition: data_source_dictionary.h:51
daal::data_management::interface1::DataSourceFeature::operator=
DataSourceFeature & operator=(const DataSourceFeature &other)
Definition: data_source_dictionary.h:80
daal::data_management::interface1::CategoricalFeatureDictionary
Definition: data_source_dictionary.h:44
daal::data_management::interface1::DataSourceFeature::getSerializationTag
virtual int getSerializationTag() const DAAL_C11_OVERRIDE
Definition: data_source_dictionary.h:245
daal::data_management::interface1::DataSourceFeature::getCategoricalDictionary
CategoricalFeatureDictionary * getCategoricalDictionary()
Definition: data_source_dictionary.h:106
daal::data_management::interface1::DataSourceFeature::DataSourceFeature
DataSourceFeature(const DataSourceFeature &other)
Definition: data_source_dictionary.h:72
daal::data_management::interface1::NumericTableFeature::setType
void setType()
Definition: data_dictionary.h:94
daal::data_management::interface1::SerializationIface
Abstract interface class that defines the interface for serialization and deserialization.
Definition: data_serialize.h:50
daal::data_management::interface1::NumericTableFeature
Data structure describes the Numeric Table feature.
Definition: data_dictionary.h:51
daal::data_management::interface1::DataSourceFeature::DataSourceFeature
DataSourceFeature()
Definition: data_source_dictionary.h:64