-
Notifications
You must be signed in to change notification settings - Fork 14
/
PirateFilter.cpp
52 lines (45 loc) · 919 Bytes
/
PirateFilter.cpp
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
#include "PirateFilter.h"
#include <fstream>
#include <iostream>
using std::cout;
using std::endl;
using std::ifstream;
using std::string;
using std::map;
using std::pair;
PirateFilter::PirateFilter()
{
ifstream in_file;
in_file.open("pirate.dict");
string english, pirate;
if(in_file.fail())
{
}
else
{
while(!in_file.eof())
{
in_file >> english;
in_file.ignore();
getline(in_file, pirate);
dictionary.insert(pair<string,string>(string(english),string(pirate)));
}
in_file.close();
}
for(map<string,string>::iterator it = dictionary.begin(); it != dictionary.end(); ++it)
{
cout << it->first << " " << it->second << endl;
}
}
void PirateFilter::apply(Document& doc)
{
map<string,string>::iterator dict_it;
for(WordIterator it = doc.begin(); it != doc.end(); ++it)
{
dict_it = dictionary.find(*it);
if(dict_it != dictionary.end())
{
*it = dict_it->second;
}
}
}