Пример #1
0
void DBDictionary::Init()
{
	// 사전 초기화
	_dic.clear();

	// 사전 생성 옵션 로드
	XmlDocument xmlDoc;
	std::string path = "./resource/DBDicConfig.xml";
	xmlDoc.LoadFile( path.c_str() );

	const XmlNode * resNode = xmlDoc.GetNode( "resource" );
	std::string create = resNode->GetAttribute( "create" );

	if( create == "true" )
	{
		// 사전 생성
		CreateDBDic( resNode );

		// 사전 저장
		XmlDocument xmlDoc;
		XmlNode * resNode = xmlDoc.AddNode( "resource" );
		SaveToXML( resNode );

		std::string path = "./resource/DBDic.xml";
		xmlDoc.SaveFile( path.c_str() );
	}
	else
	{
		// 사전 로드
		XmlDocument xmlDoc;
		std::string path = "./resource/DBDic.xml";
		xmlDoc.LoadFile( path.c_str() );

		const XmlNode * resNode = xmlDoc.GetNode( "resource" );
		LoadFromXML( resNode );
	}
}
Пример #2
0
void AnswerGenerator::LoadAnswerRule( AnswerRuleList & answerRuleList )
{
	// 질문 템플릿 xml 로드
	XmlDocument xmlDoc;
	std::string path = "./resource/AnswerRule.xml";
	xmlDoc.LoadFile( path.c_str() );

	const XmlNode *resNode = xmlDoc.GetNode( "resource");

	//
	int nodeCount = resNode->GetNodeCount( "ans" );
	for( int num = 0; num < nodeCount; num++ )
	{	
		// Question template node들을 돌며,
		const XmlNode * sqlNode = resNode->GetNode( "ans", num );
		std::string templateNum = sqlNode->GetAttribute( "tempNo" );
		std::string subNum = sqlNode->GetAttribute( "no" );

		//
		AnswerRule rule;
		rule._tempNo = atoi( templateNum.c_str() );
		rule._subNo = atoi( subNum.c_str() );

		const XmlNode * needListNode = sqlNode->GetNode( "need_slot_list" );

		// 만약 num번째 Question template에서,
		int slotCount = needListNode->GetNodeCount( "slot" );
		for( int num2 = 0; num2 < slotCount; num2++ )
		{	
			// slot의 개수만큼 돌며 
			// 속성들을 읽어오고,
			const XmlNode * slotNode = needListNode->GetNode( "slot", num2 );
			std::string slotType = slotNode->GetAttribute( "type" );
			std::string tagName = slotNode->GetAttribute( "value" );
			std::string addText = slotNode->GetAttribute( "add" );

			//
			AnswerNeedSlot slot;
			slot._slotType = slotType;
			slot._tagName = tagName;
			slot._addText = addText;

			rule._needSlotList.push_back( slot );
		}

		const XmlNode * tableNode = sqlNode->GetNode( "table" );
		std::string expression1 = tableNode->GetAttribute( "exp" );
		rule._reference._expression = expression1;

		int expCnt = tableNode->GetNodeCount( "exp" );
		for( int num2 = 0; num2 < expCnt; num2++ )
		{	
			//
			const XmlNode * expNode = tableNode->GetNode( "exp", num2 );
			std::string expType = expNode->GetAttribute( "type" );

			DataElement element = GetElement( expType );
			rule._reference._elementList.push_back( element );
		}

		const XmlNode * answerNode = sqlNode->GetNode( "answer" );
		std::string expression2 = answerNode->GetAttribute( "exp" );
		rule._answer._expression = expression2;

		int expCount = answerNode->GetNodeCount( "exp" );
		for( int num2 = 0; num2 < expCount; num2++ )
		{	
			//
			const XmlNode * expNode = answerNode->GetNode( "exp", num2 );
			std::string expType = expNode->GetAttribute( "type" );

			DataElement element = GetElement( expType );
			rule._answer._elementList.push_back( element );
		}

		answerRuleList.push_back( rule );
	}
}