Ejemplo n.º 1
0
/* get ready to run evaluator */
void
agentInit(void)
{
    Task	*t;
    int		sts;

    /* Set up local name space for agent */
    /* Only load PMNS if it's default and hence not already loaded */
    if (pmnsfile == PM_NS_DEFAULT && (sts = pmLoadNameSpace(pmnsfile)) < 0) {
	fprintf(stderr, "%s: agentInit: cannot load metric namespace: %s\n",
		pmProgname, pmErrStr(sts));
	exit(1);
    }

    /* allocate pmResult's and send pmDescs for secret agent mode */
    t = taskq;
    while (t) {
	newResult(t);
	sendDescs(t);
	t = t->next;
    }
}
Ejemplo n.º 2
0
int BCCShapeRecognizer::recognize(const LTKTraceGroup& traceGroup, const LTKScreenContext& screenContext, 
    const vector<bool>& shapeSubSet, float confThreshold, 
    int  numChoices, vector<LTKShapeRecoResult>& resultVec)
{
    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << 
        "Entered BCCShapeRecognizer::recognize"  << endl;

	vector<LTKShapeRecoResult> pcaResults;

	floatVector bordaCounts(m_numShapes, 0.0f);

	int resultIndex;

	vector<LTKShapeRecoResult> holisticResults;

	//resultVec.clear();

	pcaResults.reserve(numChoices +1);
	holisticResults.reserve(numChoices +1);

	int iRecognizeResult = -1;

	iRecognizeResult = m_pPCAObj->recognize(traceGroup, screenContext, shapeSubSet, confThreshold, numChoices, pcaResults);
	if(iRecognizeResult != SUCCESS)
	{
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) << 
            "Error while recognizing using PCA" << endl;
		return -1;
	}

	iRecognizeResult = m_pHolisticObj->recognize(traceGroup, screenContext, shapeSubSet, confThreshold, numChoices, holisticResults);
	if(iRecognizeResult != SUCCESS)
	{
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) << 
            "Error while recognizing using Holisitc" << endl;
		return -1;
	}

	LOG( LTKLogger::LTK_LOGLEVEL_ERR) << 
        "Got results from both PCA and Holistic" << endl;
	
	if(m_combinationScheme == "sum") //sum rule
	{
		for(resultIndex = 0; resultIndex < pcaResults.size(); ++resultIndex)
		{
			if(pcaResults[resultIndex].getShapeId() >=0 && pcaResults[resultIndex].getShapeId() < m_numShapes)
			{
				bordaCounts[pcaResults[resultIndex].getShapeId()] += pcaResults[resultIndex].getConfidence();
			}
		}


		for(resultIndex = 0; resultIndex < holisticResults.size(); ++resultIndex)
		{
			if(holisticResults[resultIndex].getShapeId() >=0 && holisticResults[resultIndex].getShapeId() < m_numShapes)
			{
				bordaCounts[holisticResults[resultIndex].getShapeId()] += holisticResults[resultIndex].getConfidence();
			}
		}

	}
	else//default is borda count combination
	{
		for(resultIndex = 0; resultIndex < pcaResults.size(); ++resultIndex)
		{
			//cout << pcaResults[resultIndex].getShapeId() << endl;

			if(pcaResults[resultIndex].getShapeId() >=0 && pcaResults[resultIndex].getShapeId() < m_numShapes)
			{
				bordaCounts[pcaResults[resultIndex].getShapeId()] += (m_numShapes - resultIndex);
			}
		}


		for(resultIndex = 0; resultIndex < holisticResults.size(); ++resultIndex)
		{
			//cout << holisticResults[resultIndex].getShapeId() << endl;

			if(holisticResults[resultIndex].getShapeId() >=0 && holisticResults[resultIndex].getShapeId() < m_numShapes)
			{
				bordaCounts[holisticResults[resultIndex].getShapeId()] += (m_numShapes - resultIndex);
			}
		}
	}

	int maxInd;

	float maxValue;

	int classIndex, newOrderIndex;

	for(newOrderIndex = 0; newOrderIndex < numChoices ; ++newOrderIndex)
	{
		maxValue = -1;

		maxInd = -1;

		for(classIndex = 0; classIndex < m_numShapes; ++classIndex)
		{
			if(bordaCounts.at(classIndex) > maxValue)
			{
				maxValue = bordaCounts.at(classIndex);

				maxInd = classIndex;
			}

		}

		//cout << "reordered" << endl;

		if(shapeSubSet.empty() || shapeSubSet.at(maxInd) == true)
		{
			LTKShapeRecoResult newResult(maxInd, (float)maxValue);

			resultVec.push_back(newResult);
		}

		//cout << "result pushed" << endl;

		bordaCounts.at(maxInd) = -1;
	}

	return SUCCESS;
}
Ejemplo n.º 3
0
	void HTTPClientTestObject::test<2>()
	{
		LLHTTPClient::get("http://www.invalid", newResult());
		runThePump();
		ensureStatusError();
	}
