📄 pageinit.cpp
字号:
// PageInit.cpp : implementation file
//
#include "stdafx.h"
#include "HikerWBSet.h"
#include "PageInit.h"
#include "MessWnd.h"
#include <AFXTEMPL.H>
#include "softkeyboard.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define LINE_LEN 256
#define CODE_LEN 20
#define WORD_LEN 21
//#define WORD_NUM 65536
#define POST_SUM 0.9f
#define AUTOADD2CCODE TRUE
#define DEFAULT_PRIOR 1.0f
#define TRANS_SUMLMT 0.6f //how much probabilitie assigned to exist words
struct CLItem
{
CString code;
int numw; //duplicate word number
int numw2; //duplicate word number including binary code word
CLItem ()
{
code = "";
numw = 0;
numw2 = 0;
}
CLItem (CString cd, int nw, int nw2)
{
code = cd;
numw = nw;
numw2 = nw2;
}
};
struct WLItem
{
CString word;
float pp;
WLItem ()
{
word = "";
pp = 0.0f;
}
WLItem (CString wd, float p)
{
word = wd;
pp = p;
}
};
struct CWLItem
{
CString code;
CString word;
float post; //人为设定一初始后验概率
float post2; //人为设定一初始后验概率
BOOL c2style; //二元码扩展条目
CWLItem ()
{
code = "";
word = "";
post = 0.0f;
post2 = 0.0f;
c2style = FALSE;
}
CWLItem (CString cd, CString wd, float p, float p2, BOOL c2s)
{
code = cd;
word = wd;
post = p;
post2 = p2;
c2style = c2s;
}
};
struct WCLItem
{
CString word;
CString code;
float cp; //人为设定一初始后验概率
float cp2; //人为设定一初始后验概率
BOOL c2style;
WCLItem ()
{
word = "";
code = "";
cp = 0.0f;
cp2 = 0.0f;
c2style = FALSE;
}
WCLItem (CString wd, CString cd, float p, float p2, BOOL c2s)
{
word = wd;
code = cd;
cp = p;
cp2 = p2;
c2style = c2s;
}
};
struct WWLItem
{
CString word;
CString wordc;
float tp; //人为设定一初始后验概率
WWLItem ()
{
word = "";
wordc = "";
tp = 0.0f;
}
WWLItem (CString wd, CString wdc, float p)
{
word = wd;
wordc = wdc;
tp = p;
}
};
//first level words
static unsigned char p1CWord[] = "工了以在有地一上不是中国同民为这我的要和产发人经主";
static unsigned char gKeyArr[SOFTKEYBOARD_NUM*2][SOFTKEYBOARD_LEN] = {
/*PC keyboard*/
{
SOFTKEY_PCC
},
{
SOFTKEY_PCL
},
/*Greece letter*/
{
SOFTKEY_GLC
},
{
SOFTKEY_GLL
},
/*Russia letter*/
{
SOFTKEY_RLC
},
{
SOFTKEY_RLL
},
/*chinese spell letter*/
{
SOFTKEY_NON
},
{
SOFTKEY_CSL
},
/*phonetic notation*/
{
SOFTKEY_NON
},
{
SOFTKEY_CPN
},
/*Japanese hiragana */
{
SOFTKEY_JHC
},
{
SOFTKEY_JHL
},
/*Japanese katakana*/
{
SOFTKEY_JKC
},
{
SOFTKEY_JKL
},
/*punctuation*/
{
SOFTKEY_NON
},
{
SOFTKEY_PCT
},
/*serial number*/
{
SOFTKEY_SNC
},
{
SOFTKEY_SNL
},
/*mathematics notation*/
{
SOFTKEY_NON
},
{
SOFTKEY_MAT
},
/*special notation*/
{
SOFTKEY_NON
},
{
SOFTKEY_SPC
},
/*全角字符*/
{
SOFTKEY_SBC
},
{
SOFTKEY_SBL
},
};
/////////////////////////////////////////////////////////////////////////////
// CPageInit property page
IMPLEMENT_DYNCREATE(CPageInit, CPropertyPage)
CPageInit::CPageInit() : CPropertyPage(CPageInit::IDD)
{
//{{AFX_DATA_INIT(CPageInit)
m_csFileName = _T("");
m_csFileName2 = _T("");
//}}AFX_DATA_INIT
}
CPageInit::~CPageInit()
{
}
void CPageInit::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPageInit)
DDX_Text(pDX, IDC_EDIT_FILENAME, m_csFileName);
DDV_MaxChars(pDX, m_csFileName, 256);
DDX_Text(pDX, IDC_EDIT_FILENAME2, m_csFileName2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPageInit, CPropertyPage)
//{{AFX_MSG_MAP(CPageInit)
ON_BN_CLICKED(IDC_BUTTON_CONVERT, OnButtonConvert)
ON_BN_CLICKED(IDC_BUTTON_FILEOPEN, OnButtonFileopen)
ON_BN_CLICKED(IDC_BUTTON_FILEOPEN2, OnButtonFileopen2)
ON_EN_CHANGE(IDC_EDIT_FILENAME, OnChangeEditFilename)
ON_EN_CHANGE(IDC_EDIT_FILENAME2, OnChangeEditFilename2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPageInit message handlers
static int ReadLine(CFile* file, unsigned char* buffl)
{
unsigned char c;
unsigned char* bp = buffl;
int len = 0;
for ( ; file->Read(&c, 1); )
{
if (c == 13)
{
file->Read(&c, 1); //skip char(10)
break;
}
else
{
*(bp++) = c;
len++;
}
}
return len;
}
static int ReadCode(unsigned char*& blp,unsigned char* buffc)
{
unsigned char c;
unsigned char* bcp = buffc;
int i = 0;
for ( ; ; )
{
c = *(blp++);
if (c == 32)
break;
else if (c >= 'a' && c <= 'z')
{
*(bcp++) = c;
}
if (bcp - buffc > CODE_LEN - 1)
break;
}
return bcp - buffc;
}
static int ReadWord(unsigned char*& blp,unsigned char* buffw)
{
unsigned char c;
unsigned char* bwp = buffw;
int len = 0;
int fstbyte = 1; //mark for double byte chinese
int i = 0;
for ( ; ; )
{
c = *(blp++);
if (c == 0)
break;
else if (c == 32 && (bwp - buffw) != 0)
break;
else //???
{
if (c >= 128 && fstbyte == 1) //first byte should be no less than 128
{
*(bwp++) = c;
fstbyte = 0;
}
else if (fstbyte == 0)
{
*(bwp++) = c;
fstbyte = 1;
}
if (bwp-buffw > WORD_LEN-1)
break;
}
}
return bwp - buffw;
}
static int CalcLineNum(CFile* file)
{
int numl = 0;
unsigned char c;
DWORD oldpos = file->GetPosition();
for ( ;; )
{
if (file->Read(&c, 1))
{
if (c == 10)
numl++;
}
else
break;
}
file->Seek(oldpos, CFile::begin);
return numl;
}
static int GetCodeId(CString code)
{
unsigned char c;
int id = 0;
int len = min(code.GetLength(), 4);
for (int i = 0; i < len; i++)
{
c = code.GetAt(i) - 'a'+1;
id += (c << (5*i));
}
return id;
}
static int GetWordId(CString word)
{
unsigned char c;
int id = 0;
int len = 2;
for (int i = 0; i < len; i++)
{
c = word.GetAt(i);
id += (c << (i<<3)); //8*i
}
return id;
}
static BOOL Is1CWord(CString last_strw)
{
unsigned char c1, c2;
if (2 != last_strw.GetLength())
return FALSE;
c1 = last_strw[0];
c2 = last_strw[1];
for (int i = 0; i < 50; i += 2)
{
if (c1 == p1CWord[i] && c2 == p1CWord[i+1])
return TRUE;
}
return FALSE;
}
//generate next speical code according to the given code.
//special code is leaded by character 'z' and generated automatically, which range is from zaaa to zyyy
static void NextSpcCode(CString& csSpcCode)
{
for (int i = 3; i > 0; i--)
{
if (csSpcCode[i] < 'y')
{
csSpcCode.SetAt(i, csSpcCode[i]+1);
break;
}
else
{
for (int j = i; j < 4; j++)
csSpcCode.SetAt(j, 'a');
}
}
}
//find the code's iword-th position in code-word table
static POSITION CWFind(CString code, CString word,
CList<CWLItem, CWLItem&> *listcw,
CMap<int, int&, POSITION, POSITION&> *cwidx)
{
CWLItem item;
POSITION pos = 0;
int id = GetCodeId(code);
cwidx->Lookup(id, pos);
for( ; pos; listcw->GetNext(pos))
{
item = listcw->GetAt(pos);
if (item.code != code)
break;
if (item.word == word)
return pos;
}
return FALSE;
}
//find the code-word item in code-word table.
//if the item not found, return FALSE, outherwise, TRUE
//posloc gives the position when found,
//if the code exists, posloc gives the code's the last appearing position,
//otherwise, it gives last appearing position+1, or 0;
static BOOL CWLocate(CString code, CString word,
CList<CWLItem, CWLItem&> *listcw,
CMap<int, int&, POSITION, POSITION&> *cwidx, POSITION& posloc)
{
posloc = 0;
int id = GetCodeId(code);
cwidx->Lookup(id, posloc);
for (; posloc; listcw->GetNext(posloc))
{
CWLItem item = listcw->GetAt(posloc);
if ( item.code != code)
break;
else if (item.word == word)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -