分类:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <time.h>
#include <map>
using namespace std;
struct train_data {
int index; //训练文本序号
int emotion_value; //情感值
string emotion; //情感状态
vector<string> word; //训练文本单词
int onehot[1000]; //onehot矩阵中的值
double distance; //距离
train_data(int a = 0, int b = 0, string c = "", double d = 0.0) {
index = a;
emotion_value = b;
emotion = c;
distance = d;
word.clear();
for (int i = 0; i < 1000; i ++)
onehot[i] = 0;
}
};
vector<string> train_text; //每个完整的训练文本
vector<string> all_words; //所有不同的单词 ,纵轴
vector<train_data> all_trains; //所有训练文本,横轴
int right_sum; //预测正确的个数
//NB adding part
struct each_word {
string name;
double time;
each_word(string a = "", double b = 0) {
name = a;
time = b;
}
};
//构建词带
struct emotion {
string emotion2;
vector<each_word> word_bag;
double sum_words;
double probability;
double times;
emotion(double a = 0, double b = 0, double c = 0) {
word_bag.clear();
sum_words = a;
probability = b;
times = c;
}
};
emotion each_emotion[7];
//NB adding part
// youhua part
double add[7] = {
0};
//youhua part
void reading_file(void );
void class_calculating();
bool cmp(const emotion & , const emotion & );
int main() {
train_text.clear();
all_words.clear();
all_trains.clear();
each_emotion[1].emotion2 = "anger";
each_emotion[2].emotion2 = "disgust";
each_emotion[3].emotion2 = "fear";
each_emotion[4].emotion2 = "joy";
each_emotion[5].emotion2 = "sad";
each_emotion[6].emotion2 = "surprise";
reading_file();
class_calculating();
return 0;
}
void reading_file() {
ifstream train("train.txt");
char read[100];
string temp;
train.getline(read, 100);