#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;int divisor;#define MAX_WORD 5200#define TAG_NUM 2int wordCount;map word_id; //将单词和单词数字ID对应map id_wordCount; //统计单词数字ID和单词出现次数对应map int> tag_tag_count;int true_num;int precision_num;int recall_num;class Perceptron_vector{public: int word_tag_count; map left_current_tag_count; map current_right_tag_count; map int> left_current_right_tag_count; Perceptron_vector() { this->word_tag_count = 0; this->left_current_tag_count.clear(); this->current_right_tag_count.clear(); this->left_current_right_tag_count.clear(); } int get_word_tag_count() { return word_tag_count; } int get_left_current_tag_count(int left_id) { map::iterator left_current_tag_count_it = left_current_tag_count.find(left_id); if(left_current_tag_count_it == left_current_tag_count.end()) return 0; else return left_current_tag_count_it->second; } int get_current_right_tag_count(int right_id) { map::iterator current_right_tag_count_it = current_right_tag_count.find(right_id); if(current_right_tag_count_it == current_right_tag_count.end()) return 0; else return current_right_tag_count_it->second; } int get_left_current_right_tag_count(int left_id int right_id) { map int>::iterator left_current_right_tag_count_it = left_current_right_tag_count.find(pair(left_id right_id)); if(left_current_right_tag_count_it == left_current_right_tag_count.end()) return 0; else return left_current_right_tag_count_it->second; } int get_vector(int left_id int right_id) { return get_word_tag_count() + get_left_current_tag_count(left_id) + get_current_right_tag_count(right_id) + get_left_current_right_tag_count(left_id right_id); } void update_word_tag_count(int tag) { if(tag == 1) word_tag_count++; if(tag == 0) word_tag_count--; } void update_left_current_tag_count(int tag int left_id) { map::iterator left_current_tag_count_it = left_current_tag_count.find(left_id); if(tag == 1) { if(left_current_tag_count_it == left_current_tag_count.end()) left_current_tag_count.insert(pair(left_id 1)); else left_current_tag_count_it->second++; } if(tag == 0) { if(left_current_tag_count_it == left_current_tag_count.end()) left_current_tag_count.insert(pair(left_id -1)); else left_current_tag_count_it->second--; } } void update_current_right_tag_count(int tag int right_id) { map::iterator current_right_tag_count_it = current_right_tag_cou
共有 条评论
评论
共有 条评论