feat: 过滤综合分析题主观题,重新生成客观题库共756题
This commit is contained in:
+24
-10
@@ -1,14 +1,21 @@
|
|||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import pdfplumber
|
import pdfplumber
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def extract_from_pdf(pdf_path, output_json_path):
|
def extract_from_pdf(pdf_path, output_json_paths):
|
||||||
questions = []
|
questions = []
|
||||||
current_q = None
|
current_q = None
|
||||||
global_id = 1
|
global_id = 1
|
||||||
|
|
||||||
with pdfplumber.open(pdf_path) as pdf:
|
with pdfplumber.open(pdf_path) as pdf:
|
||||||
for page_num, page in enumerate(pdf.pages):
|
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()
|
tables = page.extract_tables()
|
||||||
for table in tables:
|
for table in tables:
|
||||||
for row in table:
|
for row in table:
|
||||||
@@ -22,7 +29,6 @@ def extract_from_pdf(pdf_path, output_json_path):
|
|||||||
is_new_q = False
|
is_new_q = False
|
||||||
if col0.isdigit():
|
if col0.isdigit():
|
||||||
is_new_q = True
|
is_new_q = True
|
||||||
# q_id = int(col0)
|
|
||||||
|
|
||||||
title = row[1] if row[1] else ""
|
title = row[1] if row[1] else ""
|
||||||
options_raw = row[2] if row[2] 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 ""
|
q_answer = row[4] if row[4] else ""
|
||||||
source_file = row[5] if len(row) > 5 and row[5] else ""
|
source_file = row[5] if len(row) > 5 and row[5] else ""
|
||||||
|
|
||||||
# Split options
|
# 拆分选项
|
||||||
opts = re.split(r'(?=[A-H][\.、])', options_raw)
|
opts = re.split(r'(?=[A-H][\.、])', options_raw)
|
||||||
parsed_options = [opt.strip().replace('\n', '') for opt in opts if opt.strip()]
|
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,
|
"options": parsed_options,
|
||||||
"type": q_type.replace('\n', '').strip(),
|
"type": q_type.replace('\n', '').strip(),
|
||||||
"answer": q_answer.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,
|
"page_number": page_num + 1,
|
||||||
"source_file": source_file.replace('\n', '').strip()
|
"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
|
current_q["id"] = global_id
|
||||||
questions.append(current_q)
|
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]
|
for out_path in output_json_paths:
|
||||||
print(f"Questions with <2 options: {len(bad)}")
|
os.makedirs(os.path.dirname(os.path.abspath(out_path)), exist_ok=True)
|
||||||
|
with open(out_path, 'w', encoding='utf-8') as f:
|
||||||
with open(output_json_path, 'w', encoding='utf-8') as f:
|
|
||||||
json.dump(questions, f, ensure_ascii=False, indent=2)
|
json.dump(questions, f, ensure_ascii=False, indent=2)
|
||||||
|
print(f"已保存题库至:{out_path}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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)
|
||||||
|
|
||||||
|
|||||||
+5
-93
@@ -11360,106 +11360,18 @@
|
|||||||
"id": 755
|
"id": 755
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "下列关于政务数据安全与开放的说法,正确的有____主要内容过车时间、车牌号、车型、车速、方向、卡口编号主要内容断面车流量、平均车速、时间占有率车辆经纬度、线路号、车速;乘客上下车刷卡路段平均速度、拥堵指数(第三方脱敏)天气、降雨量;事故、施工、大型活动plate_no(车牌)",
|
"title": "下列关于政务数据安全与开放的说法,正确的有____",
|
||||||
"options": [
|
"options": [
|
||||||
"A.国家大力推进电子政务建设,提升运用数据服务经济社会发展的能力",
|
"A.国家大力推进电子政务建设,提升运用数据服务经济社会发展的能力",
|
||||||
"B.国家机关应当建立健全数据安全管理制度,保障政务数据安全",
|
"B.国家机关应当建立健全数据安全管理制度,保障政务数据安全",
|
||||||
"C.国家机关应当按照规定及时、准确地公开所有政务数据",
|
"C.国家机关应当按照规定及时、准确地公开所有政务数据",
|
||||||
"D.国家构建统一规范、互联互通、安全可控的政务数据开放平台",
|
"D.国家构建统一规范、互联互通、安全可控的政务数据开放平台"
|
||||||
"产生/上报方式",
|
|
||||||
"逐车产生“过车事件”",
|
|
||||||
"产生/上报方式",
|
|
||||||
"周期上报“断面指标”",
|
|
||||||
"持续上报/刷卡交易",
|
|
||||||
"第三方接口推送",
|
|
||||||
"接口/人工录入",
|
|
||||||
"vehicle_type(车型)"
|
|
||||||
],
|
],
|
||||||
"type": "多选上报频率逐 条 ( 高频)上报频率每 1 分钟10~30 秒分钟级不定时speed(车速km/h)",
|
"type": "多选",
|
||||||
"answer": "ABD时效要求秒级(实时)时效要求分钟级准实时分钟级准实时/离线pass_time(过车时间)",
|
"answer": "ABD",
|
||||||
"source_id": "30",
|
"source_id": "30",
|
||||||
"page_number": 142,
|
"page_number": 142,
|
||||||
"source_file": "中华人民共和国数据安全法gantry_id(卡口编号)",
|
"source_file": "中华人民共和国数据安全法",
|
||||||
"id": 756
|
"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
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -11360,106 +11360,18 @@
|
|||||||
"id": 755
|
"id": 755
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "下列关于政务数据安全与开放的说法,正确的有____主要内容过车时间、车牌号、车型、车速、方向、卡口编号主要内容断面车流量、平均车速、时间占有率车辆经纬度、线路号、车速;乘客上下车刷卡路段平均速度、拥堵指数(第三方脱敏)天气、降雨量;事故、施工、大型活动plate_no(车牌)",
|
"title": "下列关于政务数据安全与开放的说法,正确的有____",
|
||||||
"options": [
|
"options": [
|
||||||
"A.国家大力推进电子政务建设,提升运用数据服务经济社会发展的能力",
|
"A.国家大力推进电子政务建设,提升运用数据服务经济社会发展的能力",
|
||||||
"B.国家机关应当建立健全数据安全管理制度,保障政务数据安全",
|
"B.国家机关应当建立健全数据安全管理制度,保障政务数据安全",
|
||||||
"C.国家机关应当按照规定及时、准确地公开所有政务数据",
|
"C.国家机关应当按照规定及时、准确地公开所有政务数据",
|
||||||
"D.国家构建统一规范、互联互通、安全可控的政务数据开放平台",
|
"D.国家构建统一规范、互联互通、安全可控的政务数据开放平台"
|
||||||
"产生/上报方式",
|
|
||||||
"逐车产生“过车事件”",
|
|
||||||
"产生/上报方式",
|
|
||||||
"周期上报“断面指标”",
|
|
||||||
"持续上报/刷卡交易",
|
|
||||||
"第三方接口推送",
|
|
||||||
"接口/人工录入",
|
|
||||||
"vehicle_type(车型)"
|
|
||||||
],
|
],
|
||||||
"type": "多选上报频率逐 条 ( 高频)上报频率每 1 分钟10~30 秒分钟级不定时speed(车速km/h)",
|
"type": "多选",
|
||||||
"answer": "ABD时效要求秒级(实时)时效要求分钟级准实时分钟级准实时/离线pass_time(过车时间)",
|
"answer": "ABD",
|
||||||
"source_id": "30",
|
"source_id": "30",
|
||||||
"page_number": 142,
|
"page_number": 142,
|
||||||
"source_file": "中华人民共和国数据安全法gantry_id(卡口编号)",
|
"source_file": "中华人民共和国数据安全法",
|
||||||
"id": 756
|
"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
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Reference in New Issue
Block a user