-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathallomorph.cpp
344 lines (301 loc) · 7.84 KB
/
allomorph.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#include "allomorph.h"
#include "concordance.h"
#include <QRegExp>
#include <QtDebug>
Allomorph::Allomorph(QUuid guid) :
QObject(), mType(Allomorph::Null), mTextBit( TextBit() ), mId(-1), mLexicalEntryId(-1), mGuid(guid)
{
if( mGuid.isNull() )
{
mGuid = QUuid::createUuid();
}
}
Allomorph::Allomorph(qlonglong id, qlonglong lexicalEntryId, const TextBit & bit, Type type , QUuid guid) :
QObject(), mType(type), mTextBit(bit), mId(id), mLexicalEntryId(lexicalEntryId), mGuid(guid)
{
if( mGuid.isNull() )
{
mGuid = QUuid::createUuid();
}
}
Allomorph::Allomorph(qlonglong id, qlonglong lexicalEntryId, const TextBit & bit, const TextBitHash & glosses , Type type, QUuid guid ) :
QObject(), mType(type), mTextBit(bit), mId(id), mLexicalEntryId(lexicalEntryId), mGuid(guid)
{
mGlosses.unite(glosses);
if( mGuid.isNull() )
{
mGuid = QUuid::createUuid();
}
}
Allomorph::Allomorph(const Allomorph & other) :
QObject(), mType(other.mType), mTextBit(other.mTextBit), mId(other.mId), mLexicalEntryId(other.mLexicalEntryId), mGlosses(other.mGlosses), mGuid(other.mGuid)
{
}
Allomorph& Allomorph::operator=(const Allomorph & other)
{
mType = other.mType;
mId = other.mId;
mLexicalEntryId = other.mLexicalEntryId;
mTextBit = other.mTextBit;
mGlosses = other.mGlosses;
mGuid = other.mGuid;
return *this;
}
Allomorph::~Allomorph()
{
emit allomorphDestroyed(this);
}
void Allomorph::connectToConcordance(Concordance *concordance)
{
concordance->insertIntoAllomorphConcordance( this );
connect( this, SIGNAL(allomorphDestroyed(Allomorph*)), concordance, SLOT(removeFromAllomorphConcordance(Allomorph*)) );
connect( this, SIGNAL(glossesChanged(Allomorph*)), concordance, SLOT(updateAllomorphTextForms(Allomorph*)) );
}
bool Allomorph::operator==(const Allomorph & other) const
{
return mType == other.mType && mTextBit == other.mTextBit && mId == other.mId && mGlosses == other.mGlosses && mGuid == other.mGuid;
}
bool Allomorph::equalExceptGuid(const Allomorph &other) const
{
return mType == other.mType && mTextBit == other.mTextBit && mId == other.mId && mGlosses == other.mGlosses;
}
bool Allomorph::equalExceptGuid(const Allomorph * other) const
{
return mType == other->mType && mTextBit == other->mTextBit && mId == other->mId && mGlosses == other->mGlosses;
}
QString Allomorph::typeFormattedString() const
{
return mTextBit.text();
}
TextBit Allomorph::textBitForConcatenation() const
{
QString text = mTextBit.text();
if( mType == Allomorph::Proclitic )
{
text = text + "=";
}
else if ( mType == Allomorph::Enclitic )
{
text = "=" + text;
}
else if ( mType == Allomorph::Suffix )
{
text = "-" + text;
}
else if ( mType == Allomorph::Prefix )
{
text = text + "-";
}
return TextBit( text, mTextBit.writingSystem() );
}
Allomorph::Type Allomorph::type() const
{
return mType;
}
QString Allomorph::typeString() const
{
return getTypeString(mType);
}
QString Allomorph::text() const
{
return stripPunctuation(mTextBit.text());
}
TextBit Allomorph::textBit() const
{
return mTextBit;
}
WritingSystem Allomorph::writingSystem() const
{
return mTextBit.writingSystem();
}
qlonglong Allomorph::id() const
{
return mId;
}
qlonglong Allomorph::lexicalEntryId() const
{
return mLexicalEntryId;
}
void Allomorph::setId(qlonglong id)
{
mId = id;
}
TextBit Allomorph::gloss(const WritingSystem & ws) const
{
return mGlosses.value(ws);
}
void Allomorph::setGlosses(const TextBitHash & glosses)
{
if( mGlosses != glosses )
{
mGlosses = glosses;
emit glossesChanged(this);
}
}
QList<WritingSystem> Allomorph::glossLanguages() const
{
return mGlosses.keys();
}
TextBitHash Allomorph::glosses() const
{
return mGlosses;
}
bool Allomorph::isStem() const
{
return mType == Allomorph::Stem || mType == Allomorph::BoundStem;
}
bool Allomorph::isClitic() const
{
return mType == Allomorph::Proclitic || mType == Allomorph::Enclitic;
}
void Allomorph::setType( Type t )
{
mType = t;
}
QString Allomorph::guid() const
{
return mGuid.toString();
}
void Allomorph::setGuid(const QString &guidString)
{
mGuid = QUuid(guidString);
}
void Allomorph::setGuid(const QUuid &guid)
{
mGuid = guid;
}
QString Allomorph::getTypeString(Allomorph::Type t)
{
switch(t)
{
case Stem:
return "Stem";
case Prefix:
return "Prefix";
case Suffix:
return "Suffix";
case Infix:
return "Infix";
case BoundStem:
return "Bound Stem";
case Proclitic:
return "Proclitic";
case Enclitic:
return "Enclitic";
case Simulfix:
return "Simulfix";
case Suprafix:
return "Suprafix";
case Null:
return "Null";
}
return "Null";
}
Allomorph::Type Allomorph::getType(QString t)
{
if( t == "Stem" )
return Stem;
else if( t == "Prefix" )
return Prefix;
else if( t == "Suffix" )
return Suffix;
else if( t == "Infix" )
return Infix;
else if( t == "Bound Stem" )
return BoundStem;
else if( t == "Proclitic" )
return Proclitic;
else if( t == "Enclitic" )
return Enclitic;
else if( t == "Simulfix" )
return Simulfix;
else if( t == "Suprafix" )
return Suprafix;
else
return Null;
}
QString Allomorph::getTypeFormatTextString(const QString &text, Allomorph::Type t)
{
switch(t)
{
case Stem:
return text;
case Prefix:
return text + "-";
case Suffix:
return "-" + text;
case Infix:
return "-" + text + "-";
case BoundStem:
return "*" + text;
case Proclitic:
return text + "=";
case Enclitic:
return "=" + text;
case Simulfix:
return "=" + text + "=";
case Suprafix:
return "~" + text + "~";
case Null:
return text;
}
return text;
}
TextBit Allomorph::getTypeFormatTextBit(const TextBit &bit, Allomorph::Type t)
{
return TextBit( getTypeFormatTextString( bit.text(), t ) , bit.writingSystem() );
}
Allomorph::Type Allomorph::typeFromFormattedString(const QString &string)
{
QRegExp rePrefix("^[^-].*-$");
QRegExp reSuffix("^-.*[^-]$");
QRegExp reInfix("^-.*-$");
QRegExp reBoundStem("^\\*.*$");
QRegExp reProclitic("^[^=].*={1,2}$");
QRegExp reEnclitic("^={1,2}.*[^=]$");
QRegExp reSimulfix("^={1,2}.*={1,2}$");
QRegExp reSuprafix("^~.*~$");
if( rePrefix.exactMatch( string ) )
return Allomorph::Prefix;
else if( reSuffix.exactMatch( string ) )
return Allomorph::Suffix;
else if( reInfix.exactMatch( string ) )
return Allomorph::Infix;
else if( reBoundStem.exactMatch( string ) )
return Allomorph::BoundStem;
else if( reProclitic.exactMatch( string ) )
return Allomorph::Proclitic;
else if( reEnclitic.exactMatch( string ) )
return Allomorph::Enclitic;
else if( reSimulfix.exactMatch( string ) )
return Allomorph::Simulfix;
else if( reSuprafix.exactMatch( string ) )
return Allomorph::Suprafix;
else
return Allomorph::Stem;
}
Allomorph::Type Allomorph::typeFromFormattedString(const TextBit &bit)
{
return typeFromFormattedString(bit.text());
}
QString Allomorph::stripPunctuation(const QString &string)
{
QString s = string;
s.replace("=","");
s.replace("~","");
s.replace("=","");
s.replace("*","");
s.replace("-","");
return s;
}
TextBit Allomorph::stripPunctuationFromTextBit(const TextBit &bit)
{
TextBit retVal = bit;
retVal.setText( stripPunctuation( bit.text()) );
return retVal;
}
QDebug operator<<(QDebug dbg, const Allomorph &key)
{
dbg.nospace() << "Allomorph(" << key.id() << ", " << key.textBit() << ", " << key.guid();
return dbg.maybeSpace();
}