示例#1
0
    def from_json(client_context, json_data):

        sentence = Sentence(client_context)

        sentence.words = json_data['words']
        sentence.response = json_data['response']
        sentence.positivity = json_data['positivity']
        sentence.subjectivity = json_data['subjectivity']

        if 'matched_context' in json_data:
            sentence.matched_context = MatchContext.from_json(
                json_data["matched_context"])

        return sentence
示例#2
0
    def test_from_json(self):
        time1 = datetime.datetime(2019, 8, 29, 17, 25, 7,
                                  141098).strftime("%d/%m/%Y, %H:%M:%S")

        json_data = {
            'max_search_depth':
            100,
            'max_search_timeout':
            60,
            'total_search_start':
            time1,
            'sentence':
            'Hello',
            'response':
            'Hi there',
            'matched_nodes': [{
                'type': 'Topic',
                'node': 'ONEORMORE [*]',
                'words': [],
                'multi_word': True,
                'wild_card': True
            }, {
                'type': 'Word',
                'node': 'WORD [Hi]',
                'words': ['Hi'],
                'multi_word': False,
                'wild_card': False
            }, {
                'type': 'Word',
                'node': 'WORD [There]',
                'words': ['There'],
                'multi_word': False,
                'wild_card': False
            }]
        }

        match_context = MatchContext.from_json(json_data)
        self.assertIsNotNone(match_context)
        self.assertEquals(match_context._max_search_depth, 100)
        self.assertEquals(match_context._max_search_timeout, 60)
        time2 = match_context._total_search_start.strftime(
            "%d/%m/%Y, %H:%M:%S")
        self.assertEquals(time1, time2)
        self.assertEquals(match_context.template_node, None)
        self.assertEquals(match_context.sentence, "Hello")
        self.assertEquals(match_context.response, "Hi there")
        self.assertEquals(3, len(match_context._matched_nodes))