matlab一些常用的处理模块

源代码在线查看: dictionary.h

软件大小: 5075 K
上传用户: whyzhao
关键词: matlab 处理模块
下载地址: 免注册下载 普通下载 VIP

相关代码

				/******************************************************************************				 * 光学字符识别程序				 * 文件名:dictionary.h				 * 功能  :字典文件,后处理用				 * modified by PRTsinghua@hotmail.com				******************************************************************************/								#ifndef DICTIONARY_H				#define DICTIONARY_H								#include "common.h"				#include "character_database.h"				#include 								#pragma pack(1)				struct node				{					enum { transcode_char_NULL = 127,							       max_branches = character_database::dictionary_lookup_chars };					typedef enum {super_node_type, small_node_type} node_type;					bool		upper_case_start:1;					bool		lower_case_start:1;					node_type	type		:1;									node(node_type t) : upper_case_start(false), lower_case_start(false), type(t) {};					~node();									bool Test(const char* matchstr);					bool Test(list::const_iterator start,						  list::const_iterator end,						  string &result,						  string &lower_case_variant);					bool Insert(const char* matchstr);									node **walk(node* &last);					bool tree_match();					void insert(node* &last);					void tree_statistics();					static string prepare(const char *match, bool &first_is_capital);					static void build_table();					static int secure_char_name_to_char_code(char c);					static char null() { return static_cast(transcode_char_NULL); }									static char transcode[256];					static char lowercode[256];					static bool first_is_capital;					static string match;					static unsigned int pos;					static char push(char c);					static void pop() { match.resize(match.length()-1); }					static list::const_iterator now_char;					static list::const_iterator end_char;					static string far;	// 不同的案例									static int num_super_nodes;					static int num_small_nodes;					static int refs_in_super_nodes;					static int refs_in_small_nodes;				};								struct super_node : public node				{					node *		branch[max_branches];	// 所有可能字符的分支									super_node();					void free();					node **walk(node* &last);					bool tree_match();					void insert(node* &last);					void tree_statistics();				};								struct small_node : public node				{					enum {max_small_branches=2};					char  match_char[max_small_branches];					node* branch[max_small_branches];	// 分支										small_node();					void free();					node **walk(node* &last);					bool tree_match();					void insert(node* &last);					void tree_statistics();				};				#pragma pack()								class dictionary				{					public: 						dictionary();						~dictionary();						void read(const char *file);												// 特定字符:						// '['xyz']' 匹配 x, y or z (没有子组!)						// '?'       匹配任何字符						// ' '       不匹配任何字符						string match(const char *pattern);						string match(list::const_iterator start,							     list::const_iterator end);						void code_string_to_string(string &cs);						void print_statistics();									private:						super_node prefix;						super_node words;						super_node suffix;				};								// 内联函数								// 跟踪边界				inline node **node::walk(node* &last)				{					if( pos>=match.length() )						return &last;					else if( type==super_node_type )						return static_cast(this)->walk(last);					else 						return static_cast(this)->walk(last);				}								// 数匹配				inline bool node::tree_match()				{					if( now_char==end_char )					{						if( !upper_case_start && !lower_case_start )							return false;						if( (first_is_capital && upper_case_start) || (!first_is_capital && lower_case_start) )							return true;						if( far.empty() )							far=match;						return false;					}					else if( type==super_node_type )						return static_cast(this)->tree_match();					else						return static_cast(this)->tree_match();				}								// 插入节点				inline void node::insert(node* &last)				{					if( pos>=match.length() )					{						if( first_is_capital )							upper_case_start=true;						else							lower_case_start=true;					}					else if( type==super_node_type )						static_cast(this)->insert(last);					else						static_cast(this)->insert(last);				}								// 树统计				inline void node::tree_statistics()				{					if( type==super_node_type )						static_cast(this)->tree_statistics();					else						static_cast(this)->tree_statistics();				}								#endif							

相关资源