segment.h
7.61 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* 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.
*/
#ifndef SEGMENT_H
#define SEGMENT_H
#include "timedobject.h"
#include "token.h"
#include "logger.h"
class Speech;
/**
* Internal representation of a segment.
* A segment is a list of Token.
*/
class Segment : public TimedObject
{
public:
// class destructor
~Segment();
/**
* Register a Token as a begining token of this segment
* A Segment can have multiple first token as the token is part of a graph.
*/
void AddFirstToken(Token* token);
/**
* Try to retrieve the beginning token indexed number "index"
*/
Token* GetFirstToken(const size_t& index) { return f_token->GetNextToken(index); }
/**
* Register a Token as an ending token of this segment
* A Segment can have multiple ending token as the token is part of a graph.
*/
void AddLastToken(Token* token);
/**
* Try to retrieve the ending token indexed number "index"
*/
Token* GetLastToken(const size_t& index) { return l_token->GetNextToken(index); }
/**
* Return the number of last token of this segments
*/
size_t GetNumberOfLastToken() { return l_token->GetNbOfNextTokens(); }
/**
* Return the number of begin token of this segments
*/
size_t GetNumberOfFirstToken() { return f_token->GetNbOfNextTokens(); }
/**
* Set the Channel name of this segment
*/
void SetChannel(const string& x) { channel = x; }
/**
* Return the channel name of this segment
*/
string GetChannel() { return channel; }
/**
* Set the Speaker Id of this segment
*/
void SetSpeakerId(const string& x) { speakerId = x; }
/**
* Retrieve the Speaker Id of this segment
*/
string GetSpeakerId() { return speakerId; }
/**
* Set the source name of this segment
*/
void SetSource(const string& x) { source = x; }
/**
* Retrieve the source name of this segment
*/
string GetSource() { return source; }
/**
* Change the end time of this segment
*/
void SetEndTime(const int& _newEndTime) { endTime = _newEndTime; }
/**
* Set the ID of the segment
*/
void SetId(const string& _id) { id = _id; }
/**
* Retrieve ID of the segments
*/
string GetId() { return id; }
/**
* Set the line number of this element in the source file.
*/
void SetSourceLineNum(long int _ln) { sourceLineNum = _ln; }
/**
* Get the sequence number of this segment
*/
long int GetSourceLineNum() { return sourceLineNum; }
/**
* Set the element sequence number with the source file.
*/
void SetSourceElementNum(const long int& _ln) { sourceElementNum = _ln; }
/**
* Get the elements sequence number within the source file
*/
long int GetSourceElementNum() { return sourceElementNum; }
void SetLabel(const string& _label) { m_Label = _label; }
string GetLabel() { return m_Label; }
static Segment* CreateWithDuration(const int& _startTime, const int& _duration, Speech* parent);
static Segment* CreateWithEndTime(const int& _startTime, const int& _endTime, Speech* parent);
/**
* Merge all Segments in one segments
* @deprecated Shoudnt be use anymore. Try to work on the real segments instead
*/
static Segment* Merge(const vector<Segment*> & segments);
/**
* Output a planar version of the segment.
*/
vector<Token*> ToTopologicalOrderedStruct();
/**
* Return if the token is on the list of the First tokens.
*/
bool isFirstToken(Token* token);
/**
* Return if the token is on the list of the last tokens.
*/
bool isLastToken(Token* token);
/**
* Return true if no token are into this segment
*/
bool isEmpty() { return (f_token->GetNbOfNextTokens() == 0 || l_token->GetNbOfNextTokens() == 0); }
/**
* Say if this segment should be exclude from scoring
*/
bool isSegmentExcludeFromScoring() { return ignoreSegmentInScoring; }
/**
* Change the segment status as "not to score"
*/
void SetAsSegmentExcludeFromScoring() { ignoreSegmentInScoring = true; }
/** Retrieves the Speech in which this Segment is located. */
Speech* GetParentSpeech();
/** Returns a string representation of this Segment */
string ToString();
/** Returns a string representation of this Segment as a single line*/
string ToStringAsLine();
/** Determines if case is taken into account to align Tokens part of this Speech. */
bool PerformCaseSensitiveAlignment();
/** Determines if fragments are considered as correct when aligning Tokens part of this Speech. */
bool AreFragmentsCorrect();
/** Determines if optionally deletable Tokens need to be accounted for. */
bool UseOptionallyDeletable();
/** Replaces the token with the link list of tokes pointed to by the vectors containing pointers to the start and end tokens **/
void ReplaceTokenWith(Token *token, const vector<Token*> & startTokens, const vector<Token*> & endTokens);
int GetMinTokensTime();
int GetMaxTokensTime();
/** Set all the token optionaly deletable by adding () in the text */
void SetTokensOptionallyDeletable();
protected:
/** Checks that start time and duration are valid for this TimedObject. Extension point for subclasses. */
virtual bool AreStartTimeAndDurationValid(const int& _startTime, const int& _duration) { return AreStartTimeAndEndTimeValid(_startTime, _startTime + _duration); }
/** Checks that start time and end time are valid for this TimedObject. Extension point for subclasses. */
virtual bool AreStartTimeAndEndTimeValid(const int& _startTime, const int& _endTime);
// class constructor
Segment();
private:
/**
* Access to the first token of the segment.
*/
Token* f_token;
/**
* Access to the last token of the segment.
*/
Token* l_token;
/**
* The speaker identificator of this speaker.
*/
string speakerId;
/**
* The channel this segment is referenced to.
*/
string channel;
/**
* Represent the source of this segment.
* This can be a meeting number/id or a the show name...
*/
string source;
/**
* The id of the segment (if it has one)
*/
string id;
/**
* The line number of the element within the originating source file
*/
long int sourceLineNum;
/**
* The element number within the originating source file
*/
long int sourceElementNum;
/**
* Define the scoring state of this segment
*/
bool ignoreSegmentInScoring;
/**
* Return the parent speech object
*/
Speech* speech;
/**
* Labels used for stm files
*/
string m_Label;
int GetLowestTokenStartTime();
int GetHighestTokenEndTime();
/**
* Recurs methods to compute a topological order of a graph
*/
void ToTopologicalOrderedStruct(Token* start, vector<Token*> *doneNode);
static Logger* logger;
};
#endif // SEGMENT_H