当前位置: 首页>>代码示例>>C++>>正文


C++ QueryData::GetSuchThats方法代码示例

本文整理汇总了C++中QueryData::GetSuchThats方法的典型用法代码示例。如果您正苦于以下问题:C++ QueryData::GetSuchThats方法的具体用法?C++ QueryData::GetSuchThats怎么用?C++ QueryData::GetSuchThats使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QueryData的用法示例。


在下文中一共展示了QueryData::GetSuchThats方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: weightSuchThat

vector<pair<ClauseType,int>> Optimizer::optimize(QueryData qd){
	vector<pair<ClauseType,int>> tempSequence = qd.GetClauseSequence();
	vector<SuchThatClause> tempSuchThats = qd.GetSuchThats();
	vector<PatternClause> tempPatterns = qd.GetPatterns();
	vector<WithClause> tempWiths = qd.GetWiths();

	vector<pair<pair<ClauseType,int>,int>> weightMap;

	for(vector<pair<ClauseType,int>>::iterator iter=tempSequence.begin();iter!=tempSequence.end();++iter)  
    {  
		switch((*iter).first){
		case SUCHTHAT:{
			int weight = weightSuchThat(tempSuchThats[(*iter).second]);
			weightMap.push_back(pair<pair<ClauseType,int>,int>((*iter),weight));
			break;
					  }
		case WITH:{
			int weight = weightWith(tempWiths[(*iter).second]);
			weightMap.push_back(pair<pair<ClauseType,int>,int>((*iter),weight));
			break;
				  }
		case PATTERN:{
			int weight = weightPattern(tempPatterns[(*iter).second]);
			weightMap.push_back(pair<pair<ClauseType,int>,int>((*iter),weight));
			break;
					 }
		default:{
			cout << "wrong clausetype./n";
			break;
				}
		}
    }  

	sort(weightMap.begin(), weightMap.end(), strict_weak_ordering);

	vector<pair<ClauseType,int>> finalSequence;

	for(vector<pair<pair<ClauseType,int>,int>>::iterator iter=weightMap.begin();iter!=weightMap.end();++iter) {
		cout << (*iter).first.second;
		finalSequence.push_back((*iter).first); 
	}

	return finalSequence;
}
开发者ID:darrenbkl,项目名称:SPA,代码行数:44,代码来源:Optimizer.cpp

示例2: testInsertQueryData

