当前位置: 首页>>代码示例>>C++>>正文


C++ Sentence::regex_find方法代码示例

本文整理汇总了C++中Sentence::regex_find方法的典型用法代码示例。如果您正苦于以下问题:C++ Sentence::regex_find方法的具体用法?C++ Sentence::regex_find怎么用?C++ Sentence::regex_find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sentence的用法示例。


在下文中一共展示了Sentence::regex_find方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Parse_Math_Statement

/*****************************************************************
 Do the work of the Telegram :
 return  -1	=> Not handled
 else number of extra bytes extracted from the mSentence buffer.
 - besides strlen(mSentence)!
 *****************************************************************/
int Parse_Math_Statement( Sentence& mSentence, ServerHandler* mh )
{
    int retval=-1;
    mSentence.restore_reduced();
    //printf("Parse_Math_Statement: %s\n", mSentence.m_raw_sentence );
    
    int operation_count=0;
    float first_number, second_number, final_answer;
    //while()
    {
        int op = Parse_One_Statement( mSentence, first_number, second_number, final_answer );
        if (op) {
            int result = mSentence.regex_find( interrogative_expression );
            if (result) {
                mSentence.m_sentence.regex_reduce();
            }
            form_verbal_answer(mSentence, mh, final_answer);
        }        
        operation_count++;
        retval = 0;
    }
    
	int result = Parse_Unit_Conversion_Statement( mSentence, final_answer );
	if (result>0) {
		form_verbal_answer(mSentence, mh, final_answer);		
		retval=0;
		return retval;            
	} 	
	
	result = Parse_shape_geometry( mSentence, final_answer );
	if (result>0) {
		form_verbal_answer(mSentence, mh, final_answer);		
		return retval;            
	}

    int foundA = mSentence.regex_find( "area (of )?(a )?circle" );
    if (foundA)	{ 
		mh->form_response( "Area of a circle is pi times the radius squared." );	
		return 1;	
    }    
    foundA = mSentence.regex_find( "circumference (of )?(a )?circle" );
    if (foundA)	{ 		
		mh->form_response( "Circumference of a circle is pi times the diameter." );	
		return 1;	
    }    
	
    if (retval>-1)  printf( "Parse_Math_Statement done\n" );
}
开发者ID:stenniswood,项目名称:bk_code,代码行数:54,代码来源:math_protocol2_o.cpp

示例2: Parse_shape_geometry

int Parse_shape_geometry( Sentence& mSentence, float& final_answer )
{
	float first_number=0.0;
	printf("parse shape geometry\n");

    int foundA = mSentence.regex_find( "area (of )?(a )?circle with radius (of )?(\\d+)" );
    if (foundA)	{ 
    	int msize = mSentence.m_sentence.regex_matches.size();
    	get_number( mSentence.m_sentence.regex_matches, first_number, msize-1); 
    	printf("  %6.2f\n", first_number );
    	final_answer = M_PI * first_number*first_number;
  		return 1;    	
    }    

    foundA = mSentence.regex_find( "area (of )?(a )?circle with (a )?diameter (of )?(\\d+)" );
    if (foundA)	{ 
    	int msize = mSentence.m_sentence.regex_matches.size();    
    	get_number( mSentence.m_sentence.regex_matches, first_number,msize-1); 
    	printf("  %6.2f\n", first_number );    	
    	final_answer = M_PI * first_number*first_number/4.0;
  		return 1;    	
    }    

    foundA = mSentence.regex_find( "circumference (of )?(a )?(circle )?(with )?(a )?radius (of )?(\\d+)" );
    if (foundA)	{ 
    	int msize = mSentence.m_sentence.regex_matches.size();    
    	get_number( mSentence.m_sentence.regex_matches, first_number,msize-1); 
    	final_answer = M_PI * first_number*2;
  		return 1;    	
    }    

    foundA = mSentence.regex_find( "circumference (of )?(a )?(circle )?(with )?(a )?diameter (of )?(\\d+)" );
    if (foundA)	{ 
    	int msize = mSentence.m_sentence.regex_matches.size();    
    	get_number( mSentence.m_sentence.regex_matches, first_number,msize-1); 
    	final_answer = M_PI * first_number;
  		return 1;
    }    
	return 0;
}
开发者ID:stenniswood,项目名称:bk_code,代码行数:40,代码来源:math_protocol2_o.cpp

示例3: month_is_found

