Skip to content

Instantly share code, notes, and snippets.

@samidarko
Created June 19, 2019 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samidarko/484b1aff74815edee281c7c2fc571f3a to your computer and use it in GitHub Desktop.
Save samidarko/484b1aff74815edee281c7c2fc571f3a to your computer and use it in GitHub Desktop.
class SingletonIndex(object):
singleton = None
def __new__(cls, *args, **kwargs):
if not cls.singleton:
cls.singleton = object.__new__(SingletonIndex)
return cls.singleton
def __init__(self, path):
self.index = similarities.Similarity.load(path)
def get(self):
return self.index
class SingletonDictionary(object):
singleton = None
def __new__(cls, *args, **kwargs):
if not cls.singleton:
cls.singleton = object.__new__(SingletonDictionary)
return cls.singleton
def __init__(self, path):
self.dictionary = corpora.Dictionary.load(path)
def get(self):
return self.dictionary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment