簡體   English   中英

Python NLTK:Stanford NER標記器錯誤消息:NLTK無法找到Java文件

[英]Python NLTK: Stanford NER tagger error message: NLTK was unable to find the java file

試圖讓Stanford NER使用Python。 按照網上的一些說明進行操作,但收到錯誤消息:“ NLTK無法找到Java文件!使用軟件特定的配置參數或設置JAVAHOME環境變量。” 什么問題? 謝謝!

from nltk.tag.stanford import StanfordNERTagger
from nltk.tokenize import word_tokenize

model = r'C:\Stanford\NER\classifiers\english.muc.7class.distsim.crf.ser.gz'
jar = r'C:\Stanford\NER\stanford-ner-3.9.1.jar'

ner_tagger = StanfordNERTagger(model, jar, encoding = 'utf-8')

text = 'While in France, Christine Lagarde discussed short-term stimulus ' \
       'efforts in a recent interview with the Wall Street Journal.'

words = word_tokenize(text)
classified_words = ner_tagger.tag(words)

在網上找到了解決方案。 用您自己的路徑替換。

  import os java_path = "C:/../../jdk1.8.0_101/bin/java.exe" os.environ['JAVAHOME'] = java_path 

要么:

 import nltk nltk.internals.config_java('C:/../../jdk1.8.0_101/bin/java.exe') 

資料來源: https : //tianyouhu.wordpress.com/2016/09/01/problem-of-nltk-with-stanfordtokenizer/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM