我正在使用以下方法通过 Python 运行 TreeTagger(我知道有一个 Wrapper,但我尝试自己做)subprocess.call()
:
def call_treetagger(path_file, path_treetagger, language):
# Move the file with one word per line into the TreeTagger folder
source = path_file
destination = path_treetagger + '/swahili_one_word_per_line_tt.txt'
shutil.move(source, destination)
# call TreeTagger via cmd and run it with the moved file as input and in the selected language
cmd1 = 'cd ' + path_treetagger
subprocess.run(cmd1, shell=True)
if language == "sw":
tt_lang = 'tag-swahili'
if language == "en":
tt_lang = 'tag-english'
else:
tt_lang = 'tag-english'
cmd_tt = tt_lang + ' swahili_one_word_per_line_tt.txt' + ' call_via_python_results.txt'
subprocess.run(cmd_tt, shell=True)
call_treetagger("C:/Users/rosas/swahili_one_word_per_line.txt", "C:/TreeTagger", "sw")
无论我使用subprocess.call()
还是system.os()
它总是说:
Can't open swahili_one_word_per_line_tt.txt: No such file or directory at C:\TreeTagger\cmd\utf8-tokenize.perl line 86.
reading parameters ...
tagging ...
finished.
但是当我通过 Windows Shell 在同一个文件上运行 TreeTagger 时,一切正常。很明显,在 TreeTagger 的 Pearl Script 中找不到这样的文件。swahili_one_word_per_line_tt.txt
无论如何,当我通过 Python 调用它时,它为什么要在这个目录中搜索文件?