1 // Updating the main window’s tree view
2 // Copyright © 2009 The University of Chicago
3 #include "linguisticamainwindow.h"
5 #include "MiniLexicon.h"
7 #include "TreeViewItem.h"
8 #include "LPreferences.h"
9 #include "StateEmitHMM.h"
10 #include "CorpusWord.h"
11 #include "DLHistory.h"
14 #include "CorpusWordCollection.h"
15 #include "SignatureCollection.h"
16 #include "TemplateCollection.h"
17 #include "CompoundCollection.h"
18 #include "LinkerCollection.h"
19 #include "SuffixCollection.h"
20 #include "PrefixCollection.h"
21 #include "BiphoneCollection.h"
22 #include "PhoneCollection.h"
23 #include "StemCollection.h"
24 #include "WordCollection.h"
25 #include "POSCollection.h"
26 #include "AffixLocation.h"
28 /** \page page1 How to make a variable be displayed in the Tree View (left window)
30 Most of the functions here are sensitive to what information has been computed in CLexicon and
31 the MiniLexicons. A few are triggered under any conditions, but most are triggered only
32 if certain items have already been computed.
35 \section sec The main screen
40 void LinguisticaMainWindow::updateTreeViewSlot()
42 // Adapted from MFC version: CMyTree::UpdateUpperTree, CMyTree::UpdateStatistics
44 int count
, // used for various counts
45 index
; // mini-lexicon index
53 Q3ListViewItem
* MiscItem
= NULL
,
56 * WordsReadItem
= NULL
,
57 * PrefixesItem
= NULL
,
58 * SuffixesItem
= NULL
,
60 * CompoundsItem
= NULL
,
61 * ComponentItem
= NULL
,
62 * STRINGEDITITEM
= NULL
,
63 * CorpusWordsItem
= NULL
;
68 m_treeView
->setFont( GetFontPreference( "Main" ) );
69 m_treeView
->hideColumn(1);
71 //**************************************************************************************
72 // A NOTE ON THE ORGANIZATION OF THIS FUNCTION:
73 // The items are inserted into the tree in reverse order respective to their group. They
74 // are organized by depth here, i.e. what is connected to the root is the first group,
75 // then do the groups of items connected to this first group, etc. The only items that
76 // get their own name are those that have children. The rest use MiscItem
77 //**************************************************************************************
80 //======================================================================================//
81 // START CONNECTED DIRECTLY TO m_treeView
82 //======================================================================================//
85 count
= GetNumberOfTokens();
88 MiscItem
= new CTreeViewItem( m_treeView
,
89 "Tokens requested: " + IntToStringWithCommas( count
),
91 MiscItem
->setSelectable(false);
94 //======================================================================================//
96 if( m_lexicon
->GetWords() && m_lexicon
->GetMiniCount() )
98 count
= m_lexicon
->GetTokenCount();
101 WordsReadItem
= new CTreeViewItem( m_treeView
,
102 "Tokens read: " + IntToStringWithCommas( count
) );
103 WordsReadItem
->setSelectable(false);
104 WordsReadItem
->setOpen(true);
107 //======================================================================================//
109 LexiconItem
= new CTreeViewItem( m_treeView
,
110 "Lexicon : click items to display them" );
111 LexiconItem
->setSelectable(false);
112 LexiconItem
->setOpen(true);
115 //======================================================================================//
117 if ( m_projectDirectory
.length() )
119 MiscItem
= new CTreeViewItem( m_treeView
, "Project directory: " + m_projectDirectory
);
120 MiscItem
->setSelectable(false);
124 MiscItem
= new CTreeViewItem( m_treeView
, "No project directory." );
125 MiscItem
->setSelectable(false);
128 //======================================================================================//
132 MiscItem
= new CTreeViewItem( m_treeView
, "Log file (now on) " + GetLogFileName() );
133 MiscItem
->setSelectable(false);
137 MiscItem
= new CTreeViewItem( m_treeView
, "Log file (now off) " + GetLogFileName() );
138 MiscItem
->setSelectable(false);
141 //=================================================================================================
142 // END CONNECTED DIRECTLY TO m_treeView
143 // START CONNECTED TO LexiconItem
144 //=================================================================================================
146 if ( LexiconItem
&& m_lexicon
->GetHMM() )
148 MiscItem
= new CTreeViewItem( LexiconItem
,
151 double dl
= m_lexicon
->GetHMM()->GetLogProbability();
152 MiscItem1
= new CTreeViewItem(MiscItem
,"HMM description length: " + IntToStringWithCommas(int( dl
) )
154 MiscItem1
= new CTreeViewItem(MiscItem
,
155 "Iterations: " + IntToStringWithCommas( m_lexicon
->GetHMM()->m_NumberOfIterations
)
157 MiscItem1
= new CTreeViewItem(MiscItem
,
158 "Number of states: " + IntToStringWithCommas( m_lexicon
->GetHMM()->m_countOfStates
)
161 MiscItem
->setOpen(true);
163 //======================================================================================//
167 if( m_lexicon
->GetDLHistory()->count() > 0 )
169 MiscItem
= new CTreeViewItem( LexiconItem
,
170 "Description length history",
171 DESCRIPTION_LENGTH_HISTORY
);
175 //////////////////////////////
176 //// StringEdit Display
178 if ((LexiconItem
!= NULL
) && (m_Words_InitialTemplates
!= NULL
))
180 if ( m_Words_InitialTemplates
->GetCount() > 0)
182 STRINGEDITITEM
= new CTreeViewItem( LexiconItem
,
183 "StringEditDistanceTemplates: " + IntToStringWithCommas( 2 ),
184 STRINGEDITDISTANCE
, -1);
186 count
= m_Words_Templates
->GetCount();
189 MiscItem
= new CTreeViewItem( STRINGEDITITEM
,
190 "StringEdit_Templates: " + IntToStringWithCommas( count
),
191 WORKINGSTRINGEDITTEMPLATES
, -1);
195 count
= m_Words_InitialTemplates
->GetCount();
196 MiscItem
= new CTreeViewItem( STRINGEDITITEM
,
197 "StringEdit_InitialTemplates: " + IntToStringWithCommas( count
),
198 INITIALSTRINGEDITTEMPLATES
, -1);
203 Q3DictIterator
<PrefixSet
> it5( *m_lexicon
->GetAllPrefixes() );
204 for( ; it5
.current(); ++it5
)
206 count
+= it5
.current()->count();
210 PrefixesItem
= new CTreeViewItem( LexiconItem
,
211 "All Prefixes " + IntToStringWithCommas( count
),
213 PrefixesItem
->setOpen( TRUE
);
215 //======================================================================================//
217 Q3DictIterator
<SuffixSet
> it4( *m_lexicon
->GetAllSuffixes() );
218 for( ; it4
.current(); ++it4
)
220 count
+= it4
.current()->count();
224 SuffixesItem
= new CTreeViewItem( LexiconItem
,
225 "All Suffixes " + IntToStringWithCommas( count
),
227 SuffixesItem
->setOpen( TRUE
);
229 //======================================================================================//
231 Q3DictIterator
<StemSet
> it1( *m_lexicon
->GetAllStems() );
232 for( ; it1
.current(); ++it1
)
234 count
+= it1
.current()->count();
238 MiscItem
= new CTreeViewItem( LexiconItem
,
239 "All Stems " + IntToStringWithCommas( count
),
242 //======================================================================================//
244 Q3DictIterator
<StemSet
> it2( *m_lexicon
->GetAllWords() );
245 for( ; it2
.current(); ++it2
)
247 count
+= it2
.current()->count();
252 WordsItem
= new CTreeViewItem( LexiconItem
,
253 "All Words " + IntToStringWithCommas( count
),
255 WordsItem
->setOpen( TRUE
);
257 //======================================================================================//
258 if( m_lexicon
->GetMiniCount() )
260 for( index
= m_lexicon
->GetMiniSize() - 1; index
>= 0; index
-- )
262 if( m_lexicon
->GetMiniLexicon( index
) )
263 MiscItem
= GetMiniLexiconSubTree( LexiconItem
, index
);
266 //======================================================================================//
267 count
= m_lexicon
->GetCompounds()->GetCount();
270 CompoundsItem
= new CTreeViewItem( LexiconItem
,
271 "Compounds " + IntToStringWithCommas( count
),
273 CompoundsItem
->setOpen( TRUE
);
274 int count2
= m_lexicon
->GetCompounds()->GetComponents()->GetSize();
275 ComponentItem
= new CTreeViewItem( CompoundsItem
, "Components "+ IntToStringWithCommas (count2
),
276 COMPOUND_COMPONENTS
);
278 //======================================================================================//
280 count
= m_lexicon
->GetWords()->GetCount();
283 CorpusWordsItem
= new CTreeViewItem( LexiconItem
,
284 "Corpus Words " + IntToStringWithCommas( count
),
286 CorpusWordsItem
->setOpen( TRUE
);
288 //=================================================================================================
289 // END CONNECTED TO LexiconItem
290 // START CONNECTED TO CorpusWordsItem
291 //=================================================================================================
294 if( CorpusWordsItem
)
297 CCorpusWord
* pCorpusWord
;
298 CCorpusWordCollection
* pWords
= m_lexicon
->GetWords();
302 for( int i
= 0; i
< pWords
->GetCount(); i
++ )
304 pCorpusWord
= pWords
->GetAtSort(i
);
306 if( pCorpusWord
->Size() > 1 )
314 MiscItem
= new CTreeViewItem( CorpusWordsItem
,
315 "Analyzed " + IntToStringWithCommas( count
),
316 ANALYZED_CORPUS_WORDS
);
320 //=================================================================================================
321 // END CONNECTED TO CorpusWordsItem
322 // START CONNECTED TO WordsItem
323 //=================================================================================================
327 bool analyzed_exists
;
328 Q3DictIterator
<StemSet
> it3( *m_lexicon
->GetAllWords() );
329 for( ; it3
.current(); ++it3
)
331 analyzed_exists
= FALSE
;
332 //for( pWord = it3.current()->first(); pWord; pWord = it3.current()->next() )
333 for (int z
= 0; z
< it3
.current()->size(); z
++)
335 pWord
= it3
.current()->at(z
);
336 if( pWord
->Size() > 1 )
338 analyzed_exists
= TRUE
;
346 MiscItem
= new CTreeViewItem( WordsItem
,
347 "Analyzed " + IntToStringWithCommas( count
),
348 ALL_ANALYZED_WORDS
);
351 //=================================================================================================
352 // END CONNECTED TO WordsItem
353 // START CONNECTED TO SuffixesItem
354 //=================================================================================================
358 Q3DictIterator
<SignatureSet
> it7( *m_lexicon
->GetAllSuffixSigs() );
359 for( ; it7
.current(); ++it7
)
361 count
+= it7
.current()->count();
365 MiscItem
= new CTreeViewItem( SuffixesItem
,
366 "Signatures " + IntToStringWithCommas( count
),
367 ALL_SUFFIX_SIGNATURES
);
370 //=================================================================================================
371 // END CONNECTED TO SuffixesItem
372 // START CONNECTED TO PrefixesItem
373 //=================================================================================================
377 Q3DictIterator
<SignatureSet
> it6( *m_lexicon
->GetAllPrefixSigs() );
378 for( ; it6
.current(); ++it6
)
380 count
+= it6
.current()->count();
384 MiscItem
= new CTreeViewItem( PrefixesItem
,
385 "Signatures " + IntToStringWithCommas( count
),
386 ALL_PREFIX_SIGNATURES
);
389 //=================================================================================================
390 // END CONNECTED TO PrefixesItem
391 // START CONNECTED TO WordsReadItem
392 //=================================================================================================
396 if( m_lexicon
->GetWords() )
398 count
= m_lexicon
->GetWords()->GetCount();
401 MiscItem
= new CTreeViewItem( WordsReadItem
,
402 "Distinct types read: " + IntToStringWithCommas( count
) );
403 MiscItem
->setSelectable(false);
407 //======================================================================================//
409 count
= m_lexicon
->GetCorpusCount();
412 MiscItem
= new CTreeViewItem( WordsReadItem
,
413 "Tokens included: " + IntToStringWithCommas( count
) );
414 MiscItem
->setSelectable(false);
419 //=================================================================================================
420 // END CONNECTED TO WordsReadItem
421 // START CONNECTED TO CompoundsItem
422 //=================================================================================================
424 count
= m_lexicon
->GetLinkers()->GetCount();
427 MiscItem
= new CTreeViewItem( CompoundsItem
,
428 "Linkers " + IntToStringWithCommas( count
),
435 Q3ListViewItem
* LinguisticaMainWindow::GetMiniLexiconSubTree(
436 Q3ListViewItem
* parent
, int index
)
438 CMiniLexicon
* lexicon
= m_lexicon
->GetMiniLexicon(index
);
443 enum eAffixLocation affixLocation
= lexicon
->GetAffixLocation();
445 // Items are inserted into the tree in reverse order
446 // respective to their group. They are organized by depth here,
447 // i.e. what is connected to the root is the first group,
448 // then do the groups of items connected to this first group, etc.
449 // The only items that get their own name are those that have children.
451 Q3ListViewItem
* LexiconItem
=
453 new CTreeViewItem(parent
,
455 m_lexicon
->GetActiveMiniIndex() == index
456 ? "Mini-Lexicon %1\t**ACTIVE**"
459 MINI_LEXICON
, index
);
460 LexiconItem
->setSelectable(false);
461 LexiconItem
->setOpen(true);
462 // START CONNECTED TO LexiconItem
463 if (lexicon
->GetFSA() != 0)
464 static_cast<void>(new CTreeViewItem(
465 LexiconItem
, "FSA", FSA_DOC
, index
));
467 // XXX. HMMLexemes, HMM Corpus Tokens?
469 if (LexiconItem
!= 0)
470 if (m_lexicon
->GetDLHistory()->count() > 0)
471 static_cast<void>(new CTreeViewItem(
473 "Description length",
474 DESCRIPTION_LENGTH
));
476 // Suffixes or prefixes
478 Q3ListViewItem
* AffixesItem
= 0;
479 if (is_initial(affixLocation
)) {
480 // XXX. update to match suffix case
482 const int count
= lexicon
->GetPrefixes()->GetCount();
485 AffixesItem
= new CTreeViewItem(LexiconItem
,
486 QString("Prefixes %1").arg(
487 IntToStringWithCommas(count
)),
490 AffixesItem
->setOpen( true );
493 const int count
= lexicon
->GetSuffixes()->GetCount();
494 const int usecount
= lexicon
->GetSuffixes()->GetTotalUseCount();
495 lexicon
->GetSuffixes()->RecomputeCorpusCount();
496 const int corpuscount
= lexicon
->GetSuffixes()->GetCorpusCount();
499 AffixesItem
= new CTreeViewItem(LexiconItem
,
500 QString("Suffixes %1 : %2 : %3").arg(
501 IntToStringWithCommas(count
),
502 IntToStringWithCommas(usecount
),
503 IntToStringWithCommas(corpuscount
)),
506 AffixesItem
->setOpen(true);
512 const int count
= lexicon
->GetWords()->HowManyAreAnalyzed(
513 dummy
, status_display());
515 static_cast<void>(new CTreeViewItem(LexiconItem
,
516 QString("Analyzed words %1").arg(
517 IntToStringWithCommas(count
)),
523 Q3ListViewItem
* WordsItem
= 0;
525 const int count
= lexicon
->GetWords()->GetCount();
527 QString caption
= QString("Words %1 Z: %2")
528 .arg(IntToStringWithCommas(count
))
529 .arg(lexicon
->GetWords()->GetZ_Local());
530 WordsItem
= new CTreeViewItem(LexiconItem
,
531 caption
, WORDS
, index
);
532 WordsItem
->setOpen(true);
535 // END CONNECTED TO LexiconItem
536 // START CONNECTED TO WordsItem
538 const int count
= lexicon
->GetWords()->GetTrie()->GetCount();
540 if (lexicon
->GetWords()->GetReverseTrie() != 0) {
541 static_cast<void>(new CTreeViewItem(
543 QString("Reverse trie %1")
544 .arg(IntToStringWithCommas(count
)),
545 REVERSE_TRIE
, index
));
548 static_cast<void>(new CTreeViewItem(
550 QString("Forward trie %1")
551 .arg(IntToStringWithCommas(count
)),
557 // XXX. lexicon->GetVowels()?
560 const int tier1_bigrams
= lexicon
->GetWords()
561 ->GetPhonologicalContentTier1Bigrams();
562 // XXX. probably a typo.
563 if (tier1_bigrams
!= 0) {
564 static_cast<void>(new CTreeViewItem(
566 QString("Unigram description length %1")
567 .arg(IntToStringWithCommas(
569 ->GetPhonologicalContentUnigrams())),
570 UNIGRAM_INFORMATION
, index
));
573 if (tier1_bigrams
!= 0) {
574 static_cast<void>(new CTreeViewItem(
576 QString("Bigram description length %1")
577 .arg(IntToStringWithCommas(tier1_bigrams
)),
578 BIGRAM_INFORMATION
, index
));
582 if (const int distant_log_pr
=
583 lexicon
->GetWords()->GetDistantMI_Plog())
584 static_cast<void>(new CTreeViewItem(
586 QString("Distant MI model plog: %1")
587 .arg(IntToStringWithCommas(distant_log_pr
)),
588 BIGRAM_INFORMATION
, index
));
590 if (const int local_log_pr
=
591 lexicon
->GetWords()->GetLocalMI_Plog())
592 static_cast<void>(new CTreeViewItem(
594 QString("Local MI model plog: %1")
595 .arg(IntToStringWithCommas(local_log_pr
)),
596 BIGRAM_INFORMATION
, index
));
598 if (const double distant_denom
=
599 lexicon
->GetWords()->GetZ_Distant())
600 static_cast<void>(new CTreeViewItem(
602 QString("Z (distant model): %1")
604 BIGRAM_INFORMATION
, index
));
606 if (const double local_denom
=
607 lexicon
->GetWords()->GetZ_Local())
608 static_cast<void>(new CTreeViewItem(
610 QString("Z (local) : %1")
612 BIGRAM_INFORMATION
, index
));
614 // Phones inside words
616 if (CPhoneCollection
* phones
= lexicon
->GetWords()->GetPhones_Tier2()) {
617 const int count
= phones
->GetCount();
618 const int totalcount
= phones
->GetCorpusCount();
621 Q3ListViewItem
* Tier2Item
=
622 // owned by WordsItem
623 new CTreeViewItem(WordsItem
,
625 PHONES_Tier2
, index
);
626 Tier2Item
->setOpen(true);
628 static_cast<void>(new CTreeViewItem(Tier2Item
,
629 QString("Phones %1 : %2")
630 .arg(IntToStringWithCommas(count
),
631 IntToStringWithCommas(totalcount
)),
632 PHONES_Tier2
, index
));
635 CBiphoneCollection
* biphones
= phones
->GetMyBiphones();
636 const int biphone_count
= biphones
->count();
637 const int total_biphone_count
= biphones
->m_TotalCount
;
638 if (biphone_count
> 0) {
639 static_cast<void>(new CTreeViewItem(
641 QString("Biphones %1 : %2")
642 .arg(IntToStringWithCommas(biphone_count
),
643 IntToStringWithCommas(total_biphone_count
)),
644 BIPHONES_Tier2
, index
));
646 if (const int local_score
= lexicon
->GetWords()
647 ->GetTier2_LocalMI_Score())
648 static_cast<void>(new CTreeViewItem(
650 QString("Tier 2 Local MI score %1")
651 .arg(IntToStringWithCommas(
655 if (const int distant_score
= lexicon
->GetWords()
656 ->GetTier2_DistantMI_Score())
657 static_cast<void>(new CTreeViewItem(
659 QString("Tier 2 Distant MI score %1")
660 .arg(IntToStringWithCommas(
669 CPhoneCollection
* phones
=
670 lexicon
->GetWords()->GetPhones_Tier1_Skeleton();
671 const int count
= phones
->GetCount();
672 const int totalcount
= phones
->GetCorpusCount();
675 Q3ListViewItem
* Tier1Item
=
676 // owned by WordsItem
677 new CTreeViewItem(WordsItem
,
679 PHONES_Tier1_Skeleton
, index
);
680 Tier1Item
->setOpen(true);
682 static_cast<void>(new CTreeViewItem(
684 QString("Phones (skeleton) %1 : %2")
685 .arg(IntToStringWithCommas(count
),
686 IntToStringWithCommas(totalcount
)),
687 PHONES_Tier1_Skeleton
, index
));
689 CBiphoneCollection
* biphones
= phones
->GetMyBiphones();
690 const int biphone_count
= biphones
->count();
691 const int biphone_totalcount
= biphones
->m_TotalCount
;
692 if (biphone_count
> 0) {
693 static_cast<void>(new CTreeViewItem(
695 QString("Biphones (skeleton) %1 : %2")
696 .arg(IntToStringWithCommas(biphone_count
),
697 IntToStringWithCommas(biphone_totalcount
)),
698 BIPHONES_Tier1_Skeleton
, index
));
705 CPhoneCollection
* phones
= lexicon
->GetWords()->GetPhones();
706 const int count
= phones
->GetCount();
707 const int totalcount
= phones
->GetCorpusCount();
710 Q3ListViewItem
* Tier1Item
=
711 // owned by WordsItem
712 new CTreeViewItem(WordsItem
,
715 Tier1Item
->setOpen(true);
717 static_cast<void>(new CTreeViewItem(
719 QString("Phones %1 : %2")
720 .arg(IntToStringWithCommas(count
),
721 IntToStringWithCommas(totalcount
)),
724 CBiphoneCollection
* biphones
= phones
->GetMyBiphones();
725 const int biphone_count
= biphones
->count();
726 const int biphone_totalcount
= biphones
->m_TotalCount
;
727 if (biphone_count
> 0) {
728 static_cast<void>(new CTreeViewItem(
730 QString("Biphones %1 : %2")
731 .arg(IntToStringWithCommas(biphone_count
),
732 IntToStringWithCommas(biphone_totalcount
)),
737 // END CONNECTED TO WordsItem
739 // START CONNECTED TO AffixesItem
741 const int count
= lexicon
->GetStems()->GetCount();
743 static_cast<void>(new CTreeViewItem(
746 .arg(IntToStringWithCommas(count
)),
752 const int count
= lexicon
->GetSignatures()->GetCount();
754 static_cast<void>(new CTreeViewItem(
756 QString("Signatures %1")
757 .arg(IntToStringWithCommas(count
)),
762 if (LxPoSCollection
* parts_of_speech
= lexicon
->GetPOS()) {
763 const int count
= parts_of_speech
->count();
765 static_cast<void>(new CTreeViewItem(AffixesItem
,
766 QString("Parts of speech %1")
767 .arg(IntToStringWithCommas(count
)),