예제 #1
0
    def encode(self, dataset, params: EncoderParams):
        cache_key = CacheHandler.generate_cache_key(
            self._prepare_caching_params(dataset, params))
        encoded_dataset = CacheHandler.memo(
            cache_key, lambda: self._encode_new_dataset(dataset, params))

        return encoded_dataset
예제 #2
0
 def run(input_params: DataSplitterParams = None):
     cache_key = CacheHandler.generate_cache_key(
         DataSplitter._prepare_caching_params(input_params))
     fn = getattr(
         DataSplitter,
         "{}_split".format(input_params.split_strategy.name.lower()))
     datasets = CacheHandler.memo(cache_key, lambda: fn(input_params))
     return datasets
예제 #3
0
    def test_memo(self):
        fn = lambda: "abc"
        cache_key = "a123"
        obj = CacheHandler.memo(cache_key, fn)
        self.assertEqual("abc", obj)

        os.remove(
            CacheHandler._build_filename(cache_key, CacheObjectType.OTHER))
예제 #4
0
    def test_memo_with_object_type(self):
        fn = lambda: "abc"
        cache_key = "a123"
        obj = CacheHandler.memo(cache_key, fn, CacheObjectType.ENCODING)
        self.assertEqual("abc", obj)
        self.assertTrue(
            os.path.isfile(EnvironmentSettings.get_cache_path() /
                           f"encoding/{cache_key}.pickle"))

        os.remove(
            CacheHandler._build_filename(cache_key, CacheObjectType.ENCODING))