2017-12-04 3 views
0

스탠포드 워드 토크 나이저를 nltk에서 사용하는 방법을 찾고 있습니다. 스탠포드와 nltk 워드 토크 나이저의 결과를 비교할 때 둘 다 다르므로 사용하고 싶습니다. 스탠포드 토크 나이저를 사용할 방법이 있다는 것을 알고 있습니다. 스탠포드 POS 태거 (POS Tagger)와 NLTK의 NER처럼 말입니다.NLTK에서 스탠포드 워드 토크 나이저를 사용하는 방법은 무엇입니까?

서버를 실행하지 않고 스탠포드 토크 나이저를 사용할 수 있습니까?

감사

+0

https://stackoverflow.com/a/46781723/610569에서 봐 주시기 바랍니다 – alvas

답변

0

외부, 당신이 사용할 수있는 official Python interface that's recently release by Stanford NLP :

cd ~ 
wget http://nlp.stanford.edu/software/stanford-corenlp-full-2016-10-31.zip 
unzip stanford-corenlp-full-2016-10-31.zip && cd stanford-corenlp-full-2016-10-31 
pip3 install -U https://github.com/stanfordnlp/python-stanford-corenlp/archive/master.zip 

설정 Environme 설치 파이썬

에서 NT
# On Mac 
export CORENLP_HOME=/Users/<username>/stanford-corenlp-full-2016-10-31/ 

# On linux 
export CORENLP_HOME=/home/<username>/stanford-corenlp-full-2016-10-31/ 

것은
>>> import corenlp 
>>> with corenlp.client.CoreNLPClient(annotators="tokenize ssplit".split()) as client: 
...  ann = client.annotate(text) 
... 
[pool-1-thread-4] INFO CoreNLP - [/0:0:0:0:0:0:0:1:55475] API call w/annotators tokenize,ssplit 
Chris wrote a simple sentence that he parsed with Stanford CoreNLP. 
>>> sentence = ann.sentence[0] 
>>> 
>>> [token.word for token in sentence.token] 
['Chris', 'wrote', 'a', 'simple', 'sentence', 'that', 'he', 'parsed', 'with', 'Stanford', 'CoreNLP', '.'] 

1

참고 :이 솔루션은 작동합니다 : (v3.2.6는 더 간단한 인터페이스를 가지고 것)

  • NLTK의 v3.2.5

  • 스탠포드 CoreNLP (버전> = 2016-10-31)

먼저 Java 8을 올바르게 설치해야합니다. f Stanford CoreNLP가 명령 행에서 작동하는 경우 NLTK v3.2.5의 Stanford CoreNLP API는 다음과 같습니다.

참고 : NLTK의 새 CoreNLP API를 사용하기 전에 터미널에서 CoreNLP 서버를 시작해야합니다. 파이썬에서

wget http://nlp.stanford.edu/software/stanford-corenlp-full-2016-10-31.zip 
unzip stanford-corenlp-full-2016-10-31.zip && cd stanford-corenlp-full-2016-10-31 

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer \ 
-preload tokenize,ssplit,pos,lemma,parse,depparse \ 
-status_port 9000 -port 9000 -timeout 15000 

: 터미널에

NLTK의

>>> from nltk.parse.corenlp import CoreNLPParser 
>>> st = CoreNLPParser() 
>>> tokenized_sent = list(st.tokenize('What is the airspeed of an unladen swallow ?')) 
>>> tokenized_sent 
['What', 'is', 'the', 'airspeed', 'of', 'an', 'unladen', 'swallow', '?'] 
관련 문제