// "((this|last|next) month)|(\d+ months ago)|(\d+ months from now)|(in the last \d+ months)"
int month_is_found( Sentence& mSentence )
{
    int retval=0;
    retval = mSentence.is_found_in_sentence("this month");
    if (retval)
    {
    	retval = bd_now.tm_mon;
    	return retval;	
    }
    retval = mSentence.is_found_in_sentence("last month");    
    if (retval)
    {  retval = bd_now.tm_mon-1;	return retval;	}

	retval = mSentence.is_found_in_sentence("next month");
    if (retval)
    {  retval = bd_now.tm_mon+1;	return retval;	}
    
    retval = mSentence.regex_find("(\\d+) months ago");
    if (retval) 
    {
    	//mSentence.m_sentence.print_matches();
    	string val = mSentence.m_sentence.regex_matches[0];
    	int m = atoi(val.c_str());
    	retval = bd_now.tm_mon-m;
    }
    
    retval = mSentence.regex_find("(\\d+) months from now");
    if (retval) 
    {
    	//mSentence.m_sentence.print_matches();    
    	string val = mSentence.m_sentence.regex_matches[0];
    	int m = atoi( val.c_str() );
    	retval = bd_now.tm_mon+m;
    }
    
    for (int m=0; m<12; m++)
        if (mSentence.is_found_in_sentence( Months[m].c_str() ))
            return m;
    return retval;
}
开发者ID:stenniswood,项目名称:bk_code,代码行数:41,代码来源:qualitative_time.cpp

示例4: Parse_One_Statement

// The sentence may contain several operations.
// mFoundWord will be gauranteed to be part of the sentence (b/c it was from evaluate_sentence() )
int Parse_One_Statement( Sentence& mSentence, float& first_number, float& second_number, float& final_answer )
{
    string tmp;
    final_answer=0.0;
    
    int result = mSentence.regex_find(Plus_expression);
    if (result) {
//    	printf("Found PLUS\t");
        get_numbers( mSentence.m_sentence.regex_matches, first_number, second_number );
        final_answer = first_number + second_number;
        return result;
    }
    
    result = mSentence.regex_find(Minus_expression);	// will find any matching multiply Word too.
    if (result)
    {
//    	printf("Found MINUS\n");
        get_numbers( mSentence.m_sentence.regex_matches, first_number, second_number );
        final_answer = first_number - second_number;
        return result;
    }
    
    result = mSentence.regex_find( Multiply_expression );
    if (result) {
        get_numbers( mSentence.m_sentence.regex_matches, first_number, second_number );
        final_answer = first_number * second_number;
	    return result;        
    }
    result = mSentence.regex_find( Divide_expression );
    if (result) {
        get_numbers( mSentence.m_sentence.regex_matches, first_number, second_number );
        if (second_number!=0.0)
            final_answer = first_number / second_number;
        else
            final_answer = FLT_MAX;
	    return result;            
    }
    return result;
}
开发者ID:stenniswood,项目名称:bk_code,代码行数:41,代码来源:math_protocol2_o.cpp

示例5: dow_is_found

// "(yesterday|today|tomorrow)|(\d+ days ago)|(sunday|monday|tuesday|wednesday|thursday|friday|saturday)"
int dow_is_found( Sentence& mSentence )
{
    int retval=0;
    retval = mSentence.is_found_in_sentence("today");
    if (retval)    	return bd_now.tm_mday;
    retval = mSentence.is_found_in_sentence("yesterday");
    if (retval)    	return bd_now.tm_mday-1;
    retval = mSentence.is_found_in_sentence("tomorrow");
    if (retval)    	return bd_now.tm_mday+1;
    
    retval = mSentence.regex_find("(\\d+ )days ago");
    if (retval)  {
		string val = mSentence.m_sentence.regex_matches[0];
    	int d= atoi(val.c_str());
      	return bd_now.tm_mday-d;
    }
    for (int d=0; d<7; d++)
        if (mSentence.is_found_in_sentence(days_of_week[d].c_str()))
            return d;
    return retval;
}
开发者ID:stenniswood,项目名称:bk_code,代码行数:22,代码来源:qualitative_time.cpp

示例6: test_devices_db

