264 lines
15 KiB
Plaintext
264 lines
15 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"题号: 000291 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000292 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000293 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000294 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000296 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000297 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000299 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000301 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000302 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000304 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000305 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 000781 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001944 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001947 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001948 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001949 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001950 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001951 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001952 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001953 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001954 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001955 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001956 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001957 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001958 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001959 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001960 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001961 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001962 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001963 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001964 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001965 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001966 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001968 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001969 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001971 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001972 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001973 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001974 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001975 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001976 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001977 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001978 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001979 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001980 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001981 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001985 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001987 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 001991 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 003624 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 003647 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 003679 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 004096 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 004243 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 004348 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 004656 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 004698 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 004740 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009855 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009856 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009857 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009858 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009859 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009860 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009861 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009862 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009863 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009864 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009865 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009867 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009868 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009870 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009871 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009872 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 009873 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010706 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010707 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010708 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010709 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010710 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010711 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010712 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010713 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010714 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010715 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010716 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010717 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010718 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010719 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010720 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010721 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010722 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010723 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010724 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010725 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010726 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010727 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010729 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010730 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010731 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010732 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010733 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010735 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010736 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010737 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010738 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010739 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 010740 , 字段: tags 中已添加数据: 空间向量\n",
|
|
"题号: 030452 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030453 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030454 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030455 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030456 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030457 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030458 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030459 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030460 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030461 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030462 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030463 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030464 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030465 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030466 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030467 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030468 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030469 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030470 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030471 , 字段: tags 中已有该数据: 空间向量\n",
|
|
"题号: 030472 , 字段: tags 中已有该数据: 空间向量\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import os,re,json\n",
|
|
"\n",
|
|
"\"\"\"---明确数据文件位置---\"\"\"\n",
|
|
"datafile = \"文本文件/metadata.txt\"\n",
|
|
"# 双回车分隔,记录内单回车分隔列表,首行为字段名\n",
|
|
"\"\"\"---文件位置结束---\"\"\"\n",
|
|
"\n",
|
|
"def trim(string):\n",
|
|
" string = re.sub(r\"^[ \\t\\n]*\",\"\",string)\n",
|
|
" string = re.sub(r\"[ \\t\\n]*$\",\"\",string)\n",
|
|
" return string\n",
|
|
"def FloatToInt(string):\n",
|
|
" f = float(string)\n",
|
|
" if abs(f-round(f))<0.01:\n",
|
|
" f = round(f)\n",
|
|
" return f\n",
|
|
"\n",
|
|
"with open(datafile,\"r\",encoding=\"utf8\") as f:\n",
|
|
" data = f.read()\n",
|
|
"pos = data.index(\"\\n\")\n",
|
|
"field = data[:pos].strip()\n",
|
|
"appending_data = data[pos:]\n",
|
|
"\n",
|
|
"with open(r\"../题库0.3/Problems.json\",\"r\",encoding = \"utf8\") as f:\n",
|
|
" database = f.read()\n",
|
|
"pro_dict = json.loads(database)\n",
|
|
"with open(r\"../题库0.3/LessonObj.json\",\"r\",encoding = \"utf8\") as f:\n",
|
|
" database = f.read()\n",
|
|
"obj_dict = json.loads(database)\n",
|
|
"\n",
|
|
"#该字段列表可能需要更新\n",
|
|
"fields = [\"content\",\"objs\",\"tags\",\"genre\",\"ans\",\"solution\",\"duration\",\"usages\",\"origin\",\"edit\",\"same\",\"related\",\"remark\",\"space\"]\n",
|
|
"\n",
|
|
"if field in fields:\n",
|
|
" field_type = type(pro_dict[\"000001\"][field])\n",
|
|
" datalist = [record.strip() for record in appending_data.split(\"\\n\\n\") if len(trim(record)) > 0]\n",
|
|
" for record in datalist:\n",
|
|
" id = re.findall(r\"^[\\d]{1,}\",record)[0]\n",
|
|
" data = record[len(id):].strip()\n",
|
|
" id = id.zfill(6)\n",
|
|
" if not id in pro_dict:\n",
|
|
" print(\"题号:\",id,\"不在数据库中.\")\n",
|
|
" break\n",
|
|
" \n",
|
|
" #字符串类型字段添加数据\n",
|
|
" elif field_type == str and data in pro_dict[id][field]:\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已有该数据:\",data)\n",
|
|
" elif field_type == str and not data in pro_dict[id][field] and not field == \"ans\" and not field == \"space\":\n",
|
|
" origin_data = pro_dict[id][field]\n",
|
|
" new_data = trim(origin_data + \"\\n\" + data)\n",
|
|
" pro_dict[id][field] = new_data\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已添加数据:\",data)\n",
|
|
" elif field_type == str and not data in pro_dict[id][field] and field == \"ans\" or field == \"space\":\n",
|
|
" pro_dict[id][field] = data\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已修改数据:\",data)\n",
|
|
" \n",
|
|
" #数值类型字段添加数据\n",
|
|
" elif (field_type == int or field_type == float) and abs(float(data) - pro_dict[id][field])<0.01:\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已有该数据:\",FloatToInt(data))\n",
|
|
" elif (field_type == int or field_type == float) and abs(float(data) - pro_dict[id][field])>=0.01:\n",
|
|
" pro_dict[id][field] = FloatToInt(data)\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已修改数据:\",FloatToInt(data))\n",
|
|
" \n",
|
|
" #列表类型字段添加数据\n",
|
|
" elif field_type == list:\n",
|
|
" cell_data_list = [d.strip() for d in data.split(\"\\n\")]\n",
|
|
" for cell_data in cell_data_list:\n",
|
|
" if cell_data in pro_dict[id][field]:\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已有该数据:\",cell_data)\n",
|
|
" elif not field == \"objs\":\n",
|
|
" pro_dict[id][field].append(cell_data)\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已添加数据:\",cell_data)\n",
|
|
" else:\n",
|
|
" if not cell_data in obj_dict and not cell_data.upper() == \"KNONE\":\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"目标编号有误:\",cell_data)\n",
|
|
" else:\n",
|
|
" pro_dict[id][field].append(cell_data.upper())\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已添加数据:\",cell_data.upper())\n",
|
|
"\n",
|
|
"with open(r\"../题库0.3/Problems.json\",\"w\",encoding = \"utf8\") as f:\n",
|
|
" f.write(json.dumps(pro_dict,indent=4,ensure_ascii=False))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3.8.8 ('base')",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.8"
|
|
},
|
|
"orig_nbformat": 4,
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "d311ffef239beb3b8f3764271728f3972d7b090c974f8e972fcdeedf230299ac"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|