48 #ifndef __DATA_SOURCE_DICTIONARY_H__
49 #define __DATA_SOURCE_DICTIONARY_H__
53 #include "data_management/data/data_dictionary.h"
57 namespace data_management
66 class CategoricalFeatureDictionary :
public std::map<std::string, std::pair<int, int> >
75 class DataSourceFeature :
public SerializationIface
78 NumericTableFeature ntFeature;
82 CategoricalFeatureDictionary *cat_dict;
88 DataSourceFeature() : name(NULL), name_length(0), cat_dict(NULL) {}
93 DataSourceFeature &operator= (
const DataSourceFeature &f)
95 ntFeature = f.ntFeature;
97 name =
new char[f.name_length];
98 daal::services::daal_memcpy_s(name, name_length, f.name, f.name_length);
100 name_length = f.name_length;
107 virtual ~DataSourceFeature()
124 CategoricalFeatureDictionary *getCategoricalDictionary()
128 cat_dict =
new CategoricalFeatureDictionary;
138 void setFeatureName(
const std::string &featureName)
140 name_length = featureName.length() + 1;
145 name =
new char[name_length];
146 daal::services::daal_memcpy_s(name, name_length, featureName.c_str(), name_length);
156 ntFeature.setType<T>();
160 services::Status serializeImpl(InputDataArchive *arch) DAAL_C11_OVERRIDE
162 serialImpl<InputDataArchive, false>( arch );
164 return services::Status();
168 services::Status deserializeImpl(
const OutputDataArchive *arch) DAAL_C11_OVERRIDE
170 serialImpl<const OutputDataArchive, true>( arch );
172 return services::Status();
176 template<
typename Archive,
bool onDeserialize>
177 services::Status serialImpl( Archive *arch )
179 arch->setObj( &ntFeature );
181 arch->set( name_length );
185 if( name_length > 0 )
187 if( name ) {
delete[] name; }
189 name =
new char[name_length];
193 arch->set( name, name_length );
195 int categoricalFeatureDictionaryFlag = (cat_dict != 0);
197 arch->set( categoricalFeatureDictionaryFlag );
199 if( categoricalFeatureDictionaryFlag )
204 getCategoricalDictionary();
209 size_t size = cat_dict->size();
216 char* buff =
new char[buffLen];
217 for(
size_t i=0; i<size; i++)
219 size_t catNameLen = 0;
223 arch->set( catNameLen );
224 if( catNameLen>buffLen )
227 buff =
new char[catNameLen];
228 buffLen = catNameLen;
230 arch->set( buff, catNameLen );
234 (*cat_dict)[ std::string(buff, catNameLen) ] = std::pair<int,int>(catV1, catV2);
240 typedef CategoricalFeatureDictionary::iterator it_type;
242 for(it_type it=cat_dict->begin(); it != cat_dict->end(); it++)
244 const std::string & catName = it->first;
245 size_t catNameLen = catName.size();
246 int catV1 = it->second.first;
247 int catV2 = it->second.second;
249 arch->set( catNameLen );
250 arch->set( catName.c_str(), catNameLen );
261 return services::Status();
264 virtual int getSerializationTag() const DAAL_C11_OVERRIDE
266 return SERIALIZATION_DATAFEATURE_NT_ID;
269 data_feature_utils::IndexNumType getIndexType()
const
271 return ntFeature.indexType;
275 typedef Dictionary<DataSourceFeature, SERIALIZATION_DATADICTIONARY_DS_ID> DataSourceDictionary;
276 typedef services::SharedPtr<DataSourceDictionary> DataSourceDictionaryPtr;
281 using interface1::CategoricalFeatureDictionary;
282 using interface1::DataSourceFeature;
283 using interface1::DataSourceDictionary;
284 using interface1::DataSourceDictionaryPtr;
daal
Definition: algorithm_base_common.h:57
daal::data_management::interface1::DataSourceFeature::setType
void setType()
Definition: data_source_dictionary.h:154
daal::data_management::interface1::DataSourceFeature
Data structure that describes the Data Source feature.
Definition: data_source_dictionary.h:75
daal::data_management::interface1::CategoricalFeatureDictionary
Definition: data_source_dictionary.h:66
daal::data_management::interface1::DataSourceFeature::getSerializationTag
virtual int getSerializationTag() const DAAL_C11_OVERRIDE
Definition: data_source_dictionary.h:264
daal::data_management::interface1::DataSourceFeature::operator=
DataSourceFeature & operator=(const DataSourceFeature &f)
Definition: data_source_dictionary.h:93
daal::data_management::interface1::DataSourceFeature::setFeatureName
void setFeatureName(const std::string &featureName)
Definition: data_source_dictionary.h:138
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:124
daal::data_management::interface1::NumericTableFeature::setType
void setType()
Definition: data_dictionary.h:117
daal::data_management::interface1::SerializationIface
Abstract interface class that defines the interface for serialization and deserialization.
Definition: data_serialize.h:76
daal::data_management::interface1::NumericTableFeature
Data structure describes the Numeric Table feature.
Definition: data_dictionary.h:74
daal::data_management::interface1::DataSourceFeature::DataSourceFeature
DataSourceFeature()
Definition: data_source_dictionary.h:88