-
Notifications
You must be signed in to change notification settings - Fork 0
/
allPhonemeSet.cpp
153 lines (136 loc) · 2.74 KB
/
allPhonemeSet.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "allPhonemeSet.h"
#include "util.h"
allPhonemeSet::allPhonemeSet(void)
{
}
allPhonemeSet::~allPhonemeSet(void)
{
}
map<string,set<string> > allPhonemeSet::getAllPhonemeLimit()
{
return allPhonemeLimit;
}
set<string> allPhonemeSet::getAllPhoneme()
{
return allPhoneme;
}
vector<string> allPhonemeSet::getPhoneme(string letter, bool limitCandidate)
{
vector<string> out;
out.clear();
if (limitCandidate)
{
map<string, set<string> >::iterator pos;
pos = allPhonemeLimit.find(letter);
if (pos != allPhonemeLimit.end())
{
for (set<string>::iterator pos = allPhonemeLimit[letter].begin(); pos != allPhonemeLimit[letter].end(); pos++)
{
out.push_back(*pos);
}
}
else
{
// Edit Feb 6, 08 for not returning non-posible letter/phoneme pair
//out.push_back("_");
}
}
else
{
if (allPhoneme.size() < 1)
{
out.push_back("_");
}
else
{
for (set<string>::iterator pos = allPhoneme.begin(); pos != allPhoneme.end(); pos++)
{
out.push_back(*pos);
}
}
}
return out;
}
void allPhonemeSet::clear(void)
{
allPhonemeLimit.clear();
allPhoneme.clear();
}
void allPhonemeSet::clear(bool limitCandidate)
{
if (limitCandidate)
{
allPhonemeLimit.clear();
}
else
{
allPhoneme.clear();
}
}
void allPhonemeSet::addPhoneme(string phoneme, string letter, bool limitCandidate)
{
if (limitCandidate)
{
allPhonemeLimit[letter].insert(phoneme);
}
else
{
allPhoneme.insert(phoneme);
}
}
void allPhonemeSet::addFromFile(string filename, bool limitCandidate)
{
string line;
vector<string> lineList;
if (limitCandidate)
{
ifstream FILEIN;
FILEIN.open(filename.c_str());
while (! FILEIN.eof())
{
getline(FILEIN,line);
lineList = splitBySpace(line);
if (lineList.size() > 1)
{
addPhoneme(lineList[1],lineList[0],limitCandidate);
}
}
FILEIN.close();
}
}
bool allPhonemeSet::writeToFile(string filename, bool limitCandidate)
{
if (limitCandidate)
{
ofstream FILEOUT;
FILEOUT.open(filename.c_str(), ios_base::trunc);
if (! FILEOUT)
{
cerr << "ERROR: Can't write file to : " << filename << endl;
exit(-1);
}
else
{
for (map<string, set<string> >::iterator allLetterPos = allPhonemeLimit.begin(); allLetterPos != allPhonemeLimit.end(); allLetterPos++)
{
for (set<string>::iterator allPhonemePos = allPhonemeLimit[allLetterPos->first].begin(); allPhonemePos != allPhonemeLimit[allLetterPos->first].end(); allPhonemePos++)
{
FILEOUT << allLetterPos->first << "\t" << *allPhonemePos << endl;
}
}
FILEOUT.close();
return true;
}
}
else
{
// do not thing for now
return true;
}
}
allPhonemeSet& allPhonemeSet::operator= (const allPhonemeSet& param)
{
allPhoneme = param.allPhoneme;
allPhonemeLimit = param.allPhonemeLimit;
return *this;
}