0

I am running TreeTagger via Python (I know there is a Wrapper, but I try to do by myself) using the subprocess.call() method:

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")

Wether I use subprocess.call() or system.os() it always says:

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.

But when I run TreeTagger over the same file via the Windows Shell, everything works fine. It is perfectly clear that there is no such file to find within the Pearl Script of TreeTagger. Why is it searching for the file swahili_one_word_per_line_tt.txt in this directory when I call it via Python anyways?

Shan-x
  • 1,146
  • 6
  • 19
  • 44
Rosa
  • 1

1 Answers1

0

Okay, I just found a solution. When I give the whole path and not only the filename liek:

cmd_tt = tt_lang + ' C:/TreeTagger/swahili_one_word_per_line_tt.txt' + ' C:/TreeTagger/call_via_python_results.txt'

everything works. I don't know why I have to do this in PYthon and in the Windows Shell differently, but it works. Thank you anyway :D

Rosa
  • 1