def from_json(client_context, json_data): question = Question() question._srai = json_data["srai"] question._current_sentence_no = json_data["current_sentence_no"] question._properties = json_data["properties"] for sentence in json_data["sentences"]: question.sentences.append(Sentence.from_json(client_context, sentence)) return question
def test_from_json(self): json_data = { 'words': ['One', 'Two', 'Three'], 'response': "Hello", 'positivity': 0.0, 'subjectivity': 0.5, 'matched_context': { 'max_search_depth': 100, 'max_search_timeout': 60, 'total_search_start': datetime.datetime(2019, 8, 30, 7, 36, 54, 928185).strftime("%d/%m/%Y, %H:%M:%S"), '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 }] } } sentence = Sentence.from_json(self._client_context, json_data) self.assertIsNotNone(sentence) self.assertEqual(sentence.words, ['One', 'Two', 'Three']) self.assertEqual(sentence.response, "Hello") self.assertEqual(sentence.positivity, 0.0) self.assertEqual(sentence.subjectivity, 0.5) self.assertIsNotNone(sentence.matched_context)