Exemplo n.º 1
0
 def _validate_seats(self, user_input: str) -> ValidationResult:
     results = recognize_number(user_input, Culture.English)
     for result in results:
         if "value" in result.resolution:
             seats = int(result.resolution["value"])
             if 1 <= seats <= 10:
                 return ValidationResult(is_valid=True, value=seats)
     return ValidationResult(is_valid=False,
                             message="Please enter between 1 and 10 seats.")
    def _validate_age(self, user_input: str) -> ValidationResult:
        # Attempt to convert the Recognizer result to an integer. This works for "a dozen", "twelve", "12", and so on.
        # The recognizer returns a list of potential recognition results, if any.
        results = recognize_number(user_input, Culture.English)
        for result in results:
            if "value" in result.resolution:
                age = int(result.resolution["value"])
                if 18 <= age <= 120:
                    return ValidationResult(is_valid=True, value=age)

        return ValidationResult(
            is_valid=False, message="Please enter an age between 18 and 120.")
Exemplo n.º 3
0
 def _validate_preference(self, user_input: str) -> ValidationResult:
     results = recognize_number(user_input, Culture.English)
     ## COPY 2 WIN
     for result in results:
         if "value" in result.resolution:
             preference = int(result.resolution["value"])
             if 1 <= preference <= 50:
                 return ValidationResult(is_valid=True, value=preference)
     return ValidationResult(
         is_valid=False,
         message=
         "Our theater only has 50 rows. Please enter a number in between 1 and 50."
     )
Exemplo n.º 4
0
def validate_cardno(user_input: str, _claimno) -> ValidationResult:
    mydb = createSQL()
    results = recognize_number(user_input, Culture.English)
    for result in results:
        if "value" in result.resolution:
            cardno = int(result.resolution["value"])
            mycursor = mydb.cursor()
            sql = "SELECT * FROM claims WHERE cardno = {} AND claimno = {}".format(
                int(user_input), _claimno)
            mycursor.execute(sql)
            myresult = mycursor.fetchall()
            if len(myresult) > 0:
                mydb.close()
                return ValidationResult(is_valid=True, value=cardno)
    return ValidationResult(
        is_valid=False,
        message=
        "It appears that there is no claim number associated with this card number . Please try a different card number"
    )
    async def on_recognize(self, turn_context: TurnContext,
                           state: Dict[str, object],
                           options: PromptOptions) -> PromptRecognizerResult:
        if not turn_context:
            raise TypeError(
                'NumberPrompt.on_recognize(): turn_context cannot be None.')

        result = PromptRecognizerResult()
        if turn_context.activity.type == ActivityTypes.message:
            message = turn_context.activity

            # TODO: Fix constant English with correct constant from text recognizer
            culture = turn_context.activity.locale if turn_context.activity.locale != None else 'English'

            results = recognize_number(message.text, culture)
            if len(results) > 0:
                result.succeeded = True
                result.value = results[0].resolution["value"]

        return result
Exemplo n.º 6
0
    async def on_recognize(
        self,
        turn_context: TurnContext,
        state: Dict[str, object],
        options: PromptOptions,
    ) -> PromptRecognizerResult:
        if not turn_context:
            raise TypeError("NumberPrompt.on_recognize(): turn_context cannot be None.")

        result = PromptRecognizerResult()
        if turn_context.activity.type == ActivityTypes.message:
            message = turn_context.activity
            culture = self._get_culture(turn_context)
            results: [ModelResult] = recognize_number(message.text, culture)

            if results:
                result.succeeded = True
                result.value = parse_decimal(
                    results[0].resolution["value"], locale=culture.replace("-", "_")
                )

        return result