Beispiel #1
0
    def upload_from_file(self,
                         filename,
                         format=Store.TEXT_FORMAT,
                         commit=True,
                         verbose=False):

        YLogger.info(self, "Uplading spelling corpus file [%s] to Mongo",
                     filename)

        count = 0
        try:
            corpus_words = []
            with open(filename, "r") as text_file:
                for lines in text_file:
                    words = lines.split(' ')
                    for word in words:
                        corpus_words.append(word)

            corpus = Corpus(words=corpus_words)
            self.add_document(corpus)

            if verbose is True:
                print(corpus_words)

            if commit is True:
                self.commit()

            count = len(corpus_words)

        except Exception as excep:
            YLogger.expception(self,
                               "Failed to load spelling corpus from [%s]",
                               excep, filename)

        # Assume all words loaded are success, no need for additional count
        return count, count