我下载了两个名为 1)斯坦福解析器python-r22186.tar 2)stanford-english-corenlp-2018-10-05-模型
我在以下位置创建了一个名为“ jars”的文件夹 C:/ Users / Arsalan / AppData / Local / Programs / Python / Python37 / DOWNLOADED MODULES / jars
现在,我将文件1和文件2都提取到jars文件夹中。然后找到位于的“ englishPCFG.ser” C:/ Users / Arsalan / AppData / Local / Programs / Python / Python37 / DOWNLOADED MODULES / jars / edu / stanford / nlp / models / lexparser / englishPCFG.ser
我创建了环境变量 1)C:/ Users / Arsalan / AppData / Local / Programs / Python / Python37 / DOWNLOADED MODULES / jars中的CLASSPATH 2)STANFORD_MODELS位于C:/ Users / Arsalan / AppData / Local / Programs / Python / Python37 / DOWNLOADED MODULES / jars 3)在STANFORD_PARSER C:/ Users / Arsalan / AppData / Local / Programs / Python / Python37 / DOWNLOADED MODULES / jars 并将所有3个环境变量也添加到path。
我相信我已完成了让Standford解析器运行所需的一切。下面是代码。
import os
from nltk.parse import stanford
os.environ['STANFORD_PARSER'] = 'C:/Users/Arsalan/AppData/Local/Programs/Python/Python37/DOWNLOADED MODULES/jars'
os.environ['STANFORD_MODELS'] = 'C:/Users/Arsalan/AppData/Local/Programs/Python/Python37/DOWNLOADED MODULES/jars'
parser = stanford.StanfordParser(model_path="C:/Users/Arsalan/AppData/Local/Programs/Python/Python37/DOWNLOADED MODULES/jars/edu/stanford/nlp/models/lexparser/englishPCFG.ser")
sentences = parser.raw_parse_sents(("Hello, My name is Melroy.", "What is your name?"))
print(sentences)
结果应该是正确的,但是我明白了
警告(来自警告模块):文件 “ C:\ Users \ Arsalan \ AppData \ Local \ Programs \ Python \ Python37 \ MY WORK FILES \ nltk test.py“,第186行 parser = stanford.StanfordParser(model_path =“ C:/ Users / Arsalan / AppData / Local / Programs / Python / Python37 / DOWNLOADED 模块/jars/edu/stanford/nlp/models/lexparser/englishPCFG.ser“) 弃用警告:StanfordParser将被弃用。请使用 [91mnltk.parse.corenlp.CoreNLPParser [0m。追溯(最 最近通话结束):文件 “ C:\ Users \ Arsalan \ AppData \ Local \ Programs \ Python \ Python37 \ MY WORK FILES \ nltk test.py“,第186行,在 parser = stanford.StanfordParser(model_path =“ C:/ Users / Arsalan / AppData / Local / Programs / Python / Python37 / DOWNLOADED 模块/jars/edu/stanford/nlp/models/lexparser/englishPCFG.ser“)
文件 “ C:\ Users \ Arsalan \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ nltk \ parse \ stanford.py”, 第342行, init 超级(StanfordParser,self)。初始化(* args,** kwargs)文件“ C:\ Users \ Arsalan \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site \ packages \ nltk \ parse \ stanford.py”, 第67行,初始化 key = lambda model_path:os.path.dirname(model_path),文件“ C:\ Users \ Arsalan \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ nltk \ internals.py”, 在find_jar_iter中的第839行 引发LookupError('\ n \ n%s \ n%s \ n%s'%(div,msg,div))LookupError:================================================ ============================ NLTK找不到stanford-parser.jar!设置CLASSPATH
环境变量。有关更多信息,请访问stanford-parser.jar,请参阅:
https://nlp.stanford.edu/software/lex-parser.shtml
请提出建议。感谢您提前帮助我。