nltkとstandfordnlpの統合を使用したときに、混乱する問題がありました。
私の開発環境は次のとおりです。
あらゆる種類のjarファイルが正確に存在します。パスまたはStanfordSegmenterのクラスに配置したパラメーターに何か問題がありますか? この例は、nltk 3.3ドキュメントで見つけたものは非常に簡単で、「path_to_slf4j」という1つのパラメーターを入力するだけです。
だから、誰か、私を助けてください:-(!
@ libingnan54321なぜ最新の3.9.1バージョンを使用していないのですか?
最初にこれを試して、出力を提供していただけますか?
segmenter_jar_file = os.path.join(standfordNlpPath,'stanford-segmenter-2018-02-27/stanford-segmenter-3.9.1.jar')
assert(os.path.isfile(segmenter_jar_file))
stanfordSegmenter = StanfordSegmenter(
path_to_jar=segmenter_jar_file,
)
新しいCoreNLPParser
インターフェースを使用してください。
最初にNLTKを更新します。
pip3 install -U nltk
それからまだターミナルにあります:
# Get the CoreNLP package
wget http://nlp.stanford.edu/software/stanford-corenlp-full-2018-02-27.zip
unzip stanford-corenlp-full-2018-02-27.zip
cd stanford-corenlp-full-2018-02-27/
# Download the properties for chinese language
wget http://nlp.stanford.edu/software/stanford-chinese-corenlp-2018-02-27-models.jar
wget https://raw.githubusercontent.com/stanfordnlp/CoreNLP/master/src/edu/stanford/nlp/pipeline/StanfordCoreNLP-chinese.properties
# Download the properties for arabic
wget http://nlp.stanford.edu/software/stanford-arabic-corenlp-2018-02-27-models.jar
wget https://raw.githubusercontent.com/stanfordnlp/CoreNLP/master/src/edu/stanford/nlp/pipeline/StanfordCoreNLP-arabic.properties
中国語の場合:
# Start the server.
java -Xmx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer \
-serverProperties StanfordCoreNLP-chinese.properties \
-preload tokenize,ssplit,pos,lemma,ner,parse \
-status_port 9001 -port 9001 -timeout 15000 &
次にPython3で:
>>> from nltk.parse import CoreNLPParser
>>> parser = CoreNLPParser('http://localhost:9001')
>>> list(parser.tokenize(u'我家没有电脑。'))
['我家', '没有', '电脑', '。']
アラビア語の場合:
# Start the server.
java -Xmx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer \
-serverProperties StanfordCoreNLP-arabic.properties \
-preload tokenize,ssplit,pos,parse \
-status_port 9005 -port 9005 -timeout 15000
最後に、Pythonを起動します。
>>> from nltk.parse import CoreNLPParser
>>> parser = CoreNLPParser(url='http://localhost:9005')
>>> text = u'انا حامل'
>>> parser.tokenize(text)
<generator object GenericCoreNLPParser.tokenize at 0x7f4a26181bf8>
>>> list(parser.tokenize(text))
['انا', 'حامل']
今のところ解決済みの問題を解決する=)
さらに問題がある場合は開いてください。
最も参考になるコメント
新しい
CoreNLPParser
インターフェースを使用してください。最初にNLTKを更新します。
それからまだターミナルにあります:
中国語の場合:
次にPython3で:
アラビア語の場合:
最後に、Pythonを起動します。