Beispiel #1
0
	PhrasePtr Conversation::AutoChoosePhrase(SpeakerPtr speaker)
	{
		for (int i = 0; i < GetPhrasesCount(); ++i)
		{
			PhrasePtr p = GetPhrase(i);
			if (p->CheckCondition(speaker))
				return p;
		}

		return PhrasePtr();
	}
Beispiel #2
0
void GetResponseFromGroup(int KeyWordGroup, char *szUserInput, int nTailOffset, JJGui *jibber_ui)
{
	char szTemplate[]="SELECT * FROM phrases WHERE category=%d";
	char szShiftedTail[250] = "";
	char szSQLString[50]="";
	char szCloser[ 10 ], szPhrase[ 250 ], szFinalResponse[250] = "";
	int nResponse, nType, nRecordCount, nPosition, nLoop = 0;

	bool bFound = false;

	sqlite3_stmt *stmt = NULL;

	// how many response phrases in this keyword group
	nRecordCount = GetPhrasesCount( KeyWordGroup );

	// which one did we use last time
	nPosition = nGroupPositionFlags[ KeyWordGroup ];

	// if we have never used a response from this group, randomly set the first one to use
	if ( nPosition == (-2))
			nPosition = rand() % nRecordCount;
	else {
		++nPosition;
		nPosition = (nPosition >= nRecordCount) ? 0 : nPosition;
	}

	if ( bShow ) {
		AppendText(jibber_ui, DIR_SYSTEM, "Group: %d, Resp: %d, Last: %d", KeyWordGroup, nRecordCount, nPosition);
	}

	// store the new position so that next time we know which one we used last
	nGroupPositionFlags[ KeyWordGroup ] = nPosition;

	// form the SQL string
	sprintf(szSQLString, szTemplate, KeyWordGroup);

	// prepare the SQL statement
	nResponse = sqlite3_prepare_v2( knowledgeDB, szSQLString, -1, &stmt, NULL );

	// if not OK, bomb out
	if ( nResponse != SQLITE_OK)
			return;

	// if OK, start to walk through the record set
	nResponse = sqlite3_step( stmt );

	// as long as we have a valid record set row
	while (nResponse == SQLITE_ROW) {

		// if this record row is one more than the one last used
		if (nLoop == nPosition) {

			bFound = true;

			// get the type, phrase and the end punctuation
			nType  = (int) sqlite3_column_int( stmt, TYPE);
			strcpy(szPhrase, (char*) sqlite3_column_text( stmt, PHRASE ));
			strcpy(szCloser, (char *) sqlite3_column_text( stmt, CLOSER ));
		}

		// we found the response we were looking for
		if ( bFound)
				nResponse = SQLITE_ERROR;
		else {

			++nLoop;
			// step through the loop to the next record
			nResponse = sqlite3_step( stmt );
		}
	}

	sqlite3_finalize( stmt );

	// do we need to make an integrated response?
	if ( (nType == 1) && ( nTailOffset != 0 ) ) {

		// yes, and there is a tail available so compose the integrated response
		strcpy( szShiftedTail, ( szUserInput+nTailOffset ) );

		// check for changes required for change of first person perspective
		FirstPersonShiftTail( szShiftedTail );

		// compose the final response
		sprintf( szFinalResponse, "%s%s%s", szPhrase, szShiftedTail, szCloser );
	}
	else {
		// standalone response
		sprintf( szFinalResponse, "%s%s", szPhrase, szCloser );
	}

	// finally, display the response from JJ to the user
	AppendText( jibber_ui, DIR_OUT, szFinalResponse );

}	// end of GetResponseFromGroup
Beispiel #3
0
void GetResponseFromProcessGroup(int KeyWordGroup, char *szUserInput, JJGui *jibber_ui)
{
	char szTemplate[]="SELECT * FROM phrases WHERE category=%d";
	char szSQLString[50]="";
	char szCloser[ 10 ], szPhrase[ 250 ], szFinalResponse[250] = "";
	int nResponse, nRecordCount, nPosition, nLoop = 0;

	bool bFound = false;

	char szTimeStr[300]="";
	time_t t;
	struct tm *tmp;

	// get the time and date
	t = time(NULL);
	tmp = localtime(&t);

	sqlite3_stmt *stmt = NULL;

	// how many response phrases in this keyword group
	nRecordCount = GetPhrasesCount( KeyWordGroup );

	// which one did we use last time
	nPosition = nGroupPositionFlags[ KeyWordGroup ];

	// if we have never used a response from this group, randomly set the first one to use
	if ( nPosition == (-2))
			nPosition = rand() % nRecordCount;
	else {
		++nPosition;
		nPosition = (nPosition >= nRecordCount) ? 0 : nPosition;
	}

	if ( bShow ) {

		AppendText(jibber_ui, DIR_SYSTEM, "Group: %d, Resp: %d, Last: %d", KeyWordGroup, nRecordCount, nPosition);
	}

	// store the new position so that next time we know which one we used last
	nGroupPositionFlags[ KeyWordGroup ] = nPosition;

	// form the SQL string
	sprintf(szSQLString, szTemplate, KeyWordGroup);

	// prepare the SQL statement
	nResponse = sqlite3_prepare_v2( knowledgeDB, szSQLString, -1, &stmt, NULL );

	// if not OK, bomb out
	if ( nResponse != SQLITE_OK)
			return;

	// if OK, start to walk through the record set
	nResponse = sqlite3_step( stmt );

	// as long as we have a valid record set row
	while (nResponse == SQLITE_ROW) {

		// if this record row is one more than the one last used
		if (nLoop == nPosition) {

			bFound = true;

			// get phrase and the end punctuation - don't need the type
			strcpy(szPhrase, (char*) sqlite3_column_text( stmt, PHRASE ));
			strcpy(szCloser, (char *) sqlite3_column_text( stmt, CLOSER ));
		}

		// we found the response we were looking for
		if ( bFound)
				nResponse = SQLITE_ERROR;
		else {

			++nLoop;
			// step through the loop to the next record
			nResponse = sqlite3_step( stmt );
		}
	}

	sqlite3_finalize( stmt );

	// format the time string, create the complete string and then display it
	strftime(szTimeStr, sizeof(szTimeStr), szPhrase, tmp);
	sprintf( szFinalResponse, "%s%s", szTimeStr, szCloser );
	SetToUppercase( szFinalResponse );
	AppendText( jibber_ui, DIR_OUT, szFinalResponse );

	// we don't need to record the time topics
	DeleteEndTopic();

}	// end of GetResponseFromProcessGroup