void test_devices_db()
{
    // Add some samples rows : 
    connect_to_users_db();
    
    std::string mRegex;
    int user_id = sql_users.sql_find("stenniswood");  
    printf("User_id=%d\n", user_id );
    sql_devices.get_all_device_names_regex ( user_id, mRegex );    


    Sentence phrase = "main TV";
    int result = phrase.regex_find( mRegex );
    printf("REGEX result: %d\n", result );
	if (result) {
		std::string tmp = phrase.m_sentence.regex_matches[1];    
		printf("REGEX MATCH: %s\n", tmp.c_str());
    }
    
    std::string tmp = "(";
	tmp += append_int( user_id );
    
    std::string tmp1 = tmp + ", 'successroad1', '(main TV|TV)', 'RPI')";
	std::string tmp2 = tmp + ", 'successroad2', '(bedroom TV)', 'RPI')";
	std::string tmp3 = tmp + ", 'portable', '(LCD pi)', 'RPI')";

//	sql_devices.sql_add_if_not_already(user_id, dev_info_map );
//	sql_devices.sql_add_if_not_already(user_id, "( user_id, device_name, preferred_name, device_type )", tmp1, "successroad1");
//	sql_devices.sql_add_if_not_already(user_id, "( user_id, device_name, preferred_name, device_type )", tmp2, "successroad2");
//	sql_devices.sql_add_if_not_already(user_id, "( user_id, device_name, preferred_name, device_type )", tmp3, "portable");
	
	sql_devices.sql_find( user_id,"successroad1" );	sql_devices.print_results();
	sql_devices.sql_find( user_id,"successroad2" );	sql_devices.print_results();
	sql_devices.sql_find( user_id,"portable" );	sql_devices.print_results();


	printf("Done with test_devices_db()\n");
}
开发者ID:stenniswood,项目名称:bk_code,代码行数:38,代码来源:sql_device.cpp

示例7: Parse_Unit_Conversion_Statement

int Parse_Unit_Conversion_Statement( Sentence& mSentence, float& final_answer )
{
    int retval=-1;
    final_answer=0.0;
    float first_number;
    float second_number;
	float scale;

    int foundA = mSentence.regex_find( "(\\d+ )(km\\/hr|kph|metric|kilometers? per hour) (to|into|in|as) (miles? per hour|mph|miles?/hr)" );
    if (foundA)	{ scale = Km_to_Miles_per_Hour;  get_number( mSentence.m_sentence.regex_matches, first_number); }    
    int foundB = mSentence.regex_find( "(\\d+ )(miles? per hour|mph|miles?/hr) (to|into|in|as) (km/hr|kph|metric|kilometers? per hour)" );
    if (foundB)	{ scale = Miles_to_Km_per_Hour;  get_number( mSentence.m_sentence.regex_matches, first_number); }    
    if (foundA||foundB) 
    {
    	final_answer = first_number * scale;   
		//printf("%6.3f = %6.3f", first_number, final_answer );    	
    	return 1;
    }

    foundA = mSentence.regex_find( "(\\d+) (pounds?|lbs) (to|into|in|as) (kilograms?|kg|metric)" );
    if (foundA)	{ scale = Pound_to_Kg; get_number( mSentence.m_sentence.regex_matches, first_number); }
    foundB = mSentence.regex_find( "(\\d+ )(kilograms?|kg|metric) (to|into|in|as) (pounds?|lbs)" );
    if (foundB)	{ scale = Kg_to_Pound;  get_number( mSentence.m_sentence.regex_matches, first_number); }
    if (foundA || foundB)
    {
        final_answer = first_number * scale;    
        return 1;
    }

    foundA = mSentence.regex_find( "(\\d+ )(ounces?) (to|into|in|as) (grams?|g)" );
    if (foundA)	{ scale = ounces_to_g; get_number( mSentence.m_sentence.regex_matches, first_number); }
    foundB = mSentence.regex_find( "(\\d+ )(grams?|g) (to|into|in|as) (ounces?)" );        
    if (foundB)	{ scale = g_to_ounces;  get_number( mSentence.m_sentence.regex_matches, first_number); }
    if (foundA||foundB)
    {
        final_answer = first_number * scale;   
    	return 1;    	
    }
    
    foundA = mSentence.regex_find( "(\\d+ )(inches?|in) (to|into|in|as) (centimeters?|cm)" );    
    if (foundA)	{ scale = inches_to_cm; get_number( mSentence.m_sentence.regex_matches, first_number); }
    foundB = mSentence.regex_find( "(\\d+ )(centimeters?|cm) (to|into|in|as) (inches?|in)" );
    if (foundB)	{ scale = cm_to_inches;  get_number( mSentence.m_sentence.regex_matches, first_number); }    
    if (foundA||foundB)
    {    
    	final_answer = first_number * scale;   
    	return 1;    	
    }
    
    foundA = mSentence.regex_find( "(\\d+) (feets?|foot) (to|into|in|as) (meters?)" );
    if (foundA)	{ scale = feet_to_meters; get_number( mSentence.m_sentence.regex_matches, first_number); }    
    foundB = mSentence.regex_find( "(\\d+) (meters?) (to|into|in|as) (feet|foot)" );
    if (foundB)	{ scale = meters_to_feet;  get_number( mSentence.m_sentence.regex_matches, first_number); }        
    if (foundA||foundB)
    {
    	final_answer = first_number * scale;   
    	return 1;
    }

    //printf("%6.3f %6.2f = %6.3f", first_number, second_number, final_answer );
    return retval;
}
开发者ID:stenniswood,项目名称:bk_code,代码行数:62,代码来源:math_protocol2_o.cpp

