Ejemplo n.º 1
0
    def parse(self, data):
        """
        Standard parse function for checking if
        entered string is a mathematical equation

        :param data_string: the string we want to parse
        :type data_string: str
        :return: yields parse result(s) if there are any
        :rtype: ParseResult
        """
        # if we just have a number, we know this isn't an equation
        if is_number(data):
            return

        # Doing some initial data cleanup
        clean_data = self.clean_data(data)

        if not clean_data:
            return

        if self.is_simple_equation(clean_data):
            result_type = "Simple"
        elif self.is_text_equation(clean_data):
            result_type = "Text"
        else:
            return

        # If the equation proves to be solveable, we
        # calculate a confidence and report success
        calculated = self.solve_equation(self.parsed_equation)
        if calculated:
            yield self.result(result_type, self.calculate_confidence(data),
                              calculated)
Ejemplo n.º 2
0
    def parse(self, data):
        """
        Standard parse function for checking if
        entered string is a mathematical equation
        """

        # if we just have a number, we know this isn't an equation
        if is_number(data):
            return

        # Doing some initial data cleanup
        clean_data = self.clean_data(data)

        if not clean_data:
            return

        if self.is_simple_equation(clean_data):
            result_type = "Simple"
        elif self.is_text_equation(clean_data):
            result_type = "Text"
        else:
            return

        # If the equation proves to be solveable, we
        # calculate a confidence and report success
        calculated = self.solve_equation(self.parsed_equation)
        if calculated:
            yield self.result(
                result_type,
                self.calculate_confidence(data),
                calculated
            )
Ejemplo n.º 3
0
    def test_is_number(self):

        self.assertTrue(is_number("123.123"))
        self.assertTrue(is_number("123"))

        self.assertFalse(is_number("7 divided by 2"))