def _load_lookup(self):
"""The method to download the lookup dictionary from S3 and load to the memory.
Returns:
dict: a lookup table for mapping gensim index to soc code.
"""
try:
filepath = os.path.join(LOCAL_CACHE_DIRECTORY, self.lookup_name)
with open(filepath, 'r') as handle:
lookup = json.load(handle)
return lookup
except:
if not self.saved:
with tempfile.TemporaryDirectory() as td:
filepath = os.path.join(td, self.lookup_name)
print(filepath)
logging.warning('calling download from %s to %s', self.s3_path + self.lookup_name, filepath)
download(self.s3_conn, filepath, os.path.join(self.s3_path, self.lookup_name))
with open(filepath, 'r') as handle:
lookup = json.load(handle)
else:
filepath = os.path.join(LOCAL_CACHE_DIRECTORY, self.lookup_name)
if not os.path.exists(filepath):
logging.warning('calling download from %s to %s', self.s3_path + self.lookup_name, filepath)
download(self.s3_conn, filepath , os.join(self.s3_path, self.lookup_name))
with open(filepath, 'r') as handle:
lookup = json.load(handle)
return lookup
评论列表
文章目录