0

我正在尝试将 SENNA 与 python 一起使用。我得到以下信息IOError

Traceback (most recent call last):
  File "C:\Python27\senna_test.py", line 18, in <module>
    tagged = StringIO(p.communicate(sentence)[0])
  File "C:\Python27\lib\subprocess.py", line 479, in communicate
    return self._communicate(input)
  File "C:\Python27\lib\subprocess.py", line 718, in _communicate
    self.stdin.write(input)
IOError: [Errno 22] Invalid argument

我的代码如下:

import os
import csv
from StringIO import StringIO
import subprocess as sp
from nltk.draw.tree import Tree, TreeWidget
from nltk.draw.util import CanvasFrame

senna_path="C:/Python27/senna/"
sentence = 'My brother has a dog'

# read senna output
p = sp.Popen(['blabla', '-path',  senna_path],
             executable=os.path.join(senna_path, 'senna-win32.exe'),
             stdin=sp.PIPE,
             stdout=sp.PIPE,
             stderr=sp.PIPE)
tagged = StringIO(p.communicate(sentence)[0])
table = csv.reader(tagged, dialect='excel-tab')
4

1 回答 1

0

相反,您可以使用这种方法

从https://ronan.collobert.com/senna/download.html下载番泻叶

如果您使用的是 Windows,那么:

python运行带有参数的.exe应用程序

直接使用 senna-win32.exe

import subprocess
myinput = open('in.txt')
myoutput = open('out.txt', 'w')
p = subprocess.Popen('senna-win32.exe', stdin=myinput, stdout=myoutput)
p.wait()
myoutput.flush()

现在解析 out.txt 以获得结果。

于 2017-11-27T21:59:08.643 回答