speakermatch.cpp
4.18 KB
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
153
154
155
/*
* ASCLITE
* Author: Jerome Ajot, Jon Fiscus, Nicolas Radde, Chris Laprun
*
* This software was developed at the National Institute of Standards and Technology by
* employees of the Federal Government in the course of their official duties. Pursuant
* to title 17 Section 105 of the United States Code this software is not subject to
* copyright protection and is in the public domain. ASCLITE is an experimental system.
* NIST assumes no responsibility whatsoever for its use by other parties, and makes no
* guarantees, expressed or implied, about its quality, reliability, or any other
* characteristic. We would appreciate acknowledgement if the software is used.
*
* THIS SOFTWARE IS PROVIDED "AS IS." With regard to this software, NIST MAKES NO EXPRESS
* OR IMPLIED WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING MERCHANTABILITY,
* OR FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* Database for matching speaker optimization
*/
#include "speakermatch.h" // class's header file
Logger* SpeakerMatch::logger = Logger::getLogger();
/** Constructor */
SpeakerMatch::SpeakerMatch()
{
m_pMapSourceChannelSysRef = new map < string, string >;
}
/** Destructor */
SpeakerMatch::~SpeakerMatch()
{
m_pMapSourceChannelSysRef->clear();
if(m_pMapSourceChannelSysRef)
delete m_pMapSourceChannelSysRef;
}
/** Load the file */
void SpeakerMatch::LoadFile(const string& filename)
{
string line;
ifstream file;
long int lineNum = -1;
file.open(filename.c_str(), ifstream::in);
if (! file.is_open())
{
LOG_FATAL(logger, "Error opening SpeakerMatch file " + filename);
exit(E_LOAD);
}
while (getline(file,line,'\n'))
{
++lineNum;
if (line.find_first_of("#") == 0)
{
//comment so skip (for now)
}
else if(line == string("File,Channel,RefSpeaker,SysSpeaker,isMapped,timeOverlap"))
{
// CSV header
}
else
// if Type is 'LEXEME' we take it, unless we drop the line
{
size_t index = 0;
size_t lpos = 0;
string delim = string(",");
size_t pos = line.find_first_of(delim, lpos);
string tokens[6];
do
{
if(index == 6)
{
char buffer[BUFFER_SIZE];
sprintf(buffer, "Too much: Error parsing the line %li in file %s", lineNum, filename.c_str());
LOG_ERR(logger, buffer);
}
tokens[index] = line.substr(lpos, pos - lpos);
++index;
lpos = ( pos == string::npos ) ? string::npos : pos + 1;
pos = line.find_first_of(delim, lpos);
}
while( lpos != string::npos );
if(index != 6)
{
char buffer[BUFFER_SIZE];
sprintf(buffer, "Too few: Error parsing the line %li in file %s", lineNum, filename.c_str());
LOG_ERR(logger, buffer);
}
if( tokens[4] == string("mapped") )
{
//SetSysRef(string(l_file), string(l_channel), string(l_sys), string(l_ref));
//transform(tokens[3].begin(), tokens[3].end(), tokens[3].begin(), (int(*)(int)) toupper);
//transform(tokens[2].begin(), tokens[2].end(), tokens[2].begin(), (int(*)(int)) toupper);
SetSysRef(tokens[0], tokens[1], tokens[3], tokens[2]);
}
}
}
file.close();
LOG_INFO(logger, "loading of file " + filename + " done");
}
/** Initialize a couple, sys-ref */
void SpeakerMatch::SetSysRef(const string& source, const string& channel, const string& sys, const string& ref)
{
string index("");
index.append(source);
index.append("|");
index.append(channel);
index.append("|");
index.append(sys);
if(m_pMapSourceChannelSysRef->find(index) == m_pMapSourceChannelSysRef->end())
{
m_pMapSourceChannelSysRef->insert(pair < string, string > (index, ref));
}
else
{
cerr << source << " " << channel << " " << sys << " exists! -> IGNORED" << endl;
LOG_WARN(logger, source + " " + channel + " " + sys + " exists! -> IGNORED");
}
}
/** Return the ref coupled to the sys */
string SpeakerMatch::GetRef(const string& source, const string& channel, const string& sys)
{
string index("");
index.append(source);
index.append("|");
index.append(channel);
index.append("|");
index.append(sys);
map < string, string >::iterator iter = m_pMapSourceChannelSysRef->find(index);
if( iter != m_pMapSourceChannelSysRef->end() )
{
return(iter->second);
}
else
{
return( string("") );
}
}