Esempio n. 1
0
    def test_SADT_init(self):
        """
        Checks init of SentenceADT.
        """
        s1 = SentenceADT('My dog is a cat... ')
        s1.emotion = 'sadness'

        self.assertTrue(s1.emotion == 'sadness')
Esempio n. 2
0
    def test_compare_SentenceADT(self):
        """
        Compares two SentenceADT.
        """

        s1 = SentenceADT('I love my dog. ')
        s2 = SentenceADT('I love my cat. ')

        self.assertTrue(s1 != s2)
Esempio n. 3
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)
Esempio n. 4
0
    def test_SADT_str(self):
        """
        Checks str of SentenceADT.
        """

        s1 = SentenceADT('My dog is a cat... ')
        self.assertTrue(str(s1) == 'My dog is a cat... ')
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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)