NLTK 包和其他依赖项出错

Error with NLTK package and other dependencies

我已经安装了NLTK包和其他依赖,并设置了如下环境变量:

STANFORD_MODELS=/mnt/d/stanford-ner/stanford-ner-2018-10-16/classifiers/english.all.3class.distsim.crf.ser.gz:/mnt/d/stanford-ner/stanford-ner-2018-10-16/classifiers/english.muc.7class.distsim.crf.ser.gz:/mnt/d/stanford-ner/stanford-ner-2018-10-16/classifiers/english.conll.4class.distsim.crf.ser.gz

CLASSPATH=/mnt/d/stanford-ner/stanford-ner-2018-10-16/stanford-ner.jar

当我尝试访问如下分类器时:

stanford_classifier = os.environ.get('STANFORD_MODELS').split(':')[0]

stanford_ner_path = os.environ.get('CLASSPATH').split(':')[0]

st = StanfordNERTagger(stanford_classifier, stanford_ner_path, encoding='utf-8')

我收到以下错误。但是我不明白是什么导致了这个错误。

Error: Could not find or load main class edu.stanford.nlp.ie.crf.CRFClassifier
OSError: Java command failed : ['/mnt/c/Program Files (x86)/Common 
Files/Oracle/Java/javapath_target_1133041234/java.exe', '-mx1000m', '-cp', '/mnt/d/stanford-ner/stanford-ner-2018-10-16/stanford-ner.jar', 'edu.stanford.nlp.ie.crf.CRFClassifier', '-loadClassifier', '/mnt/d/stanford-ner/stanford-ner-2018-10-16/classifiers/english.all.3class.distsim.crf.ser.gz', '-textFile', '/tmp/tmpaiqclf_d', '-outputFormat', 'slashTags', '-tokenizerFactory', 'edu.stanford.nlp.process.WhitespaceTokenizer', '-tokenizerOptions', '"tokenizeNLs=false"', '-encoding', 'utf8']

我找到了这个问题的答案。我正在使用 NLTK == 3.4。从 NLTK ==3.3 和更高版本的 Stanford NLP(POS、NER、tokenizer)不是作为 nltk.tag 的一部分而是从 nltk.parse.corenlp.CoreNLPParser 加载的。 Whosebug的答案在whosebug.com/questions/13883277/stanford-parser-and-nltk/…中可用,官方文档的github link是github.com/nltk/nltk/wiki/Stanford-CoreNLP-API-in-NLTK.

如果您面临来自 NER 标记器或任何其他 coreNLP 解析器的超时问题的附加信息 API,请按照 dimazest https://github.com/nltk/nltk/wiki/Stanford-CoreNLP-API-in-NLTK/_compare/3d64e56bede5e6d93502360f2fcd286b633cbdb9...f33be8b06094dae21f1437a6cb634f86ad7d83f7 中所述增加超时限制。