txt ファイルを含む完全なフォルダーをモーフィング分析しようとしています。
https://code.google.com/archive/p/foma/を使用
これは私が書いたコードです。Pythonで各単語をfoma fstに渡していますが、1900ファイルのうち143ファイルを実行した後、ループは無期限にスタックします。ループ内のfoma call applyupにコメントしてみましたファイルは問題なく新しいフォルダー (非ルート形式) に書き込まれました。
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 は、初期化後に呼び出すことができる回数にいくつかの制限があるということですか?