def execute_conversation(self, model, candidates): c = Conversation(model, candidates, initial_topic=0) c.model.train() reactions = [Reaction.neutral, Reaction.positive, Reaction.negative, Reaction.negative, Reaction.positive] for i, r in enumerate(reactions): s = c.suggest(r, count=1) print(c.history[-1]) if i > 0: if r == Reaction.positive: self.assertEqual(c.history[-1].topic, c.history[-2].topic) if r == Reaction.negative: self.assertNotEqual(c.history[-1].topic, c.history[-2].topic)
def load_brain(cls, data_dir): import os data_file = "" model_file = "" for f in sorted(os.listdir(data_dir)): if not data_file and os.path.splitext(f)[1] == ".json": data_file = os.path.join(data_dir, f) elif not model_file and os.path.splitext(f)[1] == ".gensim": model_file = os.path.join(data_dir, f) if data_file and model_file: cls.BRAIN = Conversation.load(GTopicModel, model_file, CitySpotIds, data_file)