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


Python Statement.confidence方法代码示例

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


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

示例1: process

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import confidence [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)))

        # Returning important information
        try:
            expression += '= ' + str(
                eval(expression, {f: getattr(numpy, f) for f in self.functions})
            )

            response = Statement(expression)
            response.confidence = 1

            # return a confidence of 1 if the expression could be evaluated
            return 1, response
        except:
            response = Statement(expression)
            response.confidence = 0
            return 0, response
开发者ID:HarshGrandeur,项目名称:ChatterBot,代码行数:34,代码来源:mathematical_evaluation.py

示例2: handle_matches

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import confidence [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

示例3: process

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import confidence [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

示例4: process

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

        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 = mathparse.extract_expression(input_text, language=self.language)

        response = Statement(text=expression)

        try:
            response.text += ' = ' + str(
                mathparse.parse(expression, language=self.language)
            )

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

        return response
开发者ID:runciters,项目名称:ChatterBot,代码行数:33,代码来源:mathematical_evaluation.py

示例5: process

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import confidence [as 别名]
    def process(self, statement, additional_response_selection_parameters=None):
        now = datetime.now()

        time_features = self.time_question_features(statement.text.lower())
        confidence = self.classifier.classify(time_features)
        response = Statement(text='The current time is ' + now.strftime('%I:%M %p'))

        response.confidence = confidence
        return response
开发者ID:gunthercox,项目名称:ChatterBot,代码行数:11,代码来源:time_adapter.py

示例6: search

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import confidence [as 别名]
    def search(self, input_statement, **additional_parameters):
        """
        Search for close matches to the input. Confidence scores for
        subsequent results will order of increasing value.

        :param input_statement: A statement.
        :type input_statement: chatterbot.conversation.Statement

        :param **additional_parameters: Additional parameters to be passed
            to the ``filter`` method of the storage adapter when searching.

        :rtype: Generator yielding one closest matching statement at a time.
        """
        self.chatbot.logger.info('Beginning search for close text match')

        input_search_text = input_statement.search_text

        if not input_statement.search_text:
            self.chatbot.logger.warn(
                'No value for search_text was available on the provided input'
            )

            input_search_text = self.chatbot.storage.tagger.get_bigram_pair_string(
                input_statement.text
            )

        search_parameters = {
            'search_text_contains': input_search_text,
            'persona_not_startswith': 'bot:',
            'page_size': self.search_page_size
        }

        if additional_parameters:
            search_parameters.update(additional_parameters)

        statement_list = self.chatbot.storage.filter(**search_parameters)

        closest_match = Statement(text='')
        closest_match.confidence = 0

        self.chatbot.logger.info('Processing search results')

        # Find the closest matching known statement
        for statement in statement_list:
            confidence = self.compare_statements(input_statement, statement)

            if confidence > closest_match.confidence:
                statement.confidence = confidence
                closest_match = statement

                self.chatbot.logger.info('Similar text found: {} {}'.format(
                    closest_match.text, confidence
                ))

                yield closest_match
开发者ID:gunthercox,项目名称:ChatterBot,代码行数:57,代码来源:search.py

示例7: process

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import confidence [as 别名]
    def process(self, statement):
        from chatterbot.conversation import Statement

        now = datetime.now()

        time_features = self.time_question_features(statement.text.lower())
        confidence = self.classifier.classify(time_features)
        response = Statement(text='The current time is ' + now.strftime('%I:%M %p'))

        response.confidence = confidence
        return response
开发者ID:hundredrab,项目名称:ChatterBot,代码行数:13,代码来源:time_adapter.py

示例8: process

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import confidence [as 别名]
    def process(self, statement):
        response = Statement(text='')
        input_text = statement.text
        try:
            # Use the result cached by the process method if it exists
            if input_text in self.cache:
                response = self.cache[input_text]
                self.cache = {}
                return response

            for pattern, func in self.patterns:
                p = pattern.match(input_text)
                if p is not None:
                    response = func(p)
                    if response.confidence == 1.0:
                        break
        except Exception:
            response.confidence = 0.0
        finally:
            return response
开发者ID:dawnpower,项目名称:ChatterBot,代码行数:22,代码来源:unit_conversion.py

示例9: process

# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import confidence [as 别名]
 def process(self, statement):
     response = Statement('Good morning.')
     response.confidence = 0.2
     return response.confidence, response
开发者ID:Gustavo6046,项目名称:ChatterBot,代码行数:6,代码来源:test_multi_adapter.py


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