CMiniLexicon::FindMajorSignatures(): use log file routines
[linguistica.git] / Datum.cpp
blob1e7c537f14ca5c9a89c501dde4d7b1ec73ed4cdf
1 // Implemenation of CDatum, CDatumListViewItem methods
2 // Copyright © 2009 The University of Chicago
3 #include "Datum.h"
5 #include "VeryLong.h"
6 #include "Typedefs.h"
8 CDatumListViewItem::CDatumListViewItem( Q3ListView *parent )
9 : Q3ListViewItem( parent )
13 CDatumListViewItem::CDatumListViewItem( Q3ListView *parent,
14 QString affix,
15 CDatum* pDatum )
16 : Q3ListViewItem( parent, affix )
18 m_datum = pDatum;
22 CDatumListViewItem::CDatumListViewItem( Q3ListViewItem *parent,
23 QString affix,
24 CDatum* pDatum )
25 : Q3ListViewItem( parent, affix )
27 m_datum = pDatum;
31 QString CDatumListViewItem::key( int column, bool ascending ) const
33 switch( column )
35 case 1:
36 return QString("%1").arg( m_datum->m_Count, 10 );
37 case 2:
38 return QString("%1").arg( m_datum->m_Frequency, 10 );
39 default:
40 return Q3ListViewItem::key( column, ascending );
45 QString CDatumListViewItem::text( int column ) const
47 switch( column )
49 case 1:
50 return QString("%1").arg( m_datum->m_Count );
51 case 2:
52 return QString("%1").arg( m_datum->m_Frequency );
53 default:
54 return Q3ListViewItem::text( column );
58 CDatum::CDatum() : CParse()
60 m_Count = 0;
61 m_Frequency = 0;
65 CDatum::CDatum( CParse& parse ) : CParse( parse )
67 m_Count = 1;
68 m_Frequency = 0;
72 CDatum::CDatum ( QChar c ) : CParse ( c )
74 m_Count = 1;
75 m_Frequency = 0;
78 CDatum::CDatum( CSS& ssString ) : CParse( ssString )
80 m_Count = 1;
81 m_Frequency = 0;
85 void CDatum::SetFrequency( float f ) { m_Frequency=f; }
88 double CDatum::GetCount() { return m_Count; }
91 //CString CDatum::GetKey() { return Key; }
94 void CDatum::SetCount( double f ) { m_Count = f; }
97 void CDatum::IncrementCount( CVeryLong& VL )
99 m_Count = m_Count + VL.ToDouble();
102 void CDatum::IncrementCount()
104 m_Count++;
108 // this is normally found in MiniLexicon_deMarcken, which is temporarily not included.
110 CDatum* CMiniLexicon::LookUp ( QString s )
112 if( m_DataMap.contains( s ) )
114 StringToDatum::Iterator it = m_DataMap.find( s );
115 return &it.data();
118 return NULL;
123 /* todo: put this back
124 double CDatum::GetInformationContent( CMiniLexicon* lexicon )
126 double info = -1 * log( m_Frequency ) / log( 2 ),
127 letterInfo;
128 QChar letter;
129 CDatum* pLetter;
131 CSS key = GetKey();
133 for( int i = 0; i < key.GetLength(); i++ )
135 letter = key[i];
136 pLetter = lexicon->LookUp( letter );
137 letterInfo = -1 * log( pLetter->m_Frequency ) / log(2);
139 info -= letterInfo;
142 return info * m_Count;