22 #ifndef __DATA_SOURCE_DICTIONARY_H__
23 #define __DATA_SOURCE_DICTIONARY_H__
27 #include "data_management/data/data_dictionary.h"
31 namespace data_management
40 class CategoricalFeatureDictionary :
public std::map<std::string, std::pair<int, int> >
49 class DataSourceFeature :
public SerializationIface
52 NumericTableFeature ntFeature;
56 CategoricalFeatureDictionary *cat_dict;
62 DataSourceFeature() : name(NULL), name_length(0), cat_dict(NULL) {}
67 DataSourceFeature &operator= (
const DataSourceFeature &f)
69 ntFeature = f.ntFeature;
71 name =
new char[f.name_length];
72 daal::services::daal_memcpy_s(name, name_length, f.name, f.name_length);
74 name_length = f.name_length;
81 virtual ~DataSourceFeature()
98 CategoricalFeatureDictionary *getCategoricalDictionary()
102 cat_dict =
new CategoricalFeatureDictionary;
112 void setFeatureName(
const std::string &featureName)
114 name_length = featureName.length() + 1;
119 name =
new char[name_length];
120 daal::services::daal_memcpy_s(name, name_length, featureName.c_str(), name_length);
130 ntFeature.setType<T>();
134 services::Status serializeImpl(InputDataArchive *arch) DAAL_C11_OVERRIDE
136 serialImpl<InputDataArchive, false>( arch );
138 return services::Status();
142 services::Status deserializeImpl(
const OutputDataArchive *arch) DAAL_C11_OVERRIDE
144 serialImpl<const OutputDataArchive, true>( arch );
146 return services::Status();
150 template<
typename Archive,
bool onDeserialize>
151 services::Status serialImpl( Archive *arch )
153 arch->setObj( &ntFeature );
155 arch->set( name_length );
159 if( name_length > 0 )
161 if( name ) {
delete[] name; }
163 name =
new char[name_length];
167 arch->set( name, name_length );
169 int categoricalFeatureDictionaryFlag = (cat_dict != 0);
171 arch->set( categoricalFeatureDictionaryFlag );
173 if( categoricalFeatureDictionaryFlag )
178 getCategoricalDictionary();
183 size_t size = cat_dict->size();
190 char* buff =
new char[buffLen];
191 for(
size_t i=0; i<size; i++)
193 size_t catNameLen = 0;
197 arch->set( catNameLen );
198 if( catNameLen>buffLen )
201 buff =
new char[catNameLen];
202 buffLen = catNameLen;
204 arch->set( buff, catNameLen );
208 (*cat_dict)[ std::string(buff, catNameLen) ] = std::pair<int,int>(catV1, catV2);
214 typedef CategoricalFeatureDictionary::iterator it_type;
216 for(it_type it=cat_dict->begin(); it != cat_dict->end(); it++)
218 const std::string & catName = it->first;
219 size_t catNameLen = catName.size();
220 int catV1 = it->second.first;
221 int catV2 = it->second.second;
223 arch->set( catNameLen );
224 arch->set( catName.c_str(), catNameLen );
235 return services::Status();
238 virtual int getSerializationTag() const DAAL_C11_OVERRIDE
240 return SERIALIZATION_DATAFEATURE_NT_ID;
243 data_feature_utils::IndexNumType getIndexType()
const
245 return ntFeature.indexType;
249 typedef Dictionary<DataSourceFeature, SERIALIZATION_DATADICTIONARY_DS_ID> DataSourceDictionary;
250 typedef services::SharedPtr<DataSourceDictionary> DataSourceDictionaryPtr;
255 using interface1::CategoricalFeatureDictionary;
256 using interface1::DataSourceFeature;
257 using interface1::DataSourceDictionary;
258 using interface1::DataSourceDictionaryPtr;
daal
Definition: algorithm_base_common.h:31
daal::data_management::interface1::DataSourceFeature::setType
void setType()
Definition: data_source_dictionary.h:128
daal::data_management::interface1::DataSourceFeature
Data structure that describes the Data Source feature.
Definition: data_source_dictionary.h:49
daal::data_management::interface1::CategoricalFeatureDictionary
Definition: data_source_dictionary.h:40
daal::data_management::interface1::DataSourceFeature::getSerializationTag
virtual int getSerializationTag() const DAAL_C11_OVERRIDE
Definition: data_source_dictionary.h:238
daal::data_management::interface1::DataSourceFeature::operator=
DataSourceFeature & operator=(const DataSourceFeature &f)
Definition: data_source_dictionary.h:67
daal::data_management::interface1::DataSourceFeature::setFeatureName
void setFeatureName(const std::string &featureName)
Definition: data_source_dictionary.h:112
daal::services::daal_memcpy_s
DAAL_EXPORT void daal_memcpy_s(void *dest, size_t numberOfElements, const void *src, size_t count)
daal::data_management::interface1::DataSourceFeature::getCategoricalDictionary
CategoricalFeatureDictionary * getCategoricalDictionary()
Definition: data_source_dictionary.h:98
daal::data_management::interface1::NumericTableFeature::setType
void setType()
Definition: data_dictionary.h:91
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:48
daal::data_management::interface1::DataSourceFeature::DataSourceFeature
DataSourceFeature()
Definition: data_source_dictionary.h:62