예제 #1
0
int MenuItem::file_results(Sentence& mSentence)
{
    SuperString tmp;
    //for (auto x:mSentence.m_reduced_sentence.regex_matches)
    for (int m=1; m<mSentence.m_reduced_sentence.regex_matches.size(); m++)
    {
        tmp = mSentence.m_reduced_sentence.regex_matches[m].str();
        
        if (mSentence.m_reduced_sentence.regex_matches.size())
            m_quantity = 1;
        // is first match a number?  file as Quantity
        tmp.trim_spaces();
        tmp.split(' ');
        if (tmp.is_nth_word_a_number(0))
        {
            m_quantity = stof( tmp.c_str() );
        }
        
        // is match a required option?
        if (m_required_options.size())
        {
            string exp;
            for (int ro=0; ro<m_required_options.size(); ro++)
            {
                exp += m_required_options[ro].name;
                tmp.regex_find( exp );
                size_t result = tmp.regex_matches.size();           // Select the item, if info provided in sentence.
                if (result)                                         // (we'll not have to ask the user)
                    m_required_options[ro].selected_item = tmp.regex_matches[0];
            }
        }
        
        // Is the match an additional topping?
        for (int at=0; at<m_additional_toppings.size(); at++)
        {
            string str = m_additional_toppings[at].name.c_str();    //
            tmp.regex_find( str );
            if ( tmp.regex_matches.size() )
                m_additional_toppings[at].requested_indices.push_back( tmp.c_str() );
        }
        string tmps;
        // is match a removed topping?
        for (int st=0; st<m_standard_toppings.size(); st++)
        {
            string str = m_standard_toppings[st].name.c_str();    //
            tmp.regex_find( str );
            //tmps = tmp;
            if ( tmp.regex_matches.size() )
                m_standard_toppings[st].requested_indices.push_back( tmp );
        }
    }
    return m_quantity;
}
예제 #2
0
int Menu::how_much_is( Sentence& mSentence, ServerHandler* mh )
{
    int result =0;
    RestaurantOrder tmpOrder;
    if (mSentence.are_found_in_sentence("how much"))
    {
        result = Parse_Menu( mSentence, mh, tmpOrder);
        if (tmpOrder.m_order.size()==0)
            mh->form_response("I could not find that on the menu.");
        else {
            SuperString tmp = "Okay, ";
            tmpOrder.read_back_items( tmp );
            tmp += " costs $";
            float total = tmpOrder.get_total();
            tmp.append_float ( total );
            mh->form_response( tmp.c_str() );
        }
        return 1;
    }
    return 0;
}