⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nametable.h

📁 Amis - A maximum entropy estimator 一个最大熵模型统计工具
💻 H
字号:
#ifndef Amis_NameTable_h_#define Amis_NameTable_h_#include <amis/configure.h>#include <amis/StringStream.h>#include <amis/Feature.h>#include <map>#include <string>AMIS_NAMESPACE_BEGINclass NameTableBase {public:  NameTableBase() {}  virtual ~NameTableBase() {}  virtual std::string featureNameString( FeatureID id ) const = 0;};template < class Name = std::string >class NameTable : public NameTableBase {protected:  std::map< FeatureID, Name > feature_name;  std::map< Name, FeatureID > feature_id;public:  NameTable() {}  virtual ~NameTable() {}  int numFeatures() const { return feature_name.size(); }  std::string featureNameString( FeatureID id ) const {    OStringStream oss;    oss << featureName( id );    return oss.str();  }  const Name& featureName( FeatureID id ) const {    typename std::map< FeatureID, Name >::const_iterator it = feature_name.find( id );    if ( it == feature_name.end() ) {      OStringStream oss;      oss << "FeatureID " << id << " not found";      throw IllegalFeatureError( oss.str() );    }    return it->second;  }  FeatureID featureID( const Name& name ) const {    typename std::map< Name, FeatureID >::const_iterator it = feature_id.find( name );    if ( it == feature_id.end() ) {      OStringStream oss;      oss << "Feature " << name << " not found";      throw IllegalFeatureError( oss.str() );    }    return it->second;  }public:  void registerNewFeature( const Name& name, FeatureID id ) {    if ( feature_name.find( id ) != feature_name.end() ) {      OStringStream oss;      oss << "Feature ID " << id << " already exists";      throw IllegalFeatureError( oss.str() );    }    if ( feature_id.find( name ) != feature_id.end() ) {      OStringStream oss;      oss << "Feature " << name << " already exists";      throw IllegalFeatureError( oss.str() );    }    feature_name[ id ] = name;    feature_id[ name ] = id;  }};AMIS_NAMESPACE_END#endif // Amis_NameTable_h_// end of NameTable.h

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -