<commit_before>class Messenger:
    '''
    Selects Brief Motivational Intervention (BMI) messages to send to a user.
    '''
    def __init__(self):
        """
        Populate attributes on initialisation.

        Args:
            config (json): Client specific configuration file that contains
            the questions to send to the user.
        """
        from database import Database
        self.db = Database()
        self.config = self.__load_responses()

    def initial_message(self):
        '''
        Select an initial question at random from pre-defined list.
        The aim is to set the scene, and attempt to elicit a response from user.

        Args:
            questions (list): all initial questions to select from.

        Returns:
            str: opening message and question to send to the user.
        '''
        import random
        message = random.choice(self.config['initialQuestions'])
        return ('I would like to take a few minutes to learn ' +
                'current diet and exercise routines, and how they have ' +
                'impacted your day-to-day routine. ' + message)

    def open_ended_question(self, user_message):
        '''
        Select a context appropriate open-ended question to send to user.

        To achieve this we currently:
            1. Detect most frequent concept based on terms in user's message.
            2. Select pre-defined OEQ from database for that concept.
            3. Group OEQ's by rating.
            4. Randomly select and return one of the highest rating questions.

        Args:
            user_message (str): the message sent to the client by the user.

        Returns:
            str: the OEQ response to send to the user.
        '''
        from app import models
        from flask import request
        import random

        terms_in_message = self.__concept_frequency(user_message)

        if terms_in_message:
            most_freq_concept = terms_in_message.most_common()[0][0]
            all_questions = (models.Question.query.filter_by(
                             concept=most_freq_concept).order_by(
                             models.Question.rating.desc()))

            # Rounding for distinction, e.g. .6 vs .600000000
            highest_rated_questions = [i.question for i in all_questions<commit_msg>Explain chat purpose in initial message<commit_after>class Messenger:
    '''
    Selects Brief Motivational Intervention (BMI) messages to send to a user.
    '''
    def __init__(self):
        """
        Populate attributes on initialisation.

        Args:
            config (json): Client specific configuration file that contains
            the questions to send to the user.
        """
        from database import Database
        self.db = Database()
        self.config = self.__load_responses()

    def initial_message(self):
        '''
        Select an initial question at random from pre-defined list.
        The aim is to set the scene, and attempt to elicit a response from user.

        Args:
            questions (list): all initial questions to select from.

        Returns:
            str: opening message and question to send to the user.
        '''
        import random
        message = random.choice(self.config['initialQuestions'])
        newline = '</br></br>'
        return ('Hi there, I would like to take a few minutes to learn ' +
                'about your current diet and exercise routines, and how ' +
                'they have impacted your well-being.' +
                newline +
                'My aim is to ask questions to make you think and reflect ' +
                'upon choices that affect your health. You can down-vote ' +
                'questions that you dislike and I will ask a better one. ' +
                "I'll ask a question to get us started:" +
                newline + '<i>' + message + '</i>')

    def open_ended_question(self, user_message):
        '''
        Select a context appropriate open-ended question to send to user.

        To achieve this we currently:
            1. Detect most frequent concept based on terms in user's message.
            2. Select pre-defined OEQ from database for that concept.
            3. Group OEQ's by rating.
            4. Randomly select and return one of the highest rating questions.

        Args:
            user_message (str): the message sent to the client by the user.

        Returns:
            str: the OEQ response to send to the user.
        '''
        from app import models
        from flask import request
        import random

        terms_in_message = self.__concept_frequency(user_message)

        if terms_in_message:
            most_freq_concept = terms_in_message.most_common()[0][0]
            all_questions = (models.Question.query.filter_by(
                             concept=most_freq_concept).order_by(
                             models.Question.rating.desc()))

            # Rounding for distinction, e.g. .6 vs .600000000
            highest_rated_questions = [i.question for i in all_questions
{'fraction_non_alphanumeric': 0.06750146742320486, 'fraction_numerical': 0.006261005674036392, 'mean_word_length': 1.88, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2079120', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1199, 'n_words': 507}