Проблемы с Foma FST при использовании Python

Я пытаюсь анализировать полную папку, содержащую текстовые файлы.

используя https://code.google.com/archive/p/foma/

Это код, который я написал. Я передаю каждое слово в foma fst в python, но после запуска 143 файлов из 1900 файлов цикл застревает на неопределенное время. Я попытался прокомментировать вызов цикла foma applyup в цикле и файлы были записаны без каких-либо проблем в новую папку (не root).

class Lemmatizer:
    def __init__(self, inputFolderPath=None, outputFolderPath=None, fomaBinFilePath="Konkani.bin"):
        self.inputFolderPath = inputFolderPath
        self.outputFolderPath = outputFolderPath
        self.fomaBinFilePath=fomaBinFilePath
        self.net = foma.foma_fsm_read_binary_file(fomaBinFilePath)
        self.ah = foma.foma_apply_init(self.net)


 def lemmatize_folder(self):
        net = foma.foma_fsm_read_binary_file(self.fomaBinFilePath)
        ah = foma.foma_apply_init(net)

    if not os.path.exists(self.outputFolderPath):
        os.makedirs(self.outputFolderPath)
    for root, dirs, files in os.walk(self.inputFolderPath):
        for file in filter(lambda file: file.endswith('.txt'), files):
            with codecs.open(os.path.join(self.outputFolderPath, file), 'w') as outputFile:
                with codecs.open(os.path.join(root, file), 'r','utf-8') as inputFile:
                    for line in inputFile:
                        for word in nltk.word_tokenize(line):
                            result = foma.foma_apply_up(ah, word)
                            # result = None
                            if result is not None:
                                print file
                                print result.split('+', 1)[0]
                                # outputFile.write(result.split('+', 1)[0])
                            else:
                                outputFile.write(word.encode('utf-8'))
                            outputFile.write(' ')
                    outputFile.write('\n')

Кто-нибудь сталкивался с подобной проблемой? Неужели foma fst имеет некоторые ограничения на количество раз, которое он может вызываться после инициализации?

0 ответов

Другие вопросы по тегам