我用python写了如下程序,可是后来最后出了问题。
有谁帮我解决一下...
Nltk是python下处理语言的主要工具包,可以实现去除停用词、词性标注以及分词和分句等。
安装nltk,写python一般使用的是集成环境EPD,其中有包管理,可以在线进行安装。
如果不是集成环境,可以通过pip install nltk安装。
》pip install nltk #安装nltk》nltk.download() #弹出一个选择框,可以按照自己需要的语义或者是功能进行安装一般要实现分词,分句,以及词性标注和去除停用词的功能时,需要安装stopwords,punkt以及当出现LookupError时一般就是由于缺少相关模块所导致的
如何把python的结果导入txt文件中去?
一楼稍改:import retext="""123 we are -3.13,and 342 or 58.48"""reg=re.compile(r"((-)?\d+(\.\d+)?)")finded = map(lambda n:n[0], reg.findall(text))print finded, len(finded)执行结果:>>>['123', '-3.13', '342', '58.48'] 4
Python中extract
[python] view plain copy#coding:utf-8import sysreload(sys)sys.setdefaultencoding("utf-8")from multiprocessing import Pool,Queue,Processimport multiprocessing as mpimport time,randomimport osimport codecsimport jieba.analysejieba.analyse.set_stop_words("yy_stop_words.txt")def extract_keyword(input_string):#print("Do task by process {proc}".format(proc=os.getpid()))tags = jieba.analyse.extract_tags(input_string, topK=100)#print("key words:{kw}".format(kw=" ".join(tags)))return tags#def parallel_extract_keyword(input_string,out_file):def parallel_extract_keyword(input_string):#print("Do task by process {proc}".format(proc=os.getpid()))tags = jieba.analyse.extract_tags(input_string, topK=100)#time.sleep(random.random())#print("key words:{kw}".format(kw=" ".join(tags)))#o_f = open(out_file,'w')#o_f.write(" ".join(tags)+"\n")return tagsif __name__ == "__main__":data_file = sys.argv[1]with codecs.open(data_file) as f:lines = f.readlines()f.close()out_put = data_file.split('.')[0] +"_tags.txt"t0 = time.time()for line in lines:parallel_extract_keyword(line)#parallel_extract_keyword(line,out_put)#extract_keyword(line)print("串行处理花费时间{t}".format(t=time.time()-t0))pool = Pool(processes=int(mp.cpu_count()*0.7))t1 = time.time()#for line in lines:#pool.apply_async(parallel_extract_keyword,(line,out_put))#保存处理的结果,可以方便输出到文件res = pool.map(parallel_extract_keyword,lines)#print("Print keywords:")#for tag in res:#print(" ".join(tag))pool.close()pool.join()print("并行处理花费时间{t}s".format(t=time.time()-t1))运行:python data_process_by_multiprocess.py message.txtmessage.txt是每行是一个文档,共581行,7M的数据运行时间:不使用sleep来挂起进程,也就是把time.sleep(random.random())注释掉,运行可以大大节省时间。
python生成词云,要求频率越小生成的字词越大,老师的要求,请各...
Ma Liang and the Magic Paint BrushThis is a story from China about a boy and a magic paint brush that makes everything he draws come to life!Once upon a time in China, there was a boy named Ma Liang.Ma Liang's parents had died early so the boy had to support himself by chopping wood and cutting grass. The boy loved painting but he was so poor he could not afford to buy a paint brush!One day, Ma Liang walked past a school and saw a teacher painting with a brush. Without thinking, Ma Liang walked into the classroom and asked the teacher: “I want to learn painting. Can I borrow a paint brush from you?”The teacher glared at the shabby boy and sneered: “What? A poor kid like you wants to learn to paint? You must be daydreaming! Get out of my sight!”Quietly, Ma Liang walked away. He had just been snubbed by an adult but he remained composed and calm. In his mind he was thinking: “I just don't believe a poor child is not good enough to learn painting.”The boy made up his mind to learn to paint by himself.A Boy Learns To PaintWhen he chopped wood in the forest he would draw a bird in the sand with a branch.When he was cut grass by the river, he would dip a grass reed in water and trace a fish on the rocks.At night, when he returned to the cave which he called home, he would use a stick of charcoal to sketch on the wall everything he had drawn during the day.Year after year Ma Liang practiced never missing a day. He drew everywhere he went using anything he could find. If he wasnot actually drawing something he was drawing it in his mind. Every inch of his cave wall was covered with paintings.Even though he still didn't have a paint brush Ma Liang had developed some amazing skills.When he drew a hen on the ground of his village entrance, eagles hovered above.When he drew a black wolf at the back of the mountain, cows and sheep stayed away in fear.“It would be great to have a paint brush.” Ma Liang said to himself everyday.A Wish Come TrueOne night, feeling very tired, Ma Liang fell asleep while painting. Suddenly, there appeared rays of colorful, brilliant light. An old man with a very long white beard walked out of the light and handed Ma Liang a paint brush.“This is a magic paint brush, use it well.” said the old man whose beard was so long it stretched to the floor.Ma Liang was overcome with joy. The paint brush felt heavy in his hand and it shimmered with golden light.Before Ma Liang could thank the old man, he had disapperared just as suddenly as he had appeared.A surprised Ma Liang awoke from his sleep. What a fantastic dream! But it could not have been a dream since he was still holding tightly to the paint brush.Ma Liang drew a bird with the brush. The bird flapped its wings and flew into the sky.He then painted a fish. The fish wiggled its tail, leapt into the air and into a river Ma Liang had drawn and swam away.Ma Liang was ecstatic. The old man was right.This was indeed a magic paint brush!Each day, with paint brush in hand, the kind-hearted Ma Liang helped the poor people in his village.He painted a cow for the family that needed a cow, a stone mill for the family who wanted a stone mill, and a waterwheel for the family who didn't have a waterwheel.TroubleVery soon, news about Ma Liang's magic paint brush spread to a wealthy local landlord.The greedy landlord sent two of his bodyguards to bring Ma Liang to him and made the boy draw gold coins and ingots. But Ma Liang was a tough kid and no matter how the landlord threatened or beguiled him, he refused to obey the landlord.Angry but out of ideas, the landlord ordered Ma Liang to be locked in a stable and not given any food and water. It was thedead of winter and outside the stable the snow was several feet thick. The landlord thought it was just a matter of time before Ma Liang gave in to the cold and hunger.But what a surprise awaited the landlord two days later when he approached the stable! Through the doorway he could see a bright red light and smell delicious food. Curious, he looked inside the stable. A cheerful Ma Liang was eating piping-hot Chinese pancakes and cooking a pot of stew over a fire!The landlord knew Ma Liang had drawn the food and fire with the magic paint brush. Livid, he ordered his henchmen to kill the boy and grab the magic paint brush.A Great EscapeWhen a dozen men rushed into the stable Ma Liang was nowhere to be found!With the magic paint brush he had drawn a ladder and escaped over the eastern wall. The landlord and his men followed up the ladder but they had climbed no more than a few rungs before the ladder ...
STOP什么意思
stop vi.停止; 中断; 逗留; (使)停止工作; vt.塞住; 堵塞; 阻挠; 止付; n.停止; (管风琴的)音栓; 停车站; (管风琴的)音管; 第三人称单数:stops现在分词:stopping过去式:stopped过去分词:stopped形近词:STOPStop例句:1.He can't stop thinking about it.他没办法不再想这件事。
2.This was very effective, especially since most passing drivers had no idea where it was, and would stop out of curiosity.这很管用,尤其是因为大多数过路司机都对香港在哪儿完全没有概念,就会因为好奇停下车来。
3.I've been told to lose weight and stop smoking.我被告知要减肥并戒烟。
4.Does either of the parties want to stop the fighting?双方中没有一方想停止战斗吗?5.He proposed a new diplomatic initiative to try to stop the war.他提出了一项新的外交计划以尽力阻止这场战争。
python程序员就业薪资一般多少钱? 爱问知识人
python作为近年新兴的行业,就业薪资在5-10k之间,行业发展前景大。
想要转行做python,朋友推荐到重庆达内Python培训,重庆达内python培训. 0基础入门到精通,可下载在线视频教程,免费试听。
专注IT职业教育16年,60万学员的共同选择,在全国60个城市建立了200家培训中心,一地学习全国就业。
有实力、有信誉,可先学习后付款,7天课程免费试听.
转载请注明出处51数据库 » python stopwords