This commit is contained in:
512song committed 2024-07-15 23:14:31 +08:00
1 parent 527c1710aa
commit d837537130
6 files changed
+714 -1946

No files matched your search

+74 -40
View File
@@ -10,15 +10,15 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 26,
"id": "0569e182-b008-4173-ab0d-7f4a2904f72e",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-18T14:26:31.435612Z",
"iopub.status.busy": "2024-05-18T14:26:31.434850Z",
"iopub.status.idle": "2024-05-18T14:26:31.470444Z",
"shell.execute_reply": "2024-05-18T14:26:31.469851Z",
"shell.execute_reply.started": "2024-05-18T14:26:31.435543Z"
"iopub.execute_input": "2024-07-15T15:04:59.632546Z",
"iopub.status.busy": "2024-07-15T15:04:59.631784Z",
"iopub.status.idle": "2024-07-15T15:04:59.665250Z",
"shell.execute_reply": "2024-07-15T15:04:59.664677Z",
"shell.execute_reply.started": "2024-07-15T15:04:59.632477Z"
},
"tags": []
},
@@ -39,15 +39,15 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 27,
"id": "44683ca5-166c-4d3a-9447-6fe46ab7c12d",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-18T14:26:37.305970Z",
"iopub.status.busy": "2024-05-18T14:26:37.305254Z",
"iopub.status.idle": "2024-05-18T14:26:37.334691Z",
"shell.execute_reply": "2024-05-18T14:26:37.334144Z",
"shell.execute_reply.started": "2024-05-18T14:26:37.305904Z"
"iopub.execute_input": "2024-07-15T15:05:02.105399Z",
"iopub.status.busy": "2024-07-15T15:05:02.104659Z",
"iopub.status.idle": "2024-07-15T15:05:02.142813Z",
"shell.execute_reply": "2024-07-15T15:05:02.142274Z",
"shell.execute_reply.started": "2024-07-15T15:05:02.105335Z"
},
"tags": []
},
@@ -76,27 +76,12 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "3ecfe0a8-3af1-4f48-a2b0-6c3eb25df07d",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-21T23:57:39.161812Z",
"iopub.status.busy": "2024-05-21T23:57:39.161088Z",
"iopub.status.idle": "2024-05-21T23:57:39.171261Z",
"shell.execute_reply": "2024-05-21T23:57:39.169939Z",
"shell.execute_reply.started": "2024-05-21T23:57:39.161751Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{{ img_11 }}当{{ img_12 }}位碰为正。{{ img_12 }}至{{ img_18 }}争先亦是。{{ img_20 }}拆三当时。{{ img_21 }}可缓,当{{ img_122 }}位大飞,黑拆三尚须关补。{{ img_27 }}压、{{ img_29 }}扳活动。{{ img_32 }}不于{{ img_106 }}位打,防白{{ img_113 }}位打,黑{{ img_107 }}位提,白{{ img_187 }}位打,黑粘,白{{ img_33 }}位虎,黑{{ img_34 }}位长,白{{ img_124 }}位立,黑转,局促。{{ img_34 }}不打亦是。{{ img_35 }}等着分角尚早,有{{ img_38 }}敲,外面便生出劫。{{ img_41 }}扳,将官子着尽,是当时习气。{{ img_51 }}若{{ img_55 }}位长,嫌机缓,姑扳以图变。{{ img_52 }}至{{ img_62 }}乘间攻角,不可缓。{{ img_64 }}必长,{{ img_66 }}、{{ img_68 }}有次序。{{ img_72 }}至{{ img_78 }}机法相生,纯乎自然。{{ img_80 }}接老当,胜{{ img_142 }}位长。{{ img_81 }}长,劲。{{ img_93 }}虎应,是。{{ img_99 }}接,连三子,收{{ img_101 }}位先手断觑便宜。{{ img_103 }}因中间残损,紧逼黑边,补角顾腹,最为扼要。{{ img_104 }}扳、{{ img_108 }}反打,妙,有成算。{{ img_115 }}因三子受逼,难于转身,用借引法兼可攻角。{{ img_116 }}顾角,任白扳接,合活得先,外势自固;若呆取三子,便无余味。{{ img_117 }}至{{ img_145 }}彼此稳惬。{{ img_148 }}收法紧。{{ img_157 }}大。{{ img_170 }}落得先手分腹。{{ img_177 }}、{{ img_179 }}尖断黑子要紧。{{ img_186 }}、{{ img_188 }}收,得便宜。{{ img_190 }}必扳。{{ img_195 }}嵌法巧。{{ img_200 }}大。{{ img_274 }}官子粗,若于十▪二路补,便胜一子。 国初时,名手如林,龙士年最幼,诸家遇之辄望风而靡,唯东侯刻意追新,喜出偏锋,率战不屈。此局如春秋晋楚主盟,不相上下,可称劲敌。 (吴评) ['101', '103', '104', '106', '107', '108', '11', '113', '115', '116', '117', '12', '122', '124', '142', '145', '148', '157', '170', '177', '179', '18', '186', '187', '188', '190', '195', '20', '200', '21', '27', '274', '29', '32', '33', '34', '35', '38', '41', '51', '52', '55', '62', '64', '66', '68', '72', '78', '80', '81', '93', '99']\n"
]
}
],
"outputs": [],
"source": [
"import glob\n",
"import os,shutil\n",
@@ -137,16 +122,65 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "14696c7a-d44e-4c99-9d28-a810d991ed20",
"metadata": {},
"outputs": [],
"source": [
"import glob\n",
"import os,shutil\n",
"from pathlib import Path\n",
"import re\n",
"from docx import Document\n",
"\n",
"def find_all_numbers(text):\n",
" return re.findall(r'\\d+', text)\n",
"\n",
"def replace_numbers(text):\n",
" pattern = r'\\d+'\n",
" replacement = lambda x:'{{ '+ f'img_{x.group()}'+' }}'\n",
" modified_text = re.sub(pattern, replacement, text)\n",
" return modified_text\n",
"\n",
"def replace_numbers_with_braces(text):\n",
" # 使用正则表达式查找连续的数字\n",
" pattern = re.compile(r'\\d+')\n",
" \n",
" # 使用re.sub()进行替换\n",
" result = pattern.sub(lambda x: f\"{{{{ img_{x.group(0)} }}}}\", text)\n",
" \n",
" return result\n",
"doc = Document()\n",
"\n",
"list1 = []\n",
"filepath = '文本文件/'\n",
"files = glob.glob(f'{filepath}*.txt')\n",
"for fn in files:\n",
" with open(fn, \"r\") as f:\n",
" paragraph3 = doc.add_paragraph()\n",
" data = f.readlines()\n",
" for s in data:\n",
" list2 = []\n",
" ss = replace_numbers_with_braces(s)\n",
" list2 = find_all_numbers(s)\n",
" if len(list2)>0:\n",
" for item in list2:\n",
" list1.append(item)\n",
" \n",
" list1 = list(set(list1))\n",
" list1.sort()\n",
" #paragraph3 = doc.add_paragraph()\n",
" paragraph3.add_run(ss.replace('\\r', ''))\n",
" \n",
"print(list1)\n",
"doc.save('弈理析疑.docx')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d3f1a7a-1322-48b5-9b14-c7ba8f38bacb",
"metadata": {
"execution": {
"iopub.execute_input": "2024-05-18T14:34:33.640049Z",
"iopub.status.busy": "2024-05-18T14:34:33.639299Z",
"iopub.status.idle": "2024-05-18T14:34:33.772312Z",
"shell.execute_reply": "2024-05-18T14:34:33.771764Z",
"shell.execute_reply.started": "2024-05-18T14:34:33.639984Z"
},
"tags": []
},
"outputs": [],
@@ -157,19 +191,19 @@
"\n",
"dict1 = {}\n",
"\n",
"tpl = DocxTemplate(\"test1.docx\")\n",
"tpl = DocxTemplate(\"弈理析疑.docx\")\n",
"for item in list1: \n",
" dict1['img_'+str(item)] = InlineImage(tpl, image_descriptor=f'./img/{str(item)}.jpg',width=Mm(4))\n",
"#dict1['img_radar'] = InlineImage(tpl, image_descriptor=dict1['radar'])\n",
"\n",
"tpl.render(dict1)\n",
"tpl.save('test2.docx')"
"tpl.save('弈理析疑1.docx')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14696c7a-d44e-4c99-9d28-a810d991ed20",
"id": "efc716f8-0ec7-4e0d-9960-676764965be4",
"metadata": {},
"outputs": [],
"source": []