示例8: parse_qualitative_2_time

/* Return : -1 not processed */
int parse_qualitative_2_time( Sentence& mSentence, struct tm& sTime, struct tm& eTime )
{
	int retval = -1;
	vector<int> answers;
	vector<int> remove_wi;	
	parsed_qualitative_time     = false;
	parsed_qualitative_duration = false;

	time_t start;
	time_t now;
	time( &now );

	int result;
	int between = mSentence.is_found_in_sentence( "between" );
//	if (result)  retval = 1;
	result = mSentence.is_found_in_sentence( "today" );
	if (result)  {
		parsed_qualitative_time     = true;
		parsed_qualitative_duration = true;		
		eTime = *(localtime( &now ));
		sTime = eTime;
		sTime.tm_hour = 0;
		sTime.tm_min = 0;
		sTime.tm_sec = 0;
		retval = 1;
	}
	result = mSentence.is_found_in_sentence( "yesterday" );
	if (result)  {
		parsed_qualitative_time     = true;
		parsed_qualitative_duration = true;		
		update_now_time();
		eTime = bd_now;	
		eTime.tm_mday--;
		eTime.tm_wday--;
		eTime.tm_hour = 23;
		eTime.tm_min = 59;
		eTime.tm_sec = 59;

		sTime = eTime;
		sTime.tm_hour = 0;
		sTime.tm_min = 0;
		sTime.tm_sec = 0;
		retval = 1;
	}

	result = mSentence.are_found_in_sentence( "this week" );
	if (result)  {
		parsed_qualitative_time = true;
		parsed_qualitative_duration = true;
		eTime = bd_now;
		sTime = eTime;
		sTime.tm_mday-=sTime.tm_wday;
		sTime.tm_wday = 0;
		sTime.tm_hour =0; sTime.tm_min=0; sTime.tm_sec=0;
		retval = 1;
	}	

	// 
    result = mSentence.regex_find("(\\d+) days ago");
    if (result)  {
		SuperString val( mSentence.m_reduced_sentence.regex_matches[0] );		
		string num  = "\\d+";
		int result2 = val.regex_find(num);
		num = val.regex_matches[0];
    	int    d = atoi( num.c_str() );
	    //printf("days ago: %s  result=%d\n\n", num.c_str(), d );
		parsed_qualitative_time = true;
		parsed_qualitative_duration = true;
		eTime = bd_now;
		eTime.tm_mday = bd_now.tm_mday-d;					
		sTime = eTime;
		mk_startofday(sTime);
		mk_endofday  (eTime);
      	retval = 1; 
    }
    for (int d=0; d<7; d++)
        if (mSentence.is_found_in_sentence(days_of_week[d].c_str()))
            return d;

	int dans = mSentence.are_found_in_sentence( "in the last" );
	if (dans)
		retval = 1;

	string exp = integer_e;
	exp       += "(day|days|hour|hours|minute|minutes|seconds)";

	//parsed_qualitative_duration  = mSentence.are_found_in_sentence( "at [specific time ie five thirty]" );
	//parsed_qualitative_time = parsed_qualitative_duration;
	return retval;
}
开发者ID:stenniswood,项目名称:bk_code,代码行数:91,代码来源:qualitative_time.cpp


注:本文中的Sentence::regex_find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。