Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
斯坦福大学语法分析器&x27;无法使用python(Windows 7)_Python_Python 2.7_Nlp_Stanford Nlp - Fatal编程技术网

斯坦福大学语法分析器&x27;无法使用python(Windows 7)

斯坦福大学语法分析器&x27;无法使用python(Windows 7),python,python-2.7,nlp,stanford-nlp,Python,Python 2.7,Nlp,Stanford Nlp,我正在尝试使用这个解决方案,但它就是不能工作。这基本上是从python调用Stanford解析器,然后在python中获得输出。解析器是用java编写的 import os sentence = '''I shot an elephant in my pajamas''' os.popen("echo '"+sentence+"' > ~/stanfordtemp.txt") parser_out = os.popen("C:/Python27/stanford-parser-2012-

我正在尝试使用这个解决方案,但它就是不能工作。这基本上是从python调用Stanford解析器,然后在python中获得输出。解析器是用java编写的

import os
sentence =  '''I shot an elephant in my pajamas'''
os.popen("echo '"+sentence+"' > ~/stanfordtemp.txt")
parser_out = os.popen("C:/Python27/stanford-parser-2012-11-12/lexparser.sh   ~/stanfordtemp.txt").readlines()
print parser_out
它的工作原理很奇怪,因为当修补程序不正确时,它不会报告错误,并且当软件的修补程序正确时,windows会询问我要在哪个程序中打开应用程序。在我这样做之后,我仍然像以前一样得到空白输出。也许这与我运行Windows7而不是Unix有关

Update: Tried to install CoreNLP and I cannot ... the file location is accurate.
corenlp = StanfordCoreNLP(corenlp_dir)  # wait a few minutes...
File "C:\Python27\lib\site-packages\corenlp\corenlp.py", line 430, in __init__
self._spawn_corenlp()
File "C:\Python27\lib\site-packages\corenlp\corenlp.py", line 399, in _spawn_corenlp
self.corenlp = pexpect.spawn(self.start_corenlp, timeout=60, maxread=8192,   searchwindowsize=80)
File "C:\Python27\lib\site-packages\winpexpect-1.5-py2.7.egg\pexpect.py", line 429, in __init__
self._spawn (command, args)
File "C:\Python27\lib\site-packages\winpexpect-1.5-py2.7.egg\pexpect.py", line 516, in _spawn
raise ExceptionPexpect ('The command was not found or was not executable: %s.' % self.command)
pexpect.ExceptionPexpect: The command was not found or was not executable: java.
Exception AttributeError: "StanfordCoreNLP instance has no attribute 'corenlp'" in    <bound method StanfordCoreNLP.__del__ of <corenlp.corenlp.StanfordCoreNLP instance at  0x021DDA08>> ignored

Exception AttributeError: "StanfordCoreNLP instance has no attribute 'corenlp'" in <bound method StanfordCoreNLP.__del__ of <corenlp.corenlp.StanfordCoreNLP instance at 0x0228DA08>> ignored
更新:已尝试安装CoreNLP,但我无法。。。文件位置是准确的。
corenlp=StanfordCoreNLP(corenlp_dir)#等几分钟。。。
文件“C:\Python27\lib\site packages\corenlp\corenlp.py”,第430行,在\uuu init中__
self._spawn_corenlp()
文件“C:\Python27\lib\site packages\corenlp\corenlp.py”,第399行,在\u spawn\u corenlp中
self.corenlp=pexpect.spawn(self.start\u corenlp,超时=60,maxread=8192,searchwindowsize=80)
文件“C:\Python27\lib\site packages\winpexpect-1.5-py2.7.egg\pexpect.py”,第429行,在\uuu init中__
自我繁殖(命令,参数)
文件“C:\Python27\lib\site packages\winpexpect-1.5-py2.7.egg\pexpect.py”,第516行,在\u spawn中
raise EXCEPTIONPEEXPECT('未找到该命令或该命令不可执行:%s.%self.command)
pexpect.ExceptionPexpect:未找到该命令或该命令不可执行:java。
异常AttributeError:“StanfordCoreNLP实例在忽略中没有属性'corenlp'”
异常AttributeError:“StanfordCoreNLP实例在忽略中没有属性'corenlp'”

如果您想使用斯坦福NLP解析器,我会选择简单的方法并按照以下说明操作

将NLP解析器作为服务器启动后(请注意,默认端口是8080),打开另一个python会话并键入以下内容

刚试过,效果很好:-)

这是打印输出:


{u'句子]:[{u'parsetree]:u'(根(SBARQ)(WHNP(WP)(What))(SQ(VBZ)(NP(DT)(NN空速)(NN速度))(PP(IN of)(NP(dtan)(JJ空速)))(VP(VB燕子)))(VP(VB燕子)),u'text:'空速是多少?',u'dependencients':[[u'ROOT',u'ROOT',u'ROOT',u'swallow',u'swallow',u'What'],[u'aux',u'swallow',u'is'],[u'det',u'velocity',u'the'],[u'nn',u'velocity',u'airspeed'],[u'snubj',u'swallow',u'velocity',u'unladent',u'an'],[u'prepu'velocity',u'unladent',u'the'],[u'words':[u'What':[u'What',[u'NamedEntityTag u'O',u'CharacterOffsetEnd':u'4',u'character offsetu'velocity',u'setu lemu partu'WP',sof'WP''WP',ma':什么],[u'is',{u'NamedEntityTag':u'O',u'CharacterOffsetEnd':u'7',u'CharacterOffsetBegin':u'5',u'PartOfSpeech':u'VBZ',u'Lemma':u'be',[u'the',{u'NamedEntityTag':u'O',u'CharacterOffsetEnd':u'11',u'CharacterOffsetBegin'u'PartOfSpeech':u'DT',u'Lemma':u'DT',the',[u'Lemma the',[u'空速',{u'NamedEntityTag':u'O',u'CharacterOffsetEnd':u'20',u'CharacterOffsetBegin':u'12',u'PartOfSpeech':u'NN',u'Lemma':u'空速'}],[u'velocity',{u'NamedEntityTag':u'O',u'CharacterOffsetBegin':u'CharacterOffsetBegin':u'21',u'PartOfSpeech':u'NN',u'Lemma':u'velocity':u'velocity',',{u'NamedEntityTag':u'O',u'CharacterOffsetEnd':u'32',u'CharacterOffsetBegin':u'30',u'PartOfSpeech':u'IN',u'Lemma':u'of',[u'an',{u'NamedEntityTag':u'O',u'CharacterOffsetEnd':u'CharacterOffsetBegin':u'33',u'PartOfSpeech':u'DT',u'Lemma':u'a',[u'a',[u'unladent',{u'NamedEntityTag':u'O',u'CharacterOffsetEnd':u'43',u'CharacterOffsetBegin':u'36',u'PartOfSpeech':u'JJ',u'Lemma':u'unladen'}],[u'swallow',{u'NamedEntityTag':u'O',u'CharacterOffsetEnd':u'CharacterOffsetBegin':u'44',u'PartOfSpeech':u'VB',u'Lemma':u'swallow','swallow','u',{u'NamedEntityTag':u'O',u'CharacterOffsetEnd':u'52',u'CharacterOffsetBegin':u'51',u'PartOfSpeech':u','引理':u'indexedependences':[[u'root',u'root-0',u'swallow-9',u'What-1',[u'aux',u'swallow-9',u'is-2'],[u'det',u'velocity-5',u'root-0',u'swallow-3',u'swallow-5',airsu-4',d'],[u'nsubj',u'swallow-9',u'velocity-5',[u'det',u'unladen-8',u'an-7',[u'prep_of',u'velocity-5',u'unladen-8']}

这是因为您可能没有安装Bash shell..sh文件是用于unix样式的shell。那么我应该安装什么确切的软件呢?没有任何软件名为exactlyBash shell?我非常确定Cygwin附带Bash shell,尽管这有点过分。MinGW也有Bash。我尝试安装它,但由于下载了脚本花了这么长时间。它有多大?为什么称之为“简易路线”呢?如果我没有遗漏某些内容,则无法在windows 7上安装这些内容,因为所需的pexpect模块在任何windows上都不工作。您是在哪一个上安装的?请尝试此[链接]():)(注意:我正在Mac Mini上使用OS X,抱歉,您使用的是Windows 7。您可能是对的,这是不可能的。)已尝试安装,但它仅支持与操作系统类似的unix。无论如何,我将尝试使用CygwinI。我发现了wexpect,在此之前,我已安装了pywin32。运行得更好,但仍有一个错误。我在URL中安装,除了以下命令:git clone cd corenlp python wget unzip stanford-corenlp-full-2013-11-12.zip
import jsonrpclib
import json

server = jsonrpclib.Server("http://localhost:8080")

result = json.loads(server.parse("What is the airspeed velocity of an unladen swallow?"))
print result