CMiniLexicon::FindMajorSignatures(): use log file routines
[linguistica.git] / StemListViewItem.cpp
blobf7a586170ed5f6caf9cd443d623d86af9de87b9b
1 // Implementation of CWordListViewItem, CStemListViewItem methods
2 // Copyright © 2009 The University of Chicago
3 #include "StemListViewItem.h"
5 #include <Q3ListViewItem>
6 #include <Q3ListView>
7 #include <QString>
8 #include "Signature.h"
9 #include "Stem.h"
10 #include "CompareFunc.h"
11 #include "MiniLexicon.h"
13 namespace {
14 typedef QMap<QString, QString> StringToString;
16 //-------------------------------------------------------------------------------------------//
17 CStemListViewItem::CStemListViewItem( Q3ListView *parent,
18 QString stem,
19 int mini,
20 CStem* pStem,
21 StringToString* filter,
22 int char_count )
23 : Q3ListViewItem( parent, stem )
25 m_Stem = pStem;
26 m_filter = filter;
27 m_char_count = char_count;
28 m_mini = mini;
30 //-------------------------------------------------------------------------------------------//
31 CStemListViewItem::CStemListViewItem( Q3ListViewItem *parent,
32 QString stem,
33 int mini,
34 CStem* pStem,
35 StringToString* filter,
36 int char_count )
37 : Q3ListViewItem( parent, stem )
39 m_Stem = pStem;
40 m_filter = filter;
41 m_char_count = char_count;
42 m_mini = mini;
44 //-------------------------------------------------------------------------------------------//
45 int CStemListViewItem::compare(Q3ListViewItem* pOther, int col, bool asc) const
46 //-------------------------------------------------------------------------------------------//
48 CStemListViewItem* other = static_cast<CStemListViewItem*>(pOther);
50 switch( col )
52 case 1:
53 if( m_Stem ) return MakeComparable (m_Stem->GetPhonologicalInformationContent(), other->m_Stem->GetPhonologicalInformationContent());
54 case 2:
55 if( m_Stem ) return MakeComparable (m_Stem->GetLengthOfPointerToMe(), other->GetStem()->GetLengthOfPointerToMe());
56 case 3:
57 if( m_Stem ) return MakeComparable (m_Stem->GetCorpusCount(), other->GetStem()->GetCorpusCount());
58 case 8:
59 if( m_Stem ) return MakeComparable (m_Stem->GetUnigramLogProb(), other->GetStem()->GetUnigramLogProb());
60 default:
61 return Q3ListViewItem::compare(pOther, col, asc);
65 //-------------------------------------------------------------------------------------------//
66 QString CStemListViewItem::key( int column, bool ascending ) const
67 //-------------------------------------------------------------------------------------------//
69 CSignature* sigs;
70 int count;
72 switch( column )
75 case 3:
76 if( m_Stem )
78 return QString("%1").arg( m_Stem->GetCorpusCount(), 10 );
80 else
82 count = 0;
84 for (CStemListViewItem* child =
85 static_cast<CStemListViewItem*>(
86 firstChild());
87 child != 0;
88 child = static_cast<CStemListViewItem*>(
89 child->nextSibling()))
90 if (CStem* stem = child->GetStem())
91 count += stem->GetCorpusCount();
93 return QString("%1").arg( count, 10 );
96 case 4:
97 if( m_Stem )
99 sigs = m_Stem->GetSuffixSignature();
100 if( sigs )
102 return sigs->Display('.', m_filter);
104 else return "";
106 else return "";
107 case 5:
108 if( m_Stem )
110 sigs = m_Stem->GetPrefixSignature();
111 if( sigs ) return sigs->Display('.', m_filter);
112 else return "";
114 else return "";
115 case 6:
116 if( m_Stem ) return m_Stem->GetConfidence();
117 else return "";
118 case 7:
119 if( m_Stem ) return m_Stem->DisplayStemType();
120 else return "";
121 case 9:
122 return m_Stem->GetTier1()->Display();
123 case 10:
124 return m_Stem->GetTier1_Skeleton()->Display();
125 case 11:
126 return m_Stem->GetTier2()->Display();
129 default:
130 return Q3ListViewItem::key( column, ascending );
133 //-------------------------------------------------------------------------------------------//
134 QString CStemListViewItem::text( int column ) const
135 //-------------------------------------------------------------------------------------------//
137 // CParse* pfxs;
138 CSignature* sigs;
139 QString dummy;
140 int count;
142 switch( column )
145 case 1:
146 if( m_Stem ) return dummy.setNum( m_Stem->ComputeDL( m_char_count ) );
147 else return "";
149 case 2:
150 if( m_Stem ) return dummy.setNum( m_Stem->GetLengthOfPointerToMe( ) );
151 else return "";
154 case 3:
155 if( m_Stem )
157 return QString("%1").arg( m_Stem->GetCorpusCount() );
159 else
161 count = 0;
163 for (CStemListViewItem* child =
164 static_cast<CStemListViewItem*>(
165 firstChild());
166 child != 0;
167 child = static_cast<CStemListViewItem*>(
168 child->nextSibling()))
169 if (CStem* stem = child->GetStem())
170 count += stem->GetCorpusCount();
172 return QString("%1").arg( count );
177 case 4:
179 if( m_Stem )
181 sigs = m_Stem->GetSuffixSignature();
182 if( sigs )
184 return sigs->Display('.', m_filter);
186 else return "";
188 else return "";
190 case 5:
191 if( m_Stem )
193 sigs = m_Stem->GetPrefixSignature();
194 if( sigs ) return sigs->Display('.', m_filter);
195 else return "";
197 else return "";
198 case 6:
199 if( m_Stem ) return m_Stem->GetConfidence();
200 else return "";
201 case 7:
202 if( m_Stem ) return m_Stem->DisplayStemType();
203 else return "";
204 case 8:
205 return QString("%1").arg ( m_Stem->GetUnigramLogProb() );
206 case 9:
207 return m_Stem->GetTier1()->Display();
208 case 10:
209 return m_Stem->GetTier1_Skeleton()->Display();
210 case 11:
211 return m_Stem->GetTier2()->Display();
212 case 12:
213 return QString("just placeholdin'");
214 //return m_Stem->GetPhonologicalInformationContent();
216 default:
217 return Q3ListViewItem::text( column );
220 //-------------------------------------------------------------------------------------------//
221 CWordListViewItem::CWordListViewItem (Q3ListView *parent,
222 QString word, int mini, CStem* pWord,
223 QMap<QString, QString>* filter,
224 enum display_mode DisplayMode, int char_count)
225 : Q3ListViewItem( parent, word )
226 //-------------------------------------------------------------------------------------------//
228 m_pWord = pWord;
229 m_filter = filter;
230 m_DisplayMode = DisplayMode;
231 m_char_count = char_count;
232 m_mini = mini;
234 if ( m_pWord )
236 m_DL = m_pWord->ComputeDL( m_char_count );
237 m_prefix = m_pWord->GetPiece( m_pWord->GetPrefixLoc() )
238 .Display( m_filter );
239 m_stem = m_pWord->GetStem().Display( m_filter );
240 m_suffix = m_pWord->GetPiece( m_pWord->GetSuffixLoc() )
241 .Display( m_filter );
243 eAffixLocation affixLoc = pWord->GetMyMini()->GetAffixLocation();
244 if ( is_initial(affixLoc) )
245 m_pSig = m_pWord->GetPrefixSignature();
246 else
247 m_pSig = m_pWord->GetSuffixSignature();
249 if (m_pSig) { m_signature = m_pSig->Display( '.', m_filter ); }
250 else { m_signature = ""; }
252 // m_tier1 = m_pWord->GetTier1()->Display( ' ' );
253 // m_tier1_skeleton = m_pWord->GetTier1_Skeleton()->Display();
254 // m_tier2 = m_pWord->GetTier2()->Display();
256 else
258 m_DL = 0.0;
259 m_prefix = "";
260 m_stem = "";
261 m_suffix = "";
262 m_pSig = NULL;
263 m_signature = "";
264 m_tier1 = "";
265 m_tier1_skeleton = "";
266 m_tier2 = "";
273 //-------------------------------------------------------------------------------------------//
274 CWordListViewItem::CWordListViewItem(Q3ListViewItem *parent,
275 QString word, int mini, CStem* pWord,
276 QMap<QString, QString>* filter, enum display_mode DisplayMode,
277 int char_count)
278 : Q3ListViewItem( parent, word )
279 //-------------------------------------------------------------------------------------------//
281 m_pWord = pWord;
282 m_filter = filter;
283 m_DisplayMode = DisplayMode;
284 m_char_count = char_count;
285 m_mini = mini;
286 if( m_pWord )
288 m_DL = m_pWord->ComputeDL( m_char_count );
289 m_prefix = m_pWord->GetPiece( m_pWord->GetPrefixLoc() ).Display( m_filter );
290 m_stem = m_pWord->GetStem().Display(m_filter);
291 m_suffix = m_pWord->GetPiece( m_pWord->GetSuffixLoc() ).Display( m_filter );
292 m_pSig = m_pWord->GetSuffixSignature();
294 if( m_pSig == NULL ) m_pSig = m_pWord->GetPrefixSignature();
295 if( m_pSig != NULL ) m_signature = m_pSig->Display( '.', m_filter );
296 else m_signature = "";
298 m_tier1 = m_pWord->GetTier1()->Display();
299 m_tier1_skeleton = m_pWord->GetTier1_Skeleton()->Display();
300 m_tier2 = m_pWord->GetTier2()->Display();
302 else
304 m_DL = 0.0;
305 m_prefix = "";
306 m_stem = "";
307 m_suffix = "";
308 m_pSig = NULL;
309 m_signature = "";
310 m_tier1 = "";
311 m_tier1_skeleton= "";
312 m_tier2 = "";
316 //-------------------------------------------------------------------------------------------//
317 int CWordListViewItem::compare(Q3ListViewItem* pOther, int col, bool asc) const
318 //-------------------------------------------------------------------------------------------//
320 if (m_pWord == 0)
321 return Q3ListViewItem::compare(pOther, col, asc);
322 CWordListViewItem& other = *static_cast<CWordListViewItem*>(pOther);
323 CStem* other_word = other.m_pWord;
325 if (m_DisplayMode == MiniLexicon_MorphologyStuffFirst) {
326 switch (col) {
327 case 2:
328 return MakeComparable(m_DL, other.m_DL);
329 case 3:
330 return MakeComparable(m_pWord->GetCorpusCount(),
331 other_word->GetCorpusCount());
332 case 10:
333 return MakeComparable(m_pWord->GetUnigramLogProb(),
334 other_word->GetUnigramLogProb());
335 case 11:
336 return MakeComparable(m_pWord->GetUnigramComplexity(),
337 other_word->GetUnigramComplexity());
338 case 12:
339 return MakeComparable(m_pWord->GetBigramLogProb(),
340 other_word->GetBigramLogProb());
341 case 13:
342 return MakeComparable(m_pWord->GetBigramComplexity(),
343 other_word->GetBigramComplexity());
344 default:
345 return Q3ListViewItem::compare(pOther, col, asc);
349 // Phonology Stuff First
350 switch (col) {
351 case 1:
352 return MakeComparable(m_pWord->GetUnigramLogProb(),
353 other_word->GetUnigramLogProb());
354 case 2:
355 return MakeComparable(m_pWord->GetUnigramComplexity(),
356 other_word->GetUnigramComplexity());
357 case 3:
358 return MakeComparable(m_pWord->GetBigramLogProb(),
359 other_word->GetBigramLogProb());
360 case 4:
361 return MakeComparable(m_pWord->GetBigramComplexity(),
362 other_word->GetBigramComplexity());
363 case 5:
364 return MakeComparable(m_pWord->GetHMM_LogProbability(),
365 other_word->GetHMM_LogProbability());
366 case 9:
367 return MakeComparable(m_mini, other.m_mini);
368 case 10:
369 return MakeComparable(m_DL, other.m_DL);
370 case 11:
371 return MakeComparable(m_pWord->GetCorpusCount(),
372 other_word->GetCorpusCount());
373 default:
374 return Q3ListViewItem::compare(pOther, col, asc);
377 //-------------------------------------------------------------------------------------------//
378 QString CWordListViewItem::key( int column, bool ascending ) const
379 //-------------------------------------------------------------------------------------------//
381 // fo
383 if( m_pWord )
385 if ( m_DisplayMode == MiniLexicon_MorphologyStuffFirst )
387 switch( column )
389 case 1:
390 return QString( "%1" ).arg( 100 * m_mini, 10 );
392 case 4:
393 return m_pWord->DisplayStemType();
394 case 5:
395 return m_signature;
396 case 6:
397 if( m_pSig && m_pWord->GetConfidence() == "" )
399 return m_pSig->GetRemark();
401 else
403 return m_pWord->GetConfidence();
405 case 7:
406 return m_suffix;
407 case 8:
408 return m_stem;
409 case 9:
410 return m_prefix;
412 default:
413 return Q3ListViewItem::key( column, ascending );
415 }// end of switch for MorphologyStuffFirst --
416 else // Phonology Stuff First
418 switch (column) {
419 case 1:
420 return QString("%1").arg(static_cast<int>(
421 double(10000) * m_pWord->GetUnigramLogProb()),
422 10);
423 case 2:
424 return QString("%1").arg(static_cast<int>(
425 double(10000) * m_pWord->GetUnigramComplexity()),
426 10);
427 case 3:
428 return QString("%1").arg(static_cast<int>(
429 double(10000) * m_pWord->GetBigramLogProb()),
430 10);
431 case 4:
432 return QString("%1").arg(static_cast<int>(
433 double(10000) * m_pWord->GetBigramComplexity()),
434 10);
435 case 5:
436 return QString("%1").arg(static_cast<int>(
437 double(10000) * m_pWord->GetHMM_LogProbability()),
438 10);
439 case 6:
440 return m_tier1;
441 case 7:
442 return m_tier1_skeleton;
443 case 8:
444 return m_tier2;
445 case 9:
446 return QString("%1").arg( 100 * m_mini, 10 );
447 case 10:
448 if (m_pWord == 0)
449 return QString();
450 return QString("%1").arg(static_cast<int>(
451 double(1000) * m_DL), 10);
452 case 11:
453 return QString("%1").arg(m_pWord->GetCorpusCount(), 10);
454 case 12:
455 return m_pWord->DisplayStemType();
456 case 13:
457 return m_signature;
458 case 14:
459 if( m_pSig && m_pWord->GetConfidence() == "")
461 return m_pSig->GetRemark();
463 else
465 return m_pWord->GetConfidence();
467 case 15:
468 return m_prefix;
469 case 16:
470 return m_stem;
471 case 17:
472 return m_suffix;
475 default:
476 return Q3ListViewItem::key( column, ascending );
481 else return Q3ListViewItem::key( column, ascending );
483 //-------------------------------------------------------------------------------------------//
484 QString CWordListViewItem::text( int column ) const
485 //-------------------------------------------------------------------------------------------//
489 if(! m_pWord) return QString("");
491 switch (m_DisplayMode)
493 case MiniLexicon_MorphologyStuffFirst:
494 case Lexicon_Word:
496 switch( column )
498 case 1:
499 return QString( "%1" ).arg( m_mini );
500 case 2:
501 return QString("%1").arg( m_DL );
502 case 3:
503 return QString("%1").arg( m_pWord->GetCorpusCount() );
504 case 4:
505 return m_pWord->DisplayStemType();
506 case 5:
507 return m_signature;
508 case 6:
509 if( m_pSig && m_pWord->GetConfidence() == "")
511 return m_pSig->GetRemark();
513 else
515 return m_pWord->GetConfidence();
517 case 7:
518 return m_prefix;
519 case 8:
520 return m_stem;
521 case 9:
522 return m_suffix;
523 case 10:
524 return QString("%1").arg( m_pWord->GetUnigramLogProb() );
525 case 11:
526 return QString("%1").arg( m_pWord->GetUnigramComplexity() );
527 case 12:
528 return QString("%1").arg( m_pWord->GetBigramLogProb() );
530 case 13:
531 return QString("%1").arg( m_pWord->GetBigramComplexity() );
533 case 14:
534 return m_tier1;
535 case 15:
536 return m_tier1_skeleton;
537 case 16:
538 return m_tier2;
541 default:
542 return Q3ListViewItem::text( column );
544 break;
546 case MiniLexicon_PhonologyStuffFirst:
548 switch( column )
550 case 1:
551 return QString("%1").arg( m_pWord->GetUnigramLogProb() );
552 case 2:
553 return QString("%1").arg( m_pWord->GetUnigramComplexity() );
554 case 3:
555 return QString("%1").arg( m_pWord->GetBigramLogProb() );
556 case 4:
557 return QString("%1").arg( m_pWord->GetBigramComplexity() );
558 case 5:
559 return QString("%1").arg( m_pWord->GetHMM_LogProbability() );
560 case 6:
561 return m_tier1;
562 case 7:
563 return m_tier1_skeleton;
564 case 8:
565 return m_tier2;
566 case 9:
567 return QString( "%1" ).arg( m_mini );
568 case 10:
569 if( m_pWord ) return QString("%1").arg( m_DL );
570 else return "";
571 case 11:
572 return QString("%1").arg( m_pWord->GetCorpusCount() );
573 case 12:
574 return m_pWord->DisplayStemType();
575 case 13:
576 return m_signature;
577 case 14:
578 if( m_pSig && m_pWord->GetConfidence() == "")
580 return m_pSig->GetRemark();
582 else
584 return m_pWord->GetConfidence();
586 case 15:
587 return m_prefix;
588 case 16:
589 return m_stem;
590 case 17:
591 return m_suffix;
593 default:
594 return Q3ListViewItem::text( column );
596 }// end of switch on column...
597 }// end of MiniLexicon_Phonology stuff first
598 } //end of DisplayMode switch
600 return Q3ListViewItem::text( column );