0
import re
import subprocess
sub = subprocess.Popen(['/home/karthik/Downloads/stanford-parser-2011-06- 08/lexparser.csh'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr = subprocess.PIPE)
sub.stdin.write("i am a fan of ac milan which is the best club in the world")
relns = []
while(True):
rel = sub.stdout.readline()
m = re.search("Sentence skipped", rel)
if m != None:
print 'stop'
sys.exit(0)
if rel == '\n':
break
relns.append(rel)
print relns
sub.terminate()
所以我想斯坦福解析器和使用lexparser.csh来解析这行文本。但是当我运行这段代码时,我得到了默认文本的输出。给出的实际文本不被解析。那么,我是否正确地使用了管道?我已经在很多示例中看到了 - ' - '与命令一起使用。为什么被使用?当我使用该脚本只是在sub.stdout.readline()使用管道与python
白天('08')之前的空间是否显着? – 2011-06-15 12:49:16
不,没有空间不重要。我只是知道如何格式化它! – 2011-06-15 12:49:58
确保管道比python大,否则可能发生死锁。 ;-P – Macke 2011-06-15 12:54:53