发信人: jinzheng(Edgar), 信区: Algorithm
标 题: 求助对海量文本统计英语单词词频按照给的字典排
发信站: 饮水思源 (2012年02月18日00:14:11 星期六)
刚刚接触数据挖掘,现在boss给了个任务
数据集我进行预处理后,是有20个文件夹,每个文件夹中大概都有1000个txt文本,每个文
本都是英文单词。文本名字为数字,但是并不一定是顺序的。
这个数据集给了 一个字典 vocabulary。包括了所有文档的单词。
现在想编一个程序,达到,我可以统计词频的功能。每个词频根据vocabulary的单词顺序
排成一个矩阵。
我的c++基础不好,统计词频的 程序网上也很多。
1.如何循环打开名字不一样的不同文件夹下的这么多个文档?
2.能不能把统计的词频输出成txt
3.根据vocabulary整理成矩阵?
我现在只会统计词频。到了如何循环打开多个txt文档,处理完后输出统计结果保存为txt
都不会。
附上统计词频的代码。只能一个个打开,且不能安装vocabulary顺序排序
#include <map>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void display_map(map<string, int> &wmap);
int main()
{
const char *szInputFileName="Text.txt";
ifstream ifs(szInputFileName);
string szTemp;
map<string, int> wmap;
while (ifs>>szTemp)
wmap[szTemp]++;
display_map(wmap);
return false;
}
void display_map(map<string, int> &wmap)
{
map<string, int>::const_iterator map_it;
for (map_it=wmap.begin(); map_it!=wmap.end();map_it++)
{
cout<<"(\""<<map_it->first<<"\","<<map_it->second<<")"<<endl;
}
}
--
※ 来源:·饮水思源 bbs.sjtu.edu.cn·[FROM: 2001:da8:7001:208:495b:5c89:5d26:3274]
标 题: 求助对海量文本统计英语单词词频按照给的字典排
发信站: 饮水思源 (2012年02月18日00:14:11 星期六)
刚刚接触数据挖掘,现在boss给了个任务
数据集我进行预处理后,是有20个文件夹,每个文件夹中大概都有1000个txt文本,每个文
本都是英文单词。文本名字为数字,但是并不一定是顺序的。
这个数据集给了 一个字典 vocabulary。包括了所有文档的单词。
现在想编一个程序,达到,我可以统计词频的功能。每个词频根据vocabulary的单词顺序
排成一个矩阵。
我的c++基础不好,统计词频的 程序网上也很多。
1.如何循环打开名字不一样的不同文件夹下的这么多个文档?
2.能不能把统计的词频输出成txt
3.根据vocabulary整理成矩阵?
我现在只会统计词频。到了如何循环打开多个txt文档,处理完后输出统计结果保存为txt
都不会。
附上统计词频的代码。只能一个个打开,且不能安装vocabulary顺序排序
#include <map>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void display_map(map<string, int> &wmap);
int main()
{
const char *szInputFileName="Text.txt";
ifstream ifs(szInputFileName);
string szTemp;
map<string, int> wmap;
while (ifs>>szTemp)
wmap[szTemp]++;
display_map(wmap);
return false;
}
void display_map(map<string, int> &wmap)
{
map<string, int>::const_iterator map_it;
for (map_it=wmap.begin(); map_it!=wmap.end();map_it++)
{
cout<<"(\""<<map_it->first<<"\","<<map_it->second<<")"<<endl;
}
}
--
※ 来源:·饮水思源 bbs.sjtu.edu.cn·[FROM: 2001:da8:7001:208:495b:5c89:5d26:3274]
No comments:
Post a Comment