예제 #1
0
    def is_arithmetic_expression(exp):
        """
        Returns true if the string corresponds to an arithmetic expression, and false
        otherwise

        :param exp: the string to check
        :return: true if the string is an arithmetic expression, false otherwise
        """
        is_arithmetic_expression = False
        cur_str = ''
        for char_val in exp:
            if char_val == '+' or char_val == '-' or char_val == '/' or (
                    char_val == '*' and len(exp) > 2):
                is_arithmetic_expression = True

            if char_val == '?' or char_val == '|' or char_val == '[' or char_val == '_' or char_val == "'":
                return False

            if char_val.isalpha():
                cur_str += char_val
                continue

            if StringUtils.is_delimiter(char_val):
                if cur_str not in MathExpression.fixed_functions:
                    return False

                is_arithmetic_expression = True
                cur_str = ''

        return is_arithmetic_expression
예제 #2
0
    def __init__(self, str_val):
        if not isinstance(str_val, str):
            raise NotImplementedError("UNDEFINED PARAMETERS")
        """
        Creates a new string template.

        :param str_val: the string object
        """
        # the string corresponding to the template
        self._str_val = str_val
        # whether the string represents a whole word or phrase (and not a punctuation)
        self._whole = len(str_val) != 1 or not StringUtils.is_delimiter(
            str_val[0])
        # empty set of slots
        self._slots = set()