Ejemplo n.º 4
0
void* thread1(int sock){
	printf("New client\n");
	char buffer[256];
	int n;
	char str[50];
		char result[50];
		FILE *file;
		int i, numberTrueAnswer = 0;
		char *clientFile = "/home/user/workspace/server/registration.txt";
		int numberTest = 0;
		char *name = (char*) malloc(50 * sizeof(char));
		while (1) {
				bzero(buffer, 256);
				n = read(sock, buffer, 1);
				if (n < 0) {
					perror("ERROR reading from socket");
					exit(1);
				}
				n = write(sock, buffer, 1);
				if (n < 0) {
					perror("ERROR writing to socket");
					exit(1);
			}
				if (buffer[0] == '!')
					break;
		}
			//Registration
			int numberClient;
			int clientSize = sizeFile(clientFile);
			struct Client c[50];
			file = fopen(clientFile, "r");
			if (file == NULL) {
				perror("ERROR open file");
				exit(1);
			}
			for (i = 0; fgets(str, sizeof(str), file); i++) {
				writeSizeClient(&c[i], &str);
			}
			fclose(file);
			char bufferNew[256];
			numberClient = -1;
			bzero(buffer, 256);
			bzero(bufferNew, 256);
			n = read(sock, buffer, 255);
			if (n < 0) {
				perror("ERROR reading from socket");
				exit(1);
			}
			for (i = 0; i < strlen(buffer) - 1; i++)
				bufferNew[i] = buffer[i];
			for (i = 0; i < clientSize; i++) {
				if (strcmp(bufferNew, c[i].login) == NULL) {
					numberClient = i;
					break;
				}
			}
			//New client
			if (numberClient == -1) {
				clientSize++;
				struct Client client;
				newUser(bufferNew, &client);
				c[clientSize - 1] = client;
				numberClient = clientSize - 1;
			}
			char strres[50];
			sprintf(strres,"%d#%d#%d#%s/\n",c[numberClient].numberTest,
					c[numberClient].sizeQuestion,c[numberClient].sizeTrueAnswer,c[numberClient].login);
			strcpy(result ,strres);
			n = write(sock, result, strlen(result));
				if (n < 0) {
					perror("ERROR writing to socket");
					exit(1);
				}
			//List of test
			while (1) {
				bzero(buffer, 256);
								n = read(sock, buffer, 1);
								if (n < 0) {
									perror("ERROR reading from socket");
									exit(1);
								}
								n = write(sock, buffer, 1);
								if (n < 0) {
									perror("ERROR writing to socket");
									exit(1);
							}
								if (buffer[0] == '1')
									break;
			}
			char res[60]="/" ;
			char s[3];
			for (i = 50; i >0; i--) {
				sprintf(name, "%s%d%s", "/home/user/workspace/server/test/", i, ".txt");
				if ((file = fopen(name, "r")) != NULL) {
					sprintf(s, "#%d", i);
					strcat(res, s);
					fclose(file);
				}
			}
			n = write(sock, res, strlen(res));
			if (n < 0) {
				perror("ERROR writing to socket");
				exit(1);
			}

		//Number test
			bzero(buffer, 256);
				n = read(sock, buffer, 255);
				if (n < 0) {
					perror("ERROR reading from socket");
					exit(1);
				}
				numberTest=toInt(buffer);
				sprintf(name, "%s%d%s", "/home/user/workspace/server/test/", numberTest,
						".txt");
				file = fopen(name, "r");
			int testSize = sizeFile(name);
			int trueAnswer;
			file = fopen(name, "r");
			if (file == NULL) {
				perror("ERROR open file");
				exit(1);
			}
			int end=0;
			while(1){
				if(!fgets(str, sizeof(str), file))
					end=1;
				while (1) {
								bzero(buffer, 256);
												n = read(sock, buffer, 1);
												if (n < 0) {
													perror("ERROR reading from socket");
													exit(1);
												}
												if(end)
													buffer[0]='/';
												n = write(sock, buffer, 1);
												if (n < 0) {
													perror("ERROR writing to socket");
													exit(1);
											}
												if (buffer[0] == '2' || buffer[0] == '/')
													break;
							}
				if(end)
					break;
				trueAnswer=readTrueAnswer(str);
				n = write(sock, str, strlen(str));
					if (n < 0) {
						perror("ERROR writing to socket");
						exit(1);
					}
					//Answer
				bzero(buffer, 256);
				n = read(sock, buffer, 1);
				if (n < 0) {
					perror("ERROR reading from socket");
					exit(1);
				}
				printf("Answer: %s\n", buffer);
				if (buffer[0] == trueAnswer+'0') {
					n = write(sock, "Right\n", 6);
					if (n < 0) {
						perror("ERROR writing to socket");
						exit(1);
					}
					numberTrueAnswer = numberTrueAnswer + 1;
				} else
					n = write(sock, "Wrong\n", 6);
				if (n < 0) {
					perror("ERROR writing to socket");
					exit(1);
				}
			}
			sprintf(name, "%d#%d#%d#%s/", numberTest,testSize, numberTrueAnswer,c[numberClient].login);
			n = write(sock, name, strlen(name));
			if (n < 0) {
				perror("ERROR writing to socket");
				exit(1);
			}


			newResult(&c[numberClient], numberTest, testSize, numberTrueAnswer);
			file = fopen("/home/user/workspace/server/registration.txt", "w");
			if (file == NULL) {
				perror("ERROR open file");
				exit(1);
			}
			for (i = 0; i < clientSize; i++) {
				fprintf(file, "%d#%d#%d#%s/\n", c[i].numberTest, c[i].sizeQuestion,
						c[i].sizeTrueAnswer, c[i].login);
			};
			fclose(file);
			free(name);
}
Ejemplo n.º 5
0
bool KDBSearchEngine2::startSearch(QString str)
{
    kdDebug(0) << "Start a new search. Looking for: " << str << endl;
    
    static QString queryString;
    
    queryString=str;  //set the latest query string (note: it is static)
    
    if(autoupdate)
    {
	updateSettings();
    }
    
    
    if(!init()) return false;    //-check initialization
    di->stop(true); //stop all new emits from database interface
    emit started(); //say everybody we are starting
    
    if(searching) return true; //We already have a search loop, as soon as we come back
    //on the search loop we will start the new search (queryString).
    
    searching=true;  //really start searching
    
    QString searchingString;
    
    do //Search loop, it stops only when finished and latest searched string is the actual query string.
    {
	searchingString=queryString; //-set new search string
	di->stop(false);  	   //-unlock searching
	
	if(numberOfResult<1) numberOfResult=1;

//	di->singleWordMatch(searchingString,0,true);

	GenericSearchAlgorithm strategy(di,&settings);

	//Let's create a search sequence:
	ExactSearchAlgorithm exact(di,&settings);
	AlphaSearchAlgorithm alpha(di,&settings);
	SentenceArchiveSearchAlgorithm sent(di,&settings);
	ChunkByChunkSearchAlgorithm sbys(di,&settings);
	ChunkByChunkSearchAlgorithm wbyw(di,&settings);
	CorrelationSearchAlgorithm corr(di,&settings);
	FuzzyChunkSearchAlgorithm fs(di,&settings);
	FuzzyChunkSearchAlgorithm fw(di,&settings);

	SentenceChunkFactory sf(di);
	sbys.setChunkFactory(&sf);
	fs.setChunkFactory(&sf);


	WordChunkFactory wf(di);
	wbyw.setChunkFactory(&wf);
	fw.setChunkFactory(&wf);

	strategy.addAlgorithm(&exact);
	strategy.addAlgorithm(&alpha);
	strategy.addAlgorithm(&sent);
	strategy.addAlgorithm(&sbys);
	//strategy.addAlgorithm(&fs);
	strategy.addAlgorithm(&fw);
	strategy.addAlgorithm(&corr);
	strategy.addAlgorithm(&wbyw);


	connect(&strategy,SIGNAL(newResult(QueryResult)),this,SLOT(receiveResult(QueryResult)));
	strategy.exec(searchingString);	disconnect(&strategy,SIGNAL(newResult(QueryResult)),this,SLOT(receiveResult(QueryResult)));


	kdDebug(0) << "End of search for " << searchingString  << endl;
    }
    while(searchingString!=queryString);
    kdDebug(0) << "Exiting the search loop" << endl;
    //if != someone asked a different string when we was searching
    //so we restart our search (maybe a cleanresult is needed?).
    
    
    di->stop(false);  //-clean searching locks
    searching=false;  //-clean searching locks
    emit finished();  //Finished
    
    return true;
    
}