gpt4 book ai didi

python - 如何在 NLTK 中使用 stanford word tokenizer?

转载 作者:行者123 更新时间:2023-11-28 19:42:26 25 4
gpt4 key购买 nike

我正在寻找在 nltk 中使用 stanford word tokenizer 的方法,我想使用它是因为当我比较 stanford 和 nltk word tokenizer 的结果时,它们都是不同的。我知道可能有使用 stanford tokenizer 的方法,就像我们可以在 NLTK 中使用 stanford POS Tagger 和 NER。

是否可以在不运行服务器的情况下使用 stanford tokenizer?

谢谢

最佳答案

注意:此解决方案仅适用于:

  • NLTK v3.2.5(v3.2.6 将具有更简单的界面)

  • Stanford CoreNLP(版本 >= 2016-10-31)

首先你必须先正确安装 Java 8,如果 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

在 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', '?']

关于python - 如何在 NLTK 中使用 stanford word tokenizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47624742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com