@@ -0,0 +1,2240 @@
+import os%0Aimport codecs%0Afrom constants import DATA_DIRECTORY%0A%0ADATA_DIRECTORY = DATA_DIRECTORY%0A%0ALOADED_LANGUAGES = %7B%7D%0A%0Aclass StopWordFactory(object):%0A%0A    def __init__(self, path=DATA_DIRECTORY, fail_safe=False):%0A        self.path = path%0A        self.fail_safe = fail_safe%0A%0A    def get_stop_words(self, language):%0A        if not LOADED_LANGUAGES%5Blanguage%5D:%0A            try:%0A                language_file = codecs.open(%0A                    '%7B0%7D%7B1%7D.txt'.format(DATA_DIRECTORY, language),%0A                    'r',%0A                    encoding='utf8-sig'%0A                )%0A                collection = set(f.read().splitlines())%0A            except:%0A                if not self.fail_safe:%0A                    raise Exception(%22No file here!!!!!!!%22)%0A                collection =  set()%0A%0A            stop_words = StopWord(%0A                language,%0A                collection%0A            )%0A%0A            LOADED_LANGUAGES%5Blanguage%5D = stop_words%0A            return stop_words%0A%0A        return LOADED_LANGUAGES%5Blanguage%5D%0A%0A    def get_collection_filename(self, language):%0A        return '%7B0%7D%7B1%7D.txt'.format(DATA_DIRECTORY, language)%0A%0A    def get_available_language(cls):%0A        return os.listdir(DATA_DIRECTORY)%0A%0A    def write_collection(self, filename, collection):%0A        language_file = codecs.open(%0A                '%7B0%7D%7B1%7D'.format(DATA_DIRECTORY, filename),%0A                'w+',%0A                encoding='utf8'%0A            )%0A        for item in collection:%0A            language_file.write(%22%7B0%7D%5Cn%22.format(item.encode('utf-8')))%0A%0A%0Aclass StopWord(object):%0A%0A    def __init__(self, language, collection=None):%0A        self.language = language%0A    %09self.collection = collection%0A%0A    def __add__(self, entry):%0A        if isinstance(entry, str):%0A            self.collection.add(entry)%0A        else:%0A            self.collection = self.collection.union(entry)%0A%0A    def __sub__(self, entry):%0A        if isinstance(entry, str):%0A            self.collection.remove(entry)%0A        else:%0A            self.collection = self.collection.difference(entry)%0A%0A    def __len__(self):%0A        return len(self.collection)%0A%0A    def __contains__(self, elem):%0A        return self.collection.__contains__(elem)%0A%0A    def __iter__(self):%0A        return self.collection.__iter__()%0A

Implement API