def to_training_sentences(self, from_state: str) -> None: """Transition to training_sentences state.""" # Use doit to train saved_argv = sys.argv try: # Store doit database in profile directory sys.argv = [ sys.argv[0], "--db-file", str(self.profile.write_path(".doit.db")), ] train_profile(Path(self.profile.read_path()), self.profile) self.transition("training_intent") intent_fst_path = self.profile.read_path( self.profile.get("intent.fsticuffs.intent_fst", "intent.fst")) intent_fst = fst.Fst.read(str(intent_fst_path)) self.send(self.intent_trainer, TrainIntent(intent_fst)) except Exception as e: self.transition("ready") self.send(self.training_receiver, ProfileTrainingFailed(str(e))) finally: # Restore sys.argv sys.argv = saved_argv
def to_training_sentences(self, from_state: str) -> None: """Transition to training_sentences state.""" # Use doit to train saved_argv = sys.argv try: # Store doit database in profile directory sys.argv = [ sys.argv[0], "--db-file", str(self.profile.write_path(".doit.db")), ] code, errors = train_profile(Path(self.profile.read_path()), self.profile) if code != 0: raise Exception("\n".join(errors)) self.transition("training_intent") intent_graph_path = self.profile.read_path( self.profile.get("intent.fsticuffs.intent_graph", "intent.json") ) with open(intent_graph_path, "r") as graph_file: json_graph = json.load(graph_file) intent_graph = rhasspynlu.json_to_graph(json_graph) self.send(self.intent_trainer, TrainIntent(intent_graph)) except Exception as e: self.transition("ready") self.send(self.training_receiver, ProfileTrainingFailed(str(e))) finally: # Restore sys.argv sys.argv = saved_argv