Exemple #1
0
    def test_compare_MessageADT(self):
        """
        Compares two MessagesADT.
        """

        m1 = MessageADT('I love my dog. My dog is good! ')
        m2 = MessageADT('I love my cat. My dog is good! ')

        self.assertTrue(m1 != m2)
Exemple #2
0
    def test_CMADT_init(self):
        """
        Checks init of ChatMessagesADT.
        """

        m1 = MessageADT('I love my dog. My dog is good! ')
        m2 = MessageADT('I hope it works. It should work! I hate it... ')

        chm1 = ChatMessagesADT([m1, m2])
        self.assertTrue(len(chm1.messages) == 2)
Exemple #3
0
    def test_CMADT_contains(self):
        """
        Check __contains__ method from ChatMessagesADT.
        """

        m1 = MessageADT('I love my dog. My dog is good! ')
        m2 = MessageADT('I hope it works. It should work! ')

        chm1 = ChatMessagesADT([m1, m2])
        self.assertTrue('dog' in chm1)
        self.assertTrue('dogg' not in chm1)
Exemple #4
0
    def test_CMADT_delete_sentences(self):
        """
        Check delete_sentences method from ChatMessagesADT.
        """

        m1 = MessageADT('I love my dog. My dog is good! ')
        m2 = MessageADT('I hope it works. It should work! ')

        chm1 = ChatMessagesADT([m1, m2])
        chm1.delete_message(0)
        self.assertTrue(len(chm1) == 1)
Exemple #5
0
    def test_CMADT_delete_sentences(self):
        """
        Check delete_sentences method from ChatMessagesADT.
        """
        m1 = MessageADT('I hope it works. It should work! ')
        m2 = MessageADT('I hope it works. It should work! ')
        m2._add_sentence(SentenceADT('I hate it... ', 'anger'))

        chm1 = ChatMessagesADT([m2])

        chm1.delete_sentences('anger')
        self.assertTrue(m2 == m1)
Exemple #6
0
    def test_CMADT_compare_ChatMessagesADT(self):
        """
        Compares two ChatMessagesADT.
        """

        m1 = MessageADT('I love my dog. My dog is good! ')
        m2 = MessageADT('I love my cat. My dog is good! ')

        chm1 = ChatMessagesADT([m1])
        chm2 = ChatMessagesADT([m2])

        self.assertTrue(chm1 != chm2)
Exemple #7
0
    def test_CMADT_add_message(self):
        """
        Check add_message method from ChatMessagesADT.
        """

        m1 = MessageADT('I love my dog. My dog is good! ')
        m2 = MessageADT('I hope it works. It should work! I hate it... ')

        chm1 = ChatMessagesADT([m1])
        self.assertTrue(str(len(chm1.messages) == 1))

        chm1.add_message(m2)

        self.assertTrue(chm1.is_empty() == False)
        self.assertTrue(str(len(chm1.messages) == 2))
Exemple #8
0
    def test_MADT_init(self):
        """
        Checks init of MessageADT.
        """

        text = 'I hope it works. It should work!'
        message = MessageADT(text)
        self.assertTrue(len(message) == 2)
Exemple #9
0
def demonstrate_ADT():
    """
    Test module to see how ChatMessagesADT, MessageADT, SentenceADT
    work.
    """

    print('-' * 45, end='\n')
    s1 = SentenceADT('My dog is a cat... ', 'anger')
    print(
        f'Creating SentenceADT object:\n\n{s1}\nemotion:{s1.emotion}', end='\n\n')

    m1 = MessageADT('I love my dog. My dog is good! ')
    print('-' * 45, end='\n')
    print(f'MessageADT object before adding SentenceADT:\n\n{m1}')

    m1._add_sentence(s1)
    print('-' * 45, end='\n')
    print(f'\nMessageADT object after adding SentenceADT:\n\n{m1}')

    m2 = MessageADT('I hope it works. It should work! I hate it... ')
    chm1 = ChatMessagesADT([m1, m2])

    print('-' * 45, end='\n\n')
    print('Here are two following messages added to ChatMessagesADT:', end='\n\n')
    for elem in chm1:
        print(elem)

    print('\n'+'-' * 45, end='\n\n')
    print('Representation of emotions in chat before changes:', end='\n\n')
    pprint(chm1.emotions)
    print('-' * 45, end='\n\n')

    chm1.delete_sentences('anger')

    print('Representation of emotions in chat after changes:', end='\n\n')
    pprint(chm1.emotions)
    print('-' * 45, end='\n\n')
    print('Chat after filtering process:', end='\n\n')
    print(chm1)
Exemple #10
0
    def test_CMADT_fill_emotion(self):
        """
        Check fill_emotion method from ChatMessagesADT.
        """
        s1 = SentenceADT('My dog is a cat... ')
        s1.emotion = 'sadness'

        m1 = MessageADT('I love my dog. My dog is good! ')
        m1._add_sentence(s1)
        m2 = MessageADT('I hope it works. It should work! ')
        m2._add_sentence(SentenceADT('I hate it... ', 'anger'))

        chm1 = ChatMessagesADT([m2])
        chm1.add_message(m1)
        self.assertTrue(chm1.emotions['sadness'] == 1)
Exemple #11
0
    def load_messages_to_adt(self, messages_text):
        """Load list of messages to ChatMessagesADT"""

        for message_text in messages_text:

            if message_text is None:
                continue
            try:
                message = MessageADT(message_text)

                for sentence in message:

                    emotion = detect_tone(sentence.text)
                    if not emotion:
                        emotion = 'unrecognized'
                    sentence.emotion = emotion

                self.chat_messages.add_message(message)

            except Exception as ex:
                print(ex)
Exemple #12
0
    def test_CMADT_get_sentences(self):
        """
        Check get_sentences method from ChatMessagesADT.
        """
        result = 'I hope it works. I hate it.'
        m1 = MessageADT()
        s1 = SentenceADT('I hope it works', 'anger')
        s2 = SentenceADT('It should work', 'confident')
        s3 = SentenceADT('I hate it', 'anger')

        m1._add_sentence(s1)
        m1._add_sentence(s2)
        m1._add_sentence(s3)

        chm1 = ChatMessagesADT([m1])

        filtered_sentences = chm1.get_sentences('anger')
        self.assertTrue(filtered_sentences == result)
Exemple #13
0
    def test_CMADT_get_percentage(self):
        """
        Check get_percentage method from ChatMessagesADT.
        """

        m1 = MessageADT()
        s1 = SentenceADT('I hope it works. ', 'anger')
        s2 = SentenceADT('It should work! ', 'confident')
        s3 = SentenceADT('I hate it... ', 'anger')

        m1._add_sentence(s1)
        m1._add_sentence(s2)
        m1._add_sentence(s3)

        chm1 = ChatMessagesADT([m1])

        result = chm1.get_percentage('anger')
        self.assertTrue(result == 66.67)