示例#1
0
/**
 * Update N-Gram from standard file
 * @TODO :
 * standard file :
 * - lines are separated by .;!?\n
 * - words are separated by spaces, ',' 
 */
void NGramTrieBuild::updateFromStandardFile(string _filePath)
{
	// open file
	wifstream fin(_filePath.c_str());
	// set encoding to UTF-8
#ifdef MSVC
	fin.imbue(locale(fin.getloc(), new codecvt_utf8<wchar_t>));
#else
	//fin.imbue(std::locale("ru_RU.UTF-8"));
	fin.imbue(std::locale("en_US.UTF-8"));
#endif
	wstring line;
	getline(fin, line);
	while(getline(fin, line))
	{
		line = dic->getDictionaryTools()->refineString(line);
		vector<wstring> sentences = dic->getDictionaryTools()->dictionarySplit(line, SENTENCE_DELIMITER);
		for (int i = 0; i < (int) sentences.size(); ++i)
		{
			updateSentence(sentences.at(i));
		}
	}
	// close file
	fin.close();
}
示例#2
0
bool TextClass::initialize(
	ID3D11Device* aD3DDevice, 
	ID3D11DeviceContext* aD3DDeviceContext, 
	HWND aHwnd, int aWidth, int aHeight, 
	D3DXMATRIX aBaseViewMatrix)
{
	bool result;

	m_screenWidth = aWidth;
	m_screenHeight = aHeight;

	m_baseViewMatrix = aBaseViewMatrix;

	m_font = new FontClass;
	if(!m_font)
	{
		return false;
	}

	result = m_font->initialize(
		aD3DDevice, "./obj/fontdata.txt", L"./tex/font.dds");
	if(!result)
	{
		MessageBox(aHwnd, L"初始化字体对象失败", L"Error", MB_OK);
		return false;
	}

	m_fontShader = new FontShaderClass;
	if(!m_fontShader)
	{
		return false;
	}

	result = m_fontShader->initialize(aD3DDevice, aHwnd);
	if(!result)
	{
		MessageBox(aHwnd, L"初始化字体着色器对象失败", L"Error", MB_OK);
		return false;
	}

	result = initializeSentence(&m_sentence1, 16, aD3DDevice);
	if(!result)
	{
		return false;
	}

	result = updateSentence(
		m_sentence1, "Hello", 100, 100, 1.0f, 1.0f, 1.0f,
		aD3DDeviceContext);
	if(!result)
	{
		return false;
	}

	result = initializeSentence(&m_sentence2, 16, aD3DDevice);
	if(!result)
	{
		return false;
	}

	result = updateSentence(
		m_sentence2, "Goodbye", 100, 200, 1.0f, 1.0f, 0.0f, 
		aD3DDeviceContext);
	if(!result)
	{
		return false;
	}

	return true;
}