Python 四大名著词频画图

#coding=utf-8

import imageio as im
import wordcloud as wc
import jieba as jb
import time
import os

def excludes(myname):
    exwordsgyy=["将军","却说","二人","不可","荆州","不能","如此","商议","如何","主公","军士","左右","军马","引兵","次日","大喜","天
下","东吴","于是","今日","不敢","魏兵","陛下","一人","都督","人马","不知","汉中","只见","众将","后主","蜀兵","上马","大叫","太守","
此人","夫人","先主","后人","背后","城中","天子","一面","何不","大军","忽报","先生","百姓","何故","然后","先锋","不如","赶来","原来",
"令人","江东","下马","喊声","正是","徐州","忽然","因此","成都","不见","未知","大败","大事","之后","一军","引军","起兵","军中","接应"
,"进兵","大惊","可以","以为","大怒","不得","心中","下文","一声","追赶","粮草","曹兵","一齐","分解","回报","分付","只得","出马","三千
","大将","许都","随后","报知","前面","之兵","且说","众官","洛阳","领兵","何人","星夜","精兵","城上","之计","不肯","相见","其言","一
日","而行","文武","襄阳","准备","若何","出战","亲自","必有","此事","军师","之中","伏兵","祁山","乘势","忽见","大笑","樊城","兄弟","
首级","立于","西川","朝廷","三军","大王","传令","当先","五百","一彪","坚守","此时","之间","投降","五千","埋伏","长安","三路","遣使",
"回见","大将军","必然","将士","是夜","小路","英雄","望见","无不","有人","马下","江南","下寨","杀出","诸葛","中原","屯兵","蛮兵","之
意","城下","本部","前来","出迎","武士","城外","两路","一阵","连夜","四面","奔走","杀来","交锋","冀州","细作","使者","人报","而出","
心腹","杀入","城门","吴兵","当日","众人","皇叔","何处","江夏","先帝","如之奈何","何以","兴兵","国家","前进","两军","来到","许昌","厮
杀","拜谢","两个","岂可","慌忙","饮酒","为首","性命","进发","谋士","此言","之心","三人","掩杀","奈何","昔日","山上","父子","安敢","
有失","群臣","不及","即日","入帐","往来","相待","各自","数十","直取","纵马","使人","自有","回顾","迎接","何如","死战","攻打","前部",
"礼毕","收拾","莫非","中军","迎敌","太史慈","新野","报仇","向前","大寨","曹军","大兵","蜀中","此处","之上","勒马","果然","设宴","消
息","后面","至此","再三","乃是","十万","各引","马上","交战","刺史","其余","之地","南郡","败走","不许","不必","大半","部将","回到","
汉室","之众","而入","使君","火起","汝二人","旌旗","厉声","五万","拔剑","不曾","赶到","退兵","于禁","求救","糜竺","方可","大哭","诸侯
","当夜","手下","河北","吴侯","一个","诗赞","夹攻","今夜","之言","自此","百官","须臾","无数","计议","其人","前去","直至","一将","必
为","不足","每日","相助","众军","城池","两边","数日","一计","大小","社稷","正遇","之事","胜负","奋力","推出","太后","之策","比及","
两下","领命","早有","遥望","而进","闻言","大乱","围住","聚众","司马","何必","阵前","不想","放火","乐进","讨贼","大骂","分兵","皇帝",
"号令","正在","不住","收兵","自引","副将","去路","回寨","早晚","忠义","无人","只是","劫寨","追杀","百万","提兵","一枝","截住","飞马"
,"之士","伏于","老夫","下令","炮响","他人","某愿","重赏","火光","渡江","成功","之下","三日","兖州","拍马","营寨","死者","不过","用兵
","一千","到来","起身","不到","生擒","不已","只有","挺枪","审配","公子","闻知","不胜","部下","出城","四下","三万","败军","已毕","操
问","足下","卧龙","维曰","翻身","天明","自来","赶上","得胜","不用","那里","众视","门外","未尝","父亲","将来","三合","方才","太师","
轻敌","官僚","公曰","车仗","前后","水军","街亭","黄巾","姓名","东南","拦住","一处","上表","攻城","未及","坐于","差人","大臣","钱粮",
"之内","今若","看时","来迎","立马","山谷","江边","战船","回去","各处","四散","旗号","后堂","刀斧手","时分","左边","应声","隘口","大
路","军民","兵来","南安","魏主","献帝","校尉","明日","落马","汝南","数万","虚实","贤弟","不忍","关上","匹夫","即令","吾主","冲突","
枪刺","探知","报说","而言","接入","听知","开门","即时","飞报","益州","阿斗","雒城","言语","虽然","军器","马匹","当下","军心","径取",
"径到","锐气","使命","吾料","便是","山坡","败兵","大起","船只","不服","不然","乘虚","退去","平生","江陵","哨探","斜谷","泸水","士卒"
,"入见","其事","安肯","太傅","若得","幸得","乱箭","呐喊","重围","长子","拜伏","那时","建安","二嫂","荆襄","断后","天水","魏主曹","武
侯","四方","青州","十余","馆驿","大夫","宫中","寻思","阵势","收军","船上","一时","其意","淮南","先行","老小","土人","魏王","元年","
中郎将","再拜","三十里","不利","造反","良久","兄长","司徒","平原","可速","此必","救应","而已","多少","夺路","过去","拨马","印绶","近
臣","披挂","自己","大呼","接着","密书","白旗","一同","不出","右边","回马","动静","自回","具言","去取","中计","孙夫人","参军","剑阁",
"木牛流马","内应","叔父","安民","会合","有何","之子","尚书","少顷","行至","车上","大喝","未敢","妻子","报入","其计","之物","一万","
此计","兵马","兵到","只恐","诈败","乃谓","已知","拜辞","诈降","以致","混战","助战","危急","西门","四海","长沙","侍中","小儿","数百",
"数里","跃马","一刀","此去","探听","哥哥","一半","城内","汉水","并力","不可不","连日","主人","关某","之前","手执","退入","南阳","听
得","忽闻","无礼","屯于","退军","我军","班师","其子","从者","西凉","所以","何在","名曰","阶下","遂命","上书","上将","看看","射中","
步行","至今","表曰","现在","归路","两家","谷口","之罪","从事","端坐","守城","营中","以防","敌不住","以此","出师","关隘","下山","归降
","阳平关","魏军","大丈夫","共议","冲杀","陇西","良策","十里","正中","乘马","宗族","不幸","必来","豫州","反贼","辽东","前军","一箭",
"不得已","今番","奔回","以来","举火","运粮","一条","身长","领军","回身","红旗","都尉","提刀","斩首","山后","驱兵","西北","东门","玉
玺","若非","之力","坐定","引一军","于路","今天","特来","一封","吾兄","安排","议事","二十里","恐有","诡计","在外","下船","操兵","以图
","操笑","刘豫州","便教","水镜","入川","高定","老人","随即","施礼","操见","之际","抵敌","痛哭","勒兵","多有","车驾","之臣","老母","
默然","曹公","粮食","大喝一声","自幼","追兵","摆开","长史","骤马","整顿","不远","山路","为何","决一死战","起程","羌兵","基业","之情"
,"托孤","浮桥","统曰","深入","狂风","可惜","贼兵","半路","擂鼓","不容","方欲","少年","一路","十数","许多","安能","相府","酒食","君臣
","之主","两阵","大会","在手","衣服","不久","衣甲","相交","难以","以待","后军","数百人","大进","诸军","百余","先取","放心","保护","
拒敌","此地","不下","长坂","定军山","受计","雍州","长江","当时","大汉","欣然","不计其数","听令","二十余","一月","三十余","饮宴","五
十","太子","聪明","文书","壮士","总督","公等","战不数合","一队","发兵","无益","诸公","天文","等候","自然","流涕","四人","必将","提防
","辞去","一员大将","小沛","吊桥","一带","安营","入城","军前","即命","南征","动兵","平明","必须","官渡","童子","魏寨","汉朝","一大",
"天地","早降","攻击","追袭","岸上","降者","大功","富贵","妇人","李儒","此间","赤兔马","手提","宝剑","旦夕","飞奔","取出","甚急","两
马","遣人","拜见","鼓声","分拨","先令","五路","锦袍","不须","操军","留下","面前","只顾","弓弩","一合","目视","相随","修书","已有","
将近","急令","顿首","此城","不降","安定","之恩","未定","甘夫人","器械","利害","鼓角","吴主孙","阴平","措手不及","杀到","之声","护送"
,"安得","毕竟","回军","车骑","千余","南门","告急","下手","结连","忠臣","帐下","来降","之势","陈留王","自刎","不成","杀死","抚慰","何
为","自领","山东","直入","文官","应允","不分胜负","本寨","数千","渡河","送与","探马","前者","次子","军法","活捉","山中","书信","军到
","军来","大开","兵出","危矣","馆舍","一班","糜夫人","喝令","兵法","迤逦","老将","文聘","小童","绵竹","兀突","豪杰","立功","可图","
白马","逆贼","大战","大作","纷纷","射死","州郡","转过","互相","不明","县令","重用","守住","一行","一骑","回头","愿往","居民","齐发",
"不觉","罢兵","黄昏","计策","放声大哭","招安","不安","羞惭","百余人","纵横","鼓响","元帅","知之","安歇","将令","急退","震地","当年",
"守御","来取","救兵","蔡夫人","当阳","正言间","沿江","地理","水寨","急救","何进","长叹","左有","起处","取胜","鼓噪","奸雄","黄门","
突出","认得","直到","可怜","旧日","国舅","不宜","便行","不止","切不可","公卿","丈夫","门吏","第一","将校","来报","旗下","出阵","马挺
枪","故来","军杀","造饭","交马","受命","泄漏","脱身","有何面目","常山","兵器","多言","冲出","上山","其中","称谢","何意","安忍","十日
","遂曰","拥出","行军","身上","濮阳","二处","率兵","右有","追至","救出","黎阳","曹贼","奸计","二十余里","小舟","水中","三百","扮作",
"敌楼","乃令","一刀斩","践踏","何用","兵败","雷铜","敌人"]
    exwordshz=["你们","我们","好汉","知府","什么","头领","他们","银子","梁山","山寨","出来","就是","怎么","和尚","公人","这里","东京
","汉子","只好","回来","不是","酒店","过来","几个","起来","喽啰","却是","梁山泊","哪里","吃酒","几天","庄客","那人","太公","回合","
人称","一把","酒保","听说","女人","教头","师父","回家","坐下","衙门","一座","下来","入伙","士兵","这天","一看","朴刀","知县","官府",
"正要","小子","洒家","娘子","不要","知道","太尉","江州","祝家庄","直奔","三个","官军","就让","如今","大官人","小弟","老虎","没有","
说出","公文","管营","名叫","庄上","有个","二位","老汉","金银","清风","转身","说明","不由","经过","强人","打死","衣裳","明天","怎能",
"一天","官兵","为什么","差拨","命人","带上","一家","这个","十两","禅杖","第二天","包袱","不好","正说","说话","长老","东西","这位","
路上","这么","咱们","伙计","突然","一脚","投奔","立即","进去","酒肉","茶坊","找到","丫鬟","二龙山","这时","客人","只要","动手","坐在
","地说","客店","女儿","就要","酒菜","下去","火把","高兴","款待","8195","打开","里面","吩咐","回山","街上","弟兄","命令","山下","认
识","济州","大名府","叔叔","独自","这是","报告","喝道","一片","地方","商量","怎肯","江湖","有些","一位","家中","天色","地上","官人",
"一步","生辰","枣子","县衙","老爷","嫂嫂","真人"]
    exwordxyj=["怎么","甚么","长老","不是","国王","徒弟","这个","那怪","出来","真个","小妖","这里","那个","宝贝","取经","如今","三个
","这般","铁棒","就是","师徒","不要","妖怪","老者","上前","有些","如来","你们","起来","妖魔","进去","弟子","西天","问道","老爷","观
看","师兄","贫僧","行李","一个个","一座","看见","怎生","那些","云头","叫做","天王","公主","几个","模样","袈裟","爷爷","人家","十分",
"里面","不好","怪物","不题","变化","手段","慌得","一把","唬得","一般","东土","道士","女子","打死","吩咐","大仙","出去","神通","叫声"
,"金箍棒","太宗","听见","高叫","欢喜","晓得","还有","娘娘","西方","却是","喝道","近前","故此","叩头","毫毛","一场","大唐","那长老","
回来","走路","也罢","妖道","拜佛","仔细","一只","妖邪","听说","四众","本章","字数","抬头","空中","扯住","下回分解","魔王","降妖","不
尽","坐在","忍不住","口里","报道","罢了","妖王","有个","门前","他们","洞里","一口","葫芦","还是","造化","未曾","关文","径至","一根",
"只管","揭谛","本事","一则","中间","走出","变作","说话","花果山","不期","摇身一变","受用","众僧","金光","祖师","咒语","孩儿","东西",
"下来","进来","跪下","知道","真是","一遍","合掌","出门","一件","常言道","老妖","耳朵","儿子","僧道","列位","那厮","老君","头上","本
相","没有","天宫","母亲","双手","灵山","方便","为证","自家","昨日","一下","磕头","下界","路上","扇子","将身","躬身","四个","道人","
不了","上来","出家人","驸马","惊动","父母","战兢兢","金星","神通广大","父王","礼拜","转身","不同","教他","三年","南海","看处","包袱"
,"魔头","跳出","不多时","手中","就要","耍子","烦恼","驾云","洞口","一会","不会","胡说","倒换","这些","拿来","下去","王道","祥云","答
应","金刚","唐朝","现了","使个","半空中","且莫","祥光","神仙","放下","一一","法力","一顿","坐下","婆婆","寡人","群妖","老怪","正果",
"按落","吆喝","启奏","旨意","方丈","一定","多官","山门","保唐僧","猢狲","皈依","王子","长生","轻轻","时辰","天门","门首","放在","法
师","水帘洞","外面","走上","筋斗云","谢恩","宝杖","地下","过来","用手","半空","几时","闻得","做个","老儿","打个","求经","路旁","下卷
","上卷","不怕","天尊","旁边","嘴脸","仙气","真经","孽畜","五百年","相貌","大惊道","莫想","南无","金银","干净","果子","老魔道","一块
","果是","樵子","乾坤","拿出","动手","二郎","可是","这是","化斋","老师","腰间","明白","万岁","传旨","还要","四大","这场","僧人","其
实","精神","依言","大哥","蟠桃","罗汉","众神","只怕","端的","南天门","抽身","时节","说出","没奈何","记得","这厮","趁早","好歹","银子
","直裰","里边","修行","想必","名字","后边","一夜","半个","宝殿","怎敢","大闹天宫","寺里","钵盂","伏侍","女王","树上","一张","小龙",
"即将","心惊","迎着","不消","肚里","来看","身子","女儿","棍子","日月","远近","慈悲","打破","天色","一向","那厢","着实","天师","连忙"
,"赌斗","小姐","不吃","神僧","清风","害怕","师弟","山头","洞门","声音","不来","说道","几年","暗想","天晚","光蕊","必定","施主","驿丞
","大家","高山","去处","万望","五行","之外","祸事","君王","二哥","一双","战战兢兢","老道","圈子","依然","外公","国师","天上","个个",
"之类","真言","二则","一发","好处","决不","假若","我家","口中","睡着","二来","打开","切莫","点头","殿下","马温","吹口","进城","找寻"
,"滴泪","老魔","人间","满心欢喜","径入","一家","一壁厢","听言","即便","把门","一片","看着","挑担","山凹","那道士","多时","我来","这
泼","古人云","粗细","判官","五方","打听","暗笑","门上","雷音寺","公公","上面","冲撞","前门","大胆","筋斗","看守","上去","对众","武艺
","正说","容易","金箍","如意","相持","现出","计较","长嘴","上西天","渐渐","妈妈","一部","阴阳","供养","暗喜","大众","光明","买卖","
上天","神兵","早已","好生","滚滚","睡觉","锡杖","女婿","三位","好人","挑着","那唐僧","真假","好道","芭蕉扇","欠身","大字","朝上","打
扮","洞府","恕罪","那般","断然","上下","挡住","莫说","何方","寿星","来得","败阵","钦差","此物","分明","木叉","原身","晦气","牵马","
一纵","处处","的话","明月","前日","开口","瑞气","长短","执着","逃生","雷音","只教","沙门","一直","名唤","夫妻","莫怕","官道","莫念",
"问讯","当面","员外","一见","纵身","一抖","昼夜","相迎","若要","快早","冷笑","低头","变得","一拥","行囊","二位","夯货","左手","二魔
道","此山","善哉","你家","我且","喜道","不管","即变","既有","停当","万里","怠慢","天兵","官儿","今年","真君","努力","盘缠","往前","
不济","老和尚","变做","只要","奉旨","不识","这一去","念动","法儿","猴儿","行凶","径回","鼻子","即忙","几日","千万","弟兄","一道","天
将","这样","个人","天神","威风","云端","勾当","我儿","惫懒","那人道","世间","文牒","禅堂","本象","巡山","身体","呵呵","筵宴","想着",
"一顶","千年","适才","劈头","云雾","来此","千里","上界","身穿","展开","那壁厢","楼台","悚惧","成精","变作个","莲台","紧箍儿","强盗",
"两班","辛苦","儿女","诸天","恐怕","呼呼","尘埃","黄金","莫怪","暗中","那方","不瞒","全无","一点","别人","按下","你好","称为","一领"
,"声响","不动","七个","只闻","思量","一棒","止不住","一番","净瓶","底下","疼痛","斋饭","何来","油锅","中华","伽蓝","不打紧","解了","
大海","四时","那条","法名","那山","喜欢","前边","来时","水面","夜叉","解数","后来","打发","阴司","答道","死罪","无奈","径往","急急",
"一跌","打着","河边","无知","说得有理","几句","九霄","金銮殿","高徒","爬起来","芭蕉","公主道","火焰山","顶上","所谓","躲过","仙童","
出家","落下","无边","山前","之功","六个","何事","烧火","脸上","那伙","六甲","明早","一身","流沙河","寺院","灯火","江山","皇后","阴风
","出头","物件","天竺国","牵着","虎皮","径转","饶命","丑陋","人参果","奶奶","女怪","自从","人物","下雨","茶饭","侍立","得到","后门",
"依旧","健将","毛脸","灵霄","圣旨","差来","唱个","仙女","撞见","老大","锦绣","管教","这才","身边","行礼","开步","伤人","借宿","一头"
,"念个","捉住","下降","部洲","化作","虎豹","有缘","在于","急忙","相逢","念念","身下","焚香","玉兔","本身","七十二","自古","分开","甚
喜","正欲","大力","众臣","欺心","发怒","内有","右手","人来","情愿","地方","官员","望空","早见","算计","难禁","长枪","一伙","城里","
随身","太保","年纪","那老儿","这话","悄悄的","第二个","护持","国丈","那边","走近","话表","之理","念佛","水火","这番","陪笑","暗暗","
时候","鬼神","说来","身法","钻入","耍耍","众怪","房里","打出","奏道","大惊失色","推倒","回合","二十八宿","丢下","解脱","紧紧","火眼
金睛","尊者","卷帘","水底","过山","九齿","一救","救得","有事","念经","只好","管待","着手","乱打","原是","东土唐","没事","这伙","外边
","远来","荆棘","在家","我师","吃酒","捉弄","狮子","祭赛","朱紫国","正当","众猴","往外","人事","那洞","他家","紧闭","老实","呼唤","
半日","逍遥","当中","家火","一对","闪过","念声","一边","领着","息怒","道声","鬼王","托塔","龙床","风响","伺候","六丁","索战","香火",
"助力","胜败","下水","正要","一事","绳索","延寿","莲花","尸首","相会","途中","皇宫","甚事","报怨","太监","一杯","遇着","乃东","莫要"
,"见面","绳子","垂泪","干事","烟火","没处","窟窿","四位","松林","伶俐","天气","石崖","无量","上岸","一生","身躯","金丹","伸手","喧哗
","整衣","高声","剥皮","洞外","迎风","钢刀","满城","地上","虎狼","寻着","水晶宫","若有","或者","幽冥","快快","壁厢","帅众","喝声","
瑶池","也好","踪迹","峥嵘","公然","甚人","输赢","那贼","倘或","哀告","今朝","心肝","嫔妃","俯伏","酬谢","早到","甚话","十八","吃些",
"两只","石头","路过","西去","取水","粉碎","几番","跟着","老王","火焰","把头","走过","沙僧笑","今早","虫儿","昏君","犀牛"]
    exwordhlm=["39","阿弥陀佛","安静","安慰","安心","按着","暗暗","巴不得","罢了","百般","办事","半日","半晌","半天","拌嘴","帮着","
抱怨","背地里","本来","彼此","彼时","必定","必是","必要","便命","便宜","便知","标致","别处","别的","别管","别人","别说","并未","玻璃
","不便","不吃","不错","不大","不大好","不但","不得了","不妨","不该","不够","不顾","不管","不好","不好意思","不会","不解","不尽","不
禁","不拘","不堪","不快","不来","不了","不理","不料","不免","不怕","不去","不少","不是","不说","不算","不提","不同","不妥","不问","
不相干","不像","不小","不信","不要","不依","不用说","不在话下","不中用","不自在","才刚","操心","诧异","吵嚷","趁着","吃饭","吃酒","
吃了饭","吃药","出家","出来","出门","出气","出去","出入","出事","除了","厨房","处来","穿著","窗外","床上","垂手","此刻","从此","从来
","从前","从小儿","答道","答言","答应","打扮","打点","打发","打开","打量","打扫","打死","打算","打听","打着","大哥","大观园","大红",
"大家","大老爷","大门","大人","大嫂子","大约","呆呆","带来","带领","胆子","但是","当铺","当着","当作","倒好","倒像","倒要","到底","
道理","道人","道士","得意","得罪","的话","登时","等物","等语","低头","底下","地方","地下","弟兄","点点头","点头","点子","丢开","丢下
","东边","东府里","东西","懂得","独有","读书","赌气","端的","对联","对面","多心","多早晚","恩典","儿女","儿媳妇","而且","二两","二门
","二位","二则","二字","法儿","法子","烦恼","反倒","饭后","方知","方子","房里","房门","房内","房屋","房中","房子","放下","放在","放
着","非常","费心","分节","分明","分派","吩咐","风流","风声","风月","夫妇","夫妻","服侍","府上","父母","该死","赶忙","赶着","干净","
刚才","高兴","告辞","告诉","哥儿","个个","个人","各人","各色","跟前","跟着","更好","更加","更觉","工夫","姑妈","姑奶奶","姑爷","姑子
","辜负","古人","故此","故事","故意","怪道","馆来","管家","管事","光景","逛逛","规矩","桂花","跪下","果见","果真","果子","过不去","
过来","过于","还好","还是","还要","还有","孩子","海棠","含泪","含笑","汗巾","行礼","行事","好不好","好处","好歹","好好","好看","好人
","好容易","好生","好事","好象","好笑","好些","喝酒","合家","何曾","何尝","何等","何苦","何况","何事","荷包","盒子","横竖","红了脸",
"后悔","后来","后门","后事","后头","胡乱","胡说","胡涂","唬得","花儿","话儿","怀里","欢喜","恍惚","回避","回道","回房","回过","回家"
,"回来","回明","回说","回至","会意","混说","混账","伙计","或是","或者","及至","极好","即刻","急得","急忙","几处","几次","几个","几乎
","几件","几句","几句话","几两","几年","几日","几时","几天","几样","记得","记挂着","既有","寂寞","家常","家伙","家里","家去","家人",
"家务","家中","贾府","贾家","见过","见面","渐渐","讲究","交给","交与","角门","叫作","叫做","觉得","教训","接过","姐儿","姐妹","解劝"
,"今儿","今见","今年","金陵","金银","进城","进京","进来","进门","进去","进入","进园","近来","近日","禁不住","经过","惊动","精神","竟
是","镜子","究竟","就是","就要","舅舅","舅母","看见","看来","看守","看着","炕沿","磕头","咳嗽","可不","可不是","可见","可巧","可是",
"可笑","可知","空儿","恐怕","口里","口内","哭道","哭泣","快快","况且","拉着","来得","来回","来看","来说","来往","老嬷嬷","老娘","老
婆","老婆子","老人家","老先生","老子","姥姥","乐得","了不得","泪来","冷笑","里间","里面","里头","理会","理论","立刻","连忙","帘子","
联道","脸面","脸上","两处","两件","两句","两口","两日","两三个","两声","两天","两眼","料理","伶俐","留神","留心","留着","路上","露出
","论理","妈妈","满面","慢慢","忙乱","忙忙","忙命","没法","没法儿","没个","没见","没脸","没趣","没人","没什么","没意思","没有","梅花
","每每","每人","妹子","门口","门前","门上","门子","闷闷","勉强","庙里","名唤","名字","明白","明儿","明年","明知","命人","模样儿","
嬷嬷","母女","母亲","拿出","拿来","哪个","哪里","那边","那府","那个","那么","那年","那婆子","那人道","那日","那位","那些","那丫头","
那样","纳闷","男女","男人","男子","南边","难道","难得","难为","能够","你别","你好","你家","你老","你们","年纪","年轻","念道","念佛",
"念书","娘儿","娘儿们","宁府","宁国府","奴才","女儿","女孩儿","女孩子","女尼","女人","女婿","女子","偶然","怕人","拍手","旁边","陪笑
","朋友","脾气","偏生","平安","婆婆","菩萨","欺负","齐全","其实","奇怪","岂知","起来","气得","恰好","前儿","前日","前头","悄悄","悄
悄的","瞧瞧","亲家","亲戚","亲事","亲友","轻轻","清楚","清净","情愿","请安","取乐","取笑","娶亲","劝解","却是","热闹","人才","人道",
"人回","人家","人口","人来","人们","人去","人人","人物","认真","仍旧","日后","日夜","日子","荣府","荣国府","容易","如今","若论","若
有","撒谎","三分","三个","山石","扇子","伤感","伤心","商量","上车","上房","上来","上面","上前","上去","上头","上下","上学","上夜","
尚未","少不得","伸手","身边","身后","身体","身子","深知","什么","神仙","婶娘","婶子","生得","生恐","生气","生日","生事","省得","省亲
","省事","剩下","师父","十倍","十二个","十分","十个","时常","时候","实在","使不得","使得","使唤","使用","士隐","世人","似的","事来",
"事情","收着","手里","手帕","手中","受用","书房","叔叔","梳洗","谁家","谁知","水月庵","睡觉","睡着","顺着","说不出来","说不得","说出
","说道","说话","说来","说明","说起","说完","说闲话","说些","私自","死活","四个","四字","伺候","送到","送来","俗语说","素日","算是",
"虽是","虽说","随便","随着","孙子","所有","索性","他家","他们","她家","她们","抬头","太监","太爷","倘或","桃花","淘气","提起","题目"
,"蹄子","体面","体统","天气","天上","天天","调唆","铁槛","听到","听见","听说","听听","同着","头儿","头发","头里","头上","退出","妥当
","外边","外间","外面","外人","外头","玩话","玩耍","玩笑","晚饭","晚间","晚上","王爷","往后","往里","往前","往日","往外","微微","为
的是","为什么","惟有","委屈","委曲","未必","未可知","未了","未免","文章","闻得","问道","问好","问起","问问","我家","我见","我来","我
们","我且","我要","我原","我作","屋里","屋内","屋子","无法","无话","无可","无奈","无心","五更","喜欢","细看","细说","细问","细细","
细细的","匣子","下回分解","下来","下面","下去","先前","先时","先是","闲话","现成","现今","现有","相干","香院","箱子","想必","想不到"
,"想到","想道","想来","想起","想想","想着","潇湘","小孩子","小姐","小人","小事","小心","小子","孝敬","孝顺","笑话","笑嘻嘻","歇息","
歇歇","写道","心肠","心来","心里","心内","心上","心事","心下","心想","辛苦","新鲜","形容","兴头","幸而","幸亏","性情","薛家","丫头",
"衙门","烟道","颜色","眼睛","眼看","眼泪","眼里","眼前","央告","样儿","样子","摇头","要紧","要是","要说","要死","要知","爷们","爷爷"
,"也罢","也好","夜间","夜里","一把","一般","一杯","一辈子","一本","一边","一遍","一并","一步","一层","一场","一出","一次","一等","一
点","一点儿","一定","一段","一对","一顿","一番","一分","一副","一概","一个月","一根","一回","一会","一家","一家子","一见","一件","一
径","一句","一看","一口","一块","一两","一年","一篇","一片","一起","一瞧","一群","一色","一身","一生","一事","一手","一首","一双","
一说","一趟","一套","一天","一头","一碗","一位","一味","一下","一想","一笑","一心","一宿","一样","一夜","一一","一应","一语","一遭",
"一早","一则","一张","一只","一直","一种","衣裳","怡红院","姨妈","姨娘","疑惑","疑心","已经","以后","以及","椅子","议论","异常","益
发","意思","意欲","因而","因见","因说","因为","因问","因想","因笑","阴阳","银钱","银子","饮食","由不得","有个","有话","有理","有趣",
"有时","有事","有些","余者","预备","遇见","园里","园内","园中","园子","原该","原故","原是","原要","远远","怨不得","院门","院内","院
中","院子","愿意","阅读","越发","仔细","再说","再者","在家","在内","咱们","暂且","早饭","早起","早些","早已","造化","怎么","怎么样",
"怎么着","怎样","扎挣","站住","张家","张罗","照管","照看","照应","这般","这般光景","这边","这病","这才","这倒","这个","这话","这会子
","这件","这句","这里","这么","这么着","这日","这事","这是","这位","这些","这样","这有","这种","着急","着实","着手","着眼","针线","
真是","真真","甄家","正好","正经","正说","正要","正值","正自","之类","之外","只当","只管","只好","只觉","只怕","只求","只要","知道",
"知是","知县","执事","侄儿","止住","旨意","指着","智能","终身","诸人","诸事","主意","主子","嘱咐","转身","桌上","桌子","子弟","子们"
,"自从","自觉","自去","自为","走进","走开","走来","走上","走走","祖宗","嘴里","最是","昨儿","昨日","昨夜","作主","坐下","坐在","坐坐
"]
    myword=[]
    for name in myname:
        if len(name)==1:
            continue
        elif exwordsgyy.count(name) >0 or exwordshz.count(name) >0 or exwordxyj.count(name) >0 or exwordhlm.count(name) >0:
            continue
        elif name=="诸葛亮" or name=="孔明曰" or name=="孔明笑" or name=="孔明之" or name=="孔明自":
            outname="孔明"
        elif name=="关公" or name=="云长" or name=="关云长":
            outname="关羽"
        elif name=="玄德" or name=="玄德曰" or name=="刘玄德" or name=="玄德大" or name=="刘皇叔" or name=="玄德问" or name=="玄德自
" or name=="玄德闻" or name=="玄德见" or name=="玄德乃":
            outname="刘备"
        elif name=="孟德" or name=="丞相" or name=="操大喜" or name=="操贼" or name=="操令" or name=="操大怒":
            outname="曹操"
        elif name=="赵子龙" or name=="子龙":
            outname="赵云"
        elif name=="公瑾" or name=="周郎":
            outname="周瑜"
        elif name=="行者" or name=="大圣" or name=="老孙" or name=="孙行者" or name=="孙大圣" or name=="孙悟空" or name=="齐天大圣" 
or name=="美猴王" or name=="猴头":
            outname="悟空"
        elif name=="三藏" or name=="圣僧" or name=="玄奘" or name=="御弟" or name=="唐三藏":
            outname="唐僧"
        elif name=="" or name=="沙和尚":
            outname="沙僧"
        elif name=="呆子" or name=="猪八戒":
            outname="八戒"
        elif name=="宝二爷" or name=="宝兄弟":
            outname="宝玉"
        elif name=="黛玉道" or name=="林黛玉" or name=="林姑娘" or name=="林妹妹" or name=="黛玉忙" or name=="黛玉笑":
            outname="黛玉"
        elif name=="宝钗道" or name=="宝钗笑" or name=="宝姐姐" or name=="宝丫头" or name=="薛宝钗":
            outname="宝钗"
        elif name=="贾母房" or name=="贾母笑" or name=="贾母因" or name=="老太太" or name=="老祖宗":
            outname="贾母"
        elif name=="凤姐儿" or name=="凤姐姐" or name=="凤丫头":
            outname="凤姐"
        elif name=="贾政道" or name=="贾政听" or name=="贾政笑" or name=="贾政又":
            outname="贾政"
        else:
            outname=name
        myword.append(outname)
    return myword

def word(myfile):
    mycounts={}
    myword=[]
    if os.path.exists(myfile):   # 文件存在
        mybtime=time.perf_counter()
        mywordtmp=open(myfile).read()    # 只读打开文件
        mywordtmp=mywordtmp.lower()   # 将所有字符变为小写
        for ch in "~!@#$%^&*()_+{}|:<>?`-=[]\;',./":
            mywordtmp=mywordtmp.replace(ch," ")
        myword=jb.lcut(mywordtmp)   # 从文件变量中切出单词
        myword=excludes(myword)   # 去掉非人名单词,合并相同人名

        mymask=im.imread("china.jpg")
        mywordcloud=" ".join(myword)
        w=wc.WordCloud(font_path="msyh.ttc",max_font_size=100,min_font_size=10,background_color="white",width=800,height=600,max_wor
ds=5000,mask=mymask)
        w.generate(mywordcloud)
        w.to_file(myfile+".png")

        mycounts={}
        for word in myword:
            mycounts[word]=mycounts.get(word,0)+1
        myword=list(mycounts.items())
        mywordtime=time.perf_counter()-mybtime
        mybtime=time.perf_counter()
        myword.sort(key=lambda x:x[1],reverse=True)
        mysorttime=time.perf_counter()-mybtime
        mylen=len(myword)
        outfile=myfile+".print"
        myoutfile=open(outfile,"w")
        for i in myword:
            if i[1]>20:
                print("{:<15}频率:{:>8}次,分词量:{:>8}个,分词时间:{:>6.0f}秒,排序时间:{:>6.0f}>秒".format(i[0],i[1],mylen,myw
ordtime,mysorttime))
                myoutfile.write("{:<15}频率:{:>8}次,分词量:{:>8}个,分词时间:{:>6.0f}>秒,排序时间:{:>6.0f}>秒\r\n".format(i[0]
,i[1],mylen,mywordtime,mysorttime))
        myoutfile.close()
    return myword

word("哈姆雷特.txt")
word("三国演义.txt")
word("水浒传.txt")
word("西游记.txt")
word("红楼梦.txt")
word("新时代中国特色社会主义.txt")
word("关于实施乡村振兴战略的意见.txt")

你可能感兴趣的:(Python)