static unsigned int processDocuments( const strus::PatternMatcherInstanceInterface* ptinst, const KeyTokenMap& keytokenmap, const std::vector<TreeNode*> treear, const std::vector<strus::utils::Document>& docs, std::map<std::string,double>& stats, const char* outputpath)
{
	unsigned int totalNofmatches = 0;
	std::vector<strus::utils::Document>::const_iterator di = docs.begin(), de = docs.end();
	std::size_t didx = 0;
	for (; di != de; ++di,++didx)
	{
#ifdef STRUS_LOWLEVEL_DEBUG
		std::cout << "document " << di->tostring() << std::endl;
#endif
		std::vector<strus::analyzer::PatternMatcherResult>
			results = eliminateDuplicates( sortResults( processDocument( ptinst, *di, stats)));

		if (outputpath)
		{
			std::ostringstream out;
			out << "number of matches " << results.size() << std::endl;
			strus::utils::printResults( out, std::vector<strus::SegmenterPosition>(), results);

			std::string outputfile( outputpath);
			outputfile.push_back( strus::dirSeparator());
			outputfile.append( "res.txt");

			strus::writeFile( outputfile, out.str());
		}
		std::vector<strus::analyzer::PatternMatcherResult>
			expectedResults = eliminateDuplicates( sortResults( processDocumentAlt( keytokenmap, treear, *di)));

		if (outputpath)
		{
			std::ostringstream out;
			out << "number of matches " << expectedResults.size() << std::endl;
			strus::utils::printResults( out, std::vector<strus::SegmenterPosition>(), expectedResults);

			std::string outputfile( outputpath);
			outputfile.push_back( strus::dirSeparator());
			outputfile.append( "exp.txt");

			strus::writeFile( outputfile, out.str());
		}

		if (!compareResults( results, expectedResults))
		{
			throw std::runtime_error(std::string( "results differ to expected for document ") + di->id);
		}
		totalNofmatches += results.size();
		if (g_errorBuffer->hasError())
		{
			throw std::runtime_error("error matching rule");
		}
	}
	return totalNofmatches;
}
Example #2
0
int main()
{
	//set the global ints
	currentFunction = 1;
	uniqueVarNum = 1;
	uniqueStructNum = 1;
	numThreads = 0;

	readInput();

	processVariables();

	//First, handle parallels
	bool foundConstruct = true;
	while (foundConstruct)
	{
		foundConstruct = processParallel();
	}

	//next, handle parallel for
	foundConstruct = true;
	while (foundConstruct)
	{
		foundConstruct = processParallelFor();
	}

	//next, handle criticals
	foundConstruct = true;
	while (foundConstruct)
	{
		foundConstruct = processCritical();
	}

	//next, handle single
	foundConstruct = true;
	while (foundConstruct)
	{
		foundConstruct = processSingle();
	}

	//last, change all omp_get_thread_num calls to use the paramstruct
	processGetThreadNum();

	//put global vars at the top
	eliminateDuplicates(globalVars);
	insertAfterIncludes(globalVars);

	//put private vars back in main
	eliminateDuplicates(totalPrivBackup);
	declarePrivatesInMain(totalPrivBackup);

	//create and insert the parameter struct
	strvec newStruct = createStartEndStruct();
	insertAfterIncludes(newStruct);

	//create and add the mutex call
	strvec synchronization;
	synchronization.push_back("pthread_mutex_t theMutex = PTHREAD_MUTEX_INITIALIZER;");
	insertAfterIncludes(synchronization);

	//create and add new includes
	strvec includes;
	includes.push_back("#include <pthread.h>");
	includes.push_back("#include <algorithm>");
	includes.push_back("#include <cstring>");
	insertAfterIncludes(includes);

	//print output (to use for file redirection)
	printVector(input);
}