import os,re,json

# 读取数据库并转成题目字典
with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f:
    database = f.read()
pro_dict = json.loads(database)

count = 0
#根据特征字符识别题目类型
for p in pro_dict:
    if pro_dict[p]["genre"] == "":
        count += 1
        if "bracket" in pro_dict[p]["content"]:
            pro_dict[p]["genre"] = "选择题"
            print(p,"选择题")
        elif "blank" in pro_dict[p]["content"]:
            pro_dict[p]["genre"] = "填空题"
            print(p,"填空题")
        else:
            pro_dict[p]["genre"] = "解答题"
            pro_dict[p]["space"] = "12ex"
            print(p,"解答题")

#将修改结果写入json数据库
database = json.dumps(pro_dict,indent = 4, ensure_ascii= False)
with open(r"../题库0.3/Problems.json","w",encoding = "utf8") as f:
    f.write(database)
if count > 0:
    print("为 %d 道题目确定类型" %count)
else:
    print("均已确定题目类型")