1 // Implementation of CWordListViewItem, CStemListViewItem methods
2 // Copyright © 2009 The University of Chicago
3 #include "StemListViewItem.h"
5 #include <Q3ListViewItem>
10 #include "CompareFunc.h"
11 #include "MiniLexicon.h"
14 typedef QMap
<QString
, QString
> StringToString
;
16 //-------------------------------------------------------------------------------------------//
17 CStemListViewItem::CStemListViewItem( Q3ListView
*parent
,
21 StringToString
* filter
,
23 : Q3ListViewItem( parent
, stem
)
27 m_char_count
= char_count
;
30 //-------------------------------------------------------------------------------------------//
31 CStemListViewItem::CStemListViewItem( Q3ListViewItem
*parent
,
35 StringToString
* filter
,
37 : Q3ListViewItem( parent
, stem
)
41 m_char_count
= char_count
;
44 //-------------------------------------------------------------------------------------------//
45 int CStemListViewItem::compare(Q3ListViewItem
* pOther
, int col
, bool asc
) const
46 //-------------------------------------------------------------------------------------------//
48 CStemListViewItem
* other
= static_cast<CStemListViewItem
*>(pOther
);
53 if( m_Stem
) return MakeComparable (m_Stem
->GetPhonologicalInformationContent(), other
->m_Stem
->GetPhonologicalInformationContent());
55 if( m_Stem
) return MakeComparable (m_Stem
->GetLengthOfPointerToMe(), other
->GetStem()->GetLengthOfPointerToMe());
57 if( m_Stem
) return MakeComparable (m_Stem
->GetCorpusCount(), other
->GetStem()->GetCorpusCount());
59 if( m_Stem
) return MakeComparable (m_Stem
->GetUnigramLogProb(), other
->GetStem()->GetUnigramLogProb());
61 return Q3ListViewItem::compare(pOther
, col
, asc
);
65 //-------------------------------------------------------------------------------------------//
66 QString
CStemListViewItem::key( int column
, bool ascending
) const
67 //-------------------------------------------------------------------------------------------//
78 return QString("%1").arg( m_Stem
->GetCorpusCount(), 10 );
84 for (CStemListViewItem
* child
=
85 static_cast<CStemListViewItem
*>(
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 );
99 sigs
= m_Stem
->GetSuffixSignature();
102 return sigs
->Display('.', m_filter
);
110 sigs
= m_Stem
->GetPrefixSignature();
111 if( sigs
) return sigs
->Display('.', m_filter
);
116 if( m_Stem
) return m_Stem
->GetConfidence();
119 if( m_Stem
) return m_Stem
->DisplayStemType();
122 return m_Stem
->GetTier1()->Display();
124 return m_Stem
->GetTier1_Skeleton()->Display();
126 return m_Stem
->GetTier2()->Display();
130 return Q3ListViewItem::key( column
, ascending
);
133 //-------------------------------------------------------------------------------------------//
134 QString
CStemListViewItem::text( int column
) const
135 //-------------------------------------------------------------------------------------------//
146 if( m_Stem
) return dummy
.setNum( m_Stem
->ComputeDL( m_char_count
) );
150 if( m_Stem
) return dummy
.setNum( m_Stem
->GetLengthOfPointerToMe( ) );
157 return QString("%1").arg( m_Stem
->GetCorpusCount() );
163 for (CStemListViewItem
* child
=
164 static_cast<CStemListViewItem
*>(
167 child
= static_cast<CStemListViewItem
*>(
168 child
->nextSibling()))
169 if (CStem
* stem
= child
->GetStem())
170 count
+= stem
->GetCorpusCount();
172 return QString("%1").arg( count
);
181 sigs
= m_Stem
->GetSuffixSignature();
184 return sigs
->Display('.', m_filter
);
193 sigs
= m_Stem
->GetPrefixSignature();
194 if( sigs
) return sigs
->Display('.', m_filter
);
199 if( m_Stem
) return m_Stem
->GetConfidence();
202 if( m_Stem
) return m_Stem
->DisplayStemType();
205 return QString("%1").arg ( m_Stem
->GetUnigramLogProb() );
207 return m_Stem
->GetTier1()->Display();
209 return m_Stem
->GetTier1_Skeleton()->Display();
211 return m_Stem
->GetTier2()->Display();
213 return QString("just placeholdin'");
214 //return m_Stem->GetPhonologicalInformationContent();
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 //-------------------------------------------------------------------------------------------//
230 m_DisplayMode
= DisplayMode
;
231 m_char_count
= char_count
;
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();
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();
265 m_tier1_skeleton
= "";
273 //-------------------------------------------------------------------------------------------//
274 CWordListViewItem::CWordListViewItem(Q3ListViewItem
*parent
,
275 QString word
, int mini
, CStem
* pWord
,
276 QMap
<QString
, QString
>* filter
, enum display_mode DisplayMode
,
278 : Q3ListViewItem( parent
, word
)
279 //-------------------------------------------------------------------------------------------//
283 m_DisplayMode
= DisplayMode
;
284 m_char_count
= char_count
;
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();
311 m_tier1_skeleton
= "";
316 //-------------------------------------------------------------------------------------------//
317 int CWordListViewItem::compare(Q3ListViewItem
* pOther
, int col
, bool asc
) const
318 //-------------------------------------------------------------------------------------------//
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
) {
328 return MakeComparable(m_DL
, other
.m_DL
);
330 return MakeComparable(m_pWord
->GetCorpusCount(),
331 other_word
->GetCorpusCount());
333 return MakeComparable(m_pWord
->GetUnigramLogProb(),
334 other_word
->GetUnigramLogProb());
336 return MakeComparable(m_pWord
->GetUnigramComplexity(),
337 other_word
->GetUnigramComplexity());
339 return MakeComparable(m_pWord
->GetBigramLogProb(),
340 other_word
->GetBigramLogProb());
342 return MakeComparable(m_pWord
->GetBigramComplexity(),
343 other_word
->GetBigramComplexity());
345 return Q3ListViewItem::compare(pOther
, col
, asc
);
349 // Phonology Stuff First
352 return MakeComparable(m_pWord
->GetUnigramLogProb(),
353 other_word
->GetUnigramLogProb());
355 return MakeComparable(m_pWord
->GetUnigramComplexity(),
356 other_word
->GetUnigramComplexity());
358 return MakeComparable(m_pWord
->GetBigramLogProb(),
359 other_word
->GetBigramLogProb());
361 return MakeComparable(m_pWord
->GetBigramComplexity(),
362 other_word
->GetBigramComplexity());
364 return MakeComparable(m_pWord
->GetHMM_LogProbability(),
365 other_word
->GetHMM_LogProbability());
367 return MakeComparable(m_mini
, other
.m_mini
);
369 return MakeComparable(m_DL
, other
.m_DL
);
371 return MakeComparable(m_pWord
->GetCorpusCount(),
372 other_word
->GetCorpusCount());
374 return Q3ListViewItem::compare(pOther
, col
, asc
);
377 //-------------------------------------------------------------------------------------------//
378 QString
CWordListViewItem::key( int column
, bool ascending
) const
379 //-------------------------------------------------------------------------------------------//
385 if ( m_DisplayMode
== MiniLexicon_MorphologyStuffFirst
)
390 return QString( "%1" ).arg( 100 * m_mini
, 10 );
393 return m_pWord
->DisplayStemType();
397 if( m_pSig
&& m_pWord
->GetConfidence() == "" )
399 return m_pSig
->GetRemark();
403 return m_pWord
->GetConfidence();
413 return Q3ListViewItem::key( column
, ascending
);
415 }// end of switch for MorphologyStuffFirst --
416 else // Phonology Stuff First
420 return QString("%1").arg(static_cast<int>(
421 double(10000) * m_pWord
->GetUnigramLogProb()),
424 return QString("%1").arg(static_cast<int>(
425 double(10000) * m_pWord
->GetUnigramComplexity()),
428 return QString("%1").arg(static_cast<int>(
429 double(10000) * m_pWord
->GetBigramLogProb()),
432 return QString("%1").arg(static_cast<int>(
433 double(10000) * m_pWord
->GetBigramComplexity()),
436 return QString("%1").arg(static_cast<int>(
437 double(10000) * m_pWord
->GetHMM_LogProbability()),
442 return m_tier1_skeleton
;
446 return QString("%1").arg( 100 * m_mini
, 10 );
450 return QString("%1").arg(static_cast<int>(
451 double(1000) * m_DL
), 10);
453 return QString("%1").arg(m_pWord
->GetCorpusCount(), 10);
455 return m_pWord
->DisplayStemType();
459 if( m_pSig
&& m_pWord
->GetConfidence() == "")
461 return m_pSig
->GetRemark();
465 return m_pWord
->GetConfidence();
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
:
499 return QString( "%1" ).arg( m_mini
);
501 return QString("%1").arg( m_DL
);
503 return QString("%1").arg( m_pWord
->GetCorpusCount() );
505 return m_pWord
->DisplayStemType();
509 if( m_pSig
&& m_pWord
->GetConfidence() == "")
511 return m_pSig
->GetRemark();
515 return m_pWord
->GetConfidence();
524 return QString("%1").arg( m_pWord
->GetUnigramLogProb() );
526 return QString("%1").arg( m_pWord
->GetUnigramComplexity() );
528 return QString("%1").arg( m_pWord
->GetBigramLogProb() );
531 return QString("%1").arg( m_pWord
->GetBigramComplexity() );
536 return m_tier1_skeleton
;
542 return Q3ListViewItem::text( column
);
546 case MiniLexicon_PhonologyStuffFirst
:
551 return QString("%1").arg( m_pWord
->GetUnigramLogProb() );
553 return QString("%1").arg( m_pWord
->GetUnigramComplexity() );
555 return QString("%1").arg( m_pWord
->GetBigramLogProb() );
557 return QString("%1").arg( m_pWord
->GetBigramComplexity() );
559 return QString("%1").arg( m_pWord
->GetHMM_LogProbability() );
563 return m_tier1_skeleton
;
567 return QString( "%1" ).arg( m_mini
);
569 if( m_pWord
) return QString("%1").arg( m_DL
);
572 return QString("%1").arg( m_pWord
->GetCorpusCount() );
574 return m_pWord
->DisplayStemType();
578 if( m_pSig
&& m_pWord
->GetConfidence() == "")
580 return m_pSig
->GetRemark();
584 return m_pWord
->GetConfidence();
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
);