www.pudn.com > ChineseProcessing.rar > FreqCounter.h


// FreqCounter.h: interface for the CFreqCounter class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#if !defined(AFX_FREQCOUNTER_H__7FD0386C_7781_4758_9372_445ACEBBC476__INCLUDED_) 
#define AFX_FREQCOUNTER_H__7FD0386C_7781_4758_9372_445ACEBBC476__INCLUDED_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
#include "SentSeg.h" 
#include  
 
class CFreqCounter; 
 
// Array unit for counter 
struct AUCounter 
{ 
	ChChar ch; 
	UINT counter; 
	CFreqCounter * next; 
public: 
	static int CompareCounterUnit(const void * auc1, const void * auc2) 
	{ return (((AUCounter *)auc2)->counter - ((AUCounter *)auc1)->counter); }; 
}; 
 
// Tree unit for counter 
struct TUCounter 
{ 
	ChChar ch; 
	UINT counter; 
	TUCounter * left; 
	TUCounter * right; 
}; 
 
// Array Unit for mutual info 
struct AUMutual 
{ 
	ChChar ch[2]; 
	UINT c[2]; 
	UINT counter; 
	double mutual; 
	static double moffset; 
public: 
	static int CompareMutual(const void * aum1, const void * aum2) 
	{ 
		double d=((AUMutual *)aum1)->mutual - ((AUMutual *)aum2)->mutual; 
		if (d>0) 
			return 1; 
		else if (d<0) 
			return -1; 
		else 
			return 0; 
	}; 
	static void SetOffsetForMutual(double offset){ moffset=offset;}; 
	void CalculateMutual() 
	{ 
		mutual=log((double)(c[0]*c[1]/counter))+moffset; 
	}; 
}; 
 
 
class CFreqCounter   
{ 
public: 
	void OutputAllMutual(CFile&); 
	void InitThirdScan(); 
	void InitSecondScan(); 
	void OutputTrigramFrequency(CFile &, const void *, size_t); 
	void OutputBigramFrequency(CFile &, const void *, size_t); 
	void OutputUnigramFrequency(CFile &, const void *, size_t); 
	void PostThirdScan(); 
	void PostSecondScan(); 
	void PostFirstScan(); 
	void AddGram(ChChar, ChChar, ChChar); 
	void AddGram(ChChar, ChChar); 
	void AddGram(ChChar); 
	CFreqCounter(UINT); 
	virtual ~CFreqCounter(); 
	static ChChar chars[MAXNUMCHINESECHAR]; 
 
private: 
	UINT OutputTreeToArray(UINT, TUCounter *); 
	UINT CountUniqueGrams(TUCounter *); 
	UINT m_nSizeArray; 
	void ReleaseCounterTree(TUCounter *); 
	void InitCounterTree(TUCounter **, UINT, int, int); 
	static UINT InitChineseChars(); 
	AUCounter * m_aucArray; 
	TUCounter * m_tucRoot; 
	static UINT retvalue; 
}; 
 
#endif // !defined(AFX_FREQCOUNTER_H__7FD0386C_7781_4758_9372_445ACEBBC476__INCLUDED_)