main.cpp
上传用户:panfucai
上传日期:2022-05-28
资源大小:4678k
文件大小:3k
- # include "main.h"
- # define MAXPAGECOUNT 1000
- CRITICAL_SECTION cs;
- PDICTABLE pDic = NULL, pStopwordsDic = NULL, pSurnamesDic = NULL;
- char strCurrPath[1000];
- PSTRTABLE pTable = NULL, pInvDoc = NULL;
- int main()
- {
- //PWORDLIST pLst;
- char *pstrDicPath;
- char *pstrResultPath;
- DWORD dwStartTime = 0, dwEndTime = 0;
- dwStartTime = GetTickCount();
- //char *pstrPathPrefix;
- //char *pstrHTMLPath;
- HANDLE h[2];
- // Initialization of Critical Sections
- InitializeCriticalSection(&cs);
- InitializeCriticalSection(&csModifyStrTable);
- getcwd(strCurrPath, 1000);
- pstrDicPath = StrConcat(strCurrPath, "\Dict");
- cout<<"...Loading dictionary...";
- preMatch(pDic, pStopwordsDic, pSurnamesDic, pstrDicPath);
- cout<<"done."<<endl;
- cout<<"...Constructing the temporary string table...";
- ConstructStringTable(pTable, pDic);
- cout<<"done."<<endl;
- Sleep(0);
- delete pstrDicPath;
- h[0] = CreateThread(NULL, 0, HTMLThread, (LPVOID)1, 0, NULL);
- h[1] = CreateThread(NULL, 0, HTMLThread, (LPVOID)2, 0, NULL);
- WaitForMultipleObjects(1, h, TRUE, INFINITE);
- DeleteCriticalSection(&cs);
- DeleteCriticalSection(&csModifyStrTable);
- CloseHandle(h[0]);
- CloseHandle(h[1]);
- /*
- for(int i = 1; i <= MAXPAGECOUNT; i++)
- {
- cout<<"Processing page No."<<i<<"...";
- pstrPathPrefix = StrConcat(strCurrPath, "\Webpages\");
- pstrPathPrefix = StrConcat(pstrPathPrefix, i);
- pstrHTMLPath = StrConcat(pstrPathPrefix, ".html");
- pLst = htmlParse(pDic, pStopwordsDic, pSurnamesDic, pstrHTMLPath);
- FillStringTable(pTable, i, pLst);
- ClearWordList(pLst);
- delete pstrPathPrefix;
- delete pstrHTMLPath;
- cout<<"done."<<endl;
- }
- */
- dwEndTime = GetTickCount();
- cout<<"Time span: "<<dwEndTime - dwStartTime<<" ms."<<endl;
- cout<<"Converting...";
- pInvDoc = ConstructInvDoc(pTable);
- cout<<"done."<<endl;
- dwEndTime = GetTickCount();
- cout<<"Time span: "<<dwEndTime - dwStartTime<<" ms."<<endl;
- cout<<"Outputing into file...";
- pstrResultPath = StrConcat(strCurrPath, "\Result.txt");
- OutputInvDoc(pInvDoc, pstrResultPath);
- cout<<"done."<<endl;
- cout<<"Finished."<<endl;
- dwEndTime = GetTickCount();
- cout<<"Time span: "<<dwEndTime - dwStartTime<<" ms."<<endl;
- return 0;
- }
- void Writeln1(int i, bool bIsFinished)
- {
- EnterCriticalSection(&cs);
- if(bIsFinished)
- {
- cout<<"Page No."<<i<<" done."<<endl;
- }
- else
- {
- cout<<"Processing page No."<<i<<"..."<<endl;
- }
- LeaveCriticalSection(&cs);
- }
- DWORD WINAPI HTMLThread(LPVOID iStartOf)
- {
- PWORDLIST pLst = NULL;
- char *pstrPathPrefix = NULL;
- char *pstrHTMLPath = NULL;
- for(int i = (int)iStartOf; i <= MAXPAGECOUNT; i += 2)
- {
- Writeln1(i, false);
- pstrPathPrefix = StrConcat(strCurrPath, "\Webpages\");
- pstrPathPrefix = StrConcat(pstrPathPrefix, i);
- pstrHTMLPath = StrConcat(pstrPathPrefix, ".html");
- pLst = htmlParse(pDic, pStopwordsDic, pSurnamesDic, pstrHTMLPath);
- FillStringTable(pTable, i, pLst);
- ClearWordList(pLst);
- Writeln1(i, true);
- delete pstrPathPrefix;
- delete pstrHTMLPath;
- }
- return 0;
- }