首页 > 其他 > 详细

nltk常用函数

时间:2020-06-17 21:11:47      阅读:96      评论:0      收藏:0      [点我收藏+]

所含的包可以在这里下载:http://www.nltk.org/nltk_data/

1.WordNetLemmatizer

确定词根

import nltk
nltk.download(‘wordnet‘)
lemmatizer = WordNetLemmatizer()#确定词源
print(lemmatizer.lemmatize(‘gathering‘, ‘v‘))
print(lemmatizer.lemmatize(‘gathering‘, ‘n‘))

 

输出:

gather
gathering

2.word_tokenize

https://kite.com/python/docs/nltk.word_tokenize

分词: 

import nltk
nltk.download(‘punkt‘)

sentence = "At eight o‘clock on Thursday morning, Arthur didn‘t feel very good."
print(word_tokenize(sentence))

#
[‘At‘, ‘eight‘, "o‘clock", ‘on‘, ‘Thursday‘, ‘morning‘, ‘,‘, ‘Arthur‘, ‘did‘, "n‘t", ‘feel‘, ‘very‘, ‘good‘, ‘.‘]

 

nltk常用函数

原文:https://www.cnblogs.com/BlueBlueSea/p/13154590.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!