⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qimconsole.cpp

📁 我们一个小组
💻 CPP
字号:
#include "Qimconsole.h"
#include <vector>
#include <iostream>

using namespace std ;

QimConsole::QimConsole(bool bAutoSave):m_bAlreadyLoad(false),m_bAutoSave(bAutoSave)
{

}

bool QimConsole::Load(const string& strStaticTableFilename, const string& strDynamicTableFilename, const string& strHashtableFilename)
{
	m_strStaticTableFilename = strStaticTableFilename ;
	m_strDynamicTableFilename = strDynamicTableFilename ;
	m_strHashtableFilename = strHashtableFilename ;

	return m_Qim.Load(strStaticTableFilename, strDynamicTableFilename, strHashtableFilename) ;
}

bool QimConsole::LoadFromRawPyWordFreFile(const string& strPyWordFreFileName)
{
	//return m_Qim.LoadFromRawFile(strPyWordFreFileName) ;
	m_Qim.LoadFromRawFile(strPyWordFreFileName) ;
	return m_Qim.LoadDynamicFromRawFile("f:\\simple.txt");
}


bool QimConsole::Run()
{
	string py ;

	while (true)
	{
		cout << "input: " ;
		cin >> py ;
		cout << endl;
		Process(py) ;
		
		if (m_bAutoSave)
		{
			Save() ;
		}
		
	}
}

bool QimConsole::Save()
{
	return m_Qim.Save(m_strStaticTableFilename, m_strDynamicTableFilename, m_strHashtableFilename) ;
}

void QimConsole::Process(const string& py)
{

	string strFinalWord ;
	string strSlimcutPy ;

	int currentPos = 0 ;
	vector<string> vecResultWord ;
	bool search_flag = false;

	while ( currentPos!= py.size())
	{
		vecResultWord.clear() ;

		string strUnhandledPy = py.substr(currentPos) ;

		//add dynamic phrase
		vector<string> vecDynamicResult ;
		int nDynamicLongestMatchLength ;
		if ( ( nDynamicLongestMatchLength = m_Qim.GetDynamicPraseByLongestMatchedPy(strUnhandledPy, vecDynamicResult) ) > 0)
		{
			for (size_t i = 0; i<vecDynamicResult.size(); i++)
			{
				vecResultWord.push_back(vecDynamicResult[i]) ;
			}
		}

		//add static phrase
		vector<string> vecStaticResult ;
		int nStaticLongestMatchLength ;
		if ( ( nStaticLongestMatchLength = m_Qim.GetStaticWordByLongestMatchedPy(strUnhandledPy, vecStaticResult)) > 0)
		{
			for (size_t i = 0; i<vecStaticResult.size(); i++)
			{
				vecResultWord.push_back(vecStaticResult[i]) ;
			}
		}

		if (vecResultWord.size() == 0)
		{
			currentPos ++ ;
			continue ;
		}

		//display 
		for (size_t i = 0; i<vecResultWord.size(); i++)
		{
			cout << i+1 << "." << vecResultWord[i] << " " ;
		}
		
		//choice
		cout << endl << "choose: "  ;
		size_t choice ;
		cin >> choice ;
		strFinalWord += vecResultWord[choice-1] ;
		
		//move to next possible py
		if (choice <= vecDynamicResult.size())
		{
			strSlimcutPy += py.substr(currentPos, nDynamicLongestMatchLength) ;
			string currentpy = py.substr(currentPos, nDynamicLongestMatchLength) ;
			m_Qim.IncreaseDynamicFrequency(currentpy, vecResultWord[choice-1]);

			currentPos += nDynamicLongestMatchLength ;
		}
		else
		{
			strSlimcutPy += py.substr(currentPos, 1) ;
			string currentpy = py.substr(currentPos, nStaticLongestMatchLength) ;
			m_Qim.IncreaseStaticFrequency(currentpy, vecResultWord[choice-1]);

			currentPos += nStaticLongestMatchLength ;
		}
	}

	//add to dynamic phrase table
	//m_Qim.InsertDynamicPhrase(py, strFinalWord, 1) ;
	//m_Qim.InsertDynamicPhrase(strSlimcutPy, strFinalWord, 1) ;
	m_Qim.InsertDynamicPhrase1(py,strSlimcutPy,strFinalWord,1.5);

	cout << endl << "Final phrase is :" << strFinalWord << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -