Python 如何在NLTK中使用斯坦福单词标记器?
我正在寻找在nltk中使用斯坦福单词标记器的方法,我想使用,因为当我比较斯坦福和nltk单词标记器的结果时,它们都是不同的。我知道可能有办法使用斯坦福标记器,就像我们可以在NLTK中使用斯坦福POS标记器和NER一样 是否可以在不运行服务器的情况下使用stanford tokenizerPython 如何在NLTK中使用斯坦福单词标记器?,python,nltk,stanford-nlp,tokenize,Python,Nltk,Stanford Nlp,Tokenize,我正在寻找在nltk中使用斯坦福单词标记器的方法,我想使用,因为当我比较斯坦福和nltk单词标记器的结果时,它们都是不同的。我知道可能有办法使用斯坦福标记器,就像我们可以在NLTK中使用斯坦福POS标记器和NER一样 是否可以在不运行服务器的情况下使用stanford tokenizer 谢谢注意:此解决方案仅适用于: NLTK v3.2.5(v3.2.6会有一个更简单的接口) 斯坦福大学CoreNLP(版本>=2016-10-31) 首先,您必须首先正确安装Java 8,如果Stanfor
谢谢注意:此解决方案仅适用于:
- NLTK v3.2.5(v3.2.6会有一个更简单的接口)
- 斯坦福大学CoreNLP(版本>=2016-10-31)
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
在Python中:
>>> 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', '?']
在NLTK之外,您可以使用: 安装 设置环境
请看一下有没有一种方法可以使用服务器进行词性标注?我认为,正常的
nltk.tag.stanfordpastagger
不会将服务器地址作为参数。
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
# 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', '.']