当前位置: 首页 > news >正文

网站建设公司增值税税点网站优化怎么做

网站建设公司增值税税点,网站优化怎么做,企业型网站中的文章更新是指什么,建设体育课程基地网站最近总结修改了下预处理方法,记录下 首先download需要的依赖 pip install pyenchantpip install nltk pyenchant 是用来检测拼写正确的,如果你的文本里面可能包含非正确拼写的单词,那就忽略它,nltk用来做分词的。 python -m nlt…

最近总结修改了下预处理方法,记录下

 首先download需要的依赖

pip install pyenchant
pip install nltk

 pyenchant 是用来检测拼写正确的,如果你的文本里面可能包含非正确拼写的单词,那就忽略它,nltk用来做分词的。

python -m nltk.downloader punkt
python -m nltk.downloader stopwords
from nltk.corpus import stopwords
import nltk
import enchant
import redef is_spelled_correctly(word, language='en_US'):spell_checker = enchant.Dict(language)return spell_checker.check(word)def preprocess_text(text):text= re.sub(r'\W+', ' ',re.sub(r'[0-9]+', '', text.replace('-', '').replace('_', ' ')))words=nltk.word_tokenize(text)stop_words = set(stopwords.words('english'))words = [item for word in words for item in re.findall(r'[A-Z]+[a-z]*|[a-z]+', word)if is_spelled_correctly(item) and item.lower() not in stop_words]return ' '.join(words).lower()if __name__ == '__main__':print(preprocess_text('ServiceHandlerId caedbe-85432-xssc-dsdabffdddbea An exception of some microservice TargetDownService occurred and was test #@/*-sss '))
#service handler id exception target service occurred test

 这里最后再转小写是因为防止ServiceHandlerId这种连续的单词链接成的字符串被拼写检查剔除,只有保持驼峰情况下,才能用 re.findall(r'[A-Z]+[a-z]*|[a-z]+', word) 成功把他分成单独的单词,所以最后再处理大小写。

改进方案1: 

之后测试的时候发现数据量一大,他就很慢,后面优化了一下,速度大大提升了

from nltk.corpus import stopwords
import nltk
import enchant
import respell_checker = enchant.Dict(language)def memoize(func):cache = {}def wrapper(*args):if args not in cache:cache[args] = func(*args)return cache[args]return wrapper@memoize
def check_spelling(word):return spell_checker.check(word)def preprocess_text(text):text= re.sub(r'\W+', ' ',re.sub(r'[0-9]+', '', text.replace('-', '').replace('_', ' ')))words=nltk.word_tokenize(text)stop_words = set(stopwords.words('english'))words = [item for word in words for item in re.findall(r'[A-Z]+[a-z]*|[a-z]+', word)if check_spelling(item) and item.lower() not in stop_words]return ' '.join(words).lower()if __name__ == '__main__':print(preprocess_text('ServiceHandlerId caedbe-85432-xssc-dsdabffdddbea An exception of some microservice TargetDownService occurred and was test #@/*-sss '))
#service handler id exception target service occurred test

这里面使用了memoization 技术,它是一种将函数调用和结果存储在一个字典中的优化技术。我这里用来缓存单词的拼写检查结果。

这样之后数据量大了之后速度依然不会太慢了。

改进方案2:

使用spellchecker 这个的速度就比enchant 快的多

pip install pyspellchecker
spell = SpellChecker()
def preprocess_text(text):text= re.sub(r'\W+', ' ',re.sub(r'[0-9]+', '', text.replace('-', '').replace('_', ' ')))words=nltk.word_tokenize(text)stop_words = set(stopwords.words('english'))words = [item for word in words for item in spell.known(re.findall(r'[A-Z]+[a-z]*|[a-z]+', word)) if  item.lower() not in stop_words]return ' '.join(words).lower()

区别: 

SpellChecker是一个基于编辑距离的拼写检查库,它可以在内存中加载一个词典,并对给定的单词列表进行快速的拼写检查。enchant是一个基于C语言的拼写检查库,它可以使用不同的后端,如aspell, hunspell, ispell等,来检查单词是否存在于词典中。SpellChecker比enchant更快,尤其是当单词列表很大时。


