Example #1
0
File: clause.cpp Project: ombt/ombt
// rename variables in clause
int
Clause::renameVariables()
{
	Clause newcl;
	Map<String, String> nvs;

	// rename variables in positive clause
	BinaryTree_AVL_Iterator_InOrder<Literal> pclIter(positiveClause);
	for ( ; !pclIter.done(); pclIter++)
	{
		Literal literal(pclIter());
		if (literal.renameVariables(nvs) != OK)
		{
			ERROR("renameVariables failed.", errno);
			return(NOTOK);
		}
		if (newcl.insert(literal) != OK)
		{
			ERROR("insert failed.", errno);
			return(NOTOK);
		}
	}

	// rename variables in negative clause
	BinaryTree_AVL_Iterator_InOrder<Literal> nclIter(negativeClause);
	for ( ; !nclIter.done(); nclIter++)
	{
		Literal literal(nclIter());
		if (literal.renameVariables(nvs) != OK)
		{
			ERROR("renameVariables failed.", errno);
			return(NOTOK);
		}
		if (newcl.insert(literal) != OK)
		{
			ERROR("insert failed.", errno);
			return(NOTOK);
		}
	}

	// rename variables in answers clause
	ListIterator<Literal> ansIter(answers);
	for ( ; !ansIter.done(); ansIter++)
	{
		Literal literal(ansIter());
		if (literal.renameVariables(nvs) != OK)
		{
			ERROR("renameVariables failed.", errno);
			return(NOTOK);
		}
		if (newcl.insertAnswer(literal) != OK)
		{
			ERROR("insert failed.", errno);
			return(NOTOK);
		}
	}

#if 0
	// update table of renamed variables
	if (updateVariableNames(nvs) != OK)
		return(NOTOK);
#endif

	// overwrite existing clauses
	newcl.setDepth(getDepth());
	newcl.setNumber(getNumber());
	newcl.setConclusion(getConclusion());
	newcl.setQuery(getQuery());
	newcl.setSOS(getSOS());
	*this = newcl;

	// all done
	return(OK);
}