void QueryDataTest::testInsertQueryData() 
{
	//assign a; while w; Select a such that Parent(w,a) pattern a("x",_"x+y"_)

	QueryData qd;

	Synonym a("a", ASSIGN);
	Synonym w("w", WHILE);
	Argument arg1_suchthat("w", SYNONYM, w);
	Argument arg2_suchthat("a", SYNONYM, a);
	Argument arg1_pattern("x", IDENT);
	Argument arg2_pattern("_\"x+y\"_", EXPRESSION);

	qd.InsertDeclaration(a);
	qd.InsertDeclaration(w);
	qd.InsertSelect(a);
	qd.InsertPattern(a, arg1_pattern, arg2_pattern);
	qd.InsertSuchThat(PARENT, arg1_suchthat, arg2_suchthat);


	std::vector<Declaration> declarations = qd.GetDeclarations();
	CPPUNIT_ASSERT(declarations.size() == 2);
	CPPUNIT_ASSERT(declarations.at(0).synonym.value == "a");
	CPPUNIT_ASSERT(declarations.at(0).synonym.type == ASSIGN);
	CPPUNIT_ASSERT(declarations.at(1).synonym.value == "w");
	CPPUNIT_ASSERT(declarations.at(1).synonym.type == WHILE);

	std::vector<SelectClause> selects = qd.GetSelects();
	CPPUNIT_ASSERT(selects.size() == 1);
	CPPUNIT_ASSERT(selects.at(0).synonym.value == "a");
	CPPUNIT_ASSERT(selects.at(0).synonym.type == ASSIGN);

	std::vector<PatternClause> patterns = qd.GetPatterns();
	CPPUNIT_ASSERT(patterns.size() == 1);
	CPPUNIT_ASSERT(patterns.at(0).synonym.value == "a");
	CPPUNIT_ASSERT(patterns.at(0).synonym.type == ASSIGN);
	CPPUNIT_ASSERT(patterns.at(0).arg1.value == "x");
	CPPUNIT_ASSERT(patterns.at(0).arg1.type == IDENT);
	CPPUNIT_ASSERT(patterns.at(0).arg1.syn.value == "");
	CPPUNIT_ASSERT(patterns.at(0).arg1.syn.type == INVALID_SYNONYM_TYPE);
	CPPUNIT_ASSERT(patterns.at(0).arg2.value == "_\"x+y\"_");
	CPPUNIT_ASSERT(patterns.at(0).arg2.type == EXPRESSION);
	CPPUNIT_ASSERT(patterns.at(0).arg2.syn.value == "");
	CPPUNIT_ASSERT(patterns.at(0).arg2.syn.type == INVALID_SYNONYM_TYPE);

	std::vector<SuchThatClause> suchThats = qd.GetSuchThats();
	CPPUNIT_ASSERT(suchThats.size() == 1);
	CPPUNIT_ASSERT(suchThats.at(0).relationship == PARENT);
	CPPUNIT_ASSERT(suchThats.at(0).arg1.value == "w");
	CPPUNIT_ASSERT(suchThats.at(0).arg1.type == SYNONYM);
	CPPUNIT_ASSERT(suchThats.at(0).arg1.syn.value == "w");
	CPPUNIT_ASSERT(suchThats.at(0).arg1.syn.type == WHILE);
	CPPUNIT_ASSERT(suchThats.at(0).arg2.value == "a");
	CPPUNIT_ASSERT(suchThats.at(0).arg2.type == SYNONYM);
	CPPUNIT_ASSERT(suchThats.at(0).arg2.syn.value == "a");
	CPPUNIT_ASSERT(suchThats.at(0).arg2.syn.type == ASSIGN);


	//bool IsSynonymExist(std::string, SynonymType);
	bool exist = qd.IsSynonymExist("a", ASSIGN);
	CPPUNIT_ASSERT(exist == true);

	exist = qd.IsSynonymExist("b", ASSIGN);
	CPPUNIT_ASSERT(exist == false);


	//bool IsSynonymExist(std::string, SynonymType*);
	SynonymType type = INVALID_SYNONYM_TYPE;
	exist = qd.IsSynonymExist("a", &type);
	CPPUNIT_ASSERT(exist == true);
	CPPUNIT_ASSERT(type == ASSIGN);

	type = INVALID_SYNONYM_TYPE;
	exist = qd.IsSynonymExist("c", &type);
	CPPUNIT_ASSERT(exist == false);
	CPPUNIT_ASSERT(type == INVALID_SYNONYM_TYPE);


	//bool IsSynonymExist(std::string, std::vector<SynonymType>);
	SynonymType list[] = {STMT, ASSIGN, WHILE, PROG_LINE, CONSTANT, VARIABLE};
	std::vector<SynonymType> typeList(list, list + 6);

	exist = qd.IsSynonymExist("a",list);
	CPPUNIT_ASSERT(exist == true);

	exist = qd.IsSynonymExist("w",list);
	CPPUNIT_ASSERT(exist == true);

	exist = qd.IsSynonymExist("p",list);
	CPPUNIT_ASSERT(exist == false);

	SynonymType list2[] = {STMT, PROG_LINE, CONSTANT, VARIABLE};
	std::vector<SynonymType> typeList2(list2, list2 + 4);

	exist = qd.IsSynonymExist("a",typeList2);
	CPPUNIT_ASSERT(exist == false);

	exist = qd.IsSynonymExist("w",typeList2);
	CPPUNIT_ASSERT(exist == false);
}
开发者ID:darrenbkl,项目名称:SPA,代码行数:100,代码来源:QueryDataTest.cpp


注:本文中的QueryData::GetSuchThats方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。