Exemplo n.º 1
0
 def receive_is_correct_delay(self, f1, f2):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         if uInput == ('yes' or 'y' or 'Y'):
             self.modify(f2, isCorrect=True)
             from hspTrainInfo import getPredictedDelay
             global origCode, destCode, delayByTime, delayDepDate, delayDepTime
             try:
                 predictedDelay = getPredictedDelay(origCode, destCode,
                                                    int(delayByTime),
                                                    delayDepDate,
                                                    delayDepTime)
             except:
                 botUpdate("Sorry, something went wrong.")
             else:
                 if int(predictedDelay) > 0:
                     botUpdate('We expect a delay of %s minute(s)' %
                               predictedDelay)
                 elif int(predictedDelay) < 0:
                     predictedDelay = int(predictedDelay) * -1
                     botUpdate('We expect it will be %s minute(s) early' %
                               predictedDelay)
                 else:
                     botUpdate('We expect your train to be on time!')
         elif uInput == ('no' or 'n' or 'N'):
             from main import restartChat
             restartChat()
         else:
             botUpdate("Sorry, I didn't understand that. Enter yes or no.")
Exemplo n.º 2
0
 def get_origin_del_dep_time(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 5
         botUpdate('What time are you travelling?')
Exemplo n.º 3
0
 def get_delay_origin(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 10
         botUpdate('What station are you currently at?')
Exemplo n.º 4
0
 def get_human_origin(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 1
         botUpdate('Where are you departing from?')
Exemplo n.º 5
0
 def getWantReturn(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 7
         botUpdate('Would you like a return ticket as well, yes or no?')
Exemplo n.º 6
0
 def get_human_destination(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 2
         botUpdate('Where would you like to go?')
Exemplo n.º 7
0
 def get_delayed_by(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 12
         botUpdate('How many minutes are you delayed by?')
Exemplo n.º 8
0
 def get_delay_destination(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 11
         botUpdate('What station is your destination?')
Exemplo n.º 9
0
 def get_return_dep_time(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 9
         botUpdate('What time would you like your return ticket to be?')
         botUpdate('Please enter in hh:mm 24hr format.')
Exemplo n.º 10
0
 def get_origin_dep_time(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 5
         botUpdate('What time would you like depart?')
         botUpdate('Please enter in hh:mm 24hr format.')
Exemplo n.º 11
0
 def check_info_delay(self, f1, wantPredic, delDepD, delDepT, delDest,
                      delCurr, delBy):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply, orig, dest
         lastBotReply = 13
         botUpdate('You want to check the predicted train delay from %s to %s on %s at %s' % \
             (orig.title(), dest.title(), delDepD, delDepT))
         botUpdate('Is this information correct yes or no?')
Exemplo n.º 12
0
 def get_return_dep_date(self, f1):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 8
         botUpdate('What date would you like to return on?')
         botUpdate(
             'Please enter in dd/mm/yy format or common words like today and tomorrow.'
         )
Exemplo n.º 13
0
 def receive_delayed_by(self, f1, f2):
     try:
         self.retract(f1)
     except:
         pass
     else:
         if isNumber(uInput):
             global delayByTime
             delayByTime = uInput
             self.modify(f2, delayedBy=delayByTime)
             self.declare(Action('get-human-answer'))
         else:
             from main import botUpdate
             botUpdate(
                 "Sorry that doesn't seem to be valid. Could you please try again?"
             )
Exemplo n.º 14
0
 def receiveWantReturn(self, f1, f2):
     try:
         self.retract(f1)
     except:
         pass
     else:
         if uInput == ('yes' or 'y' or 'Y'):
             global wantsRet
             wantsRet = True
             self.modify(f2, wantsReturn=True, askedReturn=True)
         elif uInput == ('no' or 'n' or 'N'):
             self.modify(f2, askedReturn=True)
         else:
             from main import botUpdate
             botUpdate("Sorry, I didn't understand that. Enter yes or no.")
         self.declare(Action('get-human-answer'))
Exemplo n.º 15
0
 def receive_origin_del_dep_date(self, f1, f2):
     try:
         self.retract(f1)
     except:
         pass
     else:
         if isDateFormat(isDateWord(uInput)):
             global delayDepDate
             delayDepDate = isDateWord(uInput)
             self.modify(f2, delayDepDate=isDateWord(uInput))
             self.declare(Action('get-human-answer'))
         else:
             from main import botUpdate
             botUpdate(
                 "Sorry that didn't seem to be the correct date format. Could you please try again?"
             )
             botUpdate("i.e (dd/mm/yy) | 31/12/18")
Exemplo n.º 16
0
 def receive_delay_origin(self, f1, f2):
     try:
         self.retract(f1)
     except:
         pass
     else:
         if isRealStation(uInput):
             global orig, origCode
             orig = uInput
             origCode = getStationCode(uInput)
             self.modify(f2, delayCurrCode=origCode)
             self.declare(Action('get-human-answer'))
         elif len(hasMultipule(uInput)) > 1:
             from main import botUpdate
             locations = hasMultipule(uInput)
             botUpdate("Did you mean one of these? " + ', '.join(locations))
         else:
             from main import botUpdate
             botUpdate(
                 "Sorry I didn't recognise that station. Could you please try again?"
             )
Exemplo n.º 17
0
 def startup(self):
     from main import botUpdate
     global lastBotReply
     lastBotReply = 0
     botUpdate('Hello, how may I help you today?')
     botUpdate(
         'e.g. Can I book a train ticket, Get my predicted arrival time...')
     botUpdate(
         'Please enter in the format: dd/mm/yy, today, tomorrow, and time in the 24hr format: hh:mm'
     )
Exemplo n.º 18
0
 def check_info(self, f1, org, dest, orgDepDate, orgDepTime, wantsRet,
                retDepDate, retDepTime):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         global lastBotReply
         lastBotReply = 3
         botUpdate(
             'You want to book a ticket to go from %s to %s on %s at %s.' %
             (org.title(), dest.title(), orgDepDate, orgDepTime))
         if wantsRet:
             botUpdate('And you want to return on %s at %s.' %
                       (retDepDate, retDepTime))
         botUpdate('Is this information correct yes or no?')
Exemplo n.º 19
0
 def receive_origin_del_dep_time(self, f1, f2):
     try:
         self.retract(f1)
     except:
         pass
     else:
         if isTimeFormat(uInput) and isValidTime(uInput):
             global delayDepTime
             delayDepTime = uInput
             self.modify(f2, delayDepTime=delayDepTime)
             self.declare(Action('get-human-answer'))
         elif isValidTime(uInput) is False and isTimeFormat(uInput) is True:
             from main import botUpdate
             botUpdate(
                 "Sorry that didn't seem to be a valid time. Could you please try again?"
             )
         else:
             from main import botUpdate
             botUpdate(
                 "Sorry that didn't seem to be the correct format. Could you please try again?"
             )
             botUpdate("i.e (hh:mm) | 14:30")
Exemplo n.º 20
0
 def receive_is_correct(self, f1, f2):
     try:
         self.retract(f1)
     except:
         pass
     else:
         from main import botUpdate
         if uInput == ('yes' or 'y' or 'Y'):
             self.modify(f2, isCorrect=True)
             from nrailFareInfo import getFareInfo
             global orig, dest, origDepDate, origDepTime, wantsRet, retDepDate, retDepTime
             try:
                 theURL = getFareInfo(orig, dest, origDepDate, origDepTime,
                                      wantsRet, retDepDate, retDepTime)
                 botUpdate(theURL)
             except:
                 botUpdate(
                     "Sorry, something went wrong could you please try again."
                 )
         elif uInput == ('no' or 'n' or 'N'):
             from main import restartChat
             restartChat()
         else:
             botUpdate("Sorry, I didn't understand that. Enter yes or no.")
Exemplo n.º 21
0
    def receive_human_answer(self, f1, f2):
        self.retract(f1)
        global dest, orig, destCode, origCode
        question = uInput
        res = tuple(Custom_pos_tag(word_tokenize(question)))
        # print(res)
        destin = ''
        origi = ''
        origiDepDate = ''
        origiDepTime = ''
        wanRet = False
        retiDepDate = ''
        retiDepTime = ''
        origiCode = ''
        destinCode = ''
        if wantsTicket(res):
            if wantsReturn(res):
                global wantsRet
                wantsRet = wantsReturn(res)
                wanRet = wantsReturn(res)
            res = removeWantsTicketPart(res)
            loc = findINandTO(res)
            if loc:
                if loc[0][1] == 'IN':
                    origi = loc[1][0]
                    orig = origi
                    origiCode = getStationCode(loc[1][0])
                    origCode = origiCode
                    if len(loc) > 2:
                        destin = loc[3][0]
                        dest = destin
                        destinCode = getStationCode(loc[3][0])
                        destCode = destinCode
                elif loc[0][1] == 'TO':
                    destin = loc[1][0]
                    dest = destin
                    destinCode = getStationCode(loc[1][0])
                    destCode = destinCode
                    if len(loc) > 2:
                        origi = loc[3][0]
                        orig = origi
                        origiCode = getStationCode(loc[3][0])
                        origCode = origiCode

            if dateInFirstMessage(res):
                global origDepDate
                origDepDate = dateInFirstMessage(res)
                origiDepDate = dateInFirstMessage(res)

            if timeInFirstMessage(res):
                global origDepTime
                origDepTime = timeInFirstMessage(res)
                origiDepTime = timeInFirstMessage(res)

            if retDateInFirstMessage(res) != '':
                global retDepDate
                retDepDate = retDateInFirstMessage(res)
                retiDepDate = retDateInFirstMessage(res)

            if retTimeInFirstMessage(res) != '':
                global retDepTime
                retDepTime = retTimeInFirstMessage(res)
                retiDepTime = retTimeInFirstMessage(res)

            self.modify(f2,
                        booking=True,
                        destination=destin,
                        origin=origi,
                        originDepDate=origiDepDate,
                        originDepTime=origiDepTime,
                        wantsReturn=wanRet,
                        returnDepDate=retiDepDate,
                        returnDepTime=retiDepTime)
            self.declare(Action('get-human-answer'))

        elif wantsPredicted(res):
            res = removeWantsTicketPart(res)
            delDepDate = ''
            delDepTime = ''

            loc = findINandTO(res)
            if loc:
                if loc[0][1] == 'IN':
                    origi = loc[1][0]
                    orig = origi
                    origiCode = getStationCode(loc[1][0])
                    origCode = origiCode
                    if len(loc) > 2:
                        destin = loc[3][0]
                        dest = destin
                        destinCode = getStationCode(loc[3][0])
                        destCode = destinCode
                elif loc[0][1] == 'TO':
                    destin = loc[1][0]
                    dest = destin
                    destinCode = getStationCode(loc[1][0])
                    destCode = destinCode
                    if len(loc) > 2:
                        origi = loc[3][0]
                        orig = origi
                        origiCode = getStationCode(loc[3][0])
                        origCode = origiCode

            if dateInFirstMessage(res):
                global delayDepDate
                delayDepDate = dateInFirstMessage(res)
                delDepDate = dateInFirstMessage(res)

            if timeInFirstMessage(res):
                global delayDepTime
                delayDepTime = timeInFirstMessage(res)
                delDepTime = timeInFirstMessage(res)

            self.modify(f2,
                        wantsPredicted=True,
                        delayCurrCode=origiCode,
                        delayDestCode=destinCode,
                        delayDepDate=delDepDate,
                        delayDepTime=delDepTime)

            self.declare(Action('get-human-answer'))

        else:
            from main import botUpdate
            botUpdate(
                "Sorry I didn't understand what you said. Could you please try again?"
            )