def load(self, path): """ Loads this (potentially empty) resource from path (all object attributes). Args: path: path to shared resources """ if os.path.exists(path): with open(path, 'rb') as f: self.__dict__.update(pickle.load(f)) for f in os.listdir(os.path.dirname(path)): if f.startswith(os.path.basename(path) + '_') and os.path.isdir(os.path.join(os.path.dirname(path), f)): key = f.split('_')[-1] v = Vocab() v.load(path + '_' + key) self.__dict__[key] = v
def load(self, path): """ Loads this (potentially empty) resource from path (all object attributes). Args: path: path to shared resources """ if os.path.exists(path): with open(path, 'rb') as f: self.__dict__.update(pickle.load(f)) dirname = os.path.dirname(path) for f in os.listdir(dirname): if f.startswith(os.path.basename(path) + '_'): key = f[len(os.path.basename(path) + '_'):] if key == 'config.yaml': with open(os.path.join(dirname, f), 'r') as f: self.config = yaml.load(f) elif os.path.isdir(os.path.join(dirname, f)): v = Vocab() v.load(path + '_' + key) self.__dict__[key] = v
def load(self, path): """ Loads this (potentially empty) resource from path (all object attributes). Args: path: path to shared resources """ remainder_path = os.path.join(path, 'remainder') if os.path.exists(remainder_path): with open(remainder_path, 'rb') as f: self.__dict__.update(pickle.load(f)) for f in os.listdir(path): if f == 'config.yaml': with open(os.path.join(path, f), 'r') as f: self.config = yaml.load(f) elif f == 'embeddings': self.embeddings = Embeddings.from_dir(os.path.join(path, f)) else: v = Vocab() v.load(os.path.join(path, f)) self.__dict__[f] = v