StringKernel.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2009 Soeren Sonnenburg
00008  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _STRINGKERNEL_H___
00012 #define _STRINGKERNEL_H___
00013 
00014 #include "kernel/Kernel.h"
00015 #include "features/StringFeatures.h"
00016 
00017 namespace shogun
00018 {
00024 template <class ST> class CStringKernel : public CKernel
00025 {
00026     public:
00031         CStringKernel(int32_t cachesize) : CKernel(cachesize) {}
00032 
00038         CStringKernel(CFeatures *l, CFeatures *r) : CKernel(10)
00039         {
00040             init(l, r);
00041         }
00042 
00053         virtual bool init(CFeatures* l, CFeatures* r)
00054         {
00055             CKernel::init(l,r);
00056 
00057             ASSERT(l->get_feature_class()==C_STRING);
00058             ASSERT(r->get_feature_class()==C_STRING);
00059             ASSERT(l->get_feature_type()==this->get_feature_type());
00060             ASSERT(r->get_feature_type()==this->get_feature_type());
00061 
00062             return true;
00063         }
00064 
00069         inline virtual EFeatureClass get_feature_class() { return C_STRING; }
00070 
00075         virtual EFeatureType get_feature_type();
00076 
00077 #ifdef HAVE_BOOST_SERIALIZATION
00078     private:
00079 
00080         friend class ::boost::serialization::access;
00081         template<class Archive>
00082             void serialize(Archive & ar, const unsigned int archive_version)
00083             {
00084 
00085                 SG_DEBUG("archiving CStringKernel\n");
00086                 ar & ::boost::serialization::base_object<CKernel>(*this);
00087 
00088                 SG_DEBUG("done CStringKernel\n");
00089             }
00090 #endif //HAVE_BOOST_SERIALIZATION
00091 
00092 };
00093 
00094 template<> inline EFeatureType CStringKernel<float64_t>::get_feature_type() { return F_DREAL; }
00095 
00096 template<> inline EFeatureType CStringKernel<uint64_t>::get_feature_type() { return F_ULONG; }
00097 
00098 template<> inline EFeatureType CStringKernel<int32_t>::get_feature_type() { return F_INT; }
00099 
00100 template<> inline EFeatureType CStringKernel<uint16_t>::get_feature_type() { return F_WORD; }
00101 
00102 template<> inline EFeatureType CStringKernel<int16_t>::get_feature_type() { return F_SHORT; }
00103 
00104 template<> inline EFeatureType CStringKernel<uint8_t>::get_feature_type() { return F_BYTE; }
00105 
00106 template<> inline EFeatureType CStringKernel<char>::get_feature_type() { return F_CHAR; }
00107 }
00108 #endif /* _STRINGKERNEL_H__ */
00109 

SHOGUN Machine Learning Toolbox - Documentation