24 #ifndef __DATA_SOURCE_DICTIONARY_H__
25 #define __DATA_SOURCE_DICTIONARY_H__
30 #include "services/internal/buffer.h"
31 #include "data_management/features/defines.h"
32 #include "data_management/data/data_dictionary.h"
36 namespace data_management
46 class CategoricalFeatureDictionary :
public std::map<std::string, std::pair<int, int> > { };
47 typedef services::SharedPtr<CategoricalFeatureDictionary> CategoricalFeatureDictionaryPtr;
53 class DataSourceFeature :
public SerializationIface
56 NumericTableFeature ntFeature;
60 CategoricalFeatureDictionary *cat_dict;
74 DataSourceFeature(
const DataSourceFeature &other)
82 DataSourceFeature &operator= (
const DataSourceFeature &other)
88 virtual ~DataSourceFeature()
90 if (_catDictPtr.get() != cat_dict)
99 services::String getFeatureName()
const
101 return services::String(name);
108 CategoricalFeatureDictionary *getCategoricalDictionary()
112 cat_dict =
new CategoricalFeatureDictionary();
113 _catDictPtr = CategoricalFeatureDictionaryPtr(cat_dict);
119 void setCategoricalDictionary(
const CategoricalFeatureDictionaryPtr &dictionary)
121 if (_catDictPtr.get() != cat_dict)
127 _catDictPtr = dictionary;
128 cat_dict = dictionary.get();
135 void setFeatureName(
const services::String &featureName)
138 synchRawAndStringNames();
148 ntFeature.setType<T>();
152 services::Status serializeImpl(InputDataArchive *arch) DAAL_C11_OVERRIDE
154 return serialImpl<InputDataArchive, false>(arch);
158 services::Status deserializeImpl(
const OutputDataArchive *arch) DAAL_C11_OVERRIDE
160 return serialImpl<const OutputDataArchive, true>(arch);
164 template<
typename Archive,
bool onDeserialize>
165 services::Status serialImpl( Archive *arch )
167 services::Status status;
169 arch->setObj(&ntFeature);
170 arch->set(name_length);
176 _name = services::String(name_length);
177 synchRawAndStringNames();
181 arch->set(name, name_length);
183 const int categoricalFeatureDictionaryFlag = (cat_dict != 0);
184 arch->set(categoricalFeatureDictionaryFlag);
186 if (categoricalFeatureDictionaryFlag)
191 getCategoricalDictionary();
196 size_t size = cat_dict->size();
201 const size_t initialBuffSize = 10;
202 services::internal::Buffer<char> buff(initialBuffSize, &status);
203 DAAL_CHECK_STATUS_VAR(status);
205 for (
size_t i = 0; i < size; i++)
207 size_t catNameLen = 0;
211 arch->set(catNameLen);
212 if (catNameLen > buff.size())
214 DAAL_CHECK_STATUS( status, buff.reallocate(catNameLen) );
216 arch->set(buff.data(), catNameLen);
220 (*cat_dict)[ std::string(buff.data(), catNameLen) ] = std::pair<int,int>(catV1, catV2);
225 typedef CategoricalFeatureDictionary::iterator it_type;
227 for (it_type it=cat_dict->begin(); it != cat_dict->end(); it++)
229 const std::string & catName = it->first;
230 size_t catNameLen = catName.size();
231 int catV1 = it->second.first;
232 int catV2 = it->second.second;
234 arch->set(catNameLen);
235 arch->set(catName.c_str(), catNameLen);
244 _catDictPtr = CategoricalFeatureDictionaryPtr();
250 virtual int getSerializationTag() const DAAL_C11_OVERRIDE
252 return SERIALIZATION_DATAFEATURE_NT_ID;
255 features::IndexNumType getIndexType()
const
257 return ntFeature.indexType;
261 DataSourceFeature &assign(
const DataSourceFeature& other)
264 _catDictPtr = other._catDictPtr;
265 ntFeature = other.ntFeature;
266 cat_dict = other.cat_dict;
268 if (other.name == other._name.c_str())
270 synchRawAndStringNames();
275 name_length = other.name_length;
281 void synchRawAndStringNames()
283 name_length = _name.length();
284 name =
const_cast<char *
>(_name.c_str());
288 services::String _name;
289 CategoricalFeatureDictionaryPtr _catDictPtr;
292 typedef Dictionary<DataSourceFeature, SERIALIZATION_DATADICTIONARY_DS_ID> DataSourceDictionary;
293 typedef services::SharedPtr<DataSourceDictionary> DataSourceDictionaryPtr;
298 using interface1::CategoricalFeatureDictionary;
299 using interface1::CategoricalFeatureDictionaryPtr;
300 using interface1::DataSourceFeature;
301 using interface1::DataSourceDictionary;
302 using interface1::DataSourceDictionaryPtr;
daal::data_management::interface1::CategoricalFeatureDictionary
Definition: data_source_dictionary.h:46
daal::data_management::interface1::DataSourceFeature::DataSourceFeature
DataSourceFeature()
Definition: data_source_dictionary.h:66
daal::data_management::interface1::DataSourceFeature::getSerializationTag
virtual int getSerializationTag() const DAAL_C11_OVERRIDE
Definition: data_source_dictionary.h:250
daal::data_management::interface1::NumericTableFeature::setType
void setType()
Definition: data_dictionary.h:96
daal::data_management::interface1::DataSourceFeature::setFeatureName
void setFeatureName(const services::String &featureName)
Definition: data_source_dictionary.h:135
daal::data_management::interface1::SerializationIface
Abstract interface class that defines the interface for serialization and deserialization.
Definition: data_serialize.h:52
daal::data_management::interface1::DataSourceFeature::operator=
DataSourceFeature & operator=(const DataSourceFeature &other)
Definition: data_source_dictionary.h:82
daal::data_management::interface1::DataSourceFeature::getFeatureName
services::String getFeatureName() const
Definition: data_source_dictionary.h:99
daal::data_management::interface1::DataSourceFeature::DataSourceFeature
DataSourceFeature(const DataSourceFeature &other)
Definition: data_source_dictionary.h:74
daal::data_management::interface1::DataSourceFeature::setType
void setType()
Definition: data_source_dictionary.h:146
daal::data_management::interface1::NumericTableFeature
Data structure describes the Numeric Table feature.
Definition: data_dictionary.h:53
daal::data_management::interface1::InputDataArchive
Provides methods to create an archive data object (serialized) and access this object.
Definition: data_archive.h:725
daal::data_management::interface1::DataSourceFeature
Data structure that describes the Data Source feature.
Definition: data_source_dictionary.h:53
daal::data_management::interface1::DataSourceFeature::getCategoricalDictionary
CategoricalFeatureDictionary * getCategoricalDictionary()
Definition: data_source_dictionary.h:108