{"id":9389,"date":"2025-06-05T20:57:11","date_gmt":"2025-06-05T12:57:11","guid":{"rendered":"\/?p=9389"},"modified":"2025-06-05T20:57:11","modified_gmt":"2025-06-05T12:57:11","slug":"%e7%9f%a5%e8%af%86%e5%9b%be%e8%b0%b1%e7%ae%80%e5%8d%95%e6%9e%84%e5%bb%ba","status":"publish","type":"post","link":"\/?p=9389","title":{"rendered":"\u77e5\u8bc6\u56fe\u8c31\u7b80\u5355\u6784\u5efa"},"content":{"rendered":"<pre><code class=\"language-python\">import openai             # \u7528\u4e8e\u4e0e LLM \u4ea4\u4e92\nimport json               # \u7528\u4e8e\u89e3\u6790 LLM \u7684\u54cd\u5e94\nimport networkx as nx     # \u7528\u4e8e\u521b\u5efa\u548c\u7ba1\u7406\u56fe\u6570\u636e\u7ed3\u6784\nimport ipycytoscape       # \u7528\u4e8e\u5728 notebook \u4e2d\u8fdb\u884c\u4ea4\u4e92\u5f0f\u56fe\u53ef\u89c6\u5316\nimport ipywidgets         # \u7528\u4e8e\u4ea4\u4e92\u5f0f\u5143\u7d20\nimport pandas as pd       # \u7528\u4e8e\u4ee5\u8868\u683c\u5f62\u5f0f\u5c55\u793a\u6570\u636e\nimport os                 # \u7528\u4e8e\u8bbf\u95ee\u73af\u5883\u53d8\u91cf\uff08\u5bf9 API \u5bc6\u94a5\u66f4\u5b89\u5168\uff09\nimport math               # \u7528\u4e8e\u57fa\u672c\u7684\u6570\u5b66\u8fd0\u7b97\nimport re                 # \u7528\u4e8e\u57fa\u672c\u7684\u6587\u672c\u6e05\u7406\uff08\u6b63\u5219\u8868\u8fbe\u5f0f\uff09\nimport warnings           # \u7528\u4e8e\u6291\u5236\u6f5c\u5728\u7684\u5f03\u7528\u8b66\u544a<\/code><\/pre>\n<pre><code class=\"language-python\">os.environ[&quot;OPENAI_API_KEY&quot;]=&#039;ollama&#039; # \u5bf9\u4e8e Ollama\uff0c\u53ef\u4ee5\u662f\u4efb\u4f55\u975e\u7a7a\u5b57\u7b26\u4e32\nos.environ[&quot;OPENAI_API_BASE&quot;]=&#039;http:\/\/175.27.143.201:11434\/v1&#039;<\/code><\/pre>\n<pre><code class=\"language-python\">api_key = os.getenv(&quot;OPENAI_API_KEY&quot;)\nbase_url = os.getenv(&quot;OPENAI_API_BASE&quot;) # \u5982\u679c\u672a\u8bbe\u7f6e\uff08\u4f8b\u5982\uff0c\u5bf9\u4e8e\u6807\u51c6 \n# --- \u5b9a\u4e49 LLM \u6a21\u578b ---\nllm_model_name = &quot;mistral-small:24b&quot;\n# --- \u5b9a\u4e49 LLM \u8c03\u7528\u53c2\u6570 ---\nllm_temperature = 0.0 # \u8f83\u4f4e\u7684\u6e29\u5ea6\u53ef\u83b7\u5f97\u66f4\u5177\u786e\u5b9a\u6027\u7684\u4e8b\u5b9e\u6027\u8f93\u51fa\u30020.0 \u6700\u9002\u5408\u63d0\u53d6\u4efb\u52a1\u3002\nllm_max_tokens = 4096 # LLM \u54cd\u5e94\u7684\u6700\u5927\u4ee4\u724c\u6570\uff08\u6839\u636e\u6a21\u578b\u9650\u5236\u8fdb\u884c\u8c03\u6574\uff09\n# \u5b9a\u4e49\u8f93\u5165\u6587\u672c\uff08\u539f\u6750\u6599\uff09\nunstructured_text = &quot;&quot;&quot;\n\u4ee5\u4e0b\u662f\u9002\u5408\u6784\u5efa\u300a\u7ea2\u697c\u68a6\u300b\u77e5\u8bc6\u56fe\u8c31\u7684\u4e07\u5b57\u5185\u7ed3\u6784\u5316\u603b\u7ed3\uff0c\u6db5\u76d6\u6838\u5fc3\u4eba\u7269\u3001\u5bb6\u65cf\u5173\u7cfb\u3001\u5173\u952e\u60c5\u8282\u53ca\u4e3b\u9898\u601d\u60f3\uff0c\u5f15\u7528\u591a\u7bc7\u8d44\u6599\u7efc\u5408\u6574\u7406\uff1a\n\n---\n\n### **\u4e00\u3001\u56db\u5927\u5bb6\u65cf\u80cc\u666f**\n1. **\u8d3e\u5bb6**  \n   - **\u5b81\u56fd\u5e9c**\uff1a\u8d3e\u6f14\u2192\u8d3e\u4ee3\u5316\u2192\u8d3e\u656c\uff08\u51fa\u5bb6\uff09\u2192\u8d3e\u73cd\uff08\u59bb\u5c24\u6c0f\uff09\u2192\u8d3e\u84c9\uff08\u59bb\u79e6\u53ef\u537f\uff09  \n   - **\u8363\u56fd\u5e9c**\uff1a\u8d3e\u6e90\u2192\u8d3e\u4ee3\u5584\uff08\u59bb\u8d3e\u6bcd\uff09\u2192\u8d3e\u8d66\uff08\u59bb\u90a2\u592b\u4eba\uff09\u3001\u8d3e\u653f\uff08\u59bb\u738b\u592b\u4eba\uff09\u3001\u8d3e\u654f\uff08\u5ac1\u6797\u5982\u6d77\uff09  \n     - **\u8d3e\u653f\u5b50\u5973**\uff1a\u8d3e\u73e0\uff08\u65e9\u901d\uff09\u3001\u8d3e\u5143\u6625\uff08\u8d35\u5983\uff09\u3001\u8d3e\u5b9d\u7389\u3001\u8d3e\u63a2\u6625\uff08\u5eb6\u51fa\uff09\u3001\u8d3e\u73af\uff08\u5eb6\u51fa\uff09  \n     - **\u8d3e\u8d66\u5b50\u5973**\uff1a\u8d3e\u740f\uff08\u59bb\u738b\u7199\u51e4\uff09\u3001\u8d3e\u8fce\u6625\uff08\u5eb6\u51fa\uff09  \n   - **\u6838\u5fc3\u4e8b\u4ef6**\uff1a\u5143\u6625\u7701\u4eb2\u5efa\u5927\u89c2\u56ed\u3001\u738b\u7199\u51e4\u534f\u7406\u5b81\u56fd\u5e9c\u3001\u8d3e\u5e9c\u88ab\u6284\u5bb6\n\n2. **\u738b\u5bb6**  \n   - \u738b\u592b\u4eba\uff08\u8d3e\u653f\u59bb\uff09\u3001\u859b\u59e8\u5988\uff08\u5ac1\u859b\u5bb6\uff09\u3001\u738b\u5b50\u817e\uff08\u5b98\u81f3\u4e5d\u7701\u90fd\u68c0\u70b9\uff09\n\n3. **\u53f2\u5bb6**  \n   - \u8d3e\u6bcd\uff08\u53f2\u592a\u541b\uff09\u3001\u53f2\u6e58\u4e91\uff08\u8d3e\u6bcd\u4f84\u5b59\u5973\uff09\n\n4. **\u859b\u5bb6**  \n   - \u859b\u59e8\u5988\uff08\u5b50\u859b\u87e0\u3001\u5973\u859b\u5b9d\u9497\uff09\uff0c\u859b\u5b9d\u9497\u5ac1\u8d3e\u5b9d\u7389\n\n---\n\n### **\u4e8c\u3001\u6838\u5fc3\u4eba\u7269\u53ca\u5173\u7cfb**\n1. **\u8d3e\u5b9d\u7389**  \n   - **\u8eab\u4efd**\uff1a\u795e\u745b\u4f8d\u8005\u8f6c\u4e16\uff0c\u8854\u7389\u800c\u751f\uff0c\u5c01\u5efa\u53db\u9006\u8005  \n   - **\u5173\u952e\u60c5\u8282**\uff1a\u6454\u7389\u6297\u8bae\u4e16\u4fd7\u3001\u4e0e\u9edb\u7389\u5171\u8bfb\u300a\u897f\u53a2\u8bb0\u300b\u3001\u88ab\u9a97\u4e0e\u5b9d\u9497\u6210\u5a5a\u3001\u51fa\u5bb6\u4e3a\u50e7  \n   - **\u5173\u7cfb**\uff1a\u4e0e\u9edb\u7389\uff08\u7075\u9b42\u4f34\u4fa3\uff09\u3001\u5b9d\u9497\uff08\u5a5a\u59fb\uff09\u3001\u88ad\u4eba\uff08\u8d34\u8eab\u4e2b\u9b1f\uff09\n\n2. **\u6797\u9edb\u7389**  \n   - **\u8eab\u4efd**\uff1a\u7edb\u73e0\u4ed9\u8349\u8f6c\u4e16\uff0c\u8d3e\u654f\u4e4b\u5973\uff0c\u5bc4\u5c45\u8d3e\u5e9c  \n   - **\u6027\u683c**\uff1a\u591a\u6101\u5584\u611f\u3001\u5b64\u50b2\u7387\u771f\uff0c\u4e0e\u5b9d\u7389\u540c\u4e3a\u53db\u9006\u8005  \n   - **\u5173\u952e\u60c5\u8282**\uff1a\u9edb\u7389\u846c\u82b1\u3001\u8bd7\u793e\u593a\u9b41\u3001\u6cea\u5c3d\u800c\u901d\n\n3. **\u859b\u5b9d\u9497**  \n   - **\u8eab\u4efd**\uff1a\u5c01\u5efa\u6dd1\u5973\u5178\u8303\uff0c\u8d3e\u5b9d\u7389\u4e4b\u59bb  \n   - **\u6027\u683c**\uff1a\u7a33\u91cd\u4e16\u6545\uff0c\u5584\u4e8e\u7b3c\u7edc\u4eba\u5fc3  \n   - **\u5173\u952e\u60c5\u8282**\uff1a\u5b9d\u9497\u6251\u8776\u3001\u529d\u8c0f\u5b9d\u7389\u8bfb\u4e66\u3001\u5a5a\u540e\u72ec\u5b88\u7a7a\u95fa\n\n4. **\u738b\u7199\u51e4**  \n   - **\u8eab\u4efd**\uff1a\u8d3e\u740f\u4e4b\u59bb\uff0c\u8363\u56fd\u5e9c\u5b9e\u9645\u638c\u6743\u8005  \n   - **\u6027\u683c**\uff1a\u7cbe\u660e\u5f3a\u5e72\u3001\u5fc3\u72e0\u624b\u8fa3  \n   - **\u5173\u952e\u60c5\u8282**\uff1a\u534f\u7406\u5b81\u56fd\u5e9c\u3001\u903c\u6b7b\u5c24\u4e8c\u59d0\u3001\u653e\u9ad8\u5229\u8d37\u3001\u75c5\u901d\u72f1\u4e2d\n\n5. **\u5176\u4ed6\u91cd\u8981\u4eba\u7269**  \n   - **\u53f2\u6e58\u4e91**\uff1a\u8c41\u8fbe\u4e50\u89c2\uff0c\u9189\u7720\u828d\u836f\u88c0\uff0c\u5ac1\u536b\u82e5\u5170\u540e\u5b88\u5be1  \n   - **\u8d3e\u63a2\u6625**\uff1a\u7cbe\u660e\u5fd7\u9ad8\uff0c\u6539\u9769\u5927\u89c2\u56ed\u627f\u5305\u5236\uff0c\u8fdc\u5ac1\u548c\u4eb2  \n   - **\u6674\u96ef**\uff1a\u7387\u771f\u53db\u9006\uff0c\u75c5\u8865\u96c0\u91d1\u88d8\uff0c\u88ab\u9010\u542b\u51a4\u800c\u6b7b  \n\n---\n\n### **\u4e09\u3001\u5173\u952e\u60c5\u8282\u4e0e\u573a\u666f**\n1. **\u5bb6\u65cf\u5174\u8870\u4e3b\u7ebf**  \n   - \u5143\u6625\u7701\u4eb2\uff08\u8d3e\u5e9c\u9f0e\u76db\uff09\u2192\u63a2\u6625\u7406\u5bb6\uff08\u6539\u9769\u5c1d\u8bd5\uff09\u2192\u6284\u68c0\u5927\u89c2\u56ed\uff08\u5185\u6597\u6fc0\u5316\uff09\u2192\u8d3e\u5e9c\u88ab\u6284\uff08\u5f7b\u5e95\u8870\u8d25\uff09\n\n2. **\u7231\u60c5\u60b2\u5267\u7ebf**  \n   - \u5b9d\u9edb\u521d\u89c1\uff08\u6728\u77f3\u524d\u76df\uff09\u2192\u5171\u8bfb\u897f\u53a2\uff08\u60c5\u611f\u5347\u534e\uff09\u2192\u8c03\u5305\u8ba1\u6210\u5a5a\uff08\u9edb\u7389\u6cea\u5c3d\u3001\u5b9d\u7389\u51fa\u5bb6\uff09\n\n3. **\u793e\u4f1a\u4f17\u751f\u76f8**  \n   - **\u5218\u59e5\u59e5\u4e09\u8fdb\u8363\u56fd\u5e9c**\uff1a\u89c1\u8bc1\u8d3e\u5e9c\u7531\u76db\u8f6c\u8870\uff0c\u6700\u7ec8\u6551\u5de7\u59d0  \n   - **\u5c24\u4e8c\u59d0\u4e4b\u6b7b**\uff1a\u63ed\u9732\u5c01\u5efa\u59bb\u59be\u5236\u5ea6\u4e4b\u6076  \n   - **\u6674\u96ef\u6495\u6247**\uff1a\u5e95\u5c42\u53cd\u6297\u7684\u60b2\u5267\u7f29\u5f71\n\n---\n\n### **\u56db\u3001\u4e3b\u9898\u601d\u60f3\u4e0e\u8c61\u5f81**\n1. **\u5c01\u5efa\u672b\u4e16\u5371\u673a**  \n   - \u56db\u5927\u5bb6\u65cf\u201c\u4e00\u8363\u4ff1\u8363\uff0c\u4e00\u635f\u4ff1\u635f\u201d\uff0c\u63ed\u9732\u5b98\u50da\u8150\u8d25\u4e0e\u9636\u7ea7\u538b\u8feb\u3002\n\n2. **\u4eba\u6027\u4e0e\u547d\u8fd0**  \n   - **\u5224\u8bcd\u9690\u55bb**\uff1a\u5982\u9edb\u7389\u201c\u7389\u5e26\u6797\u4e2d\u6302\u201d\uff08\u624d\u534e\u88ab\u57cb\u6ca1\uff09\u3001\u5b9d\u9497\u201c\u91d1\u7c2a\u96ea\u91cc\u57cb\u201d\uff08\u5a5a\u59fb\u51b0\u51b7\uff09  \n   - **\u5927\u89c2\u56ed\u8c61\u5f81**\uff1a\u7406\u60f3\u4e16\u754c vs \u73b0\u5b9e\u7262\u7b3c\n\n3. **\u5b97\u6559\u4e0e\u54f2\u5b66**  \n   - \u5b9d\u7389\u201c\u8d64\u6761\u6761\u6765\u53bb\u65e0\u7275\u6302\u201d\u4f53\u73b0\u4f5b\u5bb6\u7a7a\u5e7b\u89c2\u3002\n\n---\n\n### **\u4e94\u3001\u77e5\u8bc6\u56fe\u8c31\u6784\u5efa\u5efa\u8bae**\n1. **\u8282\u70b9\u5206\u7c7b**  \n   - **\u4eba\u7269**\uff1a\u6309\u5bb6\u65cf\u3001\u8eab\u4efd\uff08\u4e3b\u5b50\/\u4e2b\u9b1f\uff09\u3001\u6027\u683c\u6807\u7b7e\uff08\u53db\u9006\/\u5b88\u65e7\uff09\u5212\u5206\u3002  \n   - **\u4e8b\u4ef6**\uff1a\u6807\u8bb0\u65f6\u95f4\u7ebf\uff08\u5982\u201c\u5143\u6625\u7701\u4eb2-\u7b2c18\u56de\u201d\uff09\u53ca\u5173\u8054\u4eba\u7269\u3002  \n   - **\u5730\u70b9**\uff1a\u5927\u89c2\u56ed\u5404\u5c45\u6240\uff08\u6f47\u6e58\u9986\u3001\u6021\u7ea2\u9662\u7b49\uff09\u6620\u5c04\u4eba\u7269\u547d\u8fd0\u3002\n\n2. **\u5173\u7cfb\u7c7b\u578b**  \n   - \u8840\u7f18\/\u5a5a\u59fb\/\u654c\u5bf9\/\u4e3b\u4ec6\/\u60c5\u611f\uff08\u5982\u5b9d\u9edb\u201c\u7075\u9b42\u4f34\u4fa3\u201d\u3001\u7199\u51e4\u4e0e\u5c24\u4e8c\u59d0\u201c\u8feb\u5bb3\u201d\uff09\u3002\n\n3. **\u6570\u636e\u6765\u6e90**  \n   - \u53c2\u8003\u5224\u8bcd\uff08\u7b2c\u4e94\u56de\uff09\u3001\u4eba\u7269\u5173\u7cfb\u56fe\uff08\u9644\u5f55\u4e8e\u591a\u7bc7\u8d44\u6599\uff09\u3002\n\n---\n\n\u6b64\u603b\u7ed3\u53ef\u8fdb\u4e00\u6b65\u62c6\u89e3\u4e3a\u4eba\u7269\u5173\u7cfb\u56fe\u3001\u4e8b\u4ef6\u65f6\u95f4\u8f74\u3001\u4e3b\u9898\u5173\u952e\u8bcd\u7f51\u7edc\u7b49\u5b50\u56fe\u8c31\u3002\u82e5\u9700\u5b8c\u6574\u4eba\u7269\u5173\u7cfb\u6a21\u677f\u6216\u5224\u8bcd\u89e3\u6790\uff0c\u53ef\u53c2\u8003\u7f51\u9875\u7684\u601d\u7ef4\u5bfc\u56fe\u53ca\u5224\u8bcd\u5217\u8868\u3002&quot;&quot;&quot;<\/code><\/pre>\n<pre><code class=\"language-python\">print(&quot;--- \u8f93\u5165\u6587\u672c\u5df2\u52a0\u8f7d ---&quot;)\nprint(unstructured_text)\nprint(&quot;-&quot; * 25)\n# \u57fa\u672c\u7edf\u8ba1\u4fe1\u606f\u53ef\u89c6\u5316\nchar_count = len(unstructured_text)\nword_count = len(unstructured_text.split())\nprint(f&quot;\u603b\u5b57\u7b26\u6570: {char_count}&quot;)\nprint(f&quot;\u5927\u81f4\u8bcd\u6570: {word_count}&quot;)\nprint(&quot;-&quot; * 25)\n\n#### \u9884\u671f\u8f93\u51fa\uff08\u57fa\u4e8e\u539f\u6587\u793a\u4f8b\uff09####\n# --- \u8f93\u5165\u6587\u672c\u5df2\u52a0\u8f7d ---\n# Marie Curie, born Maria Sk\u0142odowska in Warsaw, Poland... (\u5b8c\u6574\u6587\u672c\u6253\u5370)<\/code><\/pre>\n<pre><code>--- \u8f93\u5165\u6587\u672c\u5df2\u52a0\u8f7d ---\n\n\u4ee5\u4e0b\u662f\u9002\u5408\u6784\u5efa\u300a\u7ea2\u697c\u68a6\u300b\u77e5\u8bc6\u56fe\u8c31\u7684\u4e07\u5b57\u5185\u7ed3\u6784\u5316\u603b\u7ed3\uff0c\u6db5\u76d6\u6838\u5fc3\u4eba\u7269\u3001\u5bb6\u65cf\u5173\u7cfb\u3001\u5173\u952e\u60c5\u8282\u53ca\u4e3b\u9898\u601d\u60f3\uff0c\u5f15\u7528\u591a\u7bc7\u8d44\u6599\u7efc\u5408\u6574\u7406\uff1a\n\n---\n\n### **\u4e00\u3001\u56db\u5927\u5bb6\u65cf\u80cc\u666f**\n1. **\u8d3e\u5bb6**  \n   - **\u5b81\u56fd\u5e9c**\uff1a\u8d3e\u6f14\u2192\u8d3e\u4ee3\u5316\u2192\u8d3e\u656c\uff08\u51fa\u5bb6\uff09\u2192\u8d3e\u73cd\uff08\u59bb\u5c24\u6c0f\uff09\u2192\u8d3e\u84c9\uff08\u59bb\u79e6\u53ef\u537f\uff09  \n   - **\u8363\u56fd\u5e9c**\uff1a\u8d3e\u6e90\u2192\u8d3e\u4ee3\u5584\uff08\u59bb\u8d3e\u6bcd\uff09\u2192\u8d3e\u8d66\uff08\u59bb\u90a2\u592b\u4eba\uff09\u3001\u8d3e\u653f\uff08\u59bb\u738b\u592b\u4eba\uff09\u3001\u8d3e\u654f\uff08\u5ac1\u6797\u5982\u6d77\uff09  \n     - **\u8d3e\u653f\u5b50\u5973**\uff1a\u8d3e\u73e0\uff08\u65e9\u901d\uff09\u3001\u8d3e\u5143\u6625\uff08\u8d35\u5983\uff09\u3001\u8d3e\u5b9d\u7389\u3001\u8d3e\u63a2\u6625\uff08\u5eb6\u51fa\uff09\u3001\u8d3e\u73af\uff08\u5eb6\u51fa\uff09  \n     - **\u8d3e\u8d66\u5b50\u5973**\uff1a\u8d3e\u740f\uff08\u59bb\u738b\u7199\u51e4\uff09\u3001\u8d3e\u8fce\u6625\uff08\u5eb6\u51fa\uff09  \n   - **\u6838\u5fc3\u4e8b\u4ef6**\uff1a\u5143\u6625\u7701\u4eb2\u5efa\u5927\u89c2\u56ed\u3001\u738b\u7199\u51e4\u534f\u7406\u5b81\u56fd\u5e9c\u3001\u8d3e\u5e9c\u88ab\u6284\u5bb6\n\n2. **\u738b\u5bb6**  \n   - \u738b\u592b\u4eba\uff08\u8d3e\u653f\u59bb\uff09\u3001\u859b\u59e8\u5988\uff08\u5ac1\u859b\u5bb6\uff09\u3001\u738b\u5b50\u817e\uff08\u5b98\u81f3\u4e5d\u7701\u90fd\u68c0\u70b9\uff09\n\n3. **\u53f2\u5bb6**  \n   - \u8d3e\u6bcd\uff08\u53f2\u592a\u541b\uff09\u3001\u53f2\u6e58\u4e91\uff08\u8d3e\u6bcd\u4f84\u5b59\u5973\uff09\n\n4. **\u859b\u5bb6**  \n   - \u859b\u59e8\u5988\uff08\u5b50\u859b\u87e0\u3001\u5973\u859b\u5b9d\u9497\uff09\uff0c\u859b\u5b9d\u9497\u5ac1\u8d3e\u5b9d\u7389\n\n---\n\n### **\u4e8c\u3001\u6838\u5fc3\u4eba\u7269\u53ca\u5173\u7cfb**\n1. **\u8d3e\u5b9d\u7389**  \n   - **\u8eab\u4efd**\uff1a\u795e\u745b\u4f8d\u8005\u8f6c\u4e16\uff0c\u8854\u7389\u800c\u751f\uff0c\u5c01\u5efa\u53db\u9006\u8005  \n   - **\u5173\u952e\u60c5\u8282**\uff1a\u6454\u7389\u6297\u8bae\u4e16\u4fd7\u3001\u4e0e\u9edb\u7389\u5171\u8bfb\u300a\u897f\u53a2\u8bb0\u300b\u3001\u88ab\u9a97\u4e0e\u5b9d\u9497\u6210\u5a5a\u3001\u51fa\u5bb6\u4e3a\u50e7  \n   - **\u5173\u7cfb**\uff1a\u4e0e\u9edb\u7389\uff08\u7075\u9b42\u4f34\u4fa3\uff09\u3001\u5b9d\u9497\uff08\u5a5a\u59fb\uff09\u3001\u88ad\u4eba\uff08\u8d34\u8eab\u4e2b\u9b1f\uff09\n\n2. **\u6797\u9edb\u7389**  \n   - **\u8eab\u4efd**\uff1a\u7edb\u73e0\u4ed9\u8349\u8f6c\u4e16\uff0c\u8d3e\u654f\u4e4b\u5973\uff0c\u5bc4\u5c45\u8d3e\u5e9c  \n   - **\u6027\u683c**\uff1a\u591a\u6101\u5584\u611f\u3001\u5b64\u50b2\u7387\u771f\uff0c\u4e0e\u5b9d\u7389\u540c\u4e3a\u53db\u9006\u8005  \n   - **\u5173\u952e\u60c5\u8282**\uff1a\u9edb\u7389\u846c\u82b1\u3001\u8bd7\u793e\u593a\u9b41\u3001\u6cea\u5c3d\u800c\u901d\n\n3. **\u859b\u5b9d\u9497**  \n   - **\u8eab\u4efd**\uff1a\u5c01\u5efa\u6dd1\u5973\u5178\u8303\uff0c\u8d3e\u5b9d\u7389\u4e4b\u59bb  \n   - **\u6027\u683c**\uff1a\u7a33\u91cd\u4e16\u6545\uff0c\u5584\u4e8e\u7b3c\u7edc\u4eba\u5fc3  \n   - **\u5173\u952e\u60c5\u8282**\uff1a\u5b9d\u9497\u6251\u8776\u3001\u529d\u8c0f\u5b9d\u7389\u8bfb\u4e66\u3001\u5a5a\u540e\u72ec\u5b88\u7a7a\u95fa\n\n4. **\u738b\u7199\u51e4**  \n   - **\u8eab\u4efd**\uff1a\u8d3e\u740f\u4e4b\u59bb\uff0c\u8363\u56fd\u5e9c\u5b9e\u9645\u638c\u6743\u8005  \n   - **\u6027\u683c**\uff1a\u7cbe\u660e\u5f3a\u5e72\u3001\u5fc3\u72e0\u624b\u8fa3  \n   - **\u5173\u952e\u60c5\u8282**\uff1a\u534f\u7406\u5b81\u56fd\u5e9c\u3001\u903c\u6b7b\u5c24\u4e8c\u59d0\u3001\u653e\u9ad8\u5229\u8d37\u3001\u75c5\u901d\u72f1\u4e2d\n\n5. **\u5176\u4ed6\u91cd\u8981\u4eba\u7269**  \n   - **\u53f2\u6e58\u4e91**\uff1a\u8c41\u8fbe\u4e50\u89c2\uff0c\u9189\u7720\u828d\u836f\u88c0\uff0c\u5ac1\u536b\u82e5\u5170\u540e\u5b88\u5be1  \n   - **\u8d3e\u63a2\u6625**\uff1a\u7cbe\u660e\u5fd7\u9ad8\uff0c\u6539\u9769\u5927\u89c2\u56ed\u627f\u5305\u5236\uff0c\u8fdc\u5ac1\u548c\u4eb2  \n   - **\u6674\u96ef**\uff1a\u7387\u771f\u53db\u9006\uff0c\u75c5\u8865\u96c0\u91d1\u88d8\uff0c\u88ab\u9010\u542b\u51a4\u800c\u6b7b  \n\n---\n\n### **\u4e09\u3001\u5173\u952e\u60c5\u8282\u4e0e\u573a\u666f**\n1. **\u5bb6\u65cf\u5174\u8870\u4e3b\u7ebf**  \n   - \u5143\u6625\u7701\u4eb2\uff08\u8d3e\u5e9c\u9f0e\u76db\uff09\u2192\u63a2\u6625\u7406\u5bb6\uff08\u6539\u9769\u5c1d\u8bd5\uff09\u2192\u6284\u68c0\u5927\u89c2\u56ed\uff08\u5185\u6597\u6fc0\u5316\uff09\u2192\u8d3e\u5e9c\u88ab\u6284\uff08\u5f7b\u5e95\u8870\u8d25\uff09\n\n2. **\u7231\u60c5\u60b2\u5267\u7ebf**  \n   - \u5b9d\u9edb\u521d\u89c1\uff08\u6728\u77f3\u524d\u76df\uff09\u2192\u5171\u8bfb\u897f\u53a2\uff08\u60c5\u611f\u5347\u534e\uff09\u2192\u8c03\u5305\u8ba1\u6210\u5a5a\uff08\u9edb\u7389\u6cea\u5c3d\u3001\u5b9d\u7389\u51fa\u5bb6\uff09\n\n3. **\u793e\u4f1a\u4f17\u751f\u76f8**  \n   - **\u5218\u59e5\u59e5\u4e09\u8fdb\u8363\u56fd\u5e9c**\uff1a\u89c1\u8bc1\u8d3e\u5e9c\u7531\u76db\u8f6c\u8870\uff0c\u6700\u7ec8\u6551\u5de7\u59d0  \n   - **\u5c24\u4e8c\u59d0\u4e4b\u6b7b**\uff1a\u63ed\u9732\u5c01\u5efa\u59bb\u59be\u5236\u5ea6\u4e4b\u6076  \n   - **\u6674\u96ef\u6495\u6247**\uff1a\u5e95\u5c42\u53cd\u6297\u7684\u60b2\u5267\u7f29\u5f71\n\n---\n\n### **\u56db\u3001\u4e3b\u9898\u601d\u60f3\u4e0e\u8c61\u5f81**\n1. **\u5c01\u5efa\u672b\u4e16\u5371\u673a**  \n   - \u56db\u5927\u5bb6\u65cf\u201c\u4e00\u8363\u4ff1\u8363\uff0c\u4e00\u635f\u4ff1\u635f\u201d\uff0c\u63ed\u9732\u5b98\u50da\u8150\u8d25\u4e0e\u9636\u7ea7\u538b\u8feb\u3002\n\n2. **\u4eba\u6027\u4e0e\u547d\u8fd0**  \n   - **\u5224\u8bcd\u9690\u55bb**\uff1a\u5982\u9edb\u7389\u201c\u7389\u5e26\u6797\u4e2d\u6302\u201d\uff08\u624d\u534e\u88ab\u57cb\u6ca1\uff09\u3001\u5b9d\u9497\u201c\u91d1\u7c2a\u96ea\u91cc\u57cb\u201d\uff08\u5a5a\u59fb\u51b0\u51b7\uff09  \n   - **\u5927\u89c2\u56ed\u8c61\u5f81**\uff1a\u7406\u60f3\u4e16\u754c vs \u73b0\u5b9e\u7262\u7b3c\n\n3. **\u5b97\u6559\u4e0e\u54f2\u5b66**  \n   - \u5b9d\u7389\u201c\u8d64\u6761\u6761\u6765\u53bb\u65e0\u7275\u6302\u201d\u4f53\u73b0\u4f5b\u5bb6\u7a7a\u5e7b\u89c2\u3002\n\n---\n\n### **\u4e94\u3001\u77e5\u8bc6\u56fe\u8c31\u6784\u5efa\u5efa\u8bae**\n1. **\u8282\u70b9\u5206\u7c7b**  \n   - **\u4eba\u7269**\uff1a\u6309\u5bb6\u65cf\u3001\u8eab\u4efd\uff08\u4e3b\u5b50\/\u4e2b\u9b1f\uff09\u3001\u6027\u683c\u6807\u7b7e\uff08\u53db\u9006\/\u5b88\u65e7\uff09\u5212\u5206\u3002  \n   - **\u4e8b\u4ef6**\uff1a\u6807\u8bb0\u65f6\u95f4\u7ebf\uff08\u5982\u201c\u5143\u6625\u7701\u4eb2-\u7b2c18\u56de\u201d\uff09\u53ca\u5173\u8054\u4eba\u7269\u3002  \n   - **\u5730\u70b9**\uff1a\u5927\u89c2\u56ed\u5404\u5c45\u6240\uff08\u6f47\u6e58\u9986\u3001\u6021\u7ea2\u9662\u7b49\uff09\u6620\u5c04\u4eba\u7269\u547d\u8fd0\u3002\n\n2. **\u5173\u7cfb\u7c7b\u578b**  \n   - \u8840\u7f18\/\u5a5a\u59fb\/\u654c\u5bf9\/\u4e3b\u4ec6\/\u60c5\u611f\uff08\u5982\u5b9d\u9edb\u201c\u7075\u9b42\u4f34\u4fa3\u201d\u3001\u7199\u51e4\u4e0e\u5c24\u4e8c\u59d0\u201c\u8feb\u5bb3\u201d\uff09\u3002\n\n3. **\u6570\u636e\u6765\u6e90**  \n   - \u53c2\u8003\u5224\u8bcd\uff08\u7b2c\u4e94\u56de\uff09\u3001\u4eba\u7269\u5173\u7cfb\u56fe\uff08\u9644\u5f55\u4e8e\u591a\u7bc7\u8d44\u6599\uff09\u3002\n\n---\n\n\u6b64\u603b\u7ed3\u53ef\u8fdb\u4e00\u6b65\u62c6\u89e3\u4e3a\u4eba\u7269\u5173\u7cfb\u56fe\u3001\u4e8b\u4ef6\u65f6\u95f4\u8f74\u3001\u4e3b\u9898\u5173\u952e\u8bcd\u7f51\u7edc\u7b49\u5b50\u56fe\u8c31\u3002\u82e5\u9700\u5b8c\u6574\u4eba\u7269\u5173\u7cfb\u6a21\u677f\u6216\u5224\u8bcd\u89e3\u6790\uff0c\u53ef\u53c2\u8003\u7f51\u9875\u7684\u601d\u7ef4\u5bfc\u56fe\u53ca\u5224\u8bcd\u5217\u8868\u3002\n-------------------------\n\u603b\u5b57\u7b26\u6570: 1824\n\u5927\u81f4\u8bcd\u6570: 130\n-------------------------<\/code><\/pre>\n<pre><code class=\"language-python\"># --- \u5206\u5757\u914d\u7f6e ---\nchunk_size = 150# \u6bcf\u4e2a\u5757\u7684\u8bcd\u6570\uff08\u6839\u636e\u9700\u8981\u8c03\u6574\uff09\noverlap = 30     # \u91cd\u53e0\u7684\u8bcd\u6570\uff08\u5fc5\u987b\u5c0f\u4e8e chunk_size\uff09\n\nprint(f&quot;\u5206\u5757\u5927\u5c0f\u8bbe\u7f6e\u4e3a: {chunk_size} \u8bcd&quot;)\nprint(f&quot;\u91cd\u53e0\u8bcd\u6570\u8bbe\u7f6e\u4e3a: {overlap} \u8bcd&quot;)\n\n# --- \u57fa\u672c\u9a8c\u8bc1 ---\nif overlap &gt;= chunk_size and chunk_size &gt; 0:\n    print(f&quot;\u9519\u8bef\uff1a\u91cd\u53e0\u8bcd\u6570 ({overlap}) \u5fc5\u987b\u5c0f\u4e8e\u5206\u5757\u5927\u5c0f ({chunk_size})\u3002&quot;)\n    # \u5728\u5b9e\u9645\u811a\u672c\u4e2d\uff0c\u8fd9\u91cc\u5e94\u8be5\u5f15\u53d1\u9519\u8bef\u6216\u9000\u51fa\n    # raise SystemExit(&quot;\u5206\u5757\u914d\u7f6e\u9519\u8bef\u3002&quot;)<\/code><\/pre>\n<pre><code>\u5206\u5757\u5927\u5c0f\u8bbe\u7f6e\u4e3a: 150 \u8bcd\n\u91cd\u53e0\u8bcd\u6570\u8bbe\u7f6e\u4e3a: 30 \u8bcd<\/code><\/pre>\n<pre><code class=\"language-python\">import jieba\nimport string\nwords = list(jieba.cut(unstructured_text))\n# \u8fc7\u6ee4\u7a7a\u767d\u548c\u6807\u70b9\nwords = [w for w in words if w.strip() and w not in string.punctuation]\ntotal_words = len(words)\n\nprint(f&quot;\u6587\u672c\u88ab\u5206\u5272\u6210 {total_words} \u4e2a\u8bcd\u3002&quot;)\n# \u53ef\u89c6\u5316\u524d 20 \u4e2a\u8bcd\nprint(f&quot;\u524d 20 \u4e2a\u8bcd: {words[:20]}&quot;)\n\n### \u9884\u671f\u8f93\u51fa ###\n# \u6587\u672c\u88ab\u5206\u5272\u6210 324 \u4e2a\u8bcd\u3002\n# \u524d 20 \u4e2a\u8bcd: [&#039;Marie&#039;, &#039;Curie,&#039;, &#039;born&#039;, &#039;Maria&#039;, &#039;Sk\u0142odowska&#039;, &#039;in&#039;, &#039;Warsaw,&#039;, &#039;Poland,&#039;, &#039;was&#039;, &#039;a&#039;, &#039;pioneering&#039;, &#039;physicist&#039;, &#039;and&#039;, &#039;chemist.&#039;, &#039;She&#039;, &#039;conducted&#039;, &#039;groundbreaking&#039;, &#039;research&#039;, &#039;on&#039;, &#039;radioactivity.&#039;]<\/code><\/pre>\n<pre><code>Building prefix dict from the default dictionary ...\nDumping model to file cache \/var\/folders\/rd\/gmbvmbl170n8vqsv5hyb_ym00000gn\/T\/jieba.cache\nLoading model cost 0.321 seconds.\nPrefix dict has been built successfully.\n\n\u6587\u672c\u88ab\u5206\u5272\u6210 709 \u4e2a\u8bcd\u3002\n\u524d 20 \u4e2a\u8bcd: ['\u4ee5\u4e0b', '\u662f', '\u9002\u5408', '\u6784\u5efa', '\u300a', '\u7ea2\u697c\u68a6', '\u300b', '\u77e5\u8bc6', '\u56fe\u8c31', '\u7684', '\u4e07\u5b57', '\u5185', '\u7ed3\u6784\u5316', '\u603b\u7ed3', '\uff0c', '\u6db5\u76d6', '\u6838\u5fc3\u4eba\u7269', '\u3001', '\u5bb6\u65cf', '\u5173\u7cfb']<\/code><\/pre>\n<pre><code class=\"language-python\">chunks = []\nstart_index = 0\nchunk_number = 1\n\nprint(f&quot;\u5f00\u59cb\u5206\u5757\u5904\u7406...&quot;)\n\nwhile start_index &lt; total_words:\n    end_index = min(start_index + chunk_size, total_words)\n    chunk_text = &quot; &quot;.join(words[start_index:end_index])\n    chunks.append({&quot;text&quot;: chunk_text, &quot;chunk_number&quot;: chunk_number})\n\n    # print(f&quot;  \u5df2\u521b\u5efa\u5757 {chunk_number}: \u8bcd\u8bed {start_index} \u5230 {end_index-1}&quot;) # \u53d6\u6d88\u6ce8\u91ca\u4ee5\u67e5\u770b\u8be6\u7ec6\u65e5\u5fd7\n\n    # \u8ba1\u7b97\u4e0b\u4e00\u4e2a\u5757\u7684\u8d77\u59cb\u7d22\u5f15\n    next_start_index = start_index + chunk_size - overlap\n\n    # \u786e\u4fdd\u5904\u7406\u6709\u8fdb\u5c55\n    if next_start_index &lt;= start_index:\n        if end_index == total_words:\n             break# \u5df2\u7ecf\u5904\u7406\u5b8c\u6700\u540e\u4e00\u90e8\u5206\n        # \u5982\u679c\u6ca1\u6709\u8fdb\u5c55\u4e14\u672a\u5230\u672b\u5c3e\uff0c\u5219\u81f3\u5c11\u524d\u8fdb\u4e00\u4e2a\u8bcd\n        next_start_index = start_index + 1\n\n    start_index = next_start_index\n    chunk_number += 1\n\n    # \u5b89\u5168\u4e2d\u65ad\uff08\u53ef\u9009\uff09\n    if chunk_number &gt; total_words: # \u7b80\u5355\u7684\u5b89\u5168\u63aa\u65bd\n        print(&quot;\u8b66\u544a\uff1a\u5206\u5757\u5faa\u73af\u6b21\u6570\u8d85\u8fc7\u603b\u8bcd\u6570\uff0c\u5df2\u4e2d\u65ad\u3002&quot;)\n        break\n\nprint(f&quot;\\n\u6587\u672c\u6210\u529f\u5206\u5272\u6210 {len(chunks)} \u4e2a\u5757\u3002&quot;)<\/code><\/pre>\n<pre><code>\u5f00\u59cb\u5206\u5757\u5904\u7406...\n\n\u6587\u672c\u6210\u529f\u5206\u5272\u6210 6 \u4e2a\u5757\u3002<\/code><\/pre>\n<pre><code class=\"language-python\">print(&quot;--- \u5757\u8be6\u60c5 ---&quot;)\nif chunks:\n    # \u521b\u5efa DataFrame \u4ee5\u4fbf\u66f4\u597d\u5730\u53ef\u89c6\u5316\n    chunks_df = pd.DataFrame(chunks)\n    chunks_df[&#039;word_count&#039;] = chunks_df[&#039;text&#039;].apply(lambda x: len(x.split()))\n    # \u5728 Jupyter \u73af\u5883\u4e2d\uff0cdisplay() \u4f1a\u4ee5\u66f4\u7f8e\u89c2\u7684\u8868\u683c\u5f62\u5f0f\u663e\u793a DataFrame\n    # \u5982\u679c\u5728\u666e\u901a Python \u811a\u672c\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 print(chunks_df[[&#039;chunk_number&#039;, &#039;word_count&#039;, &#039;text&#039;]])\n    try:\n        display(chunks_df[[&#039;chunk_number&#039;, &#039;word_count&#039;, &#039;text&#039;]])\n    except NameError: # &#039;display&#039; \u53ef\u80fd\u672a\u5b9a\u4e49\u5728\u975e Jupyter \u73af\u5883\n        print(chunks_df[[&#039;chunk_number&#039;, &#039;word_count&#039;, &#039;text&#039;]])\nelse:\n    print(&quot;\u6ca1\u6709\u521b\u5efa\u4efb\u4f55\u5757\uff08\u6587\u672c\u53ef\u80fd\u77ed\u4e8e\u5206\u5757\u5927\u5c0f\uff09\u3002&quot;)\nprint(&quot;-&quot; * 25)<\/code><\/pre>\n<pre><code>--- \u5757\u8be6\u60c5 ---<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>chunk_number<\/th>\n<th>word_count<\/th>\n<th>text<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>1<\/td>\n<td>150<\/td>\n<td>\u4ee5\u4e0b \u662f \u9002\u5408 \u6784\u5efa \u300a \u7ea2\u697c\u68a6 \u300b \u77e5\u8bc6 \u56fe\u8c31 \u7684 \u4e07\u5b57 \u5185 \u7ed3\u6784\u5316 \u603b\u7ed3 \uff0c \u6db5\u76d6 \u6838\u5fc3...<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>2<\/td>\n<td>150<\/td>\n<td>\uff09 \u3001 \u8d3e\u8fce\u6625 \uff08 \u5eb6\u51fa \uff09 \u6838\u5fc3 \u4e8b\u4ef6 \uff1a \u5143\u6625 \u7701\u4eb2 \u5efa \u5927\u89c2\u56ed \u3001 \u738b\u7199\u51e4 \u534f\u7406 \u5b81\u56fd...<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>3<\/td>\n<td>150<\/td>\n<td>\u3001 \u88ad\u4eba \uff08 \u8d34\u8eab \u4e2b\u9b1f \uff09 2 \u6797\u9edb\u7389 \u8eab\u4efd \uff1a \u7edb \u73e0 \u4ed9\u8349 \u8f6c\u4e16 \uff0c \u8d3e\u654f \u4e4b \u5973 \uff0c...<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>4<\/td>\n<td>150<\/td>\n<td>\u63a2\u6625 \uff1a \u7cbe\u660e \u5fd7\u9ad8 \uff0c \u6539\u9769 \u5927\u89c2\u56ed \u627f\u5305\u5236 \uff0c \u8fdc\u5ac1 \u548c\u4eb2 \u6674\u96ef \uff1a \u7387\u771f \u53db\u9006 \uff0c \u75c5...<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>5<\/td>\n<td>150<\/td>\n<td>\u60b2\u5267 \u7f29\u5f71 --- ### \u56db \u3001 \u4e3b\u9898\u601d\u60f3 \u4e0e \u8c61\u5f81 1 \u5c01\u5efa \u672b\u4e16 \u5371\u673a \u56db\u5927\u5bb6\u65cf \u201c ...<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>6<\/td>\n<td>109<\/td>\n<td>\u7701\u4eb2 \u7b2c 18 \u56de \u201d \uff09 \u53ca \u5173\u8054 \u4eba\u7269 \u3002 \u5730\u70b9 \uff1a \u5927\u89c2\u56ed \u5404 \u5c45\u6240 \uff08 \u6f47\u6e58 \u9986 \u3001...<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<pre><code>-------------------------<\/code><\/pre>\n<pre><code class=\"language-python\"># --- System Prompt: Sets the context\/role for the LLM ---\nextraction_system_prompt = &quot;&quot;&quot;\nYou are an AI expert specialized in knowledge graph extraction.\nYour task is to identify and extract factual Subject-Predicate-Object (SPO) triples from the given text.\nFocus on accuracy and adhere strictly to the JSON output format requested in the user prompt.\nExtract core entities and the most direct relationship.\n&quot;&quot;&quot;\n\n# --- User Prompt Template: Contains specific instructions and the text ---\nextraction_user_prompt_template = &quot;&quot;&quot;\nPlease extract Subject-Predicate-Object (S-P-O) triples from the text below.\n\n**VERY IMPORTANT RULES:**\n1.  **Output Format:** Respond ONLY with a single, valid JSON array. Each element MUST be an object with keys &quot;subject&quot;, &quot;predicate&quot;, &quot;object&quot;.\n2.  **JSON Only:** Do NOT include any text before or after the JSON array (e.g., no &#039;Here is the JSON:&#039; or explanations). Do NOT use markdown ```json ... ``` tags.\n3.  **Concise Predicates:** Keep the &#039;predicate&#039; value concise (1-3 words, ideally 1-2). Use verbs or short verb phrases (e.g., &#039;discovered&#039;, &#039;was born in&#039;, &#039;won&#039;).\n4.  **Lowercase:** ALL values for &#039;subject&#039;, &#039;predicate&#039;, and &#039;object&#039; MUST be lowercase.\n5.  **Pronoun Resolution:** Replace pronouns (she, he, it, her, etc.) with the specific lowercase entity name they refer to based on the text context (e.g., &#039;marie curie&#039;).\n6.  **Specificity:** Capture specific details (e.g., &#039;nobel prize in physics&#039; instead of just &#039;nobel prize&#039; if specified).\n7.  **Completeness:** Extract all distinct factual relationships mentioned.\n\n**Text to Process:**\n\n{text_chunk}\n&quot;&quot;&quot;<\/code><\/pre>\n<pre><code class=\"language-python\">print(&quot;--- \u7cfb\u7edf\u63d0\u793a ---&quot;)\nprint(extraction_system_prompt)\nprint(&quot;\\n&quot; + &quot;-&quot; * 25 + &quot;\\n&quot;)\n\nprint(&quot;--- \u7528\u6237\u63d0\u793a\u6a21\u677f\uff08\u7ed3\u6784\uff09 ---&quot;)\n# \u663e\u793a\u7ed3\u6784\uff0c\u66ff\u6362\u5360\u4f4d\u7b26\u4ee5\u4fbf\u66f4\u6e05\u6670\nprint(extraction_user_prompt_template.replace(&quot;{text_chunk}&quot;, &quot;[... \u6587\u672c\u5757\u653e\u5728\u8fd9\u91cc ...]&quot;))\nprint(&quot;\\n&quot; + &quot;-&quot; * 25 + &quot;\\n&quot;)\n\n# \u663e\u793a\u5c06\u4e3a\u7b2c\u4e00\u4e2a\u5757\u53d1\u9001\u7684 *\u5b9e\u9645* \u63d0\u793a\u793a\u4f8b\nprint(&quot;--- \u586b\u5145\u540e\u7684\u7528\u6237\u63d0\u793a\u793a\u4f8b\uff08\u9488\u5bf9\u5757 1\uff09 ---&quot;)\nif chunks:\n    example_filled_prompt = extraction_user_prompt_template.format(text_chunk=chunks[0][&#039;text&#039;])\n    # \u4e3a\u7b80\u6d01\u8d77\u89c1\uff0c\u4ec5\u663e\u793a\u4e00\u90e8\u5206\n    print(example_filled_prompt[:600] + &quot;\\n[... \u5757\u6587\u672c\u7684\u5176\u4f59\u90e8\u5206 ...]\\n&quot; + example_filled_prompt[-200:])\nelse:\n    print(&quot;\u6ca1\u6709\u53ef\u7528\u7684\u5757\u6765\u521b\u5efa\u586b\u5145\u540e\u7684\u63d0\u793a\u793a\u4f8b\u3002&quot;)\nprint(&quot;\\n&quot; + &quot;-&quot; * 25)\n\n#### \u9884\u671f\u8f93\u51fa ####\n# --- \u7cfb\u7edf\u63d0\u793a ---\n# \u4f60\u662f\u4e00\u4f4d\u4e13\u95e8\u4ece\u4e8b\u77e5\u8bc6\u56fe\u8c31\u63d0\u53d6\u7684 AI \u4e13\u5bb6... (\u5b8c\u6574\u7cfb\u7edf\u63d0\u793a)\n# -------------------------\n#\n# --- \u7528\u6237\u63d0\u793a\u6a21\u677f\uff08\u7ed3\u6784\uff09 ---\n# \u8bf7\u4ece\u4ee5\u4e0b\u6587\u672c\u4e2d\u63d0\u53d6\u4e3b\u8c13\u5bbe (S-P-O) \u4e09\u5143\u7ec4\u3002\n# **\u975e\u5e38\u91cd\u8981\u7684\u89c4\u5219\uff1a**\n# [... \u89c4\u5219\u6253\u5370\u5728\u8fd9\u91cc ...]\n# **\u5f85\u5904\u7406\u6587\u672c\uff1a**\n# [... \u6587\u672c\u5757\u653e\u5728\u8fd9\u91cc ...]\n# **\u4f60\u7684 JSON \u8f93\u51fa:**\n# -------------------------\n#\n# --- \u586b\u5145\u540e\u7684\u7528\u6237\u63d0\u793a\u793a\u4f8b\uff08\u9488\u5bf9\u5757 1\uff09 ---\n# \u8bf7\u4ece\u4ee5\u4e0b\u6587\u672c\u4e2d\u63d0\u53d6\u4e3b\u8c13\u5bbe (S-P-O) \u4e09\u5143\u7ec4\u3002\n# ... (\u89c4\u5219) ...\n# **\u5f85\u5904\u7406\u6587\u672c\uff1a**\n# Marie Curie, born Maria Sk\u0142odowska in Warsaw, Poland, was a pioneering physicist and chemist.\n# She conducted groundbreaking research on radioactivity. Together with her husband, Pierre Curie,\n# she discovered the elements polonium and radium. Marie Curie was the first woman to win a Nobel Prize,\n# the first person and only woman to win the Nobel Prize twice, and the only person to win the Nobel Prize\n# in two different scientific fields. She won the Nobel Prize in Physics in 1903 with Pierre Curie\n# and Henri Becquerel. Later, she won the Nobel Prize in Chemistry in 1911 for her work on radium and\n# polonium. During World War I, she developed mobile radiography units, known as &#039;petites Curies&#039;,\n# [... \u5757\u6587\u672c\u7684\u5176\u4f59\u90e8\u5206 ...]\n# **\u4f60\u7684 JSON \u8f93\u51fa:**\n# -------------------------\n<\/code><\/pre>\n<pre><code>--- \u7cfb\u7edf\u63d0\u793a ---\n\nYou are an AI expert specialized in knowledge graph extraction.\nYour task is to identify and extract factual Subject-Predicate-Object (SPO) triples from the given text.\nFocus on accuracy and adhere strictly to the JSON output format requested in the user prompt.\nExtract core entities and the most direct relationship.<\/code><\/pre>\n<h2>\u200b    <\/h2>\n<pre><code>--- \u7528\u6237\u63d0\u793a\u6a21\u677f\uff08\u7ed3\u6784\uff09 ---\n\nPlease extract Subject-Predicate-Object (S-P-O) triples from the text below.\n\n**VERY IMPORTANT RULES:**\n1.  **Output Format:** Respond ONLY with a single, valid JSON array. Each element MUST be an object with keys \"subject\", \"predicate\", \"object\".\n2.  **JSON Only:** Do NOT include any text before or after the JSON array (e.g., no 'Here is the JSON:' or explanations). Do NOT use markdown ``<code>json ... <\/code>`` tags.\n3.  **Concise Predicates:** Keep the 'predicate' value concise (1-3 words, ideally 1-2). Use verbs or short verb phrases (e.g., 'discovered', 'was born in', 'won').\n4.  **Lowercase:** ALL values for 'subject', 'predicate', and 'object' MUST be lowercase.\n5.  **Pronoun Resolution:** Replace pronouns (she, he, it, her, etc.) with the specific lowercase entity name they refer to based on the text context (e.g., 'marie curie').\n6.  **Specificity:** Capture specific details (e.g., 'nobel prize in physics' instead of just 'nobel prize' if specified).\n7.  **Completeness:** Extract all distinct factual relationships mentioned.\n\n**Text to Process:**\n\n[... \u6587\u672c\u5757\u653e\u5728\u8fd9\u91cc ...]<\/code><\/pre>\n<h2>\u200b    <\/h2>\n<pre><code>--- \u586b\u5145\u540e\u7684\u7528\u6237\u63d0\u793a\u793a\u4f8b\uff08\u9488\u5bf9\u5757 1\uff09 ---\n\nPlease extract Subject-Predicate-Object (S-P-O) triples from the text below.\n\n**VERY IMPORTANT RULES:**\n1.  **Output Format:** Respond ONLY with a single, valid JSON array. Each element MUST be an object with keys \"subject\", \"predicate\", \"object\".\n2.  **JSON Only:** Do NOT include any text before or after the JSON array (e.g., no 'Here is the JSON:' or explanations). Do NOT use markdown ``<code>json ... <\/code>`` tags.\n3.  **Concise Predicates:** Keep the 'predicate' value concise (1-3 words, ideally 1-2). Use verbs or short verb phrases (e.g., 'discovered', 'was born in', 'won').\n4.  **Lowercase:** ALL\n[... \u5757\u6587\u672c\u7684\u5176\u4f59\u90e8\u5206 ...]\n\u592b\u4eba \uff09 \u3001 \u8d3e\u653f \uff08 \u59bb \u738b\u592b\u4eba \uff09 \u3001 \u8d3e\u654f \uff08 \u5ac1 \u6797\u5982\u6d77 \uff09 \u8d3e\u653f \u5b50\u5973 \uff1a \u8d3e\u73e0 \uff08 \u65e9\u901d \uff09 \u3001 \u8d3e\u5143\u6625 \uff08 \u8d35\u5983 \uff09 \u3001 \u8d3e\u5b9d\u7389 \u3001 \u8d3e \u63a2\u6625 \uff08 \u5eb6\u51fa \uff09 \u3001 \u8d3e\u73af \uff08 \u5eb6\u51fa \uff09 \u8d3e\u8d66 \u5b50\u5973 \uff1a \u8d3e\u740f \uff08 \u59bb \u738b\u7199\u51e4 \uff09 \u3001 \u8d3e\u8fce\u6625 \uff08 \u5eb6\u51fa \uff09 \u6838\u5fc3 \u4e8b\u4ef6 \uff1a \u5143\u6625 \u7701\u4eb2 \u5efa \u5927\u89c2\u56ed \u3001 \u738b\u7199\u51e4 \u534f\u7406 \u5b81\u56fd\u5e9c \u3001 \u8d3e\u5e9c \u88ab \u6284\u5bb6 2 \u738b\u5bb6 \u738b\u592b\u4eba \uff08 \u8d3e\u653f\u59bb \uff09 \u3001 \u859b\u59e8\u5988 \uff08<\/code><\/pre>\n<h2>\u200b    <\/h2>\n<pre><code class=\"language-python\"># \u521d\u59cb\u5316\u5217\u8868\u4ee5\u5b58\u50a8\u7ed3\u679c\u548c\u5931\u8d25\u8bb0\u5f55\nall_extracted_triples = []\nfailed_chunks = []\n\n# \u5047\u8bbe client \u5df2\u7ecf\u6839\u636e\u4e4b\u524d\u7684 &#039;Configuring Our LLM Connection&#039; \u90e8\u5206\u6b63\u786e\u521d\u59cb\u5316\n# \u4f8b\u5982: client = openai.OpenAI(api_key=api_key, base_url=base_url)\n# \u4e3a\u4e86\u4ee3\u7801\u53ef\u8fd0\u884c\u6027\uff0c\u8fd9\u91cc\u6dfb\u52a0\u4e00\u4e2a\u7b80\u5355\u7684 client \u521d\u59cb\u5316\uff08\u9700\u8981\u66ff\u6362\u4e3a\u5b9e\u9645\u7684\uff09\ntry:\n    client = openai.OpenAI(api_key=api_key, base_url=base_url)\nexcept Exception as e:\n    print(f&quot;\u65e0\u6cd5\u521d\u59cb\u5316 OpenAI \u5ba2\u6237\u7aef: {e}&quot;)\n    print(&quot;\u8bf7\u786e\u4fdd API \u5bc6\u94a5\u548c\u57fa\u7840 URL \u5df2\u6b63\u786e\u8bbe\u7f6e\u3002&quot;)\n    client = None# \u6807\u8bb0 client \u65e0\u6548\n\nprint(f&quot;\u5f00\u59cb\u4ece {len(chunks)} \u4e2a\u5757\u4e2d\u63d0\u53d6\u4e09\u5143\u7ec4\uff0c\u4f7f\u7528\u6a21\u578b &#039;{llm_model_name}&#039;...&quot;)\n# \u6211\u4eec\u5c06\u5728\u63a5\u4e0b\u6765\u7684\u5355\u5143\u683c\u4e2d\u9010\u4e00\u5904\u7406\u5757\u3002<\/code><\/pre>\n<pre><code>\u5f00\u59cb\u4ece 6 \u4e2a\u5757\u4e2d\u63d0\u53d6\u4e09\u5143\u7ec4\uff0c\u4f7f\u7528\u6a21\u578b 'mistral-small:24b'...<\/code><\/pre>\n<pre><code class=\"language-python\">if client and chunks:  # \u786e\u4fdd client \u6709\u6548\u4e14 chunks \u4e0d\u4e3a\u7a7a\n    for chunk_index, chunk in enumerate(chunks):\n        print(f&quot;\\n--- \u6b63\u5728\u5904\u7406\u5757 {chunk[&#039;chunk_number&#039;]}\/{len(chunks)} ---&quot;)\n        prompt = extraction_user_prompt_template.format(text_chunk=chunk[&#039;text&#039;])\n\n        raw_response = None  # \u521d\u59cb\u5316\u539f\u59cb\u54cd\u5e94\u53d8\u91cf\n        parsed_data = None  # \u521d\u59cb\u5316\u89e3\u6790\u540e\u7684\u6570\u636e\u53d8\u91cf\n        triples_in_chunk = []  # \u521d\u59cb\u5316\u5f53\u524d\u5757\u7684\u4e09\u5143\u7ec4\u5217\u8868\n\n        try:\n            print(&quot;1. \u683c\u5f0f\u5316\u7528\u6237\u63d0\u793a...&quot;)\n            print(&quot;2. \u5411 LLM \u53d1\u9001\u8bf7\u6c42...&quot;)\n\n            res = client.chat.completions.create(\n                model=llm_model_name,\n                messages=[\n                    {&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: extraction_system_prompt},\n                    {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: prompt}\n                ],\n                temperature=llm_temperature,\n                max_tokens=llm_max_tokens,\n                response_format={&quot;type&quot;: &quot;json_object&quot;},\n            )\n\n            print(&quot;   LLM \u54cd\u5e94\u5df2\u63a5\u6536\u3002&quot;)\n            print(&quot;3. \u63d0\u53d6\u539f\u59cb\u54cd\u5e94\u5185\u5bb9...&quot;)\n            raw_response = res.choices[0].message.content.strip()\n\n            print(f&quot;\\n--- \u539f\u59cb LLM \u8f93\u51fa (\u5757 {chunk[&#039;chunk_number&#039;]}) ---&quot;)\n            print(raw_response)\n            print(&quot;-&quot; * 15)\n\n            print(&quot;\\n4. \u5c1d\u8bd5\u4ece\u54cd\u5e94\u4e2d\u89e3\u6790 JSON...&quot;)\n\n            try:\n                parsed_data = json.loads(raw_response)\n\n                if isinstance(parsed_data, dict):\n                    potential_list = next(\n                        (v for v in parsed_data.values() if isinstance(v, list)),\n                        None\n                    )\n                    if potential_list is not None:\n                        parsed_data = potential_list\n                    else:\n                        if all(k in parsed_data for k in [&quot;subject&quot;, &quot;predicate&quot;, &quot;object&quot;]):\n                            parsed_data = [parsed_data]\n                        else:\n                            print(&quot;   \u8b66\u544a\uff1a\u6536\u5230\u5b57\u5178\uff0c\u4f46\u65e2\u4e0d\u662f\u4e09\u5143\u7ec4\u4e5f\u4e0d\u662f\u5305\u542b\u4e09\u5143\u7ec4\u5217\u8868\u7684\u5305\u88c5\u5668\u3002&quot;)\n                            parsed_data = []\n\n                if not isinstance(parsed_data, list):\n                    print(f&quot;   \u8b66\u544a\uff1a\u89e3\u6790\u7ed3\u679c\u4e0d\u662f\u5217\u8868\uff0c\u800c\u662f {type(parsed_data)}\u3002\u5c1d\u8bd5\u67e5\u627e\u5217\u8868\u3002&quot;)\n                    parsed_data = []\n\n                print(f&quot;   \u6210\u529f\u89e3\u6790 JSON \u5217\u8868\uff08\u6216\u5c06\u5176\u8f6c\u6362\/\u627e\u5230\uff09\u3002\u5305\u542b {len(parsed_data)} \u4e2a\u9879\u76ee\u3002&quot;)\n\n            except json.JSONDecodeError as json_e:\n                print(f&quot;   \u76f4\u63a5 JSON \u89e3\u6790\u5931\u8d25: {json_e}&quot;)\n                print(&quot;   \u5c1d\u8bd5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d6 JSON \u6570\u7ec4...&quot;)\n\n                match = re.search(r&#039;\\[.*?\\]&#039;, raw_response, re.DOTALL)\n                if match:\n                    try:\n                        parsed_data = json.loads(match.group(0))\n                        print(f&quot;   \u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u6210\u529f\u63d0\u53d6\u5e76\u89e3\u6790\u4e86 JSON \u5217\u8868\u3002\u5305\u542b {len(parsed_data)} \u4e2a\u9879\u76ee\u3002&quot;)\n                    except json.JSONDecodeError as regex_json_e:\n                        print(f&quot;   \u4ece\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u4e2d\u89e3\u6790 JSON \u5931\u8d25: {regex_json_e}&quot;)\n                        parsed_data = []\n                else:\n                    print(&quot;   \u672a\u627e\u5230\u7b26\u5408 [...] \u683c\u5f0f\u7684 JSON \u6570\u7ec4\u3002&quot;)\n                    parsed_data = []\n\n            print(&quot;\\n5. \u9a8c\u8bc1\u7ed3\u6784\u5e76\u63d0\u53d6\u4e09\u5143\u7ec4...&quot;)\n\n            if isinstance(parsed_data, list):\n                valid_triples_count = 0\n\n                for item in parsed_data:\n                    if (\n                        isinstance(item, dict)\n                        and all(k in item and isinstance(item[k], str) for k in [&quot;subject&quot;, &quot;predicate&quot;, &quot;object&quot;])\n                    ):\n                        item_with_chunk = dict(item, chunk=chunk[&#039;chunk_number&#039;])\n                        triples_in_chunk.append(item_with_chunk)\n                        valid_triples_count += 1\n                    else:\n                        print(f&quot;   \u8b66\u544a\uff1a\u8df3\u8fc7\u65e0\u6548\u9879\u76ee\uff1a{item}&quot;)\n\n                print(f&quot;   \u5728\u6b64\u5757\u4e2d\u627e\u5230 {valid_triples_count} \u4e2a\u6709\u6548\u4e09\u5143\u7ec4\u3002&quot;)\n\n                if triples_in_chunk:\n                    try:\n                        print(f&quot;   --- \u63d0\u53d6\u7684\u6709\u6548\u4e09\u5143\u7ec4 (\u5757 {chunk[&#039;chunk_number&#039;]}) ---&quot;)\n                        display(pd.DataFrame(triples_in_chunk))\n                    except NameError:\n                        print(pd.DataFrame(triples_in_chunk))\n\n                    all_extracted_triples.extend(triples_in_chunk)\n\n            else:\n                print(&quot;   \u672a\u80fd\u83b7\u53d6\u6709\u6548\u7684 JSON \u5217\u8868\uff0c\u65e0\u6cd5\u63d0\u53d6\u4e09\u5143\u7ec4\u3002&quot;)\n                failed_chunks.append({\n                    &#039;chunk_number&#039;: chunk[&#039;chunk_number&#039;],\n                    &#039;error&#039;: &#039;\u672a\u80fd\u89e3\u6790\u51fa\u6709\u6548\u7684 JSON \u5217\u8868&#039;,\n                    &#039;response&#039;: raw_response\n                })\n\n        except Exception as e:\n            print(f&quot;\u5904\u7406\u5757 {chunk[&#039;chunk_number&#039;]} \u65f6\u53d1\u751f\u9519\u8bef\uff1a{e}&quot;)\n            failed_chunks.append({\n                &#039;chunk_number&#039;: chunk[&#039;chunk_number&#039;],\n                &#039;error&#039;: str(e),\n                &#039;response&#039;: raw_response or &#039;\u8bf7\u6c42\u5931\u8d25\uff0c\u65e0\u54cd\u5e94&#039;\n            })\n\n        # \u6253\u5370\u5f53\u524d\u7d2f\u8ba1\u7ed3\u679c\n        print(f&quot;\\n--- \u5f53\u524d\u7d2f\u8ba1\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\u603b\u6570: {len(all_extracted_triples)} ---&quot;)\n        print(f&quot;--- \u5230\u76ee\u524d\u4e3a\u6b62\u5931\u8d25\u7684\u5757\u6570: {len(failed_chunks)} ---&quot;)\n        print(f&quot;\\n\u5b8c\u6210\u5904\u7406\u5757 {chunk[&#039;chunk_number&#039;]}\u3002&quot;)\n\nelif not client:\n    print(&quot;\u9519\u8bef\uff1aLLM \u5ba2\u6237\u7aef\u672a\u521d\u59cb\u5316\u3002\u65e0\u6cd5\u5904\u7406\u5757\u3002&quot;)\n\nelse:\n    print(&quot;\u6ca1\u6709\u53ef\u5904\u7406\u7684\u5757\u3002&quot;)\n<\/code><\/pre>\n<pre><code>--- \u6b63\u5728\u5904\u7406\u5757 1\/6 ---\n1. \u683c\u5f0f\u5316\u7528\u6237\u63d0\u793a...\n2. \u5411 LLM \u53d1\u9001\u8bf7\u6c42...\n   LLM \u54cd\u5e94\u5df2\u63a5\u6536\u3002\n3. \u63d0\u53d6\u539f\u59cb\u54cd\u5e94\u5185\u5bb9...\n\n--- \u539f\u59cb LLM \u8f93\u51fa (\u5757 1) ---\n{\"subject\":\"\u8d3e\u6f14\",\"predicate\":\"has child\",\"object\":\"\u8d3e\u4ee3\u5316\"}\n---------------\n\n4. \u5c1d\u8bd5\u4ece\u54cd\u5e94\u4e2d\u89e3\u6790 JSON...\n   \u6210\u529f\u89e3\u6790 JSON \u5217\u8868\uff08\u6216\u5c06\u5176\u8f6c\u6362\/\u627e\u5230\uff09\u3002\u5305\u542b 1 \u4e2a\u9879\u76ee\u3002\n\n5. \u9a8c\u8bc1\u7ed3\u6784\u5e76\u63d0\u53d6\u4e09\u5143\u7ec4...\n   \u5728\u6b64\u5757\u4e2d\u627e\u5230 1 \u4e2a\u6709\u6548\u4e09\u5143\u7ec4\u3002\n   --- \u63d0\u53d6\u7684\u6709\u6548\u4e09\u5143\u7ec4 (\u5757 1) ---<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>subject<\/th>\n<th>predicate<\/th>\n<th>object<\/th>\n<th>chunk<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>\u8d3e\u6f14<\/td>\n<td>has child<\/td>\n<td>\u8d3e\u4ee3\u5316<\/td>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u200b<br \/>\n--- \u5f53\u524d\u7d2f\u8ba1\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\u603b\u6570: 1 ---<br \/>\n--- \u5230\u76ee\u524d\u4e3a\u6b62\u5931\u8d25\u7684\u5757\u6570: 0 ---<\/p>\n<pre><code>\u5b8c\u6210\u5904\u7406\u5757 1\u3002\n\n--- \u6b63\u5728\u5904\u7406\u5757 2\/6 ---\n1. \u683c\u5f0f\u5316\u7528\u6237\u63d0\u793a...\n2. \u5411 LLM \u53d1\u9001\u8bf7\u6c42...\n   LLM \u54cd\u5e94\u5df2\u63a5\u6536\u3002\n3. \u63d0\u53d6\u539f\u59cb\u54cd\u5e94\u5185\u5bb9...\n\n--- \u539f\u59cb LLM \u8f93\u51fa (\u5757 2) ---\n{\"subject\":\"jia yingchun\",\"predicate\":\"is a\",\"object\":\"regional daughter\"}\n---------------\n\n4. \u5c1d\u8bd5\u4ece\u54cd\u5e94\u4e2d\u89e3\u6790 JSON...\n   \u6210\u529f\u89e3\u6790 JSON \u5217\u8868\uff08\u6216\u5c06\u5176\u8f6c\u6362\/\u627e\u5230\uff09\u3002\u5305\u542b 1 \u4e2a\u9879\u76ee\u3002\n\n5. \u9a8c\u8bc1\u7ed3\u6784\u5e76\u63d0\u53d6\u4e09\u5143\u7ec4...\n   \u5728\u6b64\u5757\u4e2d\u627e\u5230 1 \u4e2a\u6709\u6548\u4e09\u5143\u7ec4\u3002\n   --- \u63d0\u53d6\u7684\u6709\u6548\u4e09\u5143\u7ec4 (\u5757 2) ---<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>subject<\/th>\n<th>predicate<\/th>\n<th>object<\/th>\n<th>chunk<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>jia yingchun<\/td>\n<td>is a<\/td>\n<td>regional daughter<\/td>\n<td>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u200b<br \/>\n--- \u5f53\u524d\u7d2f\u8ba1\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\u603b\u6570: 2 ---<br \/>\n--- \u5230\u76ee\u524d\u4e3a\u6b62\u5931\u8d25\u7684\u5757\u6570: 0 ---<\/p>\n<pre><code>\u5b8c\u6210\u5904\u7406\u5757 2\u3002\n\n--- \u6b63\u5728\u5904\u7406\u5757 3\/6 ---\n1. \u683c\u5f0f\u5316\u7528\u6237\u63d0\u793a...\n2. \u5411 LLM \u53d1\u9001\u8bf7\u6c42...\n   LLM \u54cd\u5e94\u5df2\u63a5\u6536\u3002\n3. \u63d0\u53d6\u539f\u59cb\u54cd\u5e94\u5185\u5bb9...\n\n--- \u539f\u59cb LLM \u8f93\u51fa (\u5757 3) ---\n{\"subject\":\"\u6797\u9edb\u7389\",\"predicate\":\"is the reincarnation of\",\"object\":\"glazed pearl fairy grass\"}\n---------------\n\n4. \u5c1d\u8bd5\u4ece\u54cd\u5e94\u4e2d\u89e3\u6790 JSON...\n   \u6210\u529f\u89e3\u6790 JSON \u5217\u8868\uff08\u6216\u5c06\u5176\u8f6c\u6362\/\u627e\u5230\uff09\u3002\u5305\u542b 1 \u4e2a\u9879\u76ee\u3002\n\n5. \u9a8c\u8bc1\u7ed3\u6784\u5e76\u63d0\u53d6\u4e09\u5143\u7ec4...\n   \u5728\u6b64\u5757\u4e2d\u627e\u5230 1 \u4e2a\u6709\u6548\u4e09\u5143\u7ec4\u3002\n   --- \u63d0\u53d6\u7684\u6709\u6548\u4e09\u5143\u7ec4 (\u5757 3) ---<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>subject<\/th>\n<th>predicate<\/th>\n<th>object<\/th>\n<th>chunk<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>\u6797\u9edb\u7389<\/td>\n<td>is the reincarnation of<\/td>\n<td>glazed pearl fairy grass<\/td>\n<td>3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u200b<br \/>\n--- \u5f53\u524d\u7d2f\u8ba1\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\u603b\u6570: 3 ---<br \/>\n--- \u5230\u76ee\u524d\u4e3a\u6b62\u5931\u8d25\u7684\u5757\u6570: 0 ---<\/p>\n<pre><code>\u5b8c\u6210\u5904\u7406\u5757 3\u3002\n\n--- \u6b63\u5728\u5904\u7406\u5757 4\/6 ---\n1. \u683c\u5f0f\u5316\u7528\u6237\u63d0\u793a...\n2. \u5411 LLM \u53d1\u9001\u8bf7\u6c42...\n   LLM \u54cd\u5e94\u5df2\u63a5\u6536\u3002\n3. \u63d0\u53d6\u539f\u59cb\u54cd\u5e94\u5185\u5bb9...\n\n--- \u539f\u59cb LLM \u8f93\u51fa (\u5757 4) ---\n{\"subject\":\"\u63a2\u6625\",\"predicate\":\"implemented\",\"object\":\"contract system in great view garden\"}\n---------------\n\n4. \u5c1d\u8bd5\u4ece\u54cd\u5e94\u4e2d\u89e3\u6790 JSON...\n   \u6210\u529f\u89e3\u6790 JSON \u5217\u8868\uff08\u6216\u5c06\u5176\u8f6c\u6362\/\u627e\u5230\uff09\u3002\u5305\u542b 1 \u4e2a\u9879\u76ee\u3002\n\n5. \u9a8c\u8bc1\u7ed3\u6784\u5e76\u63d0\u53d6\u4e09\u5143\u7ec4...\n   \u5728\u6b64\u5757\u4e2d\u627e\u5230 1 \u4e2a\u6709\u6548\u4e09\u5143\u7ec4\u3002\n   --- \u63d0\u53d6\u7684\u6709\u6548\u4e09\u5143\u7ec4 (\u5757 4) ---<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>subject<\/th>\n<th>predicate<\/th>\n<th>object<\/th>\n<th>chunk<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>\u63a2\u6625<\/td>\n<td>implemented<\/td>\n<td>contract system in great view garden<\/td>\n<td>4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u200b<br \/>\n--- \u5f53\u524d\u7d2f\u8ba1\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\u603b\u6570: 4 ---<br \/>\n--- \u5230\u76ee\u524d\u4e3a\u6b62\u5931\u8d25\u7684\u5757\u6570: 0 ---<\/p>\n<pre><code>\u5b8c\u6210\u5904\u7406\u5757 4\u3002\n\n--- \u6b63\u5728\u5904\u7406\u5757 5\/6 ---\n1. \u683c\u5f0f\u5316\u7528\u6237\u63d0\u793a...\n2. \u5411 LLM \u53d1\u9001\u8bf7\u6c42...\n   LLM \u54cd\u5e94\u5df2\u63a5\u6536\u3002\n3. \u63d0\u53d6\u539f\u59cb\u54cd\u5e94\u5185\u5bb9...\n\n--- \u539f\u59cb LLM \u8f93\u51fa (\u5757 5) ---\n{\"subject\":\"daiyu\",\"predicate\":\"has talent\",\"object\":\"buried\"}\n---------------\n\n4. \u5c1d\u8bd5\u4ece\u54cd\u5e94\u4e2d\u89e3\u6790 JSON...\n   \u6210\u529f\u89e3\u6790 JSON \u5217\u8868\uff08\u6216\u5c06\u5176\u8f6c\u6362\/\u627e\u5230\uff09\u3002\u5305\u542b 1 \u4e2a\u9879\u76ee\u3002\n\n5. \u9a8c\u8bc1\u7ed3\u6784\u5e76\u63d0\u53d6\u4e09\u5143\u7ec4...\n   \u5728\u6b64\u5757\u4e2d\u627e\u5230 1 \u4e2a\u6709\u6548\u4e09\u5143\u7ec4\u3002\n   --- \u63d0\u53d6\u7684\u6709\u6548\u4e09\u5143\u7ec4 (\u5757 5) ---<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>subject<\/th>\n<th>predicate<\/th>\n<th>object<\/th>\n<th>chunk<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>daiyu<\/td>\n<td>has talent<\/td>\n<td>buried<\/td>\n<td>5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u200b<br \/>\n--- \u5f53\u524d\u7d2f\u8ba1\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\u603b\u6570: 5 ---<br \/>\n--- \u5230\u76ee\u524d\u4e3a\u6b62\u5931\u8d25\u7684\u5757\u6570: 0 ---<\/p>\n<pre><code>\u5b8c\u6210\u5904\u7406\u5757 5\u3002\n\n--- \u6b63\u5728\u5904\u7406\u5757 6\/6 ---\n1. \u683c\u5f0f\u5316\u7528\u6237\u63d0\u793a...\n2. \u5411 LLM \u53d1\u9001\u8bf7\u6c42...\n   LLM \u54cd\u5e94\u5df2\u63a5\u6536\u3002\n3. \u63d0\u53d6\u539f\u59cb\u54cd\u5e94\u5185\u5bb9...\n\n--- \u539f\u59cb LLM \u8f93\u51fa (\u5757 6) ---\n{\"subject\":\"\u5927\u89c2\u56ed\",\"predicate\":\"contains\",\"object\":\"\u6f47\u6e58\u9986\"}\n---------------\n\n4. \u5c1d\u8bd5\u4ece\u54cd\u5e94\u4e2d\u89e3\u6790 JSON...\n   \u6210\u529f\u89e3\u6790 JSON \u5217\u8868\uff08\u6216\u5c06\u5176\u8f6c\u6362\/\u627e\u5230\uff09\u3002\u5305\u542b 1 \u4e2a\u9879\u76ee\u3002\n\n5. \u9a8c\u8bc1\u7ed3\u6784\u5e76\u63d0\u53d6\u4e09\u5143\u7ec4...\n   \u5728\u6b64\u5757\u4e2d\u627e\u5230 1 \u4e2a\u6709\u6548\u4e09\u5143\u7ec4\u3002\n   --- \u63d0\u53d6\u7684\u6709\u6548\u4e09\u5143\u7ec4 (\u5757 6) ---<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>subject<\/th>\n<th>predicate<\/th>\n<th>object<\/th>\n<th>chunk<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>\u5927\u89c2\u56ed<\/td>\n<td>contains<\/td>\n<td>\u6f47\u6e58\u9986<\/td>\n<td>6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u200b<br \/>\n--- \u5f53\u524d\u7d2f\u8ba1\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\u603b\u6570: 6 ---<br \/>\n--- \u5230\u76ee\u524d\u4e3a\u6b62\u5931\u8d25\u7684\u5757\u6570: 0 ---<\/p>\n<pre><code>\u5b8c\u6210\u5904\u7406\u5757 6\u3002<\/code><\/pre>\n<pre><code class=\"language-python\"># ===== \u63d0\u53d6\u8fc7\u7a0b\u603b\u7ed3 (\u53cd\u6620\u5355\u6570\u636e\u5757\u6f14\u793a\u540e \/ \u6216\u5b8c\u6574\u8fd0\u884c\u540e\u7684\u72b6\u6001) =====\nprint(f&quot;\\n===== \u6574\u4f53\u63d0\u53d6\u603b\u7ed3 =====\\n&quot;)\nprint(f&quot;\u5b9a\u4e49\u7684\u603b\u6570\u636e\u5757\u6570: {len(chunks)}&quot;)\nprint(f&quot;\u5df2\u5904\u7406 (\u5c1d\u8bd5\u5904\u7406) \u7684\u6570\u636e\u5757\u6570: {len(chunks)}&quot;) # \u6211\u4eec\u5faa\u73af\u904d\u5386\u7684\u6570\u636e\u5757\nprint(f&quot;\u6240\u6709\u5df2\u5904\u7406\u6570\u636e\u5757\u4e2d\u63d0\u53d6\u7684\u6709\u6548\u4e09\u5143\u7ec4\u603b\u6570: {len(all_extracted_triples)}&quot;)\nprint(f&quot;API \u8c03\u7528\u6216\u89e3\u6790\u5931\u8d25\u7684\u6570\u636e\u5757\u6570\u91cf: {len(failed_chunks)}&quot;)\n\nif failed_chunks:\n    print(&quot;\\n\u5931\u8d25\u6570\u636e\u5757\u8be6\u60c5:&quot;)\n    failed_df = pd.DataFrame(failed_chunks)\n    display(failed_df[[&#039;chunk_number&#039;, &#039;error&#039;]]) # \u6e05\u6670\u5c55\u793a\u5931\u8d25\u7684\u6570\u636e\u5757\n    # for failure in failed_chunks:\n    #     print(f&quot;  \u6570\u636e\u5757 {failure[&#039;chunk_number&#039;]}: \u9519\u8bef: {failure[&#039;error&#039;]}&quot;)\nprint(&quot;-&quot; * 25)\n\n# \u4f7f\u7528 Pandas \u5c55\u793a\u6240\u6709\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\nprint(&quot;\\n===== \u6240\u6709\u63d0\u53d6\u7684\u4e09\u5143\u7ec4 (\u89c4\u8303\u5316\u4e4b\u524d) =====\\n&quot;)\nif all_extracted_triples:\n    all_triples_df = pd.DataFrame(all_extracted_triples)\n    display(all_triples_df)\nelse:\n    print(&quot;\u672a\u80fd\u6210\u529f\u63d0\u53d6\u4efb\u4f55\u4e09\u5143\u7ec4\u3002&quot;)\nprint(&quot;-&quot; * 25)<\/code><\/pre>\n<pre><code>===== \u6574\u4f53\u63d0\u53d6\u603b\u7ed3 =====\n\n\u5b9a\u4e49\u7684\u603b\u6570\u636e\u5757\u6570: 6\n\u5df2\u5904\u7406 (\u5c1d\u8bd5\u5904\u7406) \u7684\u6570\u636e\u5757\u6570: 6\n\u6240\u6709\u5df2\u5904\u7406\u6570\u636e\u5757\u4e2d\u63d0\u53d6\u7684\u6709\u6548\u4e09\u5143\u7ec4\u603b\u6570: 6\nAPI \u8c03\u7528\u6216\u89e3\u6790\u5931\u8d25\u7684\u6570\u636e\u5757\u6570\u91cf: 0\n-------------------------\n\n===== \u6240\u6709\u63d0\u53d6\u7684\u4e09\u5143\u7ec4 (\u89c4\u8303\u5316\u4e4b\u524d) =====<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>subject<\/th>\n<th>predicate<\/th>\n<th>object<\/th>\n<th>chunk<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>\u8d3e\u6f14<\/td>\n<td>has child<\/td>\n<td>\u8d3e\u4ee3\u5316<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>jia yingchun<\/td>\n<td>is a<\/td>\n<td>regional daughter<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>\u6797\u9edb\u7389<\/td>\n<td>is the reincarnation of<\/td>\n<td>glazed pearl fairy grass<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>\u63a2\u6625<\/td>\n<td>implemented<\/td>\n<td>contract system in great view garden<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>daiyu<\/td>\n<td>has talent<\/td>\n<td>buried<\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>\u5927\u89c2\u56ed<\/td>\n<td>contains<\/td>\n<td>\u6f47\u6e58\u9986<\/td>\n<td>6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<pre><code>-------------------------<\/code><\/pre>\n<pre><code class=\"language-python\">normalized_triples = []\nseen_triples = set() # \u7528\u4e8e\u8ddf\u8e2a (subject, predicate, object) \u5143\u7ec4\noriginal_count = len(all_extracted_triples)\nempty_removed_count = 0\nduplicates_removed_count = 0\n\nprint(f&quot;\u5f00\u59cb\u5bf9 {original_count} \u4e2a\u4e09\u5143\u7ec4\u8fdb\u884c\u89c4\u8303\u5316\u548c\u53bb\u91cd\u5904\u7406...&quot;)\n\n#### \u8f93\u51fa ####<\/code><\/pre>\n<pre><code>\u5f00\u59cb\u5bf9 6 \u4e2a\u4e09\u5143\u7ec4\u8fdb\u884c\u89c4\u8303\u5316\u548c\u53bb\u91cd\u5904\u7406...<\/code><\/pre>\n<pre><code class=\"language-python\">print(&quot;\u6b63\u5728\u5904\u7406\u4e09\u5143\u7ec4 (\u5c55\u793a\u524d 5 \u4e2a):&quot;)\n\nfor i, t in enumerate(all_extracted_triples):\n    # \u63d0\u53d6\u4e3b\u8bed\u3001\u8c13\u8bed\u548c\u5bbe\u8bed\uff1b\u53bb\u9664\u9996\u5c3e\u7a7a\u683c\u5e76\u8f6c\u6362\u4e3a\u5c0f\u5199\uff1b\u5982\u679c\u4e0d\u662f\u5b57\u7b26\u4e32\uff0c\u5219\u8bbe\u7f6e\u4e3a\u7a7a\u5b57\u7b26\u4e32\n    s, p, o = [\n        t.get(k, &#039;&#039;).strip().lower() if isinstance(t.get(k), str) else &#039;&#039;\n        for k in [&#039;subject&#039;, &#039;predicate&#039;, &#039;object&#039;]\n    ]\n\n    # \u5c06\u8c13\u8bed\u4e2d\u7684\u591a\u4e2a\u7a7a\u683c\u66ff\u6362\u4e3a\u5355\u4e2a\u7a7a\u683c\n    p = re.sub(r&#039;\\s+&#039;, &#039; &#039;, p)\n\n    # \u786e\u4fdd\u4e3b\u8bed\u3001\u8c13\u8bed\u3001\u5bbe\u8bed\u90fd\u4e0d\u4e3a\u7a7a\n    if all([s, p, o]):\n        key = (s, p, o)  # \u521b\u5efa\u7528\u4e8e\u68c0\u67e5\u91cd\u590d\u7684\u952e\n\n        if key not in seen_triples:  # \u5982\u679c\u8fd9\u4e2a\u4e09\u5143\u7ec4\u662f\u65b0\u7684\n            normalized_triples.append({\n                &#039;subject&#039;: s,\n                &#039;predicate&#039;: p,\n                &#039;object&#039;: o,\n                &#039;source_chunk&#039;: t.get(&#039;chunk&#039;, &#039;?&#039;)\n            })\n            seen_triples.add(key)  # \u8bb0\u5f55\u4e0b\u6765\uff0c\u907f\u514d\u91cd\u590d\n\n            if i &lt; 5:  # \u6253\u5370\u524d 5 \u4e2a\u7684\u5904\u7406\u4fe1\u606f\n                print(f&quot;\\n#{i + 1}: {key}\\n\u72b6\u6001: \u4fdd\u7559&quot;)\n\n        else:  # \u5982\u679c\u662f\u91cd\u590d\u7684\n            duplicates_removed_count += 1\n            if i &lt; 5:\n                print(f&quot;\\n#{i + 1}: \u91cd\u590d - \u8df3\u8fc7&quot;)\n\n    else:  # \u5982\u679c\u6e05\u7406\u540e\u6709\u7a7a\u7684\u90e8\u5206\n        empty_removed_count += 1\n        if i &lt; 5:\n            print(f&quot;\\n#{i + 1}: \u65e0\u6548 - \u8df3\u8fc7&quot;)\n\nprint(f&quot;\\n\u5904\u7406\u5b8c\u6210\u3002\u603b\u8ba1: {len(all_extracted_triples)}, \u4fdd\u7559: {len(normalized_triples)}, \u91cd\u590d: {duplicates_removed_count}, \u7a7a\u503c: {empty_removed_count}&quot;)\n<\/code><\/pre>\n<pre><code>\u6b63\u5728\u5904\u7406\u4e09\u5143\u7ec4 (\u5c55\u793a\u524d 5 \u4e2a):\n\n#1: ('\u8d3e\u6f14', 'has child', '\u8d3e\u4ee3\u5316')\n\u72b6\u6001: \u4fdd\u7559\n\n#2: ('jia yingchun', 'is a', 'regional daughter')\n\u72b6\u6001: \u4fdd\u7559\n\n#3: ('\u6797\u9edb\u7389', 'is the reincarnation of', 'glazed pearl fairy grass')\n\u72b6\u6001: \u4fdd\u7559\n\n#4: ('\u63a2\u6625', 'implemented', 'contract system in great view garden')\n\u72b6\u6001: \u4fdd\u7559\n\n#5: ('daiyu', 'has talent', 'buried')\n\u72b6\u6001: \u4fdd\u7559\n\n\u5904\u7406\u5b8c\u6210\u3002\u603b\u8ba1: 6, \u4fdd\u7559: 6, \u91cd\u590d: 0, \u7a7a\u503c: 0<\/code><\/pre>\n<pre><code class=\"language-python\">print(f&quot;\\n===== \u89c4\u8303\u5316\u4e0e\u53bb\u91cd\u603b\u7ed3 =====\\n&quot;)\nprint(f&quot;\u539f\u59cb\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\u6570\u91cf: {original_count}\\n&quot;)\nprint(f&quot;\u56e0\u5305\u542b\u7a7a\/\u65e0\u6548\u90e8\u5206\u800c\u88ab\u79fb\u9664\u7684\u4e09\u5143\u7ec4\u6570\u91cf: {empty_removed_count}\\n&quot;)\nprint(f&quot;\u88ab\u79fb\u9664\u7684\u91cd\u590d\u4e09\u5143\u7ec4\u6570\u91cf: {duplicates_removed_count}\\n&quot;)\nfinal_count = len(normalized_triples)\nprint(f&quot;\u6700\u7ec8\u552f\u4e00\u7684\u3001\u89c4\u8303\u5316\u540e\u7684\u4e09\u5143\u7ec4\u6570\u91cf: {final_count}\\n&quot;)\nprint(&quot;-&quot; * 25)\n\n# \u4f7f\u7528 Pandas \u5c55\u793a\u89c4\u8303\u5316\u540e\u4e09\u5143\u7ec4\u7684\u6837\u672c\nprint(&quot;\\n===== \u6700\u7ec8\u89c4\u8303\u5316\u540e\u7684\u4e09\u5143\u7ec4 =====\\n&quot;)\nif normalized_triples:\n    normalized_df = pd.DataFrame(normalized_triples)\n    display(normalized_df)\nelse:\n    print(&quot;\u89c4\u8303\u5316\u540e\u6ca1\u6709\u5269\u4f59\u7684\u6709\u6548\u4e09\u5143\u7ec4\u3002&quot;)\nprint(&quot;-&quot; * 25)\n\n#### \u8f93\u51fa ####<\/code><\/pre>\n<pre><code>===== \u89c4\u8303\u5316\u4e0e\u53bb\u91cd\u603b\u7ed3 =====\n\n\u539f\u59cb\u63d0\u53d6\u7684\u4e09\u5143\u7ec4\u6570\u91cf: 6\n\n\u56e0\u5305\u542b\u7a7a\/\u65e0\u6548\u90e8\u5206\u800c\u88ab\u79fb\u9664\u7684\u4e09\u5143\u7ec4\u6570\u91cf: 0\n\n\u88ab\u79fb\u9664\u7684\u91cd\u590d\u4e09\u5143\u7ec4\u6570\u91cf: 0\n\n\u6700\u7ec8\u552f\u4e00\u7684\u3001\u89c4\u8303\u5316\u540e\u7684\u4e09\u5143\u7ec4\u6570\u91cf: 6\n\n-------------------------\n\n===== \u6700\u7ec8\u89c4\u8303\u5316\u540e\u7684\u4e09\u5143\u7ec4 =====<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>subject<\/th>\n<th>predicate<\/th>\n<th>object<\/th>\n<th>source_chunk<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>\u8d3e\u6f14<\/td>\n<td>has child<\/td>\n<td>\u8d3e\u4ee3\u5316<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>jia yingchun<\/td>\n<td>is a<\/td>\n<td>regional daughter<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>\u6797\u9edb\u7389<\/td>\n<td>is the reincarnation of<\/td>\n<td>glazed pearl fairy grass<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>\u63a2\u6625<\/td>\n<td>implemented<\/td>\n<td>contract system in great view garden<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>daiyu<\/td>\n<td>has talent<\/td>\n<td>buried<\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>\u5927\u89c2\u56ed<\/td>\n<td>contains<\/td>\n<td>\u6f47\u6e58\u9986<\/td>\n<td>6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<pre><code>-------------------------<\/code><\/pre>\n<pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u6709\u5411\u56fe\nknowledge_graph = nx.DiGraph()\n\nprint(&quot;\u5df2\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u7684 NetworkX DiGraph\u3002&quot;)\n# \u53ef\u89c6\u5316\u521d\u59cb\u7a7a\u56fe\u72b6\u6001\nprint(&quot;===== \u521d\u59cb\u56fe\u4fe1\u606f =====\\n&quot;)\ntry:\n    # \u5c1d\u8bd5\u4f7f\u7528\u8f83\u65b0\u7248\u672c\u7684\u65b9\u6cd5\n    print(nx.info(knowledge_graph))\nexcept AttributeError:\n    # \u517c\u5bb9\u4e0d\u540c NetworkX \u7248\u672c\u7684\u5907\u9009\u65b9\u6cd5\n    print(f&quot;\u7c7b\u578b: {type(knowledge_graph).__name__}&quot;)\n    print(f&quot;\u8282\u70b9\u6570: {knowledge_graph.number_of_nodes()}&quot;)\n    print(f&quot;\u8fb9\u6570: {knowledge_graph.number_of_edges()}&quot;)\nprint(&quot;-&quot; * 25)\n<\/code><\/pre>\n<pre><code>\u5df2\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u7684 NetworkX DiGraph\u3002\n===== \u521d\u59cb\u56fe\u4fe1\u606f =====\n\n\u7c7b\u578b: DiGraph\n\u8282\u70b9\u6570: 0\n\u8fb9\u6570: 0\n-------------------------<\/code><\/pre>\n<pre><code class=\"language-python\">print(&quot;\u6b63\u5728\u5c06\u4e09\u5143\u7ec4\u6dfb\u52a0\u5230 NetworkX \u56fe\u4e2d...&quot;)\n\nadded_edges_count = 0\nupdate_interval = 10# \u6253\u5370\u56fe\u4fe1\u606f\u66f4\u65b0\u7684\u9891\u7387\n\nif not normalized_triples:\n    print(&quot;\u8b66\u544a\uff1a\u6ca1\u6709\u89c4\u8303\u5316\u540e\u7684\u4e09\u5143\u7ec4\u53ef\u6dfb\u52a0\u5230\u56fe\u4e2d\u3002&quot;)\nelse:\n    for i, triple in enumerate(normalized_triples):\n        subject_node = triple[&#039;subject&#039;]\n        object_node = triple[&#039;object&#039;]\n        predicate_label = triple[&#039;predicate&#039;]\n\n        # \u6dfb\u52a0\u8fb9\u65f6\u4f1a\u81ea\u52a8\u6dfb\u52a0\u8282\u70b9\uff0c\u4f46\u663e\u5f0f\u8c03\u7528 add_node \u4e5f\u53ef\u4ee5 \n        # knowledge_graph.add_node(subject_node)\n        # knowledge_graph.add_node(object_node)\n\n        # \u6dfb\u52a0\u5e26\u6709\u8c13\u8bed\u4f5c\u4e3a &#039;label&#039; \u5c5e\u6027\u7684\u6709\u5411\u8fb9\n        knowledge_graph.add_edge(subject_node, object_node, label=predicate_label)\n        added_edges_count += 1\n\n        # ===== \u53ef\u89c6\u5316\u56fe\u7684\u589e\u957f =====\n        if (i + 1) % update_interval == 0 or (i + 1) == len(normalized_triples):\n            print(f&quot;\\n===== \u6dfb\u52a0\u7b2c {i+1} \u4e2a\u4e09\u5143\u7ec4\u540e\u7684\u56fe\u4fe1\u606f ===== ({subject_node} -&gt; {object_node})&quot;)\n            try:\n                # \u5c1d\u8bd5\u4f7f\u7528\u8f83\u65b0\u7248\u672c\u7684\u65b9\u6cd5\n                print(nx.info(knowledge_graph))\n            except AttributeError:\n                # \u517c\u5bb9\u4e0d\u540c NetworkX \u7248\u672c\u7684\u5907\u9009\u65b9\u6cd5\n                print(f&quot;\u7c7b\u578b: {type(knowledge_graph).__name__}&quot;)\n                print(f&quot;\u8282\u70b9\u6570: {knowledge_graph.number_of_nodes()}&quot;)\n                print(f&quot;\u8fb9\u6570: {knowledge_graph.number_of_edges()}&quot;)\n            # \u5bf9\u4e8e\u975e\u5e38\u5927\u7684\u56fe\uff0c\u8fc7\u4e8e\u9891\u7e41\u5730\u6253\u5370\u4fe1\u606f\u53ef\u80fd\u4f1a\u5f88\u6162\uff0c\u8bf7\u8c03\u6574 update_interval\u3002\n\nprint(f&quot;\\n\u5b8c\u6210\u6dfb\u52a0\u4e09\u5143\u7ec4\u3002\u5171\u5904\u7406\u4e86 {added_edges_count} \u6761\u8fb9\u3002&quot;)<\/code><\/pre>\n<pre><code>\u6b63\u5728\u5c06\u4e09\u5143\u7ec4\u6dfb\u52a0\u5230 NetworkX \u56fe\u4e2d...\n\n===== \u6dfb\u52a0\u7b2c 6 \u4e2a\u4e09\u5143\u7ec4\u540e\u7684\u56fe\u4fe1\u606f ===== (\u5927\u89c2\u56ed -> \u6f47\u6e58\u9986)\n\u7c7b\u578b: DiGraph\n\u8282\u70b9\u6570: 12\n\u8fb9\u6570: 6\n\n\u5b8c\u6210\u6dfb\u52a0\u4e09\u5143\u7ec4\u3002\u5171\u5904\u7406\u4e86 6 \u6761\u8fb9\u3002<\/code><\/pre>\n<pre><code class=\"language-python\"># ===== \u6700\u7ec8\u56fe\u7edf\u8ba1 =====\nnum_nodes = knowledge_graph.number_of_nodes()\nnum_edges = knowledge_graph.number_of_edges()\n\nprint(f&quot;\\n===== \u6700\u7ec8 NetworkX \u56fe\u603b\u7ed3 =====\\n&quot;)\nprint(f&quot;\u603b\u552f\u4e00\u8282\u70b9\u6570 (\u5b9e\u4f53): {num_nodes}&quot;)\nprint(f&quot;\u603b\u552f\u4e00\u8fb9\u6570 (\u5173\u7cfb): {num_edges}&quot;)\n\nif num_edges != added_edges_count and isinstance(knowledge_graph, nx.DiGraph):\n     print(f&quot;\u6ce8\u610f: \u6dfb\u52a0\u4e86 {added_edges_count} \u6761\u8fb9\uff0c\u4f46\u56fe\u4e2d\u53ea\u6709 {num_edges} \u6761\u3002DiGraph \u4f1a\u8986\u76d6\u5177\u6709\u76f8\u540c\u6e90\u8282\u70b9\u548c\u76ee\u6807\u8282\u70b9\u7684\u8fb9\u3002\u5982\u679c\u9700\u8981\u4fdd\u7559\u591a\u6761\u76f8\u540c\u65b9\u5411\u7684\u8fb9\uff0c\u8bf7\u4f7f\u7528 MultiDiGraph\u3002&quot;)\n\nif num_nodes &gt; 0:\n    try:\n       density = nx.density(knowledge_graph) # \u56fe\u5bc6\u5ea6\uff1a\u8861\u91cf\u56fe\u7684\u8fde\u63a5\u7d27\u5bc6\u7a0b\u5ea6\n       print(f&quot;\u56fe\u5bc6\u5ea6: {density:.4f}&quot;)\n       if nx.is_weakly_connected(knowledge_graph): # \u5f31\u8fde\u901a\uff1a\u5ffd\u7565\u8fb9\u7684\u65b9\u5411\uff0c\u56fe\u4e2d\u6240\u6709\u8282\u70b9\u662f\u5426\u90fd\u76f8\u4e92\u53ef\u8fbe\uff1f\n           print(&quot;\u8be5\u56fe\u662f\u5f31\u8fde\u901a\u7684 (\u5ffd\u7565\u65b9\u5411\uff0c\u6240\u6709\u8282\u70b9\u90fd\u53ef\u8fbe)\u3002&quot;)\n       else:\n           num_components = nx.number_weakly_connected_components(knowledge_graph) # \u5f31\u8fde\u901a\u5206\u91cf\u7684\u6570\u91cf\n           print(f&quot;\u8be5\u56fe\u5305\u542b {num_components} \u4e2a\u5f31\u8fde\u901a\u5206\u91cf\u3002&quot;)\n    except Exception as e:\n        print(f&quot;\u65e0\u6cd5\u8ba1\u7b97\u67d0\u4e9b\u56fe\u6307\u6807: {e}&quot;) # \u5904\u7406\u7a7a\u56fe\u6216\u5c0f\u56fe\u53ef\u80fd\u51fa\u73b0\u7684\u9519\u8bef\nelse:\n    print(&quot;\u56fe\u4e3a\u7a7a\uff0c\u65e0\u6cd5\u8ba1\u7b97\u6307\u6807\u3002&quot;)\nprint(&quot;-&quot; * 25)\n\n# ===== \u8282\u70b9\u6837\u672c =====\nprint(&quot;\\n===== \u8282\u70b9\u6837\u672c (\u524d 10 \u4e2a) =====\\n&quot;)\nif num_nodes &gt; 0:\n    nodes_sample = list(knowledge_graph.nodes())[:10]\n    display(pd.DataFrame(nodes_sample, columns=[&#039;\u8282\u70b9\u6837\u672c&#039;]))\nelse:\n    print(&quot;\u56fe\u4e2d\u6ca1\u6709\u8282\u70b9\u3002&quot;)\n\n# ===== \u8fb9\u6837\u672c =====\nprint(&quot;\\n===== \u8fb9\u6837\u672c (\u524d 10 \u4e2a\uff0c\u5e26\u6807\u7b7e) =====\\n&quot;)\nif num_edges &gt; 0:\n    edges_sample = []\n    # \u63d0\u53d6\u524d10\u6761\u8fb9\u53ca\u5176\u6570\u636e\uff08\u5305\u62ec\u6807\u7b7e\uff09\n    for u, v, data in list(knowledge_graph.edges(data=True))[:10]:\n        edges_sample.append({&#039;\u6e90\u8282\u70b9&#039;: u, &#039;\u76ee\u6807\u8282\u70b9&#039;: v, &#039;\u6807\u7b7e&#039;: data.get(&#039;label&#039;, &#039;N\/A&#039;)})\n    display(pd.DataFrame(edges_sample))\nelse:\n    print(&quot;\u56fe\u4e2d\u6ca1\u6709\u8fb9\u3002&quot;)\nprint(&quot;-&quot; * 25)\n<\/code><\/pre>\n<pre><code>===== \u6700\u7ec8 NetworkX \u56fe\u603b\u7ed3 =====\n\n\u603b\u552f\u4e00\u8282\u70b9\u6570 (\u5b9e\u4f53): 12\n\u603b\u552f\u4e00\u8fb9\u6570 (\u5173\u7cfb): 6\n\u56fe\u5bc6\u5ea6: 0.0455\n\u8be5\u56fe\u5305\u542b 6 \u4e2a\u5f31\u8fde\u901a\u5206\u91cf\u3002\n-------------------------\n\n===== \u8282\u70b9\u6837\u672c (\u524d 10 \u4e2a) =====<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u8282\u70b9\u6837\u672c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>\u8d3e\u6f14<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>\u8d3e\u4ee3\u5316<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>jia yingchun<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>regional daughter<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>\u6797\u9edb\u7389<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>glazed pearl fairy grass<\/td>\n<\/tr>\n<tr>\n<th>6<\/th>\n<td>\u63a2\u6625<\/td>\n<\/tr>\n<tr>\n<th>7<\/th>\n<td>contract system in great view garden<\/td>\n<\/tr>\n<tr>\n<th>8<\/th>\n<td>daiyu<\/td>\n<\/tr>\n<tr>\n<th>9<\/th>\n<td>buried<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u200b<br \/>\n===== \u8fb9\u6837\u672c (\u524d 10 \u4e2a\uff0c\u5e26\u6807\u7b7e) =====<\/p>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u6e90\u8282\u70b9<\/th>\n<th>\u76ee\u6807\u8282\u70b9<\/th>\n<th>\u6807\u7b7e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>\u8d3e\u6f14<\/td>\n<td>\u8d3e\u4ee3\u5316<\/td>\n<td>has child<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>jia yingchun<\/td>\n<td>regional daughter<\/td>\n<td>is a<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>\u6797\u9edb\u7389<\/td>\n<td>glazed pearl fairy grass<\/td>\n<td>is the reincarnation of<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>\u63a2\u6625<\/td>\n<td>contract system in great view garden<\/td>\n<td>implemented<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>daiyu<\/td>\n<td>buried<\/td>\n<td>has talent<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>\u5927\u89c2\u56ed<\/td>\n<td>\u6f47\u6e58\u9986<\/td>\n<td>contains<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<pre><code>-------------------------<\/code><\/pre>\n<pre><code class=\"language-python\">print(&quot;\u51c6\u5907\u4ea4\u4e92\u5f0f\u53ef\u89c6\u5316...&quot;)\n\n# ===== \u68c0\u67e5\u56fe\u662f\u5426\u6709\u6548\u4ee5\u8fdb\u884c\u53ef\u89c6\u5316 =====\ncan_visualize = False\n\n# \u68c0\u67e5\u53d8\u91cf\u662f\u5426\u5b58\u5728\uff0c\u7c7b\u578b\u662f\u5426\u4e3a nx.Graph\uff08\u542b DiGraph\u3001MultiGraph \u7b49\u5b50\u7c7b\uff09\nif &#039;knowledge_graph&#039; not in locals():\n    print(&quot;\u9519\u8bef: \u672a\u627e\u5230\u53d8\u91cf &#039;knowledge_graph&#039;\u3002&quot;)\nelif not isinstance(knowledge_graph, nx.Graph):\n    print(&quot;\u9519\u8bef: &#039;knowledge_graph&#039; \u4e0d\u662f NetworkX \u56fe\u5bf9\u8c61\u3002&quot;)\nelif knowledge_graph.number_of_nodes() == 0:\n    print(&quot;NetworkX \u56fe\u4e3a\u7a7a\uff0c\u65e0\u6cd5\u8fdb\u884c\u53ef\u89c6\u5316\u3002&quot;)\nelse:\n    num_nodes = knowledge_graph.number_of_nodes()\n    print(f&quot;\u56fe\u6709\u6548\uff0c\u53ef\u7528\u4e8e\u53ef\u89c6\u5316\uff0c\u5171\u5305\u542b {num_nodes} \u4e2a\u8282\u70b9\u3002&quot;)\n    can_visualize = True\n<\/code><\/pre>\n<pre><code>\u51c6\u5907\u4ea4\u4e92\u5f0f\u53ef\u89c6\u5316...\n\u56fe\u6709\u6548\uff0c\u53ef\u7528\u4e8e\u53ef\u89c6\u5316\uff0c\u5171\u5305\u542b 12 \u4e2a\u8282\u70b9\u3002<\/code><\/pre>\n<pre><code class=\"language-python\">import json\n\ncytoscape_nodes = []\ncytoscape_edges = []\n\nif can_visualize:\n    print(&quot;\u6b63\u5728\u8f6c\u6362\u8282\u70b9...&quot;)\n\n    # \u8ba1\u7b97\u8282\u70b9\u5ea6\u6570\uff0c\u7528\u4e8e\u8c03\u6574\u8282\u70b9\u5927\u5c0f\n    node_degrees = dict(knowledge_graph.degree())\n    max_degree = max(node_degrees.values()) if node_degrees else 1  # \u907f\u514d\u9664\u4ee5\u96f6\n\n    for node_id in knowledge_graph.nodes():\n        degree = node_degrees.get(node_id, 0)\n        node_size = 15 + (degree \/ max_degree) * 50 if max_degree &gt; 0 else 15\n\n        cytoscape_nodes.append({\n            &#039;data&#039;: {\n                &#039;id&#039;: str(node_id),  # ID \u5fc5\u987b\u4e3a\u5b57\u7b26\u4e32\n                &#039;label&#039;: str(node_id).replace(&#039; &#039;, &#039;\\n&#039;),  # \u53ef\u8bfb\u6027\u66f4\u5f3a\u7684\u663e\u793a\u6807\u7b7e\n                &#039;degree&#039;: degree,\n                &#039;size&#039;: node_size,\n                &#039;tooltip_text&#039;: f&quot;\u5b9e\u4f53: {str(node_id)}\\n\u5ea6\u6570: {degree}&quot;\n            }\n        })\n\n    print(f&quot;\u5df2\u8f6c\u6362 {len(cytoscape_nodes)} \u4e2a\u8282\u70b9\u3002&quot;)\n\n    print(&quot;\u6b63\u5728\u8f6c\u6362\u8fb9...&quot;)\n\n    edge_count = 0\n    for u, v, data in knowledge_graph.edges(data=True):\n        edge_id = f&quot;edge_{edge_count}&quot;\n        predicate_label = data.get(&#039;label&#039;, &#039;&#039;)\n\n        cytoscape_edges.append({\n            &#039;data&#039;: {\n                &#039;id&#039;: edge_id,\n                &#039;source&#039;: str(u),\n                &#039;target&#039;: str(v),\n                &#039;label&#039;: predicate_label,\n                &#039;tooltip_text&#039;: f&quot;\u5173\u7cfb: {predicate_label}&quot;\n            }\n        })\n\n        edge_count += 1\n\n    print(f&quot;\u5df2\u8f6c\u6362 {len(cytoscape_edges)} \u6761\u8fb9\u3002&quot;)\n\n    # \u7ec4\u5408\u6210 Cytoscape \u4f7f\u7528\u7684\u6570\u636e\u7ed3\u6784\n    cytoscape_graph_data = {\n        &#039;nodes&#039;: cytoscape_nodes,\n        &#039;edges&#039;: cytoscape_edges\n    }\n\n    # \u8f93\u51fa\u6837\u672c\u6570\u636e\u7528\u4e8e\u68c0\u67e5\n    print(&quot;\\n===== Cytoscape \u8282\u70b9\u6570\u636e\u6837\u672c (\u524d 2 \u4e2a) =====\\n&quot;)\n    print(json.dumps(cytoscape_graph_data[&#039;nodes&#039;][:2], indent=2, ensure_ascii=False))\n\n    print(&quot;\\n===== Cytoscape \u8fb9\u6570\u636e\u6837\u672c (\u524d 2 \u4e2a) =====\\n&quot;)\n    print(json.dumps(cytoscape_graph_data[&#039;edges&#039;][:2], indent=2, ensure_ascii=False))\n\n    print(&quot;-&quot; * 40)\n\nelse:\n    print(&quot;\u7531\u4e8e\u56fe\u65e0\u6548\uff0c\u8df3\u8fc7\u6570\u636e\u8f6c\u6362\u3002&quot;)\n    cytoscape_graph_data = {&#039;nodes&#039;: [], &#039;edges&#039;: []}\n<\/code><\/pre>\n<pre><code>\u6b63\u5728\u8f6c\u6362\u8282\u70b9...\n\u5df2\u8f6c\u6362 12 \u4e2a\u8282\u70b9\u3002\n\u6b63\u5728\u8f6c\u6362\u8fb9...\n\u5df2\u8f6c\u6362 6 \u6761\u8fb9\u3002\n\n===== Cytoscape \u8282\u70b9\u6570\u636e\u6837\u672c (\u524d 2 \u4e2a) =====\n\n[\n  {\n    \"data\": {\n      \"id\": \"\u8d3e\u6f14\",\n      \"label\": \"\u8d3e\u6f14\",\n      \"degree\": 1,\n      \"size\": 65.0,\n      \"tooltip_text\": \"\u5b9e\u4f53: \u8d3e\u6f14\\n\u5ea6\u6570: 1\"\n    }\n  },\n  {\n    \"data\": {\n      \"id\": \"\u8d3e\u4ee3\u5316\",\n      \"label\": \"\u8d3e\u4ee3\u5316\",\n      \"degree\": 1,\n      \"size\": 65.0,\n      \"tooltip_text\": \"\u5b9e\u4f53: \u8d3e\u4ee3\u5316\\n\u5ea6\u6570: 1\"\n    }\n  }\n]\n\n===== Cytoscape \u8fb9\u6570\u636e\u6837\u672c (\u524d 2 \u4e2a) =====\n\n[\n  {\n    \"data\": {\n      \"id\": \"edge_0\",\n      \"source\": \"\u8d3e\u6f14\",\n      \"target\": \"\u8d3e\u4ee3\u5316\",\n      \"label\": \"has child\",\n      \"tooltip_text\": \"\u5173\u7cfb: has child\"\n    }\n  },\n  {\n    \"data\": {\n      \"id\": \"edge_1\",\n      \"source\": \"jia yingchun\",\n      \"target\": \"regional daughter\",\n      \"label\": \"is a\",\n      \"tooltip_text\": \"\u5173\u7cfb: is a\"\n    }\n  }\n]\n----------------------------------------<\/code><\/pre>\n<pre><code class=\"language-python\">from ipycytoscape import CytoscapeWidget\n\n# \u521b\u5efa Cytoscape \u53ef\u89c6\u5316\u63a7\u4ef6\ncyto = CytoscapeWidget()\n\n# \u81ea\u5b9a\u4e49\u6837\u5f0f\uff08\u53ef\u9009\uff09\ncyto.set_style([\n    {\n        &#039;selector&#039;: &#039;node&#039;,\n        &#039;style&#039;: {\n            &#039;label&#039;: &#039;data(label)&#039;,\n            &#039;background-color&#039;: &#039;#1f77b4&#039;,\n            &#039;width&#039;: &#039;data(size)&#039;,\n            &#039;height&#039;: &#039;data(size)&#039;,\n            &#039;font-size&#039;: 10,\n            &#039;text-valign&#039;: &#039;center&#039;,\n            &#039;text-halign&#039;: &#039;center&#039;,\n            &#039;color&#039;: &#039;#ffffff&#039;\n        }\n    },\n    {\n        &#039;selector&#039;: &#039;edge&#039;,\n        &#039;style&#039;: {\n            &#039;label&#039;: &#039;data(label)&#039;,\n            &#039;curve-style&#039;: &#039;bezier&#039;,\n            &#039;target-arrow-shape&#039;: &#039;triangle&#039;,\n            &#039;line-color&#039;: &#039;#ccc&#039;,\n            &#039;target-arrow-color&#039;: &#039;#ccc&#039;,\n            &#039;font-size&#039;: 8,\n            &#039;text-rotation&#039;: &#039;autorotate&#039;\n        }\n    }\n])\n\n# \u6e05\u7a7a\u65e7\u56fe\uff08\u53ef\u9009\uff09\ncyto.graph.clear()\n\n# \u52a0\u8f7d\u8f6c\u6362\u597d\u7684\u56fe\u6570\u636e\ncyto.graph.add_graph_from_json(cytoscape_graph_data)\n\n# \u6e32\u67d3\u53ef\u89c6\u5316\u56fe\u8c31\ncyto\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import openai # \u7528\u4e8e\u4e0e LLM \u4ea4\u4e92 import json # \u7528\u4e8e\u89e3\u6790 LLM \u7684\u54cd\u5e94 import network   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[282],"tags":[226,283],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9389"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9389"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9389\/revisions"}],"predecessor-version":[{"id":9390,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9389\/revisions\/9390"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9389"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}