Beispiel #1
0
 def get_dataset(self, dsname):
     if dsname not in self.list_datasets():
         raise InterfaceError(
             f'Tried to load a dataset called "{dsname}" that does not exist'
         )
     hash_dir = self.config['datasets'][dsname]
     return Dataset.load(self.datasets_path.joinpath(hash_dir))
Beispiel #2
0
 def get_pron_dict(self, pdname):
     if pdname not in self.list_pron_dicts():
         raise InterfaceError(
             f'Tried to load a pron dict called "{pdname}" that does not exist'
         )
     hash_dir = self.config['pron_dicts'][pdname]
     pd = PronDict.load(self.pron_dicts_path.joinpath(hash_dir))
     pd.dataset = self.get_dataset(pd.config['dataset_name'])
     return pd
Beispiel #3
0
 def get_transcription(self, tname):
     if tname not in self.list_transcriptions():
         raise InterfaceError(
             f'Tried to load a transcription called "{tname}" that does not exist'
         )
     hash_dir = self.config['transcriptions'][tname]
     t = self.engine.transcription.load(
         self.transcriptions_path.joinpath(hash_dir))
     t.model = self.get_model(t.config['model_name'])
     return t
Beispiel #4
0
 def new_dataset(self, dsname):
     existing_names = self.list_datasets()
     if dsname in self.config['datasets'].keys():
         raise InterfaceError(
             f'Tried adding \'{dsname}\' which is already in {existing_names} with hash {self.config["datasets"][dsname]}.',
             human_message=f'Dataset with name "{dsname}" already exists')
     ds = Dataset(parent_path=self.datasets_path, name=dsname)
     datasets = self.config['datasets']
     datasets[dsname] = ds.hash
     self.config['datasets'] = datasets
     return ds
Beispiel #5
0
 def get_model(self, mname):
     if self.engine is None:
         raise RuntimeError("Engine must be set to get a model")
     if mname not in self.list_models():
         raise InterfaceError(
             f'Tried to load a model called "{mname}" that does not exist')
     hash_dir = self.config['models'][mname]
     m = self.engine.model.load(self.models_path.joinpath(hash_dir))
     m.dataset = self.get_dataset(m.config['dataset_name'])
     if m.config['pron_dict_name'] is not None:
         m.pron_dict = self.get_pron_dict(m.config['pron_dict_name'])
     return m
Beispiel #6
0
 def new_pron_dict(self, pdname):
     existing_names = self.list_pron_dicts()
     if pdname in self.config['pron_dicts'].keys():
         raise InterfaceError(
             f'Tried adding \'{pdname}\' which is already in {existing_names} with hash {self.config["pron_dicts"][pdname]}.',
             human_message=
             f'Pronunciation dictionary with name "{pdname}" already exists'
         )
     pd = PronDict(parent_path=self.pron_dicts_path, name=pdname)
     pron_dicts = self.config['pron_dicts']
     pron_dicts[pdname] = pd.hash
     self.config['pron_dicts'] = pron_dicts
     return pd
Beispiel #7
0
 def new_model(self, mname):
     if self.engine is None:
         raise RuntimeError("Engine must be set before model creation")
     existing_names = self.list_models()
     if mname in self.config['models'].keys():
         raise InterfaceError(
             f'Tried adding \'{mname}\' which is already in {existing_names} with hash {self.config["models"][mname]}.',
             human_message=f'Model with name "{mname}" already exists')
     m = self.engine.model(parent_path=self.models_path, name=mname)
     models = self.config['models']
     models[mname] = m.hash
     self.config['models'] = models
     return m