Beispiel #1
0
void Database::initSchemes(vector<Predicate> schemes){
	for(int i = 0; i < (int)schemes.size(); i++){
		Predicate r = schemes[i];
		Relation r1(r.getID());
		for(int j = 0; j < (int)r.getParameters().size(); j++)
			r1.addParam(r.getParameters()[j].getValue());
		relations.push_back(r1);
	}
}
Beispiel #2
0
void Database::initFacts(vector<Predicate> facts){
	for(int i = 0; i < (int)facts.size(); i++){
		Predicate r = facts[i];
		string name = r.getID();
		Tuple t;
		for(int j = 0; j < (int)r.getParameters().size(); j++)
			t.push_back(r.getParameters()[j].getValue());
		addTuple(name, t);
	}
}
Beispiel #3
0
Relation Database::performRename(Predicate query, Relation r){
	vector<int> indexes = performSearch(query, r);
	for(int i = 0; i < (int)indexes.size(); i++)
		r = r.rename(i, query.getParameters()[indexes[i]].getValue());

	return r;
}
Beispiel #4
0
Relation Database::performSelect(Predicate query, Relation r){
	vector<Parameter> params = query.getParameters();
	for(int j = 0; j < (int)params.size(); j++){
		if(params[j].getType() == "ID")
			for(int k = j + 1; k < (int)params.size(); k++)
				if(params[j].getValue() == params[k].getValue())
					r = r.select(j, k);
		if(params[j].getType() == "STRING")
			r = r.select(j, params[j].getValue());
	}
	return r;
}
Beispiel #5
0
vector<int> Database::performSearch(Predicate query, Relation r){

	vector<int> indexes = vector<int>();
	vector<Parameter> params = query.getParameters();
	for(int j = 0; j < (int)params.size(); j++){
		bool next = true;
		if(params[j].getType() == "ID"){
			next = false;
			for(int k = 0; k < j; k++)
				if(params[j].getValue() == params[k].getValue())
					next = true;
		}
		if(!next)
			indexes.push_back(j);
	}
	return indexes;
}
Beispiel #6
0
void DatalogProgram::addQuery(Predicate newQuery){
	queries.push_back(newQuery);
	addDomain(newQuery.getParameters());
}
Beispiel #7
0
void DatalogProgram::addFact(Predicate newFact){
	facts.push_back(newFact);
	addDomain(newFact.getParameters());
}
Beispiel #8
0
Rule::Rule(Predicate _headPredicate, vector<Predicate> _predicateList) : headPredicate(_headPredicate.getFirstString(), _headPredicate.getSecondString(), _headPredicate.getParameters())
{
    predicateList = _predicateList;
    headPredicate = _headPredicate;
}