def intentIdentifier(clean_input, context,current_intent): clean_input = clean_input.lower() #Scoring Algorithm, can be changed. scores = ngrammatch(clean_input) #choosing here the intent with the highest score scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) # print clean_input #print 'scores', scores if(current_intent==None): #if(clean_input=="search"): # return loadIntent('params/newparams.cfg', 'SearchStore') if(clean_input=='selectrestro'): print('selectrestro intent') return loadIntent('params/newparams.cfg','RestroSelect') if(clean_input=='BuyBook'): #print('BuyBook intent') return loadIntent('params/newparams.cfg','BuyBook') else: #print('ngrams intent') return loadIntent('params/newparams.cfg',scores[-1][0]) #return loadIntent('params/newparams.cfg','BuyBook') else: #If current intent is not none, stick with the ongoing intent return current_intent
def intentIdentifier(clean_input, context, current_intent): #Identifying the intent to be performed with the help of ngram match clean_input = clean_input.lower() #ngram match algorithm which gives a score of how close the user input matches with each intents available. scores = ngrammatch(clean_input) #choosing here the intent with the highest score scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) if (current_intent == None): #primary keys for determining the action restaurant_keyword = [ 'restaurant', 'food court', 'cafe', 'hotel', 'dining room', 'canteen', 'eatery', 'hungry' ] vegetables_keyword = [ 'vegetables', 'vegetable', 'fruit', 'fruits', 'leafy' ] #with the help of a few straigtforward keywords from user input the intent is directly matched. for i in range(len(restaurant_keyword)): if (restaurant_keyword[i] in clean_input): return loadIntent('params/newparams.cfg', 'BookRestaurant') for i in range(len(vegetables_keyword)): if (vegetables_keyword[i] in clean_input): return loadIntent('params/newparams.cfg', 'BuyVegetables') else: #if no straigtforward keyword is found in userinput then ngramscore is used to decide up on the intent. if (scores[-1][1] > 0.1): return loadIntent('params/newparams.cfg', scores[-1][0]) else: return None else: #If current intent is not none, stick with the ongoing intent return current_intent
def intentIdentifier(clean_input, context,current_intent): clean_input = clean_input.lower() scores = ngrammatch(clean_input) scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) if((current_intent==None) and (scores[-1][1] > 0.02)): return loadIntent('params/Movie_Restaurants_Params.cfg',scores[-1][0]) else: # 'same intent' return current_intent
def intentIdentifier(clean_input, context, current_intent): clean_input = clean_input.lower() scores = ngrammatch(clean_input) scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) if DEBUG_LEVEL >= DEBUG_LEVEL_DBG: print('Clean Input: ', clean_input) print('Scores:', scores) if (current_intent == None): return loadIntent('params/newparams.cfg', scores[-1][0]) else: # print 'same intent' return current_intent
def intentIdentifier(clean_input, context,current_intent): clean_input = clean_input.lower() scores = ngrammatch(clean_input) scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) if(current_intent==None): if(clean_input=='book'): return loadIntent('params/skills.cfg','LibraryBook') if(clean_input=='restaurant'): return loadIntent('params/skills.cfg','Restaurant') else: return loadIntent('params/skills.cfg',scores[-1][0]) else: #print 'same intent' return current_intent
def intentIdentifier(clean_input, context, current_intent): clean_input = clean_input.lower() scores = ngrammatch(clean_input) scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) # print clean_input #print 'scores', scores if (current_intent == None): if (clean_input == "search"): return loadIntent('params/newparams.cfg', 'SearchStore') if (clean_input == 'book'): return loadIntent('params/newparams.cfg', 'OrderBook') else: return loadIntent('params/newparams.cfg', scores[-1][0]) else: #print 'same intent' return current_intent
def intentIdentifier(clean_input, context, current_intent): clean_input = clean_input.lower() scores = ngrammatch(clean_input) scores = sorted(scores, key=lambda tup: tup[1]) # print clean_input #print 'scores', scores if (current_intent == None): if (re.search(RESTAURANT_REGEX, clean_input)): return loadIntent('params/newparams.cfg', 'RestaurantBooking') if (re.search(HOTEL_REGEX, clean_input)): return loadIntent('params/newparams.cfg', 'HotelBooking') else: return loadIntent('params/newparams.cfg', scores[-1][0]) else: #print 'same intent' return current_intent
def intentIdentifier(clean_input, context, current_intent): clean_input = clean_input.lower() scores = ngrammatch(clean_input) scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) # print clean_input # print 'scores', scores if current_intent is None: if 'create' in clean_input and 'ticket' in clean_input: return loadIntent('params/newparams.cfg', 'CreateTicket') if 'ticket' in clean_input: return loadIntent('params/newparams.cfg', 'TicketSearch') if 'restaurant' in clean_input: return loadIntent('params/newparams.cfg', 'RestaurantSearch') else: return loadIntent('params/newparams.cfg', scores[-1][0]) else: # print 'same intent' return current_intent
def intentIdentifier(clean_input, context, current_intent): clean_input = clean_input.lower() if (current_intent != 'Reset' and current_intent != None): return current_intent #Scoring Algorithm, can be changed. scores = ngrammatch(clean_input) #choosing here the intent with the highest score scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) # print clean_input #print 'scores', scores newIntent = loadIntent('params/newparams.cfg', scores[-1][0]) if (newIntent.name == 'Reset'): return newIntent if (current_intent == None): return newIntent else: #If current intent is not none, stick with the ongoing intent return current_intent
def intentIdentifier(clean_input, context,current_intent): # print(clean_input, context,current_intent) clean_input = clean_input.lower() #Scoring Algorithm, can be changed. scores = ngrammatch(clean_input) #choosing here the intent with the highest score scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) # print('clean_input',clean_input) # print('scores', scores) if(current_intent==None): if(clean_input=="restaurant"): return loadIntent('params/newparams.cfg', 'StoreSearch') if(clean_input=='mobile'): return loadIntent('params/newparams.cfg','OrderBook') else: return loadIntent('params/newparams.cfg',scores[-1][0]) else: #If current intent is not none, stick with the ongoing intent return current_intent
def intentIdentifier(clean_input, context, current_intent): clean_input = clean_input.lower() #print(clean_input) #Scoring Algorithm, can be changed. scores = ngrammatch(clean_input) #choosing here the intent with the highest score scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) #using KNN to get the intent class intentclass, probabilities = predict_class(clean_input) #printing the probabilities of ngram and KNN print(scores, intentclass, probabilities) if (current_intent == None): if (clean_input == "movie"): return loadIntent('params/newparams.cfg', 'movieChoice') elif (clean_input == "restaurant"): return loadIntent('params/newparams.cfg', 'BookRestaurant') else: return loadIntent('params/newparams.cfg', intentclass) else: #If current intent is not none, stick with the ongoing intent return current_intent
def intentIdentifier(clean_input, context, current_intent): clean_input = clean_input.lower() scores = ngrammatch(clean_input) scores = sorted_by_second = sorted(scores, key=lambda tup: tup[1]) # print clean_input # print 'scores', scores return loadIntent('data/params/params.cfg', 'FlightSearch') if (current_intent == "None"): if (clean_input == "search"): return loadIntent('data/params/params.cfg', 'FlightSearch') if (clean_input == 'book'): return loadIntent('data/params/params.cfg', 'FlightBook') if (clean_input == 'track'): return loadIntent('data/params/params.cfg', 'FlightTrack') else: if scores[-1][0].startswith('book'): return loadIntent('data/params/params.cfg', 'FlightBook') elif scores[-1][0].startswith('search'): return loadIntent('data/params/params.cfg', 'FlightSearch') else: return loadIntent('data/params/params.cfg', 'FlightSearch') else: return current_intent