1 // Implementation of CBiphone, CBiphoneListViewItem methods
2 // Copyright © 2009 The University of Chicago
4 #include "CompareFunc.h"
6 #include "implicit_cast.h"
8 CBiphoneListViewItem::CBiphoneListViewItem(Q3ListView
* parent
,
9 QString bigram_text
, CBiphone
* bigram
)
10 : Q3ListViewItem(parent
, bigram_text
), m_MyBiphone(bigram
) { }
12 CBiphoneListViewItem::CBiphoneListViewItem(Q3ListViewItem
* parent
,
13 QString bigram_text
, CBiphone
* bigram
)
14 : Q3ListViewItem(parent
, bigram_text
), m_MyBiphone(bigram
) { }
16 QString
CBiphoneListViewItem::text( int column
) const
22 return QString("%1").arg( m_MyBiphone
->GetCorpusCount() );
24 return QString("%1").arg( m_MyBiphone
->m_Freq
);
26 return QString("%1").arg( -1 * m_MyBiphone
->m_LogCondProb
);
28 return QString("%1").arg( m_MyBiphone
->m_LogCondProb
);
30 return QString("%1").arg( m_MyBiphone
->m_MI
);
32 return QString("%1").arg( m_MyBiphone
->m_WMI
);
34 return QString("%1").arg( m_MyBiphone
->m_CondProb
);
36 return QString("%1").arg( m_MyBiphone
->m_NormalizedMI
);
38 return Q3ListViewItem::text( column
);
42 int CBiphoneListViewItem::compare(Q3ListViewItem
* item
, int col
, bool asc
) const
44 const CBiphoneListViewItem
& other
=
45 *static_cast<CBiphoneListViewItem
*>(item
);
46 const CBiphone
& this_biphone
= *GetBiphone();
47 const CBiphone
& other_biphone
= *other
.GetBiphone();
51 return MakeComparable(other_biphone
.GetCorpusCount(),
52 this_biphone
.GetCorpusCount());
54 return MakeComparable(this_biphone
.m_Freq
, other_biphone
.m_Freq
);
57 return MakeComparable(this_biphone
.m_LogCondProb
,
58 other_biphone
.m_LogCondProb
);
60 return MakeComparable(this_biphone
.m_MI
,
63 return MakeComparable(this_biphone
.m_WMI
,
66 return MakeComparable(this_biphone
.m_NormalizedMI
,
67 other_biphone
.m_NormalizedMI
);
69 return Q3ListViewItem::compare(item
, col
, asc
);
73 enum eBiphoneSortStyle
CBiphone::m_SortStyle
;
75 //////////////////////////////////////////////////////////////////////
76 // Construction/Destruction
77 //////////////////////////////////////////////////////////////////////
80 using linguistica::implicit_cast
;
84 : CLParse(implicit_cast
<CMiniLexicon
*, CMiniLexicon
*>(0)),
93 m_MyFirst(), m_MySecond() { }
95 CBiphone::CBiphone(QString String
)
96 : CLParse(implicit_cast
<CMiniLexicon
*, CMiniLexicon
*>(0)),
105 m_MyFirst(), m_MySecond() { }
107 CBiphone::~CBiphone() { }
109 CBiphone::CBiphone(const CBiphone
& x
)
110 : CLParse(implicit_cast
<CMiniLexicon
*, CMiniLexicon
*>(0)),
113 m_LogFreq(x
.m_LogFreq
),
116 m_LogCondProb(x
.m_LogCondProb
),
117 m_CondProb(x
.m_CondProb
),
118 m_NormalizedMI(x
.m_NormalizedMI
),
119 m_MyFirst(x
.m_MyFirst
), m_MySecond(x
.m_MySecond
) { }
121 CBiphone
& CBiphone::operator=(const CBiphone
& x
)
123 CLParse::operator=(x
);
126 m_LogFreq
= x
.m_LogFreq
;
129 m_LogCondProb
= x
.m_LogCondProb
;
130 m_CondProb
= x
.m_CondProb
;
131 m_NormalizedMI
= x
.m_NormalizedMI
;
132 m_MyFirst
= x
.m_MyFirst
;
133 m_MySecond
= x
.m_MySecond
;
137 void CBiphone::SetMI (double mi
) { m_MI
= mi
; }
139 bool CBiphone::operator==(const CBiphone
& rhs
)
144 if (m_WMI
== rhs
.m_WMI
)
150 if (m_MI
== rhs
.m_MI
)
163 bool CBiphone::operator<(const CBiphone
& rhs
)
168 if (m_WMI
< rhs
.m_WMI
)
188 void CBiphone::BiphoneListDisplay(Q3ListView
* List
)
189 { static_cast<void>(new CBiphoneListViewItem(List
, m_Key
, this)); }