文本分类

在无所事事快两周过后,终于开始做毕设了!

首先要做的是文本的预处理:

语料库我选的是复旦大学的那个,感觉用那个的比较多吧。。。

预处理我参考的是http://www.cnblogs.com/zhangchaoyang/articles/2232205.html

1、选择了文本数较多的8个类别,然后使用FindDupFile工具分别找到train和answer文件夹的重复文件,删除他们。

2、少于500字的文本删除

3、将训练集中的文本数减少到500左右,测试集在400左右

程序中遍历文件夹参考了http://blog.csdn.net/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;
}
结果:
 艺术历史太空计算机环境农业经济体育总计
训练集516447471492491488500498 
测试集413349362391402399400401 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值