基于朴素贝叶斯分类器的文本分类算法(C语言).txt两个人吵架,先说对不起的人,并不是认输了,并不是原谅了。他只是比对方更珍惜这份感情。#include#include#include//_getcwd(),_chdir()#include//_MAX_PATH,system()#include//_finddata_t,_findfirst(),_findnext(),_findclose()charvocabulary[1000][20];/*声明公有二维数组,用来存储分割好的单词*//*=================将要分类的文本分割成单词存储在二维数组vocabulary中================*///@输入参数:要分类的文本//@输出参数:该文本中总单词数intSplitToWord(chartext[]){inti=0;charseps[]=",.\n";/*定义单词的分隔符*/char*substring;/******利用分隔符将文本内容分割成单词并存储******/substring=strtok(text,seps);while(substring!=NULL){strcpy(vocabulary[i],substring);//将单词存储到vocabulary数组中substring=strtok(NULL,seps);i++;}returni;//返回一共多少个单词}/*===============================计算该目录下的文件数================================*///@输入参数:无//@输出参数:该目录下.txt文件数intCountDirectory(){intcount=0;//txt文件计数器longhFile;_finddata_tfileinfo;/********查找.txt文件,记录文件数**********/if((hFile=_findfirst("*.txt",&fileinfo))!=-1L){do{count++;}while(_findnext(hFile,&fileinfo)==0);}returncount;}/*===================================计算某类别中∏P(ai|vj)===================================*///@输入参数:分类文本中单词数//@输出参数:该类别下∏P(ai|vj)floatCalculateWordProbability(intwordCount){intcountSame;//分类文本中的某单词在所有训练样本中出现次数intcountAll=0;//训练样本中总单词数chartoken;FILE*fp;floatwordProbability=1;//为后面联乘做准备inti,j;longhFile;_finddata_tfileinfo;for(j=0;j