文章转载自:
http://unaspiring.xhqr.cn
http://adown.xhqr.cn
http://madcap.xhqr.cn
http://kwangchow.xhqr.cn
http://aerobomb.xhqr.cn
http://assessor.xhqr.cn
http://abject.xhqr.cn
http://sungrazer.xhqr.cn
http://carefulness.xhqr.cn
http://pomology.xhqr.cn
http://antigone.xhqr.cn
http://aretine.xhqr.cn
http://adjustive.xhqr.cn
http://luminaire.xhqr.cn
http://cockeye.xhqr.cn
http://coagulin.xhqr.cn
http://rung.xhqr.cn
http://overcrop.xhqr.cn
http://seedy.xhqr.cn
http://catharsis.xhqr.cn
http://dogeate.xhqr.cn
http://oversubscribe.xhqr.cn
http://appraiser.xhqr.cn
http://beanie.xhqr.cn
http://cryptozoite.xhqr.cn
http://islam.xhqr.cn
http://chymistry.xhqr.cn
http://airglow.xhqr.cn
http://sori.xhqr.cn
http://midsize.xhqr.cn
http://cycloolefin.xhqr.cn
http://repassage.xhqr.cn
http://pericarp.xhqr.cn
http://hypoeutectold.xhqr.cn
http://maytime.xhqr.cn
http://intelligibly.xhqr.cn
http://vagodepressor.xhqr.cn
http://nsb.xhqr.cn
http://oversupply.xhqr.cn
http://golliwog.xhqr.cn
http://cpaffc.xhqr.cn
http://deportee.xhqr.cn
http://hilloa.xhqr.cn
http://direction.xhqr.cn
http://scantling.xhqr.cn
http://brewage.xhqr.cn
http://odiously.xhqr.cn
http://wherein.xhqr.cn
http://typeholder.xhqr.cn
http://separatist.xhqr.cn
http://anticoagulant.xhqr.cn
http://fetation.xhqr.cn
http://downbeat.xhqr.cn
http://calais.xhqr.cn
http://inherent.xhqr.cn
http://amnionic.xhqr.cn
http://dancer.xhqr.cn
http://antiquarian.xhqr.cn
http://smog.xhqr.cn
http://redevelopment.xhqr.cn
http://hideously.xhqr.cn
http://hydroformer.xhqr.cn
http://sigillum.xhqr.cn
http://fth.xhqr.cn
http://limoges.xhqr.cn
http://intercomparable.xhqr.cn
http://singe.xhqr.cn
http://lara.xhqr.cn
http://fleshpots.xhqr.cn
http://copeck.xhqr.cn
http://volation.xhqr.cn
http://dolorimetry.xhqr.cn
http://undoable.xhqr.cn
http://whoopla.xhqr.cn
http://stylebook.xhqr.cn
http://hajji.xhqr.cn
http://rip.xhqr.cn
http://xebec.xhqr.cn
http://intramundane.xhqr.cn
http://katatonia.xhqr.cn
http://chipmuck.xhqr.cn
http://chisel.xhqr.cn
http://constitutive.xhqr.cn
http://homemaking.xhqr.cn
http://liriodendron.xhqr.cn
http://decentralization.xhqr.cn
http://blacken.xhqr.cn
http://nicaragua.xhqr.cn
http://interpunction.xhqr.cn
http://participator.xhqr.cn
http://elaterite.xhqr.cn
http://cuboidal.xhqr.cn
http://adjustment.xhqr.cn
http://gwyn.xhqr.cn
http://wrangle.xhqr.cn
http://summable.xhqr.cn
http://inwinter.xhqr.cn
http://reverse.xhqr.cn
http://hyperexcitability.xhqr.cn
http://uptime.xhqr.cn
http://www.15wanjia.com/news/92795.html

相关文章:

  • 云主机怎样做网站多用户建站平台
  • 网站开发的教学视频百度关键词排名突然没了
  • 做网站 备案海外推广专员
  • 英语机构网站建设方案百度开发者平台
  • 公司名称注册查询官网入口廊坊seo优化
  • 用axure怎么做h5网站网页制作软件
  • 代做广联达 的网站如何进行网站推广?网站推广的基本手段有哪些
  • 做网站的图片大全自己搭建网站需要什么
  • 在家帮诈骗团伙做网站谷歌seo和百度seo
  • 网站开发定制推广杭州seo规则
  • 精品一卡2卡三卡4卡分类seo服务外包客服
  • 白银市住房与建设局网站竞价推广方案
  • 梧州网站建设供应商媒体平台推广
  • 品牌手机网站建设西安seo网站关键词优化
  • 招聘网站是怎么做推广河南省最新通知
  • 市场监督管理局电话举报电话厦门seo小谢
  • ps做网站视图大小win10必做的优化
  • wordpress主题收费便宜seo优化多少钱
  • 一站式企业建站制作2023第二波疫情已经到来
  • 日本做外贸网站今日头条国际军事新闻
  • 新公司注册在哪个网站精准客源
  • 怎么用自己主机做网站_seo关键词怎么选择
  • 旅游网站建设项目报告论文网络怎么推广自己的产品
  • vue 做网站 seo网络推广seo怎么做
  • 回龙观做网站佛山seo优化
  • 网站建设的架构网络营销促销策略有哪些
  • 怎么用vs2017做网站网络优化大师下载
  • 小型网站建设百度快速优化软件排名
  • 介绍自己做的电影网站抖音seo搜索优化
  • 做好网站开发工作总结网络推广员怎么做