新增 文件或剪贴板提取答案 功能并加入面板
This commit is contained in:
parent
611eb4041e
commit
ba573b4dce
|
|
@ -1803,6 +1803,31 @@ def getindex(string,pos = 2):
|
||||||
para = string.split(".")
|
para = string.split(".")
|
||||||
return int(para[pos-1])
|
return int(para[pos-1])
|
||||||
|
|
||||||
|
def generateListOfIDandContent(string): #根据标准的讲义LaTeX源码字符串(可能含答案)生成一个list, 每一项是一个(id,id后内容)的tuple
|
||||||
|
return re.findall(r"\((\d{6})\)([\s\S]*?)(?:(?:\\item)|(?:\\end\{enumerate\}))",string)
|
||||||
|
|
||||||
|
def CountEffectiveBraces(string): #在string中统计有效的(LaTeX的\{和\}不算作有效)的大括号的个数, 返回(左大括号个数, 右大括号个数)
|
||||||
|
string_ref = re.sub(r"\\[\{\}]"," ",string)
|
||||||
|
return (string_ref.count("{"),string_ref.count("}"))
|
||||||
|
|
||||||
|
def generateAnswerTex(content,anspreamble = "答案: \\textcolor{red}{"): #在从anspreamble开始的字符串后找到答案字符串(anspreamble中的字符不算)
|
||||||
|
startpos = content.index(anspreamble) + len(anspreamble) - 1
|
||||||
|
endpos = startpos + 1
|
||||||
|
l,r = CountEffectiveBraces(content[startpos:endpos])
|
||||||
|
while not l == r:
|
||||||
|
endpos += 1
|
||||||
|
l,r = CountEffectiveBraces(content[startpos:endpos])
|
||||||
|
return content[startpos+1:endpos-1].strip()
|
||||||
|
|
||||||
|
def generateAnswerList(string,anspreamble = "答案: \\textcolor{red}{"): #从LaTeX源代码string中分析题号与对应的答案
|
||||||
|
alist = generateListOfIDandContent(string)
|
||||||
|
anslist = []
|
||||||
|
for a in alist:
|
||||||
|
id,content = a
|
||||||
|
if anspreamble in content:
|
||||||
|
anslist.append((id,generateAnswerTex(content,anspreamble)))
|
||||||
|
return anslist
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("数据库工具, import用.")
|
print("数据库工具, import用.")
|
||||||
|
|
@ -92,7 +92,7 @@ MaintainenceMenu.add_command(label = "合并使用记录并排序", command = la
|
||||||
MaintainenceMenu.add_separator()
|
MaintainenceMenu.add_separator()
|
||||||
MaintainenceMenu.add_command(label = "统考数据导入", command = lambda: SetButton("统考数据导入",["统考数据导入.py"]))
|
MaintainenceMenu.add_command(label = "统考数据导入", command = lambda: SetButton("统考数据导入",["统考数据导入.py"]))
|
||||||
MaintainenceMenu.add_command(label = "手动统计结果导入", command = lambda: SetButton("手动统计结果导入",["临时文件/手动统计结果.txt"]))
|
MaintainenceMenu.add_command(label = "手动统计结果导入", command = lambda: SetButton("手动统计结果导入",["临时文件/手动统计结果.txt"]))
|
||||||
MaintainenceMenu.add_command(label = "转换手打答案至metadata", command = lambda: SetButton("转换手打答案至metadata",["转换手打答案至metadata.py"]))
|
MaintainenceMenu.add_command(label = "文件或剪贴板提取答案", command = lambda: SetButton("文件或剪贴板提取答案",["文件或剪贴板提取答案.py"]))
|
||||||
MaintainenceMenu.add_separator()
|
MaintainenceMenu.add_separator()
|
||||||
MaintainenceMenu.add_command(label = "移除关联题号", command = lambda: SetButton("移除关联题号",["文本文件/metadata.txt"]))
|
MaintainenceMenu.add_command(label = "移除关联题号", command = lambda: SetButton("移除关联题号",["文本文件/metadata.txt"]))
|
||||||
MaintainenceMenu.add_separator()
|
MaintainenceMenu.add_separator()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
from database_tools import *
|
||||||
|
|
||||||
|
configjson = load_dict("文本文件/config.json")["文件或剪贴板提取答案.py"]
|
||||||
|
preamble = configjson["前缀"]
|
||||||
|
|
||||||
|
|
||||||
|
if configjson["来自剪贴板"] == True:
|
||||||
|
data = getCopy()
|
||||||
|
else:
|
||||||
|
data = ReadTextFile(configjson["文件地址"])
|
||||||
|
|
||||||
|
anslist = generateAnswerList(data,preamble)
|
||||||
|
|
||||||
|
output = "ans\n\n"
|
||||||
|
for id,ans in anslist:
|
||||||
|
if not ans == "暂无答案":
|
||||||
|
output += f"{id}\n{ans}\n\n"
|
||||||
|
|
||||||
|
SaveTextFile(output,"文本文件/metadata.txt")
|
||||||
|
|
||||||
|
|
@ -67,5 +67,10 @@
|
||||||
"备注": true,
|
"备注": true,
|
||||||
"届别": []
|
"届别": []
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"文件或剪贴板提取答案.py": {
|
||||||
|
"来自剪贴板": true,
|
||||||
|
"文件地址": "d:/temp/test5.tex",
|
||||||
|
"前缀": "答案: \\textcolor{red}{"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue