{"id":141,"date":"2016-11-24T17:06:09","date_gmt":"2016-11-24T09:06:09","guid":{"rendered":"http:\/\/blog.defjia.top\/?p=141"},"modified":"2016-11-24T17:06:09","modified_gmt":"2016-11-24T09:06:09","slug":"python%e8%87%aa%e7%84%b6%e8%af%ad%e8%a8%80%e5%a4%84%e7%90%86natural-language-processing%e5%9f%ba%e4%ba%8enltk%e5%ba%93%e7%9a%84%e5%ad%a6%e4%b9%a0%e5%be%85%e6%9b%b4%e6%96%b0","status":"publish","type":"post","link":"https:\/\/blog.defjia.top\/?p=141","title":{"rendered":"Python\u81ea\u7136\u8bed\u8a00\u5904\u7406(Natural Language Processing)\u57fa\u4e8enltk\u5e93\u7684\u5b66\u4e601.1"},"content":{"rendered":"<blockquote><p>nltk\u901f\u6210<br \/>\nimport nltk<br \/>\nnltk.download()<\/p>\n<p>from nltk.book import * #import text 1-9<\/p>\n<p>text1.concordance() #\u67e5\u627e<br \/>\ntesti.similar() #\u53ef\u66ff\u4ee3\u7684\u8bcd<br \/>\ntesti.common_contexts() #\u76f8\u540c\u7684\u524d\u540e\u6587<br \/>\ntexti.dispersion_plot([&#8220;&#8221;,&#8221;&#8221;]) #\u7279\u5b9a\u8bcd\u4f4d\u7f6e<br \/>\ntexti.generate() #\u81ea\u52a8\u751f\u6210\uff0cnltk 3.x\u7248\u672c\u4e0d\u652f\u6301\uff0c\u9700\u89812.0.1<\/p>\n<p>len(texti) #\u5b57\u7b26\u4e32\u957f\u5ea6<br \/>\nset(texti) #\u5b57\u7b26\u4e32-&gt;\u7c7b\u94fe\u8868\uff0c\u83b7\u53d6\u8bcd\u6c47\u8868\u79cd\u7c7b\uff0c\u76f4\u63a5print\u51fa\u6765\uff0c\u592a\u591a\u4f1a\u5d29\u6e83<br \/>\nsorted(set(texti)) #\u83b7\u53d6\u6240\u6709\u7684\u9879\u76ee(\u5305\u62ec\u6807\u70b9)\uff0c\u6309\u7167\u5b57\u6bcd\u8868\u6392\u5e8f<br \/>\nsorted(texti) #\u83b7\u53d6\u6240\u6709\u7684\u5143\u7d20\uff0c\u5168\u90e8\u5c55\u73b0\uff0c\u5373\u4f7f\u91cd\u590d<br \/>\nlen(set(texti)) #\u5171\u6709\u591a\u5c11\u79cd<br \/>\nfrom __future__ import division #\u6d6e\u70b9\u9664\u6cd5<br \/>\nlen(text5)\/len(set(text5)) #\u5e73\u5747\u4e00\u4e2a\u9879\u76ee\u51e0\u6b21<br \/>\ntexti.count() #\u67d0\u8bcd\u6c47\u51fa\u73b0\u4e86\u51e0\u6b21<br \/>\n#\u4e0etext\u76f8\u540c\uff0csenti\u4e5f\u662f\u4e00\u4e2a\u5df2\u7ecf\u5b9a\u4e49\u597d\u7684\u53d8\u91cf<br \/>\nsent1.append()#\u94fe\u8868\u7684\u8ffd\u52a0<br \/>\n&#8221;.join([&#8216;a&#8217;,&#8217;b&#8217;])#\u94fe\u8868-&gt;\u5b57\u7b26\u4e32<br \/>\n$string.split()#\u5b57\u7b26\u4e32-&gt;\u94fe\u8868<\/p>\n<p>FreqDist(texti)#\u5404\u9879\u76ee\u9891\u7387\uff0c\u5b57\u5178\uff0c\u9879\u76ee-&gt;\u6b21\u6570<br \/>\nFreqDist(texti).keys()#\u8f6c\u4e3a\u4ece\u5927\u5230\u5c0f\u7684\u94fe\u8868,all show,keys&#8211;\u952e\u503c<br \/>\nFreqDist(texti)[]#\u67d0\u9879\u76ee\u51fa\u73b0\u7684\u6b21\u6570<br \/>\nFreqDist(texti).hapaxas()#\u5f69\u86cb\uff0c\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u9879\u76ee<\/p>\n<p>#\u957f\u8bcd<br \/>\nline32 = [i for i in set(text5) if len(i) &gt; 15]<br \/>\n#select * from text5 where len()&gt;15\uff0c\u884c\u5185\u904d\u5386\uff0c\u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5f00\u5934\u662fu<br \/>\nsorted(line32)<br \/>\n#\u6570\u7ec4 \u94fe\u8868\uff0c\u6709\u6392\u5e8f\uff0c\u4f46\u662f\u4e3a\u4ec0\u4e48\u6bcf\u4e2a\u5143\u7d20\u5f00\u5934\u662fu\uff1f\u5b58\u7591<br \/>\nfd5 = FreqDisk(text5)<br \/>\nsorted([i for i in set(text5) if len(i) &gt; 7 and fd5[i] &gt; 7])<br \/>\n#\u6ce8\u610f\u8fd9\u91cc\u7684len()\u548cfd5[]\uff0c\u8fd9\u662f\u4e24\u4e2a\u5c5e\u6027\u503c\uff0c\u4f46\u8868\u793a\u65b9\u6cd5\u5374\u6709\u6240\u4e0d\u540c\uff0c\u5f88\u6709\u8da3<\/p>\n<p>#\u642d\u914d<br \/>\nbigrams([&#8221;, &#8221;])#\u8fde\u8bcd \u6ca1\u5565\u7528<br \/>\ntexti.collocations(texti)#\u56fa\u5b9a\u642d\u914d\uff0c\u600e\u4e48\u5b9e\u73b0\u5f85\u5b66<\/p>\n<p>&nbsp;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>nltk\u901f\u6210 import nltk nltk.download() from nltk.book import * #import text 1-9 text1.concordance() #\u67e5\u627e testi.similar() #\u53ef\u66ff\u4ee3\u7684\u8bcd testi.common_contexts() #\u76f8\u540c\u7684\u524d\u540e\u6587 texti.dispersio\u2026\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-3"],"_links":{"self":[{"href":"https:\/\/blog.defjia.top\/index.php?rest_route=\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.defjia.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.defjia.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.defjia.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.defjia.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=141"}],"version-history":[{"count":0,"href":"https:\/\/blog.defjia.top\/index.php?rest_route=\/wp\/v2\/posts\/141\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.defjia.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.defjia.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.defjia.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}