{"id":185,"date":"2022-09-06T15:04:02","date_gmt":"2022-09-06T07:04:02","guid":{"rendered":"http:\/\/www.hufe.org.cn\/?p=185"},"modified":"2022-09-06T15:24:14","modified_gmt":"2022-09-06T07:24:14","slug":"python%e4%b8%ad%e6%96%87%e5%88%86%e8%af%8d%e5%b7%a5%e5%85%b7%e6%b1%87%e6%80%bb","status":"publish","type":"post","link":"https:\/\/www.hufe.org.cn\/?p=185","title":{"rendered":"python\u4e2d\u6587\u5206\u8bcd\u5de5\u5177\u6c47\u603b"},"content":{"rendered":"\n<p>\u5927\u5bb6\u597d\uff0c\u6b22\u8fce\u6765\u5230 Crossin\u7684\u7f16\u7a0b\u6559\u5ba4 \uff01<\/p>\n\n\n\n<p>\u5206\u8bcd\u662f\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4e2d\u975e\u5e38\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\uff0c\u6bd4\u5982\u4ece\u4e00\u7bc7\u6587\u7ae0\u4e2d\u81ea\u52a8\u63d0\u53d6\u5173\u952e\u8bcd\u5c31\u9700\u8981\u7528\u5230\u5206\u8bcd\u5de5\u5177\uff0c\u4e2d\u6587\u641c\u7d22\u9886\u57df\u540c\u6837\u79bb\u4e0d\u5f00\u5206\u8bcd\u3002python\u4e2d\uff0c\u6709\u5f88\u591a\u5f00\u6e90\u7684\u5206\u8bcd\u5de5\u5177\u3002\u4eca\u5929\u5c31\u6765\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4ee5\u4e0b\u6bd4\u8f83\u5e38\u7528\u7684\u51e0\u6b3e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. jieba \u5206\u8bcd<\/h3>\n\n\n\n<p>\u201c\u7ed3\u5df4\u201d\u5206\u8bcd\uff0cGitHub\u6700\u53d7\u6b22\u8fce\u7684\u5206\u8bcd\u5de5\u5177\uff0c\u7acb\u5fd7\u505a\u6700\u597d\u7684 Python \u4e2d\u6587\u5206\u8bcd\u7ec4\u4ef6\uff0c\u652f\u6301\u591a\u79cd\u5206\u8bcd\u6a21\u5f0f\uff0c\u652f\u6301\u81ea\u5b9a\u4e49\u8bcd\u5178\u3002<\/p>\n\n\n\n<p>github star\uff1a26k<\/p>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import&nbsp;jieba<br><br>strs=&#91;\"\u6211\u6765\u5230\u5317\u4eac\u6e05\u534e\u5927\u5b66\",\"\u4e52\u4e53\u7403\u62cd\u5356\u5b8c\u4e86\",\"\u4e2d\u56fd\u79d1\u5b66\u6280\u672f\u5927\u5b66\"]<br><br>for&nbsp;str&nbsp;in&nbsp;strs:<br>&nbsp;&nbsp;&nbsp;&nbsp;seg_list&nbsp;=&nbsp;jieba.cut(str,use_paddle=True)&nbsp;<em>#&nbsp;\u4f7f\u7528paddle\u6a21\u5f0f<\/em><br>&nbsp;&nbsp;&nbsp;&nbsp;print(\"Paddle&nbsp;Mode:&nbsp;\"&nbsp;+&nbsp;'\/'.join(list(seg_list)))<br><br>seg_list&nbsp;=&nbsp;jieba.cut(\"\u6211\u6765\u5230\u5317\u4eac\u6e05\u534e\u5927\u5b66\",&nbsp;cut_all=True)<br>print(\"\u5168\u6a21\u5f0f:&nbsp;\"&nbsp;+&nbsp;\"\/&nbsp;\".join(seg_list))&nbsp;&nbsp;<em>#&nbsp;\u5168\u6a21\u5f0f<\/em><br><br>seg_list&nbsp;=&nbsp;jieba.cut(\"\u6211\u6765\u5230\u5317\u4eac\u6e05\u534e\u5927\u5b66\",&nbsp;cut_all=False)<br>print(\"\u7cbe\u786e\u6a21\u5f0f:&nbsp;\"&nbsp;+&nbsp;\"\/&nbsp;\".join(seg_list))&nbsp;&nbsp;<em>#&nbsp;\u7cbe\u786e\u6a21\u5f0f<\/em><br><br>seg_list&nbsp;=&nbsp;jieba.cut(\"\u4ed6\u6765\u5230\u4e86\u7f51\u6613\u676d\u7814\u5927\u53a6\")&nbsp;&nbsp;<em>#&nbsp;\u9ed8\u8ba4\u662f\u7cbe\u786e\u6a21\u5f0f<\/em><br>print(\"\u65b0\u8bcd\u8bc6\u522b\uff1a\",&nbsp;\",\".join(seg_list))<br><br>seg_list&nbsp;=&nbsp;jieba.cut_for_search(\"\u5c0f\u660e\u7855\u58eb\u6bd5\u4e1a\u4e8e\u4e2d\u56fd\u79d1\u5b66\u9662\u8ba1\u7b97\u6240\uff0c\u540e\u5728\u65e5\u672c\u4eac\u90fd\u5927\u5b66\u6df1\u9020\")&nbsp;&nbsp;<em>#&nbsp;\u641c\u7d22\u5f15\u64ce\u6a21\u5f0f<\/em><br>print(\"\u641c\u7d22\u5f15\u64ce\u6a21\u5f0f:\",&nbsp;\".join(seg_list))<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u3010\u5168\u6a21\u5f0f\u3011:&nbsp;\u6211\/&nbsp;\u6765\u5230\/&nbsp;\u5317\u4eac\/&nbsp;\u6e05\u534e\/&nbsp;\u6e05\u534e\u5927\u5b66\/&nbsp;\u534e\u5927\/&nbsp;\u5927\u5b66<br><br>\u3010\u7cbe\u786e\u6a21\u5f0f\u3011:&nbsp;\u6211\/&nbsp;\u6765\u5230\/&nbsp;\u5317\u4eac\/&nbsp;\u6e05\u534e\u5927\u5b66<br><br>\u3010\u65b0\u8bcd\u8bc6\u522b\u3011\uff1a\u4ed6, \u6765\u5230, \u4e86, \u7f51\u6613, \u676d\u7814, \u5927\u53a6&nbsp;&nbsp;&nbsp;&nbsp;(\u6b64\u5904\uff0c\u201c\u676d\u7814\u201d\u5e76\u6ca1\u6709\u5728\u8bcd\u5178\u4e2d\uff0c\u4f46\u662f\u4e5f\u88abViterbi\u7b97\u6cd5\u8bc6\u522b\u51fa\u6765\u4e86)<br><br>\u3010\u641c\u7d22\u5f15\u64ce\u6a21\u5f0f\u3011\uff1a&nbsp;\u5c0f\u660e, \u7855\u58eb, \u6bd5\u4e1a, \u4e8e, \u4e2d\u56fd, \u79d1\u5b66, \u5b66\u9662, \u79d1\u5b66\u9662, \u4e2d\u56fd\u79d1\u5b66\u9662, \u8ba1\u7b97, \u8ba1\u7b97\u6240, \u540e, \u5728, \u65e5\u672c, \u4eac\u90fd, \u5927\u5b66, \u65e5\u672c\u4eac\u90fd\u5927\u5b66, \u6df1\u9020<\/code><\/pre>\n\n\n\n<p><br>github\u5730\u5740\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/fxsjy\/jieba\">https:\/\/github.com\/fxsjy\/jieba<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. pkuseg \u5206\u8bcd<\/h3>\n\n\n\n<p>pkuseg \u662f\u5317\u5927\u8bed\u8a00\u8ba1\u7b97\u4e0e\u673a\u5668\u5b66\u4e60\u7814\u7a76\u7ec4\u5f00\u6e90\u7684\u4e00\u6b3e\u5206\u8bcd\u5de5\u5177\uff0c\u5b83\u7684\u7279\u70b9\u662f\u652f\u6301\u591a\u9886\u57df\u5206\u8bcd\uff0c\u76ee\u524d\u652f\u6301\u65b0\u95fb\u9886\u57df\uff0c\u7f51\u7edc\u9886\u57df\uff0c\u533b\u836f\u9886\u57df\uff0c\u65c5\u6e38\u9886\u57df\uff0c\u4ee5\u53ca\u6df7\u5408\u9886\u57df\u7684\u5206\u8bcd\u9884\u8bad\u7ec3\u6a21\u578b\uff0c\u7528\u6237\u53ef\u4ee5\u81ea\u7531\u5730\u9009\u62e9\u4e0d\u540c\u7684\u6a21\u578b\u3002\u76f8\u6bd4\u901a\u7528\u5206\u8bcd\u5de5\u5177\uff0c\u5b83\u7684\u5206\u8bcd\u51c6\u786e\u7387\u66f4\u9ad8 \u3002<\/p>\n\n\n\n<p>github star\uff1a5.4k<\/p>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><br>import&nbsp;pkuseg<br><br>seg&nbsp;=&nbsp;pkuseg.pkuseg()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>#&nbsp;\u4ee5\u9ed8\u8ba4\u914d\u7f6e\u52a0\u8f7d\u6a21\u578b<\/em><br>text&nbsp;=&nbsp;seg.cut('python\u662f\u4e00\u95e8\u5f88\u68d2\u7684\u8bed\u8a00')&nbsp;&nbsp;<em>#&nbsp;\u8fdb\u884c\u5206\u8bcd<\/em><br>print(text)<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;'python',&nbsp;'\u662f',&nbsp;'\u4e00',&nbsp;'\u95e8',&nbsp;'\u5f88',&nbsp;'\u68d2',&nbsp;'\u7684',&nbsp;'\u8bed\u8a00']<\/code><\/pre>\n\n\n\n<p>github\u5730\u5740\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/lancopku\/pkuseg-python\">https:\/\/github.com\/lancopku\/pkuseg-python<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. FoolNLTK \u5206\u8bcd<\/h3>\n\n\n\n<p>\u57fa\u4e8eBiLSTM\u6a21\u578b\u8bad\u7ec3\u800c\u6210\uff0c\u636e\u8bf4\u53ef\u80fd\u662f\u6700\u51c6\u7684\u5f00\u6e90\u4e2d\u6587\u5206\u8bcd\uff0c\u540c\u6837\u652f\u6301\u7528\u6237\u81ea\u5b9a\u4e49\u8bcd\u5178\u3002<\/p>\n\n\n\n<p>GitHub &nbsp;star: 1.6k<\/p>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import&nbsp;fool<br><br>text&nbsp;=&nbsp;\"\u4e00\u4e2a\u50bb\u5b50\u5728\u5317\u4eac\"<br>print(fool.cut(text))<br><em>#&nbsp;&#91;'\u4e00\u4e2a',&nbsp;'\u50bb\u5b50',&nbsp;'\u5728',&nbsp;'\u5317\u4eac']<\/em><\/code><\/pre>\n\n\n\n<p>github\u5730\u5740\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/rockyzhengwu\/FoolNLTK\">https:\/\/github.com\/rockyzhengwu\/FoolNLTK<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. THULAC<\/h3>\n\n\n\n<p>THULAC\u7531\u6e05\u534e\u5927\u5b66\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4e0e\u793e\u4f1a\u4eba\u6587\u8ba1\u7b97\u5b9e\u9a8c\u5ba4\u7814\u5236\u63a8\u51fa\u7684\u4e00\u5957\u4e2d\u6587\u8bcd\u6cd5\u5206\u6790\u5de5\u5177\u5305\u3002\u5177\u6709\u8bcd\u6027\u6807\u6ce8\u529f\u80fd\uff0c\u80fd\u5206\u6790\u51fa\u67d0\u4e2a\u8bcd\u662f\u540d\u8bcd\u8fd8\u662f\u52a8\u8bcd\u6216\u8005\u5f62\u5bb9\u8bcd\u3002<\/p>\n\n\n\n<p>github star\uff1a1.5k<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp;\u4ee3\u7801\u793a\u4f8b1<br>&nbsp;&nbsp;\u4ee3\u7801\u793a\u4f8b1<br>&nbsp;import&nbsp;thulac&nbsp;&nbsp;<br><br>&nbsp;thu1&nbsp;=&nbsp;thulac.thulac()&nbsp;&nbsp;<em>#\u9ed8\u8ba4\u6a21\u5f0f<\/em><br>&nbsp;text&nbsp;=&nbsp;thu1.cut(\"\u6211\u7231\u5317\u4eac\u5929\u5b89\u95e8\",&nbsp;text=True)&nbsp;&nbsp;<em>#\u8fdb\u884c\u4e00\u53e5\u8bdd\u5206\u8bcd<\/em><br>&nbsp;print(text)&nbsp;<em>#&nbsp;\u6211_r&nbsp;\u7231_v&nbsp;\u5317\u4eac_ns&nbsp;\u5929\u5b89\u95e8_ns<\/em><br>&nbsp;\u4ee3\u7801\u793a\u4f8b2<br>&nbsp;thu1&nbsp;=&nbsp;thulac.thulac(seg_only=True)&nbsp;&nbsp;<em>#\u53ea\u8fdb\u884c\u5206\u8bcd\uff0c\u4e0d\u8fdb\u884c\u8bcd\u6027\u6807\u6ce8<\/em><br>&nbsp;thu1.cut_f(\"input.txt\",&nbsp;\"output.txt\")&nbsp;&nbsp;<em>#\u5bf9input.txt\u6587\u4ef6\u5185\u5bb9\u8fdb\u884c\u5206\u8bcd\uff0c\u8f93\u51fa\u5230output.txt<\/em><\/code><\/pre>\n\n\n\n<p>github\u5730\u5740\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/thunlp\/THULAC-Python\">https:\/\/github.com\/thunlp\/THULAC-Python<\/a><\/p>\n\n\n\n<p>\u76ee\u524d\u6211\u5728\u7528\u7684\u8fd8\u662f\u7ed3\u5df4\u5206\u8bcd\uff0c\u914d\u5408\u7528\u6237\u81ea\u5b9a\u4e49\u8bcd\u5178\uff0c\u89e3\u51b3\u5e38\u89c1\u7684\u7f51\u7edc\u8bcd\u8bed\uff0c\u57fa\u672c\u4e0a\u5c31\u80fd\u6ee1\u8db3\u6211\u5728\u9879\u76ee\u4e2d\u7684\u9700\u6c42\u3002<\/p>\n\n\n\n<p>\u4f60\u5728\u7528\u4ec0\u4e48\u5206\u8bcd\u5de5\u5177\uff1f\u6b22\u8fce\u7559\u8a00\u8ba8\u8bba\u3002<\/p>\n\n\n\n<p>\u611f\u8c22<strong>\u8f6c\u53d1<\/strong>\u548c<strong>\u70b9\u8d5e<\/strong>\u7684\u5404\u4f4d~<\/p>\n\n\n\n<p>\u4f5c\u8005\uff1a\u5218\u5fd7\u519b\u6765\u6e90\uff1aPython\u4e4b\u7985<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6b22\u8fce\u6765\u5230 Crossin\u7684\u7f16\u7a0b\u6559\u5ba4 \uff01 \u5206\u8bcd\u662f\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4e2d\u975e\u5e38\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\uff0c\u6bd4\u5982\u4ece\u4e00\u7bc7\u6587\u7ae0\u4e2d\u81ea\u52a8\u63d0&hellip;&nbsp;<a href=\"https:\/\/www.hufe.org.cn\/?p=185\" class=\"\" rel=\"bookmark\">\u9605\u8bfb\u66f4\u591a &raquo;<span class=\"screen-reader-text\">python\u4e2d\u6587\u5206\u8bcd\u5de5\u5177\u6c47\u603b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"[\"title\",\"meta\",\"thumbnail\",\"content\",\"tags\",\"comments\"]","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/185"}],"collection":[{"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=185"}],"version-history":[{"count":1,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/185\/revisions"}],"predecessor-version":[{"id":186,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/185\/revisions\/186"}],"wp:attachment":[{"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hufe.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}