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);
114 // add FSA at Lexixon level
115 if(m_lexicon
->GetFSA())
116 static_cast<void>(new CTreeViewItem(LexiconItem
, "FSA", FSA_DOC
, index
));
119 //======================================================================================//
121 if ( m_projectDirectory
.length() )
123 MiscItem
= new CTreeViewItem( m_treeView
, "Project directory: " + m_projectDirectory
);
124 MiscItem
->setSelectable(false);
128 MiscItem
= new CTreeViewItem( m_treeView
, "No project directory." );
129 MiscItem
->setSelectable(false);
132 //======================================================================================//
135 if ( m_corpusFileName
.length() )
137 MiscItem
= new CTreeViewItem( m_treeView
, "Corpus file: " + m_corpusFileName
);
138 MiscItem
->setSelectable(false);
141 //======================================================================================//
145 MiscItem
= new CTreeViewItem( m_treeView
, "Log file (now on) " + GetLogFileName() );
146 MiscItem
->setSelectable(false);
150 MiscItem
= new CTreeViewItem( m_treeView
, "Log file (now off) " + GetLogFileName() );
151 MiscItem
->setSelectable(false);
154 //=================================================================================================
155 // END CONNECTED DIRECTLY TO m_treeView
156 // START CONNECTED TO LexiconItem
157 //=================================================================================================
159 if ( LexiconItem
&& m_lexicon
->GetHMM() )
161 MiscItem
= new CTreeViewItem( LexiconItem
,
164 double dl
= m_lexicon
->GetHMM()->GetLogProbability();
165 MiscItem1
= new CTreeViewItem(MiscItem
,"HMM description length: " + IntToStringWithCommas(int( dl
) )
167 MiscItem1
= new CTreeViewItem(MiscItem
,
168 "Iterations: " + IntToStringWithCommas( m_lexicon
->GetHMM()->m_NumberOfIterations
)
170 MiscItem1
= new CTreeViewItem(MiscItem
,
171 "Number of states: " + IntToStringWithCommas( m_lexicon
->GetHMM()->m_countOfStates
)
174 MiscItem
->setOpen(true);
176 //======================================================================================//
180 if( m_lexicon
->GetDLHistory()->count() > 0 )
182 MiscItem
= new CTreeViewItem( LexiconItem
,
183 "Description length history",
184 DESCRIPTION_LENGTH_HISTORY
);
188 //////////////////////////////
189 //// StringEdit Display
191 if ((LexiconItem
!= NULL
) && (m_Words_InitialTemplates
!= NULL
))
193 if ( m_Words_InitialTemplates
->GetCount() > 0)
195 STRINGEDITITEM
= new CTreeViewItem( LexiconItem
,
196 "StringEditDistanceTemplates: " + IntToStringWithCommas( 2 ),
197 STRINGEDITDISTANCE
, -1);
199 count
= m_Words_Templates
->GetCount();
202 MiscItem
= new CTreeViewItem( STRINGEDITITEM
,
203 "StringEdit_Templates: " + IntToStringWithCommas( count
),
204 WORKINGSTRINGEDITTEMPLATES
, -1);
208 count
= m_Words_InitialTemplates
->GetCount();
209 MiscItem
= new CTreeViewItem( STRINGEDITITEM
,
210 "StringEdit_InitialTemplates: " + IntToStringWithCommas( count
),
211 INITIALSTRINGEDITTEMPLATES
, -1);
216 Q3DictIterator
<PrefixSet
> it5( *m_lexicon
->GetAllPrefixes() );
217 for( ; it5
.current(); ++it5
)
219 count
+= it5
.current()->count();
223 PrefixesItem
= new CTreeViewItem( LexiconItem
,
224 "All Prefixes " + IntToStringWithCommas( count
),
226 PrefixesItem
->setOpen( TRUE
);
228 //======================================================================================//
230 Q3DictIterator
<SuffixSet
> it4( *m_lexicon
->GetAllSuffixes() );
231 for( ; it4
.current(); ++it4
)
233 count
+= it4
.current()->count();
237 SuffixesItem
= new CTreeViewItem( LexiconItem
,
238 "All Suffixes " + IntToStringWithCommas( count
),
240 SuffixesItem
->setOpen( TRUE
);
242 //======================================================================================//
244 Q3DictIterator
<StemSet
> it1( *m_lexicon
->GetAllStems() );
245 for( ; it1
.current(); ++it1
)
247 count
+= it1
.current()->count();
251 MiscItem
= new CTreeViewItem( LexiconItem
,
252 "All Stems " + IntToStringWithCommas( count
),
255 //======================================================================================//
257 Q3DictIterator
<StemSet
> it2( *m_lexicon
->GetAllWords() );
258 for( ; it2
.current(); ++it2
)
260 count
+= it2
.current()->count();
265 WordsItem
= new CTreeViewItem( LexiconItem
,
266 "All Words " + IntToStringWithCommas( count
),
268 WordsItem
->setOpen( TRUE
);
270 //======================================================================================//
271 if( m_lexicon
->GetMiniCount() )
273 for( index
= m_lexicon
->GetMiniSize() - 1; index
>= 0; index
-- )
275 if( m_lexicon
->GetMiniLexicon( index
) )
276 MiscItem
= GetMiniLexiconSubTree( LexiconItem
, index
);
279 //======================================================================================//
280 count
= m_lexicon
->GetCompounds()->GetCount();
283 CompoundsItem
= new CTreeViewItem( LexiconItem
,
284 "Compounds " + IntToStringWithCommas( count
),
286 CompoundsItem
->setOpen( TRUE
);
287 int count2
= m_lexicon
->GetCompounds()->GetComponents()->GetSize();
288 ComponentItem
= new CTreeViewItem( CompoundsItem
, "Components "+ IntToStringWithCommas (count2
),
289 COMPOUND_COMPONENTS
);
291 //======================================================================================//
293 count
= m_lexicon
->GetWords()->GetCount();
296 CorpusWordsItem
= new CTreeViewItem( LexiconItem
,
297 "Corpus Words " + IntToStringWithCommas( count
),
299 CorpusWordsItem
->setOpen( TRUE
);
301 //=================================================================================================
302 // END CONNECTED TO LexiconItem
303 // START CONNECTED TO CorpusWordsItem
304 //=================================================================================================
307 if( CorpusWordsItem
)
310 CCorpusWord
* pCorpusWord
;
311 CCorpusWordCollection
* pWords
= m_lexicon
->GetWords();
315 for( int i
= 0; i
< pWords
->GetCount(); i
++ )
317 pCorpusWord
= pWords
->GetAtSort(i
);
319 if( pCorpusWord
->Size() > 1 )
327 MiscItem
= new CTreeViewItem( CorpusWordsItem
,
328 "Analyzed " + IntToStringWithCommas( count
),
329 ANALYZED_CORPUS_WORDS
);
333 //=================================================================================================
334 // END CONNECTED TO CorpusWordsItem
335 // START CONNECTED TO WordsItem
336 //=================================================================================================
340 bool analyzed_exists
;
341 Q3DictIterator
<StemSet
> it3( *m_lexicon
->GetAllWords() );
342 for( ; it3
.current(); ++it3
)
344 analyzed_exists
= FALSE
;
345 //for( pWord = it3.current()->first(); pWord; pWord = it3.current()->next() )
346 for (int z
= 0; z
< it3
.current()->size(); z
++)
348 pWord
= it3
.current()->at(z
);
349 if( pWord
->Size() > 1 )
351 analyzed_exists
= TRUE
;
359 MiscItem
= new CTreeViewItem( WordsItem
,
360 "Analyzed " + IntToStringWithCommas( count
),
361 ALL_ANALYZED_WORDS
);
364 //=================================================================================================
365 // END CONNECTED TO WordsItem
366 // START CONNECTED TO SuffixesItem
367 //=================================================================================================
371 Q3DictIterator
<SignatureSet
> it7( *m_lexicon
->GetAllSuffixSigs() );
372 for( ; it7
.current(); ++it7
)
374 count
+= it7
.current()->count();
378 MiscItem
= new CTreeViewItem( SuffixesItem
,
379 "Signatures " + IntToStringWithCommas( count
),
380 ALL_SUFFIX_SIGNATURES
);
383 //=================================================================================================
384 // END CONNECTED TO SuffixesItem
385 // START CONNECTED TO PrefixesItem
386 //=================================================================================================
390 Q3DictIterator
<SignatureSet
> it6( *m_lexicon
->GetAllPrefixSigs() );
391 for( ; it6
.current(); ++it6
)
393 count
+= it6
.current()->count();
397 MiscItem
= new CTreeViewItem( PrefixesItem
,
398 "Signatures " + IntToStringWithCommas( count
),
399 ALL_PREFIX_SIGNATURES
);
402 //=================================================================================================
403 // END CONNECTED TO PrefixesItem
404 // START CONNECTED TO WordsReadItem
405 //=================================================================================================
409 if( m_lexicon
->GetWords() )
411 count
= m_lexicon
->GetWords()->GetCount();
414 MiscItem
= new CTreeViewItem( WordsReadItem
,
415 "Distinct types read: " + IntToStringWithCommas( count
) );
416 MiscItem
->setSelectable(false);
420 //======================================================================================//
422 count
= m_lexicon
->GetCorpusCount();
425 MiscItem
= new CTreeViewItem( WordsReadItem
,
426 "Tokens included: " + IntToStringWithCommas( count
) );
427 MiscItem
->setSelectable(false);
432 //=================================================================================================
433 // END CONNECTED TO WordsReadItem
434 // START CONNECTED TO CompoundsItem
435 //=================================================================================================
437 count
= m_lexicon
->GetLinkers()->GetCount();
440 MiscItem
= new CTreeViewItem( CompoundsItem
,
441 "Linkers " + IntToStringWithCommas( count
),
448 Q3ListViewItem
* LinguisticaMainWindow::GetMiniLexiconSubTree(
449 Q3ListViewItem
* parent
, int index
)
451 CMiniLexicon
* lexicon
= m_lexicon
->GetMiniLexicon(index
);
456 enum eAffixLocation affixLocation
= lexicon
->GetAffixLocation();
458 // Items are inserted into the tree in reverse order
459 // respective to their group. They are organized by depth here,
460 // i.e. what is connected to the root is the first group,
461 // then do the groups of items connected to this first group, etc.
462 // The only items that get their own name are those that have children.
464 Q3ListViewItem
* LexiconItem
=
466 new CTreeViewItem(parent
,
468 m_lexicon
->GetActiveMiniIndex() == index
469 ? "Mini-Lexicon %1\t**ACTIVE**"
472 MINI_LEXICON
, index
);
473 LexiconItem
->setSelectable(false);
474 LexiconItem
->setOpen(true);
475 // START CONNECTED TO LexiconItem
476 if (m_lexicon
->GetFSA() != 0) //get from lexicon, not mini-lexicon
477 static_cast<void>(new CTreeViewItem(
478 LexiconItem
, "FSA", FSA_DOC
, index
));
480 // XXX. HMMLexemes, HMM Corpus Tokens?
482 if (LexiconItem
!= 0)
483 if (m_lexicon
->GetDLHistory()->count() > 0)
484 static_cast<void>(new CTreeViewItem(
486 "Description length",
487 DESCRIPTION_LENGTH
));
489 // Suffixes or prefixes
491 Q3ListViewItem
* AffixesItem
= 0;
492 if (is_initial(affixLocation
)) {
493 // XXX. update to match suffix case
495 const int count
= lexicon
->GetPrefixes()->GetCount();
498 AffixesItem
= new CTreeViewItem(LexiconItem
,
499 QString("Prefixes %1").arg(
500 IntToStringWithCommas(count
)),
503 AffixesItem
->setOpen( true );
506 const int count
= lexicon
->GetSuffixes()->GetCount();
507 const int usecount
= lexicon
->GetSuffixes()->GetTotalUseCount();
508 lexicon
->GetSuffixes()->RecomputeCorpusCount();
509 const int corpuscount
= lexicon
->GetSuffixes()->GetCorpusCount();
512 AffixesItem
= new CTreeViewItem(LexiconItem
,
513 QString("Suffixes %1 : %2 : %3").arg(
514 IntToStringWithCommas(count
),
515 IntToStringWithCommas(usecount
),
516 IntToStringWithCommas(corpuscount
)),
519 AffixesItem
->setOpen(true);
525 const int count
= lexicon
->GetWords()->HowManyAreAnalyzed(
526 dummy
, status_display());
528 static_cast<void>(new CTreeViewItem(LexiconItem
,
529 QString("Analyzed words %1").arg(
530 IntToStringWithCommas(count
)),
536 Q3ListViewItem
* WordsItem
= 0;
538 const int count
= lexicon
->GetWords()->GetCount();
540 QString caption
= QString("Words %1 Z: %2")
541 .arg(IntToStringWithCommas(count
))
542 .arg(lexicon
->GetWords()->GetZ_Local());
543 WordsItem
= new CTreeViewItem(LexiconItem
,
544 caption
, WORDS
, index
);
545 WordsItem
->setOpen(true);
548 // END CONNECTED TO LexiconItem
549 // START CONNECTED TO WordsItem
551 const int count
= lexicon
->GetWords()->GetTrie()->GetCount();
553 if (lexicon
->GetWords()->GetReverseTrie() != 0) {
554 static_cast<void>(new CTreeViewItem(
556 QString("Reverse trie %1")
557 .arg(IntToStringWithCommas(count
)),
558 REVERSE_TRIE
, index
));
561 static_cast<void>(new CTreeViewItem(
563 QString("Forward trie %1")
564 .arg(IntToStringWithCommas(count
)),
570 // XXX. lexicon->GetVowels()?
573 const int tier1_bigrams
= lexicon
->GetWords()
574 ->GetPhonologicalContentTier1Bigrams();
575 // XXX. probably a typo.
576 if (tier1_bigrams
!= 0) {
577 static_cast<void>(new CTreeViewItem(
579 QString("Unigram description length %1")
580 .arg(IntToStringWithCommas(
582 ->GetPhonologicalContentUnigrams())),
583 UNIGRAM_INFORMATION
, index
));
586 if (tier1_bigrams
!= 0) {
587 static_cast<void>(new CTreeViewItem(
589 QString("Bigram description length %1")
590 .arg(IntToStringWithCommas(tier1_bigrams
)),
591 BIGRAM_INFORMATION
, index
));
595 if (const int distant_log_pr
=
596 lexicon
->GetWords()->GetDistantMI_Plog())
597 static_cast<void>(new CTreeViewItem(
599 QString("Distant MI model plog: %1")
600 .arg(IntToStringWithCommas(distant_log_pr
)),
601 BIGRAM_INFORMATION
, index
));
603 if (const int local_log_pr
=
604 lexicon
->GetWords()->GetLocalMI_Plog())
605 static_cast<void>(new CTreeViewItem(
607 QString("Local MI model plog: %1")
608 .arg(IntToStringWithCommas(local_log_pr
)),
609 BIGRAM_INFORMATION
, index
));
611 if (const double distant_denom
=
612 lexicon
->GetWords()->GetZ_Distant())
613 static_cast<void>(new CTreeViewItem(
615 QString("Z (distant model): %1")
617 BIGRAM_INFORMATION
, index
));
619 if (const double local_denom
=
620 lexicon
->GetWords()->GetZ_Local())
621 static_cast<void>(new CTreeViewItem(
623 QString("Z (local) : %1")
625 BIGRAM_INFORMATION
, index
));
627 // Phones inside words
629 if (CPhoneCollection
* phones
= lexicon
->GetWords()->GetPhones_Tier2()) {
630 const int count
= phones
->GetCount();
631 const int totalcount
= phones
->GetCorpusCount();
634 Q3ListViewItem
* Tier2Item
=
635 // owned by WordsItem
636 new CTreeViewItem(WordsItem
,
638 PHONES_Tier2
, index
);
639 Tier2Item
->setOpen(true);
641 static_cast<void>(new CTreeViewItem(Tier2Item
,
642 QString("Phones %1 : %2")
643 .arg(IntToStringWithCommas(count
),
644 IntToStringWithCommas(totalcount
)),
645 PHONES_Tier2
, index
));
648 CBiphoneCollection
* biphones
= phones
->GetMyBiphones();
649 const int biphone_count
= biphones
->count();
650 const int total_biphone_count
= biphones
->m_TotalCount
;
651 if (biphone_count
> 0) {
652 static_cast<void>(new CTreeViewItem(
654 QString("Biphones %1 : %2")
655 .arg(IntToStringWithCommas(biphone_count
),
656 IntToStringWithCommas(total_biphone_count
)),
657 BIPHONES_Tier2
, index
));
659 if (const int local_score
= lexicon
->GetWords()
660 ->GetTier2_LocalMI_Score())
661 static_cast<void>(new CTreeViewItem(
663 QString("Tier 2 Local MI score %1")
664 .arg(IntToStringWithCommas(
668 if (const int distant_score
= lexicon
->GetWords()
669 ->GetTier2_DistantMI_Score())
670 static_cast<void>(new CTreeViewItem(
672 QString("Tier 2 Distant MI score %1")
673 .arg(IntToStringWithCommas(
682 CPhoneCollection
* phones
=
683 lexicon
->GetWords()->GetPhones_Tier1_Skeleton();
684 const int count
= phones
->GetCount();
685 const int totalcount
= phones
->GetCorpusCount();
688 Q3ListViewItem
* Tier1Item
=
689 // owned by WordsItem
690 new CTreeViewItem(WordsItem
,
692 PHONES_Tier1_Skeleton
, index
);
693 Tier1Item
->setOpen(true);
695 static_cast<void>(new CTreeViewItem(
697 QString("Phones (skeleton) %1 : %2")
698 .arg(IntToStringWithCommas(count
),
699 IntToStringWithCommas(totalcount
)),
700 PHONES_Tier1_Skeleton
, index
));
702 CBiphoneCollection
* biphones
= phones
->GetMyBiphones();
703 const int biphone_count
= biphones
->count();
704 const int biphone_totalcount
= biphones
->m_TotalCount
;
705 if (biphone_count
> 0) {
706 static_cast<void>(new CTreeViewItem(
708 QString("Biphones (skeleton) %1 : %2")
709 .arg(IntToStringWithCommas(biphone_count
),
710 IntToStringWithCommas(biphone_totalcount
)),
711 BIPHONES_Tier1_Skeleton
, index
));
718 CPhoneCollection
* phones
= lexicon
->GetWords()->GetPhones();
719 const int count
= phones
->GetCount();
720 const int totalcount
= phones
->GetCorpusCount();
723 Q3ListViewItem
* Tier1Item
=
724 // owned by WordsItem
725 new CTreeViewItem(WordsItem
,
728 Tier1Item
->setOpen(true);
730 static_cast<void>(new CTreeViewItem(
732 QString("Phones %1 : %2")
733 .arg(IntToStringWithCommas(count
),
734 IntToStringWithCommas(totalcount
)),
737 CBiphoneCollection
* biphones
= phones
->GetMyBiphones();
738 const int biphone_count
= biphones
->count();
739 const int biphone_totalcount
= biphones
->m_TotalCount
;
740 if (biphone_count
> 0) {
741 static_cast<void>(new CTreeViewItem(
743 QString("Biphones %1 : %2")
744 .arg(IntToStringWithCommas(biphone_count
),
745 IntToStringWithCommas(biphone_totalcount
)),
750 // END CONNECTED TO WordsItem
752 // START CONNECTED TO AffixesItem
754 const int count
= lexicon
->GetStems()->GetCount();
756 static_cast<void>(new CTreeViewItem(
759 .arg(IntToStringWithCommas(count
)),
765 const int count
= lexicon
->GetSignatures()->GetCount();
767 static_cast<void>(new CTreeViewItem(
769 QString("Signatures %1")
770 .arg(IntToStringWithCommas(count
)),
775 if (LxPoSCollection
* parts_of_speech
= lexicon
->GetPOS()) {
776 const int count
= parts_of_speech
->count();
778 static_cast<void>(new CTreeViewItem(AffixesItem
,
779 QString("Parts of speech %1")
780 .arg(IntToStringWithCommas(count
)),