def __init__(self, index):
"""Initialize the TokI object from a MongoDB or load from disk."""
self.index = index
if pymongo:
if 'toki' in self.index.mongo_db.collection_names():
self.mongo_toki = self.index.mongo_db['toki']
if self.mongo_toki.count() == 0:
raise IndexLoadError
else:
raise IndexLoadError
else:
# Load into memory (not suitable for large corpora!)
try:
with open(self.index.base_fname + '.toki', mode='rb') as f:
self.toki = pickle.load(f)
if not self.toki:
raise IndexLoadError
except (IOError, pickle.UnpicklingError):
raise IndexLoadError
评论列表
文章目录