From b13b519046ed32a7db2d06fa343bf566bdb9d0bb Mon Sep 17 00:00:00 2001 From: abigwc Date: Mon, 17 Aug 2026 09:15:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=87=E6=BB=A4=E7=BB=BC=E5=90=88?= =?UTF-8?q?=E5=88=86=E6=9E=90=E9=A2=98=E4=B8=BB=E8=A7=82=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=94=9F=E6=88=90=E5=AE=A2=E8=A7=82=E9=A2=98?= =?UTF-8?q?=E5=BA=93=E5=85=B1756=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extract_table.py | 36 +++++++++----- questions.json | 98 ++----------------------------------- quiz-app/src/questions.json | 98 ++----------------------------------- 3 files changed, 35 insertions(+), 197 deletions(-) diff --git a/extract_table.py b/extract_table.py index 165b4c0..49b5c4f 100644 --- a/extract_table.py +++ b/extract_table.py @@ -1,14 +1,21 @@ import json +import os import pdfplumber import re -def extract_from_pdf(pdf_path, output_json_path): +def extract_from_pdf(pdf_path, output_json_paths): questions = [] current_q = None global_id = 1 with pdfplumber.open(pdf_path) as pdf: for page_num, page in enumerate(pdf.pages): + text = page.extract_text() or "" + # 当遇到综合分析题或页码超过142页时停止抽取 + if "大数据工程技术人员技能竞赛综合分析题" in text or page_num >= 142: + print(f"在第 {page_num + 1} 页检测到综合分析题或达到客观题边界,停止解析。") + break + tables = page.extract_tables() for table in tables: for row in table: @@ -22,7 +29,6 @@ def extract_from_pdf(pdf_path, output_json_path): is_new_q = False if col0.isdigit(): is_new_q = True - # q_id = int(col0) title = row[1] if row[1] else "" options_raw = row[2] if row[2] else "" @@ -30,7 +36,7 @@ def extract_from_pdf(pdf_path, output_json_path): q_answer = row[4] if row[4] else "" source_file = row[5] if len(row) > 5 and row[5] else "" - # Split options + # 拆分选项 opts = re.split(r'(?=[A-H][\.、])', options_raw) parsed_options = [opt.strip().replace('\n', '') for opt in opts if opt.strip()] @@ -44,7 +50,7 @@ def extract_from_pdf(pdf_path, output_json_path): "options": parsed_options, "type": q_type.replace('\n', '').strip(), "answer": q_answer.replace('\n', '').strip(), - "source_id": col0, # keeping original id for reference + "source_id": col0, "page_number": page_num + 1, "source_file": source_file.replace('\n', '').strip() } @@ -64,13 +70,21 @@ def extract_from_pdf(pdf_path, output_json_path): current_q["id"] = global_id questions.append(current_q) - print(f"Extracted {len(questions)} questions via table parsing.") + print(f"共提取题目 {len(questions)} 道。") + single_count = sum(1 for q in questions if q['type'] == '单选') + multi_count = sum(1 for q in questions if q['type'] == '多选') + print(f"其中单选 {single_count} 道,多选 {multi_count} 道。") - bad = [x for x in questions if len(x['options']) < 2] - print(f"Questions with <2 options: {len(bad)}") - - with open(output_json_path, 'w', encoding='utf-8') as f: - json.dump(questions, f, ensure_ascii=False, indent=2) + for out_path in output_json_paths: + os.makedirs(os.path.dirname(os.path.abspath(out_path)), exist_ok=True) + with open(out_path, 'w', encoding='utf-8') as f: + json.dump(questions, f, ensure_ascii=False, indent=2) + print(f"已保存题库至:{out_path}") if __name__ == "__main__": - extract_from_pdf("d:/code/bigdata/题库.pdf", "d:/code/bigdata/questions.json") + targets = [ + "d:/code/bigdata/questions.json", + "d:/code/bigdata/quiz-app/src/questions.json" + ] + extract_from_pdf("d:/code/bigdata/题库.pdf", targets) + diff --git a/questions.json b/questions.json index 5d3e754..e28a82a 100644 --- a/questions.json +++ b/questions.json @@ -11360,106 +11360,18 @@ "id": 755 }, { - "title": "下列关于政务数据安全与开放的说法,正确的有____主要内容过车时间、车牌号、车型、车速、方向、卡口编号主要内容断面车流量、平均车速、时间占有率车辆经纬度、线路号、车速;乘客上下车刷卡路段平均速度、拥堵指数(第三方脱敏)天气、降雨量;事故、施工、大型活动plate_no(车牌)", + "title": "下列关于政务数据安全与开放的说法,正确的有____", "options": [ "A.国家大力推进电子政务建设,提升运用数据服务经济社会发展的能力", "B.国家机关应当建立健全数据安全管理制度,保障政务数据安全", "C.国家机关应当按照规定及时、准确地公开所有政务数据", - "D.国家构建统一规范、互联互通、安全可控的政务数据开放平台", - "产生/上报方式", - "逐车产生“过车事件”", - "产生/上报方式", - "周期上报“断面指标”", - "持续上报/刷卡交易", - "第三方接口推送", - "接口/人工录入", - "vehicle_type(车型)" + "D.国家构建统一规范、互联互通、安全可控的政务数据开放平台" ], - "type": "多选上报频率逐 条 ( 高频)上报频率每 1 分钟10~30 秒分钟级不定时speed(车速km/h)", - "answer": "ABD时效要求秒级(实时)时效要求分钟级准实时分钟级准实时/离线pass_time(过车时间)", + "type": "多选", + "answer": "ABD", "source_id": "30", "page_number": 142, - "source_file": "中华人民共和国数据安全法gantry_id(卡口编号)", + "source_file": "中华人民共和国数据安全法", "id": 756 - }, - { - "title": "沪A·O12Z3", - "options": [ - "小型客车" - ], - "type": "45", - "answer": "2026-05-3008:15:03", - "source_id": "1001", - "page_number": 152, - "source_file": "G0207", - "id": 757 - }, - { - "title": "沪A·88K21", - "options": [ - "(空)" - ], - "type": "62", - "answer": "2026-05-3008:15:05", - "source_id": "1002", - "page_number": 152, - "source_file": "G0207", - "id": 758 - }, - { - "title": "沪A·88K21", - "options": [ - "小型客车" - ], - "type": "62", - "answer": "2026-05-3008:15:05", - "source_id": "1003", - "page_number": 152, - "source_file": "G0207", - "id": 759 - }, - { - "title": "沪A·88K21", - "options": [ - "小型客车" - ], - "type": "62", - "answer": "2026-05-3008:15:05", - "source_id": "1004", - "page_number": 152, - "source_file": "G0207", - "id": 760 - }, - { - "title": "沪B·5566F", - "options": [ - "大型货车" - ], - "type": "263", - "answer": "2026-05-3008:14:58", - "source_id": "1005", - "page_number": 152, - "source_file": "G0311", - "id": 761 - }, - { - "title": "(空)含义过车记录流水号车牌号含义车型瞬时车速(km/h)过车时间卡口编号", - "options": [ - "小型客车", - "类型", - "BIGINT", - "STRING", - "类型", - "STRING", - "INT", - "TIMESTAMP", - "STRING" - ], - "type": "38是否可空否否是否可空是是否否", - "answer": "2026-05-3008:16:10备注主键个人信息,需脱敏管控备注小型客车 /大型货车等合理范围 0~200存在乱序关联卡口点位维表", - "source_id": "1006", - "page_number": 152, - "source_file": "G0311", - "id": 762 } ] \ No newline at end of file diff --git a/quiz-app/src/questions.json b/quiz-app/src/questions.json index 5d3e754..e28a82a 100644 --- a/quiz-app/src/questions.json +++ b/quiz-app/src/questions.json @@ -11360,106 +11360,18 @@ "id": 755 }, { - "title": "下列关于政务数据安全与开放的说法,正确的有____主要内容过车时间、车牌号、车型、车速、方向、卡口编号主要内容断面车流量、平均车速、时间占有率车辆经纬度、线路号、车速;乘客上下车刷卡路段平均速度、拥堵指数(第三方脱敏)天气、降雨量;事故、施工、大型活动plate_no(车牌)", + "title": "下列关于政务数据安全与开放的说法,正确的有____", "options": [ "A.国家大力推进电子政务建设,提升运用数据服务经济社会发展的能力", "B.国家机关应当建立健全数据安全管理制度,保障政务数据安全", "C.国家机关应当按照规定及时、准确地公开所有政务数据", - "D.国家构建统一规范、互联互通、安全可控的政务数据开放平台", - "产生/上报方式", - "逐车产生“过车事件”", - "产生/上报方式", - "周期上报“断面指标”", - "持续上报/刷卡交易", - "第三方接口推送", - "接口/人工录入", - "vehicle_type(车型)" + "D.国家构建统一规范、互联互通、安全可控的政务数据开放平台" ], - "type": "多选上报频率逐 条 ( 高频)上报频率每 1 分钟10~30 秒分钟级不定时speed(车速km/h)", - "answer": "ABD时效要求秒级(实时)时效要求分钟级准实时分钟级准实时/离线pass_time(过车时间)", + "type": "多选", + "answer": "ABD", "source_id": "30", "page_number": 142, - "source_file": "中华人民共和国数据安全法gantry_id(卡口编号)", + "source_file": "中华人民共和国数据安全法", "id": 756 - }, - { - "title": "沪A·O12Z3", - "options": [ - "小型客车" - ], - "type": "45", - "answer": "2026-05-3008:15:03", - "source_id": "1001", - "page_number": 152, - "source_file": "G0207", - "id": 757 - }, - { - "title": "沪A·88K21", - "options": [ - "(空)" - ], - "type": "62", - "answer": "2026-05-3008:15:05", - "source_id": "1002", - "page_number": 152, - "source_file": "G0207", - "id": 758 - }, - { - "title": "沪A·88K21", - "options": [ - "小型客车" - ], - "type": "62", - "answer": "2026-05-3008:15:05", - "source_id": "1003", - "page_number": 152, - "source_file": "G0207", - "id": 759 - }, - { - "title": "沪A·88K21", - "options": [ - "小型客车" - ], - "type": "62", - "answer": "2026-05-3008:15:05", - "source_id": "1004", - "page_number": 152, - "source_file": "G0207", - "id": 760 - }, - { - "title": "沪B·5566F", - "options": [ - "大型货车" - ], - "type": "263", - "answer": "2026-05-3008:14:58", - "source_id": "1005", - "page_number": 152, - "source_file": "G0311", - "id": 761 - }, - { - "title": "(空)含义过车记录流水号车牌号含义车型瞬时车速(km/h)过车时间卡口编号", - "options": [ - "小型客车", - "类型", - "BIGINT", - "STRING", - "类型", - "STRING", - "INT", - "TIMESTAMP", - "STRING" - ], - "type": "38是否可空否否是否可空是是否否", - "answer": "2026-05-3008:16:10备注主键个人信息,需脱敏管控备注小型客车 /大型货车等合理范围 0~200存在乱序关联卡口点位维表", - "source_id": "1006", - "page_number": 152, - "source_file": "G0311", - "id": 762 } ] \ No newline at end of file