{"id":975989,"date":"2024-12-27T06:17:52","date_gmt":"2024-12-26T22:17:52","guid":{"rendered":""},"modified":"2024-12-27T06:17:55","modified_gmt":"2024-12-26T22:17:55","slug":"python%e5%a6%82%e4%bd%95%e8%be%93%e5%87%bajieba%e7%bb%93%e6%9e%9c","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/975989.html","title":{"rendered":"python\u5982\u4f55\u8f93\u51fajieba\u7ed3\u679c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24200944\/8ea541cc-35ce-406b-9b79-022eb8c74a46.webp\" alt=\"python\u5982\u4f55\u8f93\u51fajieba\u7ed3\u679c\" \/><\/p>\n<p><p> \u4e00\u3001PYTHON\u5982\u4f55\u8f93\u51faJIEBA\u7ed3\u679c<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528jieba\u5e93\u8fdb\u884c\u4e2d\u6587\u5206\u8bcd\u3001\u6253\u5370\u5206\u8bcd\u7ed3\u679c\u3001\u4fdd\u5b58\u5206\u8bcd\u7ed3\u679c\u5230\u6587\u4ef6\u4e2d<\/strong>\u3002\u5728\u4f7f\u7528jieba\u5e93\u8fdb\u884c\u4e2d\u6587\u5206\u8bcd\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u8f93\u51fa\u7ed3\u679c\uff0c\u5305\u62ec\u76f4\u63a5\u5728\u63a7\u5236\u53f0\u6253\u5370\u3001\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\u8fdb\u884c\u8fdb\u4e00\u6b65\u5904\u7406\uff0c\u6216\u8005\u5c06\u7ed3\u679c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\u4ee5\u4fbf\u540e\u7eed\u4f7f\u7528\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3jieba\u5e93\u7684\u4f7f\u7528\uff0c\u9996\u5148\u6211\u4eec\u9700\u8981\u5b89\u88c5jieba\u5e93\u5e76\u5bfc\u5165\u5230\u6211\u4eec\u7684Python\u811a\u672c\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install jieba<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165jieba\u5e93\u5e76\u8fdb\u884c\u5206\u8bcd\u64cd\u4f5c\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u9010\u6b65\u4ecb\u7ecd\u5982\u4f55\u5b9e\u73b0\u8f93\u51fajieba\u7ed3\u679c\u7684\u4e0d\u540c\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001JIEBA\u5e93\u7b80\u4ecb\u4e0e\u57fa\u672c\u7528\u6cd5<\/p>\n<\/p>\n<p><p>jieba\u662f\u4e00\u4e2a\u57fa\u4e8ePython\u7684\u4e2d\u6587\u5206\u8bcd\u5e93\uff0c\u5177\u6709\u7b80\u5355\u6613\u7528\u3001\u9ad8\u6548\u7684\u7279\u70b9\u3002\u5b83\u652f\u6301\u4e09\u79cd\u5206\u8bcd\u6a21\u5f0f\uff1a\u7cbe\u786e\u6a21\u5f0f\u3001\u5168\u6a21\u5f0f\u548c\u641c\u7d22\u5f15\u64ce\u6a21\u5f0f\u3002\u7cbe\u786e\u6a21\u5f0f\u662f\u6700\u5e38\u7528\u7684\u6a21\u5f0f\uff0c\u80fd\u591f\u51c6\u786e\u5730\u5c06\u6587\u672c\u5207\u5206\u6210\u4e00\u4e2a\u4e2a\u8bcd\u8bed\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u57fa\u672c\u7528\u6cd5<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u4f7f\u7528jieba\u8fdb\u884c\u5206\u8bcd\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u9009\u62e9\u7cbe\u786e\u6a21\u5f0f\uff0c\u56e0\u4e3a\u5b83\u80fd\u591f\u63d0\u4f9b\u6bd4\u8f83\u51c6\u786e\u7684\u5206\u8bcd\u7ed3\u679c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528jieba\u8fdb\u884c\u5206\u8bcd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import jieba<\/p>\n<p>text = &quot;\u6211\u7231\u5317\u4eac\u5929\u5b89\u95e8&quot;<\/p>\n<p>words = jieba.cut(text, cut_all=False)<\/p>\n<p>print(&quot;\/&quot;.join(words))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86jieba\u5e93\uff0c\u7136\u540e\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5f85\u5206\u8bcd\u7684\u6587\u672c\u5b57\u7b26\u4e32<code>text<\/code>\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8c03\u7528<code>jieba.cut()<\/code>\u65b9\u6cd5\u5bf9\u6587\u672c\u8fdb\u884c\u5206\u8bcd\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u53d8\u91cf<code>words<\/code>\u4e2d\u3002\u6700\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>join()<\/code>\u65b9\u6cd5\u5c06\u5206\u8bcd\u7ed3\u679c\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5e76\u8f93\u51fa\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4e0d\u540c\u5206\u8bcd\u6a21\u5f0f<\/strong><\/li>\n<\/ol>\n<p><p>jieba\u63d0\u4f9b\u4e86\u4e09\u79cd\u5206\u8bcd\u6a21\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u6a21\u5f0f\uff1a<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u7cbe\u786e\u6a21\u5f0f<\/strong>\uff1a\u8be5\u6a21\u5f0f\u4e0b\uff0cjieba\u4f1a\u5c3d\u53ef\u80fd\u7cbe\u786e\u5730\u5207\u5206\u6587\u672c\uff0c\u4e0d\u4f1a\u591a\u5207\u5206\u51fa\u4e0d\u5fc5\u8981\u7684\u8bcd\u8bed\u3002\u8fd9\u79cd\u6a21\u5f0f\u9002\u5408\u5927\u591a\u6570\u6587\u672c\u5904\u7406\u573a\u666f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5168\u6a21\u5f0f<\/strong>\uff1a\u8be5\u6a21\u5f0f\u4e0b\uff0cjieba\u4f1a\u5c06\u6587\u672c\u4e2d\u6240\u6709\u53ef\u80fd\u7684\u8bcd\u8bed\u5207\u5206\u51fa\u6765\u3002\u8fd9\u79cd\u6a21\u5f0f\u4e0b\u7684\u5206\u8bcd\u7ed3\u679c\u53ef\u80fd\u4f1a\u5305\u542b\u5f88\u591a\u5197\u4f59\u7684\u8bcd\u8bed\uff0c\u56e0\u6b64\u9002\u5408\u7528\u4e8e\u4e00\u4e9b\u7279\u6b8a\u7684\u573a\u666f\uff0c\u5982\u9700\u8981\u5bf9\u6587\u672c\u8fdb\u884c\u5168\u8986\u76d6\u7684\u8bcd\u8bed\u7edf\u8ba1\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u641c\u7d22\u5f15\u64ce\u6a21\u5f0f<\/strong>\uff1a\u8be5\u6a21\u5f0f\u662f\u5728\u7cbe\u786e\u6a21\u5f0f\u7684\u57fa\u7840\u4e0a\uff0c\u5bf9\u957f\u8bcd\u518d\u6b21\u8fdb\u884c\u5207\u5206\uff0c\u63d0\u9ad8\u53ec\u56de\u7387\uff0c\u9002\u5408\u7528\u4e8e\u641c\u7d22\u5f15\u64ce\u7684\u5206\u8bcd\u9700\u6c42\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u4f7f\u7528\u4e0d\u540c\u6a21\u5f0f\u8fdb\u884c\u5206\u8bcd\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5728<code>jieba.cut()<\/code>\u65b9\u6cd5\u4e2d\u8bbe\u7f6e<code>cut_all<\/code>\u53c2\u6570\u6765\u8fdb\u884c\u9009\u62e9\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5168\u6a21\u5f0f<\/p>\n<p>words_all = jieba.cut(text, cut_all=True)<\/p>\n<p>print(&quot;\u5168\u6a21\u5f0f:&quot;, &quot;\/&quot;.join(words_all))<\/p>\n<h2><strong>\u641c\u7d22\u5f15\u64ce\u6a21\u5f0f<\/strong><\/h2>\n<p>words_search = jieba.cut_for_search(text)<\/p>\n<p>print(&quot;\u641c\u7d22\u5f15\u64ce\u6a21\u5f0f:&quot;, &quot;\/&quot;.join(words_search))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u6253\u5370JIEBA\u5206\u8bcd\u7ed3\u679c<\/p>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u5206\u8bcd\u64cd\u4f5c\u540e\uff0c\u6211\u4eec\u901a\u5e38\u9700\u8981\u5c06\u5206\u8bcd\u7ed3\u679c\u8f93\u51fa\u5230\u63a7\u5236\u53f0\u6216\u8005\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\u4ee5\u4fbf\u540e\u7eed\u5904\u7406\u3002\u4e0b\u9762\u4ecb\u7ecd\u5982\u4f55\u5c06jieba\u5206\u8bcd\u7ed3\u679c\u6253\u5370\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u6253\u5370\u5206\u8bcd\u7ed3\u679c<\/strong><\/li>\n<\/ol>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684\u5185\u7f6e<code>print()<\/code>\u51fd\u6570\u6765\u8f93\u51fa\u5206\u8bcd\u7ed3\u679c\u3002\u4e3a\u4e86\u4fbf\u4e8e\u9605\u8bfb\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u5c06\u5206\u8bcd\u7ed3\u679c\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5e76\u5728\u8bcd\u8bed\u4e4b\u95f4\u63d2\u5165\u5206\u9694\u7b26\uff08\u4f8b\u5982\u659c\u6760\u201c\/\u201d\uff09\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import jieba<\/p>\n<p>text = &quot;\u6211\u7231\u5317\u4eac\u5929\u5b89\u95e8&quot;<\/p>\n<p>words = jieba.cut(text, cut_all=False)<\/p>\n<p>print(&quot;\u5206\u8bcd\u7ed3\u679c:&quot;, &quot;\/&quot;.join(words))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528jieba\u8fdb\u884c\u5206\u8bcd\uff0c\u7136\u540e\u5c06\u5206\u8bcd\u7ed3\u679c\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u6700\u540e\u4f7f\u7528<code>print()<\/code>\u51fd\u6570\u8f93\u51fa\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u7ed3\u5408\u5176\u4ed6\u5b57\u7b26\u4e32\u64cd\u4f5c<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5bf9\u5206\u8bcd\u7ed3\u679c\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\uff0c\u4f8b\u5982\u7edf\u8ba1\u8bcd\u9891\u3001\u53bb\u9664\u505c\u7528\u8bcd\u7b49\u3002\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u4ee5\u5728\u5c06\u5206\u8bcd\u7ed3\u679c\u8fde\u63a5\u6210\u5b57\u7b26\u4e32\u4e4b\u524d\u8fdb\u884c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import jieba<\/p>\n<p>from collections import Counter<\/p>\n<p>text = &quot;\u6211\u7231\u5317\u4eac\u5929\u5b89\u95e8&quot;<\/p>\n<p>words = jieba.cut(text, cut_all=False)<\/p>\n<p>word_list = list(words)<\/p>\n<h2><strong>\u7edf\u8ba1\u8bcd\u9891<\/strong><\/h2>\n<p>word_freq = Counter(word_list)<\/p>\n<p>print(&quot;\u8bcd\u9891\u7edf\u8ba1:&quot;, word_freq)<\/p>\n<h2><strong>\u53bb\u9664\u505c\u7528\u8bcd<\/strong><\/h2>\n<p>stopwords = {&quot;\u6211&quot;, &quot;\u5317\u4eac&quot;}<\/p>\n<p>filtered_words = [word for word in word_list if word not in stopwords]<\/p>\n<p>print(&quot;\u53bb\u9664\u505c\u7528\u8bcd\u540e:&quot;, &quot;\/&quot;.join(filtered_words))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528<code>Counter<\/code>\u7c7b\u5bf9\u5206\u8bcd\u7ed3\u679c\u8fdb\u884c\u8bcd\u9891\u7edf\u8ba1\uff0c\u7136\u540e\u901a\u8fc7\u5217\u8868\u63a8\u5bfc\u5f0f\u53bb\u9664\u505c\u7528\u8bcd\uff0c\u6700\u540e\u5c06\u5904\u7406\u540e\u7684\u7ed3\u679c\u8f93\u51fa\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4fdd\u5b58JIEBA\u5206\u8bcd\u7ed3\u679c\u5230\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06\u5206\u8bcd\u7ed3\u679c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u7684\u5206\u6790\u548c\u5904\u7406\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684\u6587\u4ef6\u64cd\u4f5c\u529f\u80fd\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4fdd\u5b58\u5206\u8bcd\u7ed3\u679c\u5230\u6587\u672c\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>open()<\/code>\u51fd\u6570\u6253\u5f00\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u7136\u540e\u5c06\u5206\u8bcd\u7ed3\u679c\u5199\u5165\u6587\u4ef6\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import jieba<\/p>\n<p>text = &quot;\u6211\u7231\u5317\u4eac\u5929\u5b89\u95e8&quot;<\/p>\n<p>words = jieba.cut(text, cut_all=False)<\/p>\n<p>word_list = list(words)<\/p>\n<p>with open(&quot;jieba_result.txt&quot;, &quot;w&quot;, encoding=&quot;utf-8&quot;) as f:<\/p>\n<p>    f.write(&quot;\/&quot;.join(word_list))<\/p>\n<p>print(&quot;\u5206\u8bcd\u7ed3\u679c\u5df2\u4fdd\u5b58\u5230jieba_result.txt\u6587\u4ef6\u4e2d&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>open()<\/code>\u51fd\u6570\u4ee5\u5199\u6a21\u5f0f\u6253\u5f00\u4e00\u4e2a\u540d\u4e3a<code>jieba_result.txt<\/code>\u7684\u6587\u4ef6\uff0c\u7136\u540e\u5c06\u5206\u8bcd\u7ed3\u679c\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5e76\u5199\u5165\u6587\u4ef6\u4e2d\u3002\u6700\u540e\uff0c\u6211\u4eec\u5173\u95ed\u6587\u4ef6\u5e76\u8f93\u51fa\u63d0\u793a\u4fe1\u606f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4fdd\u5b58\u5206\u8bcd\u7ed3\u679c\u5230CSV\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u67d0\u4e9b\u573a\u666f\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06\u5206\u8bcd\u7ed3\u679c\u4fdd\u5b58\u5230CSV\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4fbf\u4f7f\u7528\u7535\u5b50\u8868\u683c\u8f6f\u4ef6\u8fdb\u884c\u67e5\u770b\u548c\u5206\u6790\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>csv<\/code>\u6a21\u5757\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import jieba<\/p>\n<p>import csv<\/p>\n<p>text = &quot;\u6211\u7231\u5317\u4eac\u5929\u5b89\u95e8&quot;<\/p>\n<p>words = jieba.cut(text, cut_all=False)<\/p>\n<p>word_list = list(words)<\/p>\n<p>with open(&quot;jieba_result.csv&quot;, &quot;w&quot;, newline=&quot;&quot;, encoding=&quot;utf-8&quot;) as csvfile:<\/p>\n<p>    writer = csv.writer(csvfile)<\/p>\n<p>    writer.writerow([&quot;Word&quot;])<\/p>\n<p>    for word in word_list:<\/p>\n<p>        writer.writerow([word])<\/p>\n<p>print(&quot;\u5206\u8bcd\u7ed3\u679c\u5df2\u4fdd\u5b58\u5230jieba_result.csv\u6587\u4ef6\u4e2d&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>csv<\/code>\u6a21\u5757\u521b\u5efa\u4e00\u4e2aCSV\u6587\u4ef6\uff0c\u5e76\u5c06\u5206\u8bcd\u7ed3\u679c\u9010\u884c\u5199\u5165\u6587\u4ef6\u4e2d\u3002\u6bcf\u4e2a\u8bcd\u8bed\u5360\u636e\u4e00\u884c\uff0c\u5e76\u4fdd\u5b58\u5728\u4e00\u4e2a\u540d\u4e3a<code>jieba_result.csv<\/code>\u7684\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001JIEBA\u5206\u8bcd\u7ed3\u679c\u7684\u5e94\u7528\u573a\u666f<\/p>\n<\/p>\n<p><p>jieba\u5206\u8bcd\u7ed3\u679c\u53ef\u4ee5\u5e94\u7528\u4e8e\u591a\u4e2a\u9886\u57df\u548c\u573a\u666f\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u6587\u672c\u5206\u7c7b\u548c\u60c5\u611f\u5206\u6790<\/strong><\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u5bf9\u6587\u672c\u8fdb\u884c\u5206\u8bcd\uff0c\u6211\u4eec\u53ef\u4ee5\u63d0\u53d6\u6587\u672c\u4e2d\u7684\u5173\u952e\u8bcd\u548c\u7279\u5f81\u8bcd\uff0c\u4ece\u800c\u7528\u4e8e\u6587\u672c\u5206\u7c7b\u548c\u60c5\u611f\u5206\u6790\u3002\u5206\u8bcd\u7ed3\u679c\u53ef\u4ee5\u4f5c\u4e3a\u7279\u5f81\u5411\u91cf\u8f93\u5165\u5230<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u6a21\u578b\u4e2d\uff0c\u4ee5\u8fdb\u884c\u6587\u672c\u5206\u7c7b\u548c\u60c5\u611f\u5206\u6790\u4efb\u52a1\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u641c\u7d22\u5f15\u64ce\u548c\u4fe1\u606f\u68c0\u7d22<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u641c\u7d22\u5f15\u64ce\u548c\u4fe1\u606f\u68c0\u7d22\u7cfb\u7edf\u4e2d\uff0c\u5206\u8bcd\u662f\u4e00\u4e2a\u5173\u952e\u6b65\u9aa4\u3002\u901a\u8fc7\u5bf9\u7528\u6237\u8f93\u5165\u7684\u67e5\u8be2\u8bed\u53e5\u8fdb\u884c\u5206\u8bcd\uff0c\u53ef\u4ee5\u63d0\u9ad8\u68c0\u7d22\u7684\u51c6\u786e\u6027\u548c\u6548\u7387\u3002\u641c\u7d22\u5f15\u64ce\u53ef\u4ee5\u6839\u636e\u5206\u8bcd\u7ed3\u679c\u5bf9\u6587\u6863\u8fdb\u884c\u7d22\u5f15\u548c\u6392\u540d\uff0c\u4ece\u800c\u63d0\u9ad8\u641c\u7d22\u7ed3\u679c\u7684\u76f8\u5173\u6027\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u81ea\u7136\u8bed\u8a00\u5904\u7406\u548c\u673a\u5668\u7ffb\u8bd1<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u81ea\u7136\u8bed\u8a00\u5904\u7406\u548c\u673a\u5668\u7ffb\u8bd1\u4efb\u52a1\u4e2d\uff0c\u5206\u8bcd\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u9884\u5904\u7406\u6b65\u9aa4\u3002\u5206\u8bcd\u7ed3\u679c\u53ef\u4ee5\u7528\u4e8e\u6784\u5efa\u8bed\u8a00\u6a21\u578b\u3001\u751f\u6210\u8bcd\u5411\u91cf\u4ee5\u53ca\u8fdb\u884c\u53e5\u6cd5\u5206\u6790\u548c\u8bed\u4e49\u5206\u6790\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u793e\u4ea4\u5a92\u4f53\u548c\u8206\u60c5\u5206\u6790<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u793e\u4ea4\u5a92\u4f53\u548c\u8206\u60c5\u5206\u6790\u4e2d\uff0c\u5206\u8bcd\u53ef\u4ee5\u7528\u4e8e\u63d0\u53d6\u7528\u6237\u8bc4\u8bba\u548c\u5e16\u5b50\u4e2d\u7684\u5173\u952e\u8bcd\u548c\u70ed\u70b9\u8bdd\u9898\uff0c\u4ece\u800c\u5e2e\u52a9\u4f01\u4e1a\u548c\u7ec4\u7ec7\u4e86\u89e3\u516c\u4f17\u7684\u89c2\u70b9\u548c\u6001\u5ea6\u3002\u901a\u8fc7\u5bf9\u5206\u8bcd\u7ed3\u679c\u8fdb\u884c\u805a\u7c7b\u548c\u60c5\u611f\u5206\u6790\uff0c\u53ef\u4ee5\u8bc6\u522b\u51fa\u8206\u60c5\u7684\u53d8\u5316\u8d8b\u52bf\u548c\u6f5c\u5728\u98ce\u9669\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001JIEBA\u5206\u8bcd\u7684\u4f18\u5316\u4e0e\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528jieba\u8fdb\u884c\u5206\u8bcd\u65f6\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5bf9\u5206\u8bcd\u7ed3\u679c\u8fdb\u884c\u4f18\u5316\uff0c\u4ee5\u63d0\u9ad8\u5206\u8bcd\u7684\u51c6\u786e\u6027\u548c\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f18\u5316\u7b56\u7565\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u81ea\u5b9a\u4e49\u8bcd\u5178<\/strong><\/li>\n<\/ol>\n<p><p>jieba\u652f\u6301\u52a0\u8f7d\u81ea\u5b9a\u4e49\u8bcd\u5178\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u7279\u5b9a\u9886\u57df\u7684\u4e13\u6709\u540d\u8bcd\u3001\u77ed\u8bed\u548c\u65b0\u8bcd\u6dfb\u52a0\u5230\u81ea\u5b9a\u4e49\u8bcd\u5178\u4e2d\uff0c\u4ee5\u63d0\u9ad8\u5206\u8bcd\u7684\u51c6\u786e\u6027\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u52a0\u8f7d\u81ea\u5b9a\u4e49\u8bcd\u5178\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">jieba.load_userdict(&quot;user_dict.txt&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728<code>user_dict.txt<\/code>\u6587\u4ef6\u4e2d\uff0c\u6bcf\u884c\u5305\u542b\u4e00\u4e2a\u8bcd\u8bed\u548c\u8bcd\u9891\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code>\u673a\u5668\u5b66\u4e60 1000<\/p>\n<p>\u6df1\u5ea6\u5b66\u4e60 800<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u8c03\u6574\u8bcd\u9891<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u8c03\u6574\u67d0\u4e9b\u8bcd\u8bed\u7684\u8bcd\u9891\uff0c\u4ee5\u6539\u53d8\u5206\u8bcd\u7ed3\u679c\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>jieba.suggest_freq()<\/code>\u65b9\u6cd5\u6765\u5efa\u8bae\u8bcd\u9891\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">jieba.suggest_freq((&#39;\u5317\u4eac&#39;, &#39;\u5929\u5b89\u95e8&#39;), True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u544a\u8bc9jieba\u5c06\u201c\u5317\u4eac\u5929\u5b89\u95e8\u201d\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u8bcd\u8bed\u8fdb\u884c\u5206\u8bcd\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u505c\u7528\u8bcd\u5904\u7406<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u5206\u8bcd\u7ed3\u679c\u4e2d\uff0c\u505c\u7528\u8bcd\uff08\u5982\u201c\u7684\u201d\u3001\u201c\u4e86\u201d\u7b49\uff09\u901a\u5e38\u4e0d\u5177\u6709\u5b9e\u9645\u610f\u4e49\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u53bb\u9664\u505c\u7528\u8bcd\u6765\u7b80\u5316\u5206\u8bcd\u7ed3\u679c\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u505c\u7528\u8bcd\u5217\u8868\u6765\u8fc7\u6ee4\u5206\u8bcd\u7ed3\u679c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">stopwords = {&quot;\u7684&quot;, &quot;\u4e86&quot;}<\/p>\n<p>filtered_words = [word for word in word_list if word not in stopwords]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u7b56\u7565\uff0c\u6211\u4eec\u53ef\u4ee5\u4f18\u5316jieba\u7684\u5206\u8bcd\u7ed3\u679c\uff0c\u63d0\u9ad8\u5206\u8bcd\u7684\u51c6\u786e\u6027\u548c\u6548\u7387\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u4f18\u5316\u7b56\u7565\uff0c\u4ee5\u83b7\u5f97\u6700\u4f73\u7684\u5206\u8bcd\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528jieba\u8fdb\u884c\u4e2d\u6587\u5206\u8bcd\uff1f<\/strong><br \/>jieba\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u4e2d\u6587\u5206\u8bcd\u5e93\uff0c\u4f7f\u7528\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88c5jieba\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<code>pip install jieba<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u52a0\u8f7djieba\u5e76\u8fdb\u884c\u5206\u8bcd\uff1a  <\/p>\n<pre><code class=\"language-python\">import jieba\n\ntext = &quot;\u6211\u7231\u5b66\u4e60Python\u7f16\u7a0b&quot;\nwords = jieba.cut(text)\nprint(&quot;\/ &quot;.join(words))\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u60a8\u5c31\u53ef\u4ee5\u770b\u5230\u5206\u8bcd\u540e\u7684\u7ed3\u679c\u3002<\/p>\n<p><strong>jieba\u7684\u5206\u8bcd\u6548\u679c\u5982\u4f55\u8bc4\u4f30\uff1f<\/strong><br \/>\u5206\u8bcd\u6548\u679c\u7684\u597d\u574f\u901a\u5e38\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u6587\u672c\u548c\u5e94\u7528\u573a\u666f\u3002\u4e3a\u4e86\u8bc4\u4f30jieba\u7684\u5206\u8bcd\u6548\u679c\uff0c\u53ef\u4ee5\u5bf9\u6bd4jieba\u7684\u8f93\u51fa\u4e0e\u4eba\u5de5\u6807\u6ce8\u7684\u5206\u8bcd\u7ed3\u679c\u3002\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528jieba\u7684\u81ea\u5b9a\u4e49\u8bcd\u5178\u529f\u80fd\u6765\u63d0\u5347\u5206\u8bcd\u7684\u51c6\u786e\u6027\uff0c\u65b9\u6cd5\u662f\u901a\u8fc7<code>jieba.load_userdict(&#39;your_dict.txt&#39;)<\/code>\u52a0\u8f7d\u81ea\u5b9a\u4e49\u8bcd\u5178\u6587\u4ef6\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528jieba\u5206\u8bcd\u65f6\uff0c\u6709\u54ea\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u9700\u8981\u6ce8\u610f\uff1f<\/strong><br \/>\u5e38\u89c1\u7684\u9519\u8bef\u5305\u62ec\u6ca1\u6709\u6b63\u786e\u5b89\u88c5jieba\u5e93\u3001\u672a\u6b63\u786e\u52a0\u8f7d\u81ea\u5b9a\u4e49\u8bcd\u5178\u3001\u4ee5\u53ca\u5bf9\u590d\u6742\u53e5\u5b50\u7684\u5206\u8bcd\u7406\u89e3\u4e0d\u591f\u3002\u786e\u4fdd\u6587\u672c\u8f93\u5165\u683c\u5f0f\u6b63\u786e\uff0c\u907f\u514d\u4f7f\u7528\u7279\u6b8a\u5b57\u7b26\u6216\u7b26\u53f7\uff0c\u8fd9\u53ef\u4ee5\u5e2e\u52a9\u63d0\u9ad8\u5206\u8bcd\u7684\u51c6\u786e\u6027\u3002\u6b64\u5916\uff0c\u4e86\u89e3jieba\u7684\u5206\u8bcd\u6a21\u5f0f\uff08\u5982\u7cbe\u786e\u6a21\u5f0f\u3001\u5168\u6a21\u5f0f\u548c\u641c\u7d22\u5f15\u64ce\u6a21\u5f0f\uff09\u4e5f\u80fd\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u9009\u62e9\u9002\u5408\u7684\u5206\u8bcd\u65b9\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001PYTHON\u5982\u4f55\u8f93\u51faJIEBA\u7ed3\u679c \u4f7f\u7528jieba\u5e93\u8fdb\u884c\u4e2d\u6587\u5206\u8bcd\u3001\u6253\u5370\u5206\u8bcd\u7ed3\u679c\u3001\u4fdd\u5b58\u5206\u8bcd\u7ed3\u679c\u5230\u6587\u4ef6\u4e2d\u3002\u5728\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":976000,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/975989"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=975989"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/975989\/revisions"}],"predecessor-version":[{"id":976003,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/975989\/revisions\/976003"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/976000"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=975989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=975989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=975989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}