From 3196dce1a8c3070689f12b87987076e158565268 Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Wed, 28 Jun 2023 13:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A7=BB=E9=99=A4=E5=85=B3?= =?UTF-8?q?=E8=81=94=E9=A2=98=E5=8F=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 16 +++++++++++ 工具v2/文本文件/metadata.txt | 53 ++---------------------------------- 工具v2/移除关联题号.py | 10 +++++++ 3 files changed, 29 insertions(+), 50 deletions(-) create mode 100644 工具v2/移除关联题号.py diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index c67e5deb..fae138ca 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -566,5 +566,21 @@ def ModifyProblembyTeX(id_string,prodict,toeditfilepath,editor): # vscode打开. save_dict(prodict,"../题库0.3/problems.json") return generate_exp(editedIDList) # 返回编辑过的字典 + +def RemoveMutualLink(metadata,prodict): # 删除双向关联id(same,related,unrelated), 输入为一个字符串, 每行表示一对题号, 用空格或制表符隔开 + lines = [re.sub(r"[\s]+",r"\t",line).strip() for line in metadata.split("\n")] + for line in lines: + if not line == []: + id1,id2 = line.split("\t") + id1 = id1.zfill(6) + id2 = id2.zfill(6) + for field in ["same","related","unrelated"]: + if id1 in prodict[id2][field]: + prodict[id2][field].remove(id1) + if id2 in prodict[id1][field]: + prodict[id1][field].remove(id2) + return 0 # 返回0 + + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file diff --git a/工具v2/文本文件/metadata.txt b/工具v2/文本文件/metadata.txt index 0d158334..ce7d7d26 100644 --- a/工具v2/文本文件/metadata.txt +++ b/工具v2/文本文件/metadata.txt @@ -1,50 +1,3 @@ -usages - -000003 -20220825 2023届高三02班 0.909 0.758 -20220825 2023届高三08班 0.929 0.818 -20220825 2023届高三10班 0.963 -20220826 2023届高三11班 0.543 0.213 - -ans -1 -$2$ - -2 -正好 - -objs -123 -K0102001B - -opp -121 -23456 - - -id -000008 -000009 - -origin -12345 -123456 - -unrelated -3 -4 - -unrelated -4 -3 - -tags -5 -哈哈 -六六 - -usages - -000003 -20220825 2023届高三08班 0.929 0.818 FORCE -20220824 2023届高三08班 0.939 0.818 \ No newline at end of file +52 8096 +52 8097 +53 8096 \ No newline at end of file diff --git a/工具v2/移除关联题号.py b/工具v2/移除关联题号.py new file mode 100644 index 00000000..22545ac5 --- /dev/null +++ b/工具v2/移除关联题号.py @@ -0,0 +1,10 @@ +metadatafilepath = "文本文件/metadata.txt" + + +from database_tools import * +pro_dict = load_dict("../题库0.3/problems.json") + +metadata = ReadTextFile(metadatafilepath).strip() +RemoveMutualLink(metadata,pro_dict) + +save_dict(pro_dict,"../题库0.3/problems.json") \ No newline at end of file