示例#1
0
	TEST(RandomIterator, init) {

		int cnt;
		std::vector<int> values = {1,2,3,4,5,6};

		RandomIterator<int> it1(values, 1); it1.randomize();
		cnt = 0; for(int i : it1) {(void) i; ++cnt;} ASSERT_EQ(1, cnt);

		RandomIterator<int> it2(values, 2); it2.randomize();
		cnt = 0; for(int i: it2) {(void) i; ++cnt;} ASSERT_EQ(2, cnt);

		RandomIterator<int> it3(values, 3); it3.randomize();
		cnt = 0; for(int i: it3) {(void) i; ++cnt;} ASSERT_EQ(3, cnt);

		RandomIterator<int> it4(values, 4); it4.randomize();
		cnt = 0; for(int i: it4) {(void) i; ++cnt;} ASSERT_EQ(4, cnt);

		RandomIterator<int> it5(values, 5); it5.randomize();
		cnt = 0; for(int i: it5) {(void) i; ++cnt;} ASSERT_EQ(5, cnt);

		RandomIterator<int> it6(values, 6); it6.randomize();
		cnt = 0; for(int i: it6) {(void) i; ++cnt;} ASSERT_EQ(6, cnt);

	}
void LinguisticaMainWindow::updateTreeViewSlot()
{
  // Adapted from MFC version: CMyTree::UpdateUpperTree, CMyTree::UpdateStatistics

  int     count,    // used for various counts
          index;    // mini-lexicon index
  index = 0;
  count = 0;

//  bool      add = TRUE;

  CStem* pWord;

  Q3ListViewItem  * MiscItem      = NULL,
		  * MiscItem1       = NULL,
          * LexiconItem     = NULL,
          * WordsReadItem   = NULL,
          * PrefixesItem    = NULL,
          * SuffixesItem    = NULL,
          * WordsItem       = NULL,
 		  * CompoundsItem   = NULL,
          * ComponentItem   = NULL,
		  *	STRINGEDITITEM  = NULL,
		  * CorpusWordsItem = NULL;
		  
 
  // Clear the tree
  m_treeView->clear();
  m_treeView->setFont( GetFontPreference( "Main" ) );
  m_treeView->hideColumn(1);

//**************************************************************************************
// A NOTE ON THE ORGANIZATION OF THIS FUNCTION:
// The items are inserted into the tree in reverse order respective to their group.  They
// are organized by depth here, i.e. what is connected to the root is the first group,
// then do the groups of items connected to this first group, etc.  The only items that
// get their own name are those that have children.  The rest use MiscItem
//**************************************************************************************


//======================================================================================//
  // START CONNECTED DIRECTLY TO m_treeView
//======================================================================================//


	count = GetNumberOfTokens();
	if( count >= 0 )
	{
		MiscItem = new CTreeViewItem( m_treeView,
									  "Tokens requested: " + IntToStringWithCommas( count ),
									  TOKENS_REQUESTED );
		MiscItem->setSelectable(false);
	}  

//======================================================================================//

	if( m_lexicon->GetWords() && m_lexicon->GetMiniCount() )
	{
		count = m_lexicon->GetTokenCount();
		if ( count >= 0 )
		{
			WordsReadItem = new CTreeViewItem( m_treeView,
											   "Tokens read: " + IntToStringWithCommas( count ) );
			WordsReadItem->setSelectable(false);
			WordsReadItem->setOpen(true);
		}

//======================================================================================//

		LexiconItem = new CTreeViewItem( m_treeView,
						 "Lexicon : click items to display them" );
		LexiconItem->setSelectable(false);
		LexiconItem->setOpen(true);
	}

//======================================================================================//

  if ( m_projectDirectory.length()  )
  {
    MiscItem = new CTreeViewItem( m_treeView, "Project directory: " + m_projectDirectory );
    MiscItem->setSelectable(false);
  }
  else
  {
    MiscItem = new CTreeViewItem( m_treeView, "No project directory." );
    MiscItem->setSelectable(false);
  }

//======================================================================================//

  if ( m_logging )
  {
    MiscItem = new CTreeViewItem( m_treeView, "Log file (now on) " + GetLogFileName() );
    MiscItem->setSelectable(false);
  }
  else
  {
    MiscItem = new CTreeViewItem( m_treeView, "Log file (now off) " + GetLogFileName() );
    MiscItem->setSelectable(false);
  }

//=================================================================================================
  // END CONNECTED DIRECTLY TO m_treeView
  // START CONNECTED TO LexiconItem
//=================================================================================================

	if ( LexiconItem && m_lexicon->GetHMM() )
	{		
		MiscItem = new CTreeViewItem( LexiconItem,
									   "HMM",
									   HMM_Document);
		double dl = m_lexicon->GetHMM()->GetLogProbability();
		MiscItem1 = new CTreeViewItem(MiscItem,"HMM description length: " + IntToStringWithCommas(int( dl) )
									   );		
		MiscItem1 = new CTreeViewItem(MiscItem,
									  "Iterations: " + IntToStringWithCommas( m_lexicon->GetHMM()->m_NumberOfIterations )
									   );		
		MiscItem1 = new CTreeViewItem(MiscItem,
									  "Number of states: " + IntToStringWithCommas( m_lexicon->GetHMM()->m_countOfStates )
									   );		
	}
	MiscItem->setOpen(true);

//======================================================================================//

  if( LexiconItem )
  {
	  if( m_lexicon->GetDLHistory()->count() > 0 )
	  {
		 MiscItem = new CTreeViewItem( LexiconItem,
									   "Description length history",
									   DESCRIPTION_LENGTH_HISTORY );
	  }
  }

//////////////////////////////
//// StringEdit Display

	if ((LexiconItem != NULL) && (m_Words_InitialTemplates != NULL))
	{
		if ( m_Words_InitialTemplates ->GetCount() > 0)
		{
			STRINGEDITITEM = new CTreeViewItem( LexiconItem,
										  "StringEditDistanceTemplates: " + IntToStringWithCommas( 2 ), 
										  STRINGEDITDISTANCE, -1);

			count = m_Words_Templates ->GetCount();
			if ( count != 0)
			{
				MiscItem = new CTreeViewItem( STRINGEDITITEM,
										  "StringEdit_Templates: " + IntToStringWithCommas( count ), 
										  WORKINGSTRINGEDITTEMPLATES, -1);

			}

			count = m_Words_InitialTemplates ->GetCount();
			MiscItem = new CTreeViewItem( STRINGEDITITEM,
										  "StringEdit_InitialTemplates: " + IntToStringWithCommas( count ), 
										  INITIALSTRINGEDITTEMPLATES, -1);
		}
	}

		count = 0;
		Q3DictIterator<PrefixSet> it5( *m_lexicon->GetAllPrefixes() );
		for( ; it5.current(); ++it5 )
		{
			count += it5.current()->count();
		}
		if( count > 0 )
		{
			PrefixesItem = new CTreeViewItem( LexiconItem,
											  "All Prefixes " + IntToStringWithCommas( count ),
											  ALL_PREFIXES );
			PrefixesItem->setOpen( TRUE );
		}    
//======================================================================================//
		count = 0;
		Q3DictIterator<SuffixSet> it4( *m_lexicon->GetAllSuffixes() );
		for( ; it4.current(); ++it4 )
		{
			count += it4.current()->count();
		}
		if( count > 0 )
		{
			SuffixesItem = new CTreeViewItem( LexiconItem,
											  "All Suffixes " + IntToStringWithCommas( count ),
											  ALL_SUFFIXES );
			SuffixesItem->setOpen( TRUE );
		}
//======================================================================================//
		count = 0;
		Q3DictIterator<StemSet> it1( *m_lexicon->GetAllStems() );
		for( ; it1.current(); ++it1 )
		{
			count += it1.current()->count();
		}
		if( count > 0 )
		{
			MiscItem = new CTreeViewItem( LexiconItem,
										  "All Stems " + IntToStringWithCommas( count ),
										  ALL_STEMS );
		}
 //======================================================================================//
		count = 0;
		Q3DictIterator<StemSet> it2( *m_lexicon->GetAllWords() );
		for( ; it2.current(); ++it2 )
		{
			count += it2.current()->count();
		}

		if( count > 0 )
		{
			WordsItem = new CTreeViewItem( LexiconItem,
										  "All Words " + IntToStringWithCommas( count ),
										  ALL_WORDS );
			WordsItem->setOpen( TRUE );
		}	
//======================================================================================//
	  if( m_lexicon->GetMiniCount() )
	  {
		for( index = m_lexicon->GetMiniSize() - 1; index >= 0; index-- )
		{
			if( m_lexicon->GetMiniLexicon( index ) )
				MiscItem = GetMiniLexiconSubTree( LexiconItem, index );
		}
	  }
//======================================================================================//
		count = m_lexicon->GetCompounds()->GetCount();
		if( count > 0 )
		{
			CompoundsItem = new CTreeViewItem( LexiconItem,
											   "Compounds " + IntToStringWithCommas( count ),
											   COMPOUNDS );
			CompoundsItem->setOpen( TRUE );
            int count2 = m_lexicon->GetCompounds()->GetComponents()->GetSize();
            ComponentItem = new CTreeViewItem( CompoundsItem, "Components "+ IntToStringWithCommas (count2),
                                                COMPOUND_COMPONENTS);
		}
//======================================================================================//

	  count = m_lexicon->GetWords()->GetCount();
	  if( count > 0 )
	  {
		CorpusWordsItem = new CTreeViewItem( LexiconItem,
											 "Corpus Words " + IntToStringWithCommas( count ),
											 CORPUS_WORDS );
		CorpusWordsItem->setOpen( TRUE );
	  }
//=================================================================================================
  // END CONNECTED TO LexiconItem
  // START CONNECTED TO CorpusWordsItem
//=================================================================================================

	count = 0;
	if( CorpusWordsItem )
	{

		CCorpusWord* pCorpusWord;
		CCorpusWordCollection* pWords = m_lexicon->GetWords();

		pWords->Sort( KEY );

		for( int i = 0; i < pWords->GetCount(); i++ )
		{
			pCorpusWord = pWords->GetAtSort(i);

			if( pCorpusWord->Size() > 1 )
			{
				count++;
			}
		}

		if( count > 0 )
		{
			MiscItem = new CTreeViewItem( CorpusWordsItem,
										  "Analyzed " + IntToStringWithCommas( count ),
										  ANALYZED_CORPUS_WORDS );
		}
	}
 
//=================================================================================================
  // END CONNECTED TO CorpusWordsItem
  // START CONNECTED TO WordsItem
//=================================================================================================

	count = 0;

	bool analyzed_exists;
	Q3DictIterator<StemSet> it3( *m_lexicon->GetAllWords() );
        for( ; it3.current(); ++it3 )
	{
            analyzed_exists = FALSE;
            //for( pWord = it3.current()->first(); pWord; pWord = it3.current()->next() )
            for (int z = 0; z < it3.current()->size(); z++)
            {
                pWord = it3.current()->at(z);
                if( pWord->Size() > 1 )
                {
                        analyzed_exists = TRUE;
                        count++;
                }
            }
	}

	if( count > 0 )
	{
		MiscItem = new CTreeViewItem( WordsItem,
									  "Analyzed " + IntToStringWithCommas( count ),
									  ALL_ANALYZED_WORDS );
	}

//=================================================================================================
  // END CONNECTED TO WordsItem
  // START CONNECTED TO SuffixesItem
//=================================================================================================

	count = 0;

	Q3DictIterator<SignatureSet> it7( *m_lexicon->GetAllSuffixSigs() );
	for( ; it7.current(); ++it7 )
	{
		count += it7.current()->count();
	}
	if( count > 0 )
	{
		MiscItem = new CTreeViewItem( SuffixesItem,
									  "Signatures " + IntToStringWithCommas( count ),
									  ALL_SUFFIX_SIGNATURES );
	}

//=================================================================================================
  // END CONNECTED TO SuffixesItem
  // START CONNECTED TO PrefixesItem
//=================================================================================================

	count = 0;

	Q3DictIterator<SignatureSet> it6( *m_lexicon->GetAllPrefixSigs() );
	for( ; it6.current(); ++it6 )
	{
		count += it6.current()->count();
	}
	if( count > 0 )
	{
		MiscItem = new CTreeViewItem( PrefixesItem,
									  "Signatures " + IntToStringWithCommas( count ),
									  ALL_PREFIX_SIGNATURES );
	}

//=================================================================================================
  // END CONNECTED TO PrefixesItem
  // START CONNECTED TO WordsReadItem
//=================================================================================================

	if( WordsReadItem )
	{
		if( m_lexicon->GetWords() )
		{
			count = m_lexicon->GetWords()->GetCount();
			if( count > 0 )
			{
				MiscItem = new CTreeViewItem( WordsReadItem,
											  "Distinct types read: " + IntToStringWithCommas( count ) );
				MiscItem->setSelectable(false);
			}
		} 

//======================================================================================//

		count = m_lexicon->GetCorpusCount();
		if( count >= 0 )
		{
			MiscItem = new CTreeViewItem( WordsReadItem,
										  "Tokens included: " + IntToStringWithCommas( count ) );
			MiscItem->setSelectable(false);
		} 
	}


//=================================================================================================
  // END CONNECTED TO WordsReadItem
  // START CONNECTED TO CompoundsItem
//=================================================================================================

	count = m_lexicon->GetLinkers()->GetCount();
	if( count > 0 )
	{
		MiscItem = new CTreeViewItem( CompoundsItem,
									  "Linkers " + IntToStringWithCommas( count ),
									  LINKERS, index );
	}
}