python自然语言处理

python自然语言处理

句子拆分器

sent_tokenize

from nltk.tokenize import sent_tokenize
inputstring='This is an example sent. The sen' \
            'tence splitter will split on sent markers. Ohh really !!'
all_sent=sent_tokenize(inputstring)
print(all_sent)

在这里插入图片描述

标记解析

regexp_tokenize,wordpunct_tokenize,blankline_tokenize

from nltk.tokenize import word_tokenize
print(word_tokenize(s))

from nltk.tokenize import regexp_tokenize,wordpunct_tokenize,blankline_tokenize
print(regexp_tokenize(s,pattern='\w+'))
print(regexp_tokenize(s,pattern='\d+'))
print(wordpunct_tokenize(s))
print(blankline_tokenize(s))

词干提取

LancasterStemmer,SnowballStemmer

'''词干提取'''
from nltk.stem import PorterStemmer
from nltk.stem.lancaster import LancasterStemmer
from nltk.stem.snowball import SnowballStemmer
pst=PorterStemmer()
lst=LancasterStemmer()
print(lst.stem('eating'))
print(pst.stem('shopping'))

词形还原

'''词形还原'''
from nltk.stem import WordNetLemmatizer
wlem=WordNetLemmatizer()
print(wlem.lemmatize('ate'))

停用词删除

'''停用词删除'''
from nltk.corpus import stopwords
stoplist=stopwords.words('english')
text='This is just a test'
cleanwordlist=[word for word in text.split() if word not in stoplist]
print(cleanwordlist)

拼写矫正

edit_distance

''''''
from nltk.metrics import edit_distance
print(edit_distance('rain','shine'))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值