当前位置: 首页>>代码示例>>Python>>正文


Python Statement.text方法代码示例

本文整理汇总了Python中chatterbot.conversation.Statement.text方法的典型用法代码示例。如果您正苦于以下问题:Python Statement.text方法的具体用法?Python Statement.text怎么用?Python Statement.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chatterbot.conversation.Statement的用法示例。


在下文中一共展示了Statement.text方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_matches

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import text [as 别名]
    def handle_matches(self, match):
        """
        Returns a response statement from a matched input statement.

        :param match: It is a valid matched pattern from the input statement
        :type: `_sre.SRE_Match`
        """
        response = Statement(text='')
        try:
            from_parsed = match.group("from")
            target_parsed = match.group("target")
            n_statement = match.group("number")

            if n_statement == 'a' or n_statement == 'an':
                n_statement = '1.0'

            n = mathparse.parse(n_statement, self.language)

            ureg = UnitRegistry()
            from_parsed, target_parsed = self.get_valid_units(ureg, from_parsed, target_parsed)

            if from_parsed is None or target_parsed is None:
                raise

            from_value = ureg.Quantity(float(n), from_parsed)
            target_value = from_value.to(target_parsed)
            response.confidence = 1.0
            response.text = str(target_value.magnitude)
        except Exception:
            response.confidence = 0.0
        finally:
            return response
开发者ID:dawnpower,项目名称:ChatterBot,代码行数:34,代码来源:unit_conversion.py

示例2: process

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import text [as 别名]
    def process(self, statement):
        """
        Takes a statement string.
        Returns the simplified statement string
        with the mathematical terms solved.
        """
        input_text = statement.text

        # Use the result cached by the process method if it exists
        if input_text in self.cache:
            cached_result = self.cache[input_text]
            self.cache = {}
            return cached_result

        # Getting the mathematical terms within the input statement
        expression = str(self.simplify_chunks(self.normalize(input_text)))

        response = Statement(text=expression)

        try:
            response.text += '= ' + str(
                eval(expression, {f: self.functions[f] for f in self.functions})
            )

            # Replace '**' with '^' for evaluated exponents
            response.text = response.text.replace('**', '^')

            # The confidence is 1 if the expression could be evaluated
            response.confidence = 1
        except:
            response.confidence = 0

        return response
开发者ID:PrabinPC,项目名称:ChatterBot-1,代码行数:35,代码来源:mathematical_evaluation.py


注:本文中的chatterbot.conversation.Statement.text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。