在无所事事快两周过后,终于开始做毕设了!
首先要做的是文本的预处理:
语料库我选的是复旦大学的那个,感觉用那个的比较多吧。。。
预处理我参考的是http://www.cnblogs.com/zhangchaoyang/articles/2232205.html
1、选择了文本数较多的8个类别,然后使用FindDupFile工具分别找到train和answer文件夹的重复文件,删除他们。
2、少于500字的文本删除
3、将训练集中的文本数减少到500左右,测试集在400左右
程序中遍历文件夹参考了http://blog.youkuaiyun.com/zkn_cs_dn_2013/article/details/14228477
程序1:删除小于500字的文本
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<io.h>
int main()
{
long Handle;
int count = 0;
//char path[100];
struct _finddata_t FileInfo;
if((Handle = _findfirst("train\\C39-Sports\\*.txt",&FileInfo)) == -1L)
{
printf("没有找到匹配的项目");
}
else
{
do
{
//printf("%d\n",FileInfo.size);
if(FileInfo.size <= 1000)
{
char path[100] = "train\\C39-Sports\\";
strcat(path,FileInfo.name);
printf("%s\n",FileInfo.name);
remove(path);
}
else
count++;
}
while(_findnext(Handle,&FileInfo) == 0);
}
printf("共有文档:%d\n",count);
//system("pause");
return 0;
}
程序2:把文档数目减小的500和400
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<map>
#include<io.h>
using namespace std;
int main()
{
long Handle;
int count = 0;
map<int,string> mymap;
struct _finddata_t FileInfo;
if((Handle = _findfirst("answer\\C3-Art\\*.txt",&FileInfo)) == -1L)
{
printf("没有找到匹配的项目");
}
else
{
do
{
mymap[count] = FileInfo.name;
count++;
}
while(_findnext(Handle,&FileInfo) == 0);
}
printf("共有文档:%d\n",count);
for(int i = 0; i < 200; i++)//985,500
{
if(i % 2 == 0)
{
char path[100] = "answer\\C3-Art\\";
strcat(path,mymap[i].c_str());
//printf("%s\n",FileInfo.name);
remove(path);
}
}
count = 0;
mymap.clear();
if((Handle = _findfirst("answer\\C3-Art\\*.txt",&FileInfo)) == -1L)
{
printf("没有找到匹配的项目");
}
else
{
do
{
mymap[count] = FileInfo.name;
count++;
}
while(_findnext(Handle,&FileInfo) == 0);
}
printf("删除后还有文档:%d\n",count);
//system("pause");
return 0;
}
结果:
艺术 | 历史 | 太空 | 计算机 | 环境 | 农业 | 经济 | 体育 | 总计 | |
训练集 | 516 | 447 | 471 | 492 | 491 | 488 | 500 | 498 | |
测试集 | 413 | 349 | 362 | 391 | 402 | 399 | 400 | 401 |