我想在nltk包中使用带有python的Stanford解析器,它在pos tagger和NER tagger上运行良好,但是当涉及到解析器时,它不起作用。 这是代码:
import nltk
from nltk.parse import stanford
import os
from nltk.parse import stanford
os.environ['CLASSPATH'] = '/Users/caoyue/PycharmProjects/iepy_/jars'
os.environ['STANFORD_MODELS'] = '/Users/caoyue/PycharmProjects/iepy_/jars'
from nltk.tag.stanford import StanfordPOSTagger
st = StanfordPOSTagger('english-left3words-distsim.tagger')
a=st.tag('What is the airspeed of an unladen swallow ?'.split())
print(a)
from nltk.tag import StanfordNERTagger
st = StanfordNERTagger('english.all.3class.distsim.crf.ser.gz')
b=st.tag('Rami Eid is studying at Stony Brook University in NY'.split())
print(b)
from nltk.parse.stanford import StanfordDependencyParser
dep_parser=StanfordDependencyParser(model_path="/Users/caoyue/PycharmProjects/iepy_/jars/english.all.3class.distsim.crf.ser.gz ")
list(dep_parser.raw_parse("the quick brown fox jumps over the lazy dog"))
错误是:
我认为model_path是错误的,我该如何设置它是正确的?
答案 0 :(得分:0)
我没有测试它,但我认为english.all.3class.distsim.crf.ser.gz
之后的尾随空格会导致一些混乱:
model_path="..../english.all.3class.distsim.crf.ser.gz ")
(删除部分路径以提高可读性)