-
Notifications
You must be signed in to change notification settings - Fork 0
/
DictProducer.cc
79 lines (61 loc) · 1.11 KB
/
DictProducer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
///
/// @file DictProducer.cc
/// @author sgzed([email protected])
/// @date 2018-03-26 23:20:20
///
#include "DictProducer.h"
#include <fstream>
#include <cctype>
#include <sstream>
#include <iostream>
#include <iterator>
#include <algorithm>
using std::ifstream;
using std::ofstream;
using std::istringstream;
DictProducer::DictProducer(const string& dir)
:_dir(dir)
{
}
void DictProducer::build_dict()
{
ifstream ifs(_dir);
string line;
string word;
while(getline(ifs,line))
{
istringstream iss(line);
while(iss >> word)
{
string useful;
std::copy_if(word.begin(),word.end(),back_inserter(useful),isalpha);
for(auto& iter : useful)
{
if(isupper(iter))
iter = std::tolower(iter);
}
if(useful != "")
{
// std::cout << useful << std::endl;
++_dic[useful];
}
}
}
}
void DictProducer::store_dict(const char* filepath)
{
ofstream ofs(filepath);
for(auto iter : _dic)
{
ofs << iter.first << " " << iter.second << "\n";
}
}
void DictProducer::show_files() const
{
}
void get_files()
{
}
void DictProducer::push_dict(const string& word)
{
}