def from_json(json_data): match_context = MatchContext(0, 0) match_context._max_search_depth = json_data["max_search_depth"] match_context._max_search_timeout = json_data["max_search_timeout"] match_context._total_search_start = json_data["total_search_start"] match_context._sentence = json_data["sentence"] match_context._response = json_data["response"] for match_data in json_data["matched_nodes"]: match_context._matched_nodes.append(Match.from_json(match_data)) return match_context
def from_json(json_data): match_context = MatchContext(0, 0) match_context.max_search_depth = json_data["max_search_depth"] match_context.max_search_timeout = json_data["max_search_timeout"] match_context.total_search_start = datetime.datetime.strptime( json_data["total_search_start"], "%d/%m/%Y, %H:%M:%S") match_context.sentence = json_data["sentence"] match_context.response = json_data["response"] for match_data in json_data["matched_nodes"]: match_context.matched_nodes.append(Match.from_json(match_data)) return match_context
def test_from_json(self): json_data = { "type": Match.type_to_string(Match.WORD), "node": "WORD [Hello]", "words": ["Hello"], "multi_word": False, "wild_card": False } match = Match.from_json(json_data) self.assertIsNotNone(match) self.assertEqual(Match.WORD, match.matched_node_type) self.assertEqual(False, match._matched_node_multi_word) self.assertEqual(False, match._matched_node_wildcard) self.assertEqual("WORD [Hello]", match._matched_node_str) self.assertEqual(["Hello"], match._matched_node_words)