我有两个代码段: -
1)get_pos_tags.py
import sys
import json
from nltk.tokenize import word_tokenize
from nltk.tag import pos_tag
def getPOSTags(sentence=sys.argv[1]):
sentence_s=str(sentence)
word_token=word_tokenize(sentence_s)
print word_token
word_POS_tags=pos_tag(word_token)
if __name__=='__main__':
getPOSTags()
2)test.php
<?php
$sentence="I became the king of rome";
echo("python get_pos_tags.py "."'".$sentence."'",$output);
var_dump($output);
当我在xampp上运行test.php时,我收到xampp的输出为null,而我应该以python List的形式获得输出。任何人都可以帮助解决这段代码的错误吗?我使用的是MAC OS X El Capitan和PHP7。
答案 0 :(得分:0)
我不太了解PHP,但您可能希望使用sys.stdout来查看将python脚本的输出汇总到您的php脚本中