20230329 night
This commit is contained in:
parent
92163e763f
commit
2650c34c04
|
|
@ -39,6 +39,8 @@ def run_command():
|
||||||
call(["python","修改题目数据库.py"])
|
call(["python","修改题目数据库.py"])
|
||||||
elif selectedtool == "修改题目STEP2":
|
elif selectedtool == "修改题目STEP2":
|
||||||
call(["python","修改结果汇入.py"])
|
call(["python","修改结果汇入.py"])
|
||||||
|
elif selectedtool == "mathpix预处理":
|
||||||
|
call(["python","../文本处理工具/剪贴板文本整理_mathpix.py"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -101,6 +103,11 @@ LabelUSE.place(x=20,y=400)
|
||||||
ButtonTHXT = Button(root, text = "题号选题pdf生成", command = lambda: (commandname.set("题号选题pdf生成"),LabelTool.config(text = "题号选题pdf生成")))
|
ButtonTHXT = Button(root, text = "题号选题pdf生成", command = lambda: (commandname.set("题号选题pdf生成"),LabelTool.config(text = "题号选题pdf生成")))
|
||||||
ButtonTHXT.place(x=20,y=420)
|
ButtonTHXT.place(x=20,y=420)
|
||||||
|
|
||||||
|
|
||||||
|
# 剪贴板文字处理按钮
|
||||||
|
ButtonClip = Button(root, text = "mathpix预处理", height= 1, width = 13, command = lambda: (commandname.set("mathpix预处理"),LabelTool.config(text = "mathpix预处理")))
|
||||||
|
ButtonClip.place(x=420, y = 550)
|
||||||
|
|
||||||
# 运行按钮
|
# 运行按钮
|
||||||
ButtonGo = Button(root, text ="运行", height = 1, width = 5, command = run_command)
|
ButtonGo = Button(root, text ="运行", height = 1, width = 5, command = run_command)
|
||||||
ButtonGo.place(x=600, y= 550)
|
ButtonGo.place(x=600, y= 550)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
from tkinter import *
|
||||||
|
from subprocess import call
|
||||||
|
import os
|
||||||
|
|
||||||
|
root = Tk()
|
||||||
|
|
||||||
|
root.geometry('800x600')
|
||||||
|
|
||||||
|
root.title('题库v2.0工具面板')
|
||||||
|
|
||||||
|
def temp():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def SetButton1(str):
|
||||||
|
commandname.set(str)
|
||||||
|
LabelTool.config(text = str)
|
||||||
|
button1.place(x = 600, y = 550)
|
||||||
|
button2.place_forget()
|
||||||
|
|
||||||
|
|
||||||
|
def run_command1():
|
||||||
|
selectedtool = commandname.get()
|
||||||
|
if selectedtool == "题号选题pdf生成":
|
||||||
|
call(["python","题号选题pdf生成.py"])
|
||||||
|
elif selectedtool == "寻找空闲题号":
|
||||||
|
call(["python","寻找空闲题号.py"])
|
||||||
|
elif selectedtool == "批量收录题目":
|
||||||
|
call(["python","批量收录题目.py"])
|
||||||
|
elif selectedtool == "添加关联题目":
|
||||||
|
call(["python","添加关联题目.py"])
|
||||||
|
elif selectedtool == "修改题目数据库":
|
||||||
|
call(["python","修改题目数据库.py"])
|
||||||
|
elif selectedtool == "mathpix预处理":
|
||||||
|
call(["python","../文本处理工具/剪贴板文本整理_mathpix.py"])
|
||||||
|
elif selectedtool == "带圈数字处理":
|
||||||
|
call(["python","../文本处理工具/带圈数字处理.py"])
|
||||||
|
LabelTool.config(text = "STEP1命令执行完毕")
|
||||||
|
|
||||||
|
def run_command2():
|
||||||
|
selectedtool = commandname.get()
|
||||||
|
if selectedtool == "添加关联题目":
|
||||||
|
call(["python","导入关联题目.py"])
|
||||||
|
elif selectedtool == "修改题目数据库":
|
||||||
|
call(["python","修改结果汇入.py"])
|
||||||
|
LabelTool.config(text = "STEP2命令执行完毕")
|
||||||
|
|
||||||
|
commandname = StringVar()
|
||||||
|
commandname.set("none")
|
||||||
|
LabelTool = Label(root, text = "工具选择待定", height = 1, width = 25, anchor=W)
|
||||||
|
LabelTool.place(x=420,y=50)
|
||||||
|
|
||||||
|
button1 = Button(root, text = "运行STEP1", command = run_command1)
|
||||||
|
button2 = Button(root, text = "运行STEP2", command = run_command2)
|
||||||
|
button3 = Button(root, text = "运行STEP3")
|
||||||
|
|
||||||
|
menubar = Menu(root)
|
||||||
|
|
||||||
|
# 设置 录入 菜单项
|
||||||
|
ImportMenu = Menu(menubar, tearoff = False)
|
||||||
|
menubar.add_cascade(label = "录入", menu = ImportMenu)
|
||||||
|
ImportMenu.add_command(label = "寻找空闲题号", command = lambda: (commandname.set("寻找空闲题号"),LabelTool.config(text = "寻找空闲题号"),button1.place(x = 600, y = 550),button2.place_forget()))
|
||||||
|
ImportMenu.add_separator()
|
||||||
|
ImportMenu.add_command(label = "批量收录题目", command = lambda: (commandname.set("批量收录题目"),LabelTool.config(text = "批量收录题目"),button1.place(x = 600, y = 550),button2.place_forget(),os.system("code 批量收录题目.py")))
|
||||||
|
ImportMenu.add_command(label = "添加关联题目", command = lambda: (commandname.set("添加关联题目"),LabelTool.config(text = "添加关联题目(两阶段)"),button1.place(x = 600, y = 550),button2.place(x = 700, y = 550),os.system("code 添加关联题目.py")))
|
||||||
|
|
||||||
|
# 设置 维护 菜单项
|
||||||
|
MaintainenceMenu = Menu(menubar, tearoff = False)
|
||||||
|
menubar.add_cascade(label = "维护", menu = MaintainenceMenu)
|
||||||
|
MaintainenceMenu.add_command(label = "修改题目", command = lambda: (commandname.set("修改题目数据库"),LabelTool.config(text = "修改题目(两阶段)"),button1.place(x = 600, y = 550),button2.place(x = 700, y = 550),os.system("code 修改题目数据库.py")))
|
||||||
|
|
||||||
|
# 设置 使用 菜单项
|
||||||
|
UseMenu = Menu(menubar, tearoff = False)
|
||||||
|
menubar.add_cascade(label = "使用", menu = UseMenu)
|
||||||
|
UseMenu.add_command(label = "题号选题pdf生成", command = lambda: (commandname.set("题号选题pdf生成"),LabelTool.config(text = "题号选题pdf生成"),button1.place(x = 600, y = 550),button2.place_forget(),os.system("code 题号选题pdf生成.py")))
|
||||||
|
|
||||||
|
# 设置 其他 菜单项
|
||||||
|
OtherMenu = Menu(menubar, tearoff = False)
|
||||||
|
menubar.add_cascade(label = "其他", menu = OtherMenu)
|
||||||
|
OtherMenu.add_command(label = "mathpix预处理", command = lambda: (commandname.set("mathpix预处理"),LabelTool.config(text = "mathpix预处理"),button1.place(x = 600, y = 550),button2.place_forget()))
|
||||||
|
OtherMenu.add_command(label = "带圈数字处理", command = lambda: (commandname.set("带圈数字处理"),LabelTool.config(text = "带圈数字处理"),button1.place(x = 600, y = 550),button2.place_forget()))
|
||||||
|
|
||||||
|
|
||||||
|
menubar.add_command(label = "退出", command = root.destroy)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
root.config(menu = menubar)
|
||||||
|
|
||||||
|
root.mainloop()
|
||||||
|
|
@ -7,13 +7,13 @@ import os,re,time,json,sys
|
||||||
"""---设置题目列表---"""
|
"""---设置题目列表---"""
|
||||||
#留空为编译全题库, a为读取临时文件中的题号筛选.txt文件生成题库
|
#留空为编译全题库, a为读取临时文件中的题号筛选.txt文件生成题库
|
||||||
problems = r"""
|
problems = r"""
|
||||||
a
|
1:10
|
||||||
"""
|
"""
|
||||||
"""---设置题目列表结束---"""
|
"""---设置题目列表结束---"""
|
||||||
|
|
||||||
"""---设置文件名---"""
|
"""---设置文件名---"""
|
||||||
#目录和文件的分隔务必用/
|
#目录和文件的分隔务必用/
|
||||||
filename = "临时文件/易错题"
|
filename = "临时文件/测试"
|
||||||
"""---设置文件名结束---"""
|
"""---设置文件名结束---"""
|
||||||
|
|
||||||
"""---设置是否需要解答题的空格---"""
|
"""---设置是否需要解答题的空格---"""
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,368 @@
|
||||||
|
import os,re
|
||||||
|
import win32clipboard as wc
|
||||||
|
import win32con
|
||||||
|
|
||||||
|
# 获取剪切板内容
|
||||||
|
def getCopy():
|
||||||
|
wc.OpenClipboard()
|
||||||
|
t = wc.GetClipboardData(win32con.CF_UNICODETEXT)
|
||||||
|
wc.CloseClipboard()
|
||||||
|
return t
|
||||||
|
|
||||||
|
# 写入剪切板内容
|
||||||
|
def setCopy(str):
|
||||||
|
wc.OpenClipboard()
|
||||||
|
wc.EmptyClipboard()
|
||||||
|
wc.SetClipboardData(win32con.CF_UNICODETEXT, str)
|
||||||
|
wc.CloseClipboard()
|
||||||
|
|
||||||
|
def full_stop(matchobj):
|
||||||
|
if matchobj.group(1) == "。" or matchobj.group(1) == ".":
|
||||||
|
return ". "
|
||||||
|
else:
|
||||||
|
return ".\n"
|
||||||
|
def refine_brackets(matchobj):
|
||||||
|
return matchobj.group(1)[1:-1]
|
||||||
|
def insert_a_blank(matchobj):
|
||||||
|
return matchobj.group(1)[:-1]+" "+matchobj.group(1)[-1]
|
||||||
|
def multiple_choice(matchobj):
|
||||||
|
string = "\\fourch" + "{" + matchobj.group(1) + "}{" + matchobj.group(2) + "}{" + matchobj.group(3) + "}{" + matchobj.group(4) + "}\n"
|
||||||
|
return string
|
||||||
|
def boldsymbols(matchobj):
|
||||||
|
return "\\i"+matchobj.group(1)[:-1]+"\\mathbf{"+matchobj.group(1)[-1]+"}"
|
||||||
|
def boldsymbols_star(matchobj):
|
||||||
|
return "\\in \\mathbf{"+matchobj.group(1)+"}^*"
|
||||||
|
def singleboldsymbols(matchobj):
|
||||||
|
return "$\\mathbf{" + matchobj.group(1) + "}$"
|
||||||
|
def blackboardbold(matchobj):
|
||||||
|
string = "\\mathbf" + "{" + matchobj.group(1) + "}"
|
||||||
|
return string
|
||||||
|
def limit(matchobj):
|
||||||
|
return "\\displaystyle\\lim_{"+matchobj.group(1)+"}"
|
||||||
|
def replace_i(matchobj):
|
||||||
|
string = matchobj.group(1)
|
||||||
|
length = len(string)
|
||||||
|
for i in range(length-1,-1,-1):
|
||||||
|
if string[i] == "i" and not "item" in string[i:] and not "overline" in string[i:]:
|
||||||
|
string = string[:i] + "\\mathrm{i}" + string[i+1:]
|
||||||
|
return string
|
||||||
|
def refine_log(matchobj):
|
||||||
|
return r"\log_"+matchobj.group(1)
|
||||||
|
def refine_powers(matchobj):
|
||||||
|
base = matchobj.group(1)
|
||||||
|
power = matchobj.group(2)
|
||||||
|
return base + "^" + power
|
||||||
|
def refine_sequences(matchobj):
|
||||||
|
return "\{" + matchobj.group(1) + "\}"
|
||||||
|
def refine_starting_brackets(matchobj):
|
||||||
|
return "$" + matchobj.group(1)
|
||||||
|
def refine_left_operating_brackets(matchobj):
|
||||||
|
obj = matchobj.group(2)
|
||||||
|
return matchobj.group(1)+obj
|
||||||
|
def refine_right_operating_brackets(matchobj):
|
||||||
|
obj = matchobj.group(1)
|
||||||
|
return obj + matchobj.group(2)
|
||||||
|
def refine_brackets_in_brackets(matchobj):
|
||||||
|
return matchobj.group(1) + matchobj.group(2) + matchobj.group(3)
|
||||||
|
def mathbf(matchobj):
|
||||||
|
return "\\mathbf{" + matchobj.group(1) + "}^" + matchobj.group(2)
|
||||||
|
#以上是202207之前的文本处理机制
|
||||||
|
global layer
|
||||||
|
def rename_bracket(matchobj):
|
||||||
|
return "leftbracket" + str(layer) + matchobj.group(1) + "rightbracket" + str(layer)
|
||||||
|
def frac_brackets(matchobj):
|
||||||
|
return "frac{"+matchobj.group(1)+"}{"+matchobj.group(2)+"}"
|
||||||
|
def frac_single_second_bracket(matchobj):
|
||||||
|
return "frac "+matchobj.group(1)+"{"+matchobj.group(2)+"}"
|
||||||
|
def recall_vital_bracket(matchobj):
|
||||||
|
return matchobj.group(1) + "{" + matchobj.group(2) + "}"
|
||||||
|
def sqrt_brackets(matchobj):
|
||||||
|
if matchobj.group(1) == None:
|
||||||
|
first_group = ""
|
||||||
|
else:
|
||||||
|
first_group = matchobj.group(1)
|
||||||
|
return "sqrt "+ first_group +"{" + matchobj.group(2) + "}"
|
||||||
|
#def refine_frac(string):
|
||||||
|
# for s in range(7):
|
||||||
|
# for t in range(7):
|
||||||
|
# string = re.sub(r"frac[\s]*leftbracket"+str(s)+"(.*?)"+r"rightbracket"+str(s)+"[\s]*"+r"leftbracket"+str(t)+"(.*?)"+r"rightbracket"+str(t),frac_brackets,string)
|
||||||
|
# return string
|
||||||
|
def refine_single_second_frac(string):
|
||||||
|
for s in range(7):
|
||||||
|
string = re.sub(r"frac[\s]*(\w)[\s]*leftbracket"+str(s)+"(.*?)"+r"rightbracket"+str(s),frac_single_second_bracket,string)
|
||||||
|
return string
|
||||||
|
def refine_vital_bracket(string):
|
||||||
|
for s in range(7):
|
||||||
|
string = re.sub(r"(frac)[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),recall_vital_bracket,string)
|
||||||
|
string = re.sub(r"(line)[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),recall_vital_bracket,string)
|
||||||
|
string = re.sub(r"(arrow)[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),recall_vital_bracket,string)
|
||||||
|
string = re.sub(r"(_)[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),recall_vital_bracket,string)
|
||||||
|
string = re.sub(r"(\^)[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),recall_vital_bracket,string)
|
||||||
|
string = re.sub(r"(mathrm)[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),recall_vital_bracket,string)
|
||||||
|
string = re.sub(r"(mathbf)[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),recall_vital_bracket,string)
|
||||||
|
string = re.sub(r"(begin)[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),recall_vital_bracket,string)
|
||||||
|
string = re.sub(r"(end)[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),recall_vital_bracket,string)
|
||||||
|
return string
|
||||||
|
def refine_sqrt(string):
|
||||||
|
for s in range(7):
|
||||||
|
string = re.sub(r"sqrt[\s]*(\[\w*\])*[\s]*leftbracket"+str(s)+"(.*?)rightbracket"+str(s),sqrt_brackets,string)
|
||||||
|
return string
|
||||||
|
def give_blanks(string):
|
||||||
|
string = re.sub(r"(sqrt[\w])",insert_a_blank,string)
|
||||||
|
string = re.sub(r"(frac[\w])",insert_a_blank,string)
|
||||||
|
return string
|
||||||
|
def give_brackets(string):
|
||||||
|
string = re.sub(r"leftbracket\d","",string)
|
||||||
|
string = re.sub(r"rightbracket\d","",string)
|
||||||
|
string = re.sub(r"leftset",r"\{",string)
|
||||||
|
string = re.sub(r"rightset",r"\}",string)
|
||||||
|
return string
|
||||||
|
#以上是20220715新加的文本处理机制
|
||||||
|
def initial_bracket_search(string):
|
||||||
|
t = re.search(r"^[\s]*?leftbracket(\d)",string)
|
||||||
|
if t == None:
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
return t.span()[1]
|
||||||
|
def initial_brackets_pair_search(string,d):
|
||||||
|
t = re.search("rightbracket"+d,string)
|
||||||
|
if t == None:
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
return t.span()[1]
|
||||||
|
def refine_frac(string):
|
||||||
|
eq_left = ""
|
||||||
|
eq_right = string
|
||||||
|
while re.search("frac",eq_right) != None:
|
||||||
|
pos = re.search("frac",eq_right)
|
||||||
|
eq_left += eq_right[:pos.span()[1]]
|
||||||
|
eq_right = eq_right[pos.span()[1]:]
|
||||||
|
if initial_bracket_search(eq_right)>0:
|
||||||
|
pos = initial_brackets_pair_search(eq_right,eq_right[initial_bracket_search(eq_right)-1])
|
||||||
|
first_bracket = eq_right[:pos]
|
||||||
|
first_layer = first_bracket[-1]
|
||||||
|
eq_remain = eq_right[pos:]
|
||||||
|
if initial_bracket_search(eq_remain)>0:
|
||||||
|
pos = initial_brackets_pair_search(eq_remain,eq_remain[initial_bracket_search(eq_remain)-1])
|
||||||
|
second_bracket = eq_remain[:pos]
|
||||||
|
second_layer = second_bracket[-1]
|
||||||
|
first_bracket = re.sub(r"leftbracket"+first_layer,"{",first_bracket)
|
||||||
|
second_bracket = re.sub(r"leftbracket"+second_layer,"{",second_bracket)
|
||||||
|
first_bracket = re.sub(r"rightbracket"+first_layer,"}",first_bracket)
|
||||||
|
second_bracket = re.sub(r"rightbracket"+second_layer,"}",second_bracket)
|
||||||
|
eq_right = first_bracket+second_bracket+eq_remain[pos:]
|
||||||
|
return eq_left+eq_right
|
||||||
|
#以上是20220718修改的大括号处理机制, 修复了一个bug
|
||||||
|
def reduce_blank(matchobj):
|
||||||
|
return matchobj.group(1).replace(" ","")
|
||||||
|
def add_dollars(matchobj):
|
||||||
|
return matchobj.group(1)[0] + r"$" + matchobj.group(1)[1:-1] + r"$" + matchobj.group(1)[-1]
|
||||||
|
def del_first_char(matchobj):
|
||||||
|
return matchobj.group(1)[1:]
|
||||||
|
def add_underline(matchobj):
|
||||||
|
return matchobj.group(1)[0] + "_" + matchobj.group(1)[-1]
|
||||||
|
def brackets_to_cwords(matchobj):
|
||||||
|
return "左括号"+matchobj.group(1)+"右括号"
|
||||||
|
def cwords_to_brackets(matchobj):
|
||||||
|
return "("+matchobj.group(1)+")"
|
||||||
|
def circled_brackets(matchobj):
|
||||||
|
return matchobj.group(1)[:-1]+"{"+matchobj.group(1)[-1] + "}"
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# os.chdir(r"D:\mathdept\mathdept\文本处理程序等")
|
||||||
|
# except:
|
||||||
|
# os.chdir(r"D:\mathdept\文本处理程序等")
|
||||||
|
# with open("textfile.txt", "r", encoding = "utf8") as textfile:
|
||||||
|
# data = textfile.read()
|
||||||
|
|
||||||
|
data = getCopy()
|
||||||
|
|
||||||
|
|
||||||
|
#去除左右括号的前缀
|
||||||
|
data = data.replace(r"\rightarrow",r"\to")
|
||||||
|
data = data.replace(r"\left.","").replace(r"\left","").replace(r"\right.","").replace(r"\right","")
|
||||||
|
|
||||||
|
#全角半角符号替换
|
||||||
|
data = re.sub(" "," ",data)
|
||||||
|
data = re.sub("(。[\n]*)",full_stop,data)
|
||||||
|
data = re.sub("(.[\n]*)",full_stop,data)
|
||||||
|
data = re.sub(",",", ",data)
|
||||||
|
data = re.sub(":",": ",data)
|
||||||
|
data = re.sub(";","; ",data)
|
||||||
|
data = re.sub("(","(",data)
|
||||||
|
data = re.sub(")",")",data)
|
||||||
|
data = re.sub("?","? ",data)
|
||||||
|
data = re.sub("“","``",data)
|
||||||
|
data = re.sub("”","''",data)
|
||||||
|
data = re.sub(" ``","``",data)
|
||||||
|
data = re.sub("'' ","''",data)
|
||||||
|
|
||||||
|
#替换题号
|
||||||
|
data = re.sub("(^[例]*[0-9]+[\s]*\.[\s]+)","\\n\\\\item ",data)
|
||||||
|
data = re.sub("(^[例]*[0-9]+[\s]*、[\s]*)","\\n\\\\item ",data)
|
||||||
|
data = re.sub("(\\n[例]*[0-9]+[\s]*\.[\s]+)","\\n\\\\item ",data)
|
||||||
|
data = re.sub("(\\n[例]*[0-9]+[\s]*、[\s]*)","\\n\\\\item ",data)
|
||||||
|
|
||||||
|
#公式标志换成$符号
|
||||||
|
data = re.sub("\\\\\[",r"$",data)
|
||||||
|
data = re.sub("\\\\\]",r"$",data)
|
||||||
|
data = re.sub("\$\$","",data)
|
||||||
|
|
||||||
|
#标点和$符号分开
|
||||||
|
data = re.sub(r"([,.:;])\$",lambda x:x.group(1)+" $",data)
|
||||||
|
|
||||||
|
#选择题替换成标准格式
|
||||||
|
data = re.sub("A\.([\s\S]*?)B\.([\s\S]*?)C\.([\s\S]*?)D\.([\s\S]*?)\\n",multiple_choice,data)
|
||||||
|
data = re.sub("\(A\)([\s\S]*?)\(B\)([\s\S]*?)\(C\)([\s\S]*?)\(D\)([\s\S]*?)\\n",multiple_choice,data)
|
||||||
|
data = re.sub("A\.([\s\S]*?)B\.([\s\S]*?)C\.([\s\S]*?)D\.([\s\S]*?)\\n",multiple_choice,data)
|
||||||
|
data = re.sub("\(A\)([\s\S]*?)\(B\)([\s\S]*?)\(C\)([\s\S]*?)\(D\)([\s\S]*?)\\n",multiple_choice,data)
|
||||||
|
data = re.sub("\$[ ]+\}","$}",data)
|
||||||
|
data = re.sub("\{[ ]+\$","{$",data)
|
||||||
|
|
||||||
|
#替换frac为dfrac
|
||||||
|
data = data.replace("\\frac","\\dfrac")
|
||||||
|
|
||||||
|
#替换多余的空行
|
||||||
|
for i in range(20):
|
||||||
|
data = re.sub("\n[\t ]*\n","\n",data)
|
||||||
|
|
||||||
|
#删除\quad
|
||||||
|
data = re.sub(r"\\q+uad","",data)
|
||||||
|
|
||||||
|
#删除~
|
||||||
|
data = re.sub(r"~","",data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
data1 = data #替换后暂存data1
|
||||||
|
|
||||||
|
#分离文字和公式
|
||||||
|
raw_texts = [] #文字数组
|
||||||
|
raw_equations = [] #公式数组
|
||||||
|
d = data
|
||||||
|
while len(d) > 0:
|
||||||
|
interval = re.search(r"\$[\s\S]*?\$",d)
|
||||||
|
if not interval == None:
|
||||||
|
(start, end) = interval.span()
|
||||||
|
raw_texts.append(d[:start])
|
||||||
|
raw_equations.append(d[start:end])
|
||||||
|
d = d[end:]
|
||||||
|
else:
|
||||||
|
raw_texts.append(d)
|
||||||
|
d = ""
|
||||||
|
#至此已经分离了文字和公式,公式在两个$之内,包含两个$
|
||||||
|
|
||||||
|
modified_texts = []
|
||||||
|
modified_equations = []
|
||||||
|
|
||||||
|
for text in raw_texts:
|
||||||
|
text1 = text
|
||||||
|
#删除选项中无用的空格
|
||||||
|
text1 = re.sub("\{[\s]+?","{",text1)
|
||||||
|
text1 = re.sub("[\s]+?\}","}",text1)
|
||||||
|
#填空题的处理
|
||||||
|
# text1 = re.sub("[ _]{2,}",r"\\blank{50}",text1)
|
||||||
|
#选择题的处理
|
||||||
|
text1 = re.sub(r"\(\\blank\{50\}\)","\\\\bracket{20}",text1)
|
||||||
|
text1 = re.sub(r"\([\s]{1,10}\)","\\\\bracket{20}",text1)
|
||||||
|
#逗号后面加空格
|
||||||
|
text1 = re.sub(",[ ]*",", ",text1)
|
||||||
|
text1 = re.sub(r"\.\}","}",text1)
|
||||||
|
text1 = re.sub(r"\n\d{1,3}\.",r"\n\\item ",text1)
|
||||||
|
# text1 = re.sub(r"\s{2,}\.",r"\\blank{50}.",text1)
|
||||||
|
# text1 = re.sub(r"\s{2,}\,",r"\\blank{50},",text1)
|
||||||
|
text1 = re.sub(r"\s*\\bracket\{20\}\s*\n",r"\\bracket{20}.\n",text1)
|
||||||
|
#改非规范选择题
|
||||||
|
text1 = re.sub(r"[\.;]\}","}",text1)
|
||||||
|
text1 = re.sub(r"([\u4e00-\u9fa5])[\s]+([\d]{1,6})[\s]+([\u4e00-\u9fa5])",lambda x:x.group(1)+"$"+x.group(2)+"$"+x.group(3),text1)
|
||||||
|
modified_texts.append(text1)
|
||||||
|
|
||||||
|
|
||||||
|
for equation in raw_equations:
|
||||||
|
equation1 = equation
|
||||||
|
#删除一些无效大括号
|
||||||
|
for i in range(3):
|
||||||
|
equation1 = re.sub(r"_\{([0-9a-zA-Z])\}",lambda x:"_"+x.group(1),equation1)
|
||||||
|
equation1 = re.sub(r"\^\{([0-9a-zA-Z])\}",lambda x:"^"+x.group(1),equation1)
|
||||||
|
#合并一些公式中的无效空格
|
||||||
|
for i in range(2):
|
||||||
|
equation1 = re.sub(r"([0-9A-Z])\s+([0-9A-Z])",lambda x:x.group(1)+x.group(2),equation1)
|
||||||
|
#改变组合数和排列数
|
||||||
|
equation1 = re.sub(r"([CP])(_[^_\^]{,5}\^)",lambda x:r"\mathrm{"+x.group(1)+"}"+x.group(2),equation1)
|
||||||
|
#改单位
|
||||||
|
equation1 = re.sub(r"mathrm\{cm\}","text{cm}",equation1)
|
||||||
|
equation1 = re.sub(r"mathrm\{km\}","text{km}",equation1)
|
||||||
|
modified_equations.append(equation1)
|
||||||
|
|
||||||
|
|
||||||
|
#整合修改过的文本和公式
|
||||||
|
modified_data = ""
|
||||||
|
for i in range(len(modified_texts)):
|
||||||
|
try:
|
||||||
|
modified_data += modified_texts[i]
|
||||||
|
except:
|
||||||
|
a = 1
|
||||||
|
try:
|
||||||
|
modified_data += modified_equations[i]
|
||||||
|
except:
|
||||||
|
a = 1
|
||||||
|
modified_data = re.sub(r"[ ]+\n","\n",modified_data)
|
||||||
|
modified_data = re.sub(r"\$[\s]*?\\parallel[\s]*?\$",r"\\parallel",modified_data)
|
||||||
|
modified_data = re.sub(r"\n例\s*?\d{1,3}\s*",r"\n\\item ",modified_data)
|
||||||
|
modified_data = re.sub(r"(\$[\,\.:;]\$)",refine_brackets,modified_data)
|
||||||
|
|
||||||
|
|
||||||
|
#以下是mathpix之后的空格去除
|
||||||
|
for i in range(3):
|
||||||
|
modified_data = re.sub(r"([\u4e00-\u9fa5])( )([\u4e00-\u9fa5])",lambda x:x.group(1)+x.group(3),modified_data)
|
||||||
|
modified_data = re.sub(r"\$ ","$",modified_data)
|
||||||
|
modified_data = re.sub(r" \$","$",modified_data)
|
||||||
|
#mathpix的错别字修改
|
||||||
|
modified_data = modified_data.replace("雉","锥")
|
||||||
|
modified_data = re.sub("[粗秿]圆","椭圆",modified_data)
|
||||||
|
modified_data = modified_data.replace("针角","钝角")
|
||||||
|
modified_data = re.sub("投郑","投掷",modified_data)
|
||||||
|
modified_data = re.sub("抛郑","抛掷",modified_data)
|
||||||
|
modified_data = re.sub("范目","范围",modified_data)
|
||||||
|
modified_data = re.sub("揷","插",modified_data)
|
||||||
|
#mathpix的自由向量修改
|
||||||
|
modified_data = modified_data.replace(r"\vec",r"\overrightarrow ")
|
||||||
|
modified_data = modified_data.replace(r"\bar",r"\overline ")
|
||||||
|
#mathpix的极限修改
|
||||||
|
modified_data = re.sub(r"\\lim[\s]*_\{n \\to \\infty\}",r"\\displaystyle\\lim_{n\\to\\infty}",modified_data)
|
||||||
|
#mathpix的顿号修改
|
||||||
|
modified_data = modified_data.replace(r" 、 ",r"$、$")
|
||||||
|
#改slant等
|
||||||
|
modified_data = modified_data.replace(r"slant","")
|
||||||
|
modified_data = modified_data.replace(r"\mid","|")
|
||||||
|
modified_data = re.sub(r"\\mathrm\{\\mathrm\{i\}\}",r"\\mathrm{i}",modified_data)
|
||||||
|
modified_data = modified_data.replace(",$",", $")
|
||||||
|
modified_data = modified_data.replace(" / /",r"\parallel")
|
||||||
|
modified_data = modified_data.replace("mathrmR",r"mathbf{R}")
|
||||||
|
modified_data = modified_data.replace(r"^{\prime}","'")
|
||||||
|
modified_data = re.sub(r"\^\{\\dfrac",r"^{\\frac",modified_data)
|
||||||
|
modified_data = re.sub(r"\^\{-\\dfrac",r"^{-\\frac",modified_data)
|
||||||
|
modified_data = re.sub(r"_\{\\dfrac",r"_{\\frac",modified_data)
|
||||||
|
modified_data = re.sub(r"_\{-\\dfrac",r"_{-\\frac",modified_data)
|
||||||
|
|
||||||
|
#改分段函数等
|
||||||
|
modified_data = re.sub(r"\\{\\begin\{array\}\{[rcl]*\}",r"\\begin{cases}",modified_data)
|
||||||
|
modified_data = re.sub(r"\\end{array}",r"\\end{cases}",modified_data)
|
||||||
|
|
||||||
|
#冒号后加空格
|
||||||
|
modified_data = re.sub(r":([\S])", lambda x:": "+x.group(1),modified_data)
|
||||||
|
|
||||||
|
#识别填空题加空格
|
||||||
|
modified_data = re.sub(r"([\u4e00-\u9fa5\$])[\s]*\n\\item",lambda x: x.group(1)+"\\blank{50}.\n\\item",modified_data)
|
||||||
|
|
||||||
|
#识别选择题加括号
|
||||||
|
modified_data = re.sub(r"\$\(\s*\)\$",r"\\bracket{20}",modified_data)
|
||||||
|
modified_data = re.sub(r"([\u4e00-\u9fa5\$])[\s]*\n\\fourch",lambda x: x.group(1)+"\\bracket{20}.\n\\fourch",modified_data)
|
||||||
|
|
||||||
|
#改圆弧
|
||||||
|
modified_data = re.sub(r"overparen",r"overset\\frown",modified_data)
|
||||||
|
|
||||||
|
setCopy(modified_data)
|
||||||
|
|
||||||
|
with open("临时文件/outputfile.txt","w",encoding = "utf8") as f:
|
||||||
|
f.write(modified_data)
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
import os,re
|
||||||
|
import win32clipboard as wc
|
||||||
|
import win32con
|
||||||
|
|
||||||
|
# 获取剪切板内容
|
||||||
|
def getCopy():
|
||||||
|
wc.OpenClipboard()
|
||||||
|
t = wc.GetClipboardData(win32con.CF_UNICODETEXT)
|
||||||
|
wc.CloseClipboard()
|
||||||
|
return t
|
||||||
|
|
||||||
|
# 写入剪切板内容
|
||||||
|
def setCopy(str):
|
||||||
|
wc.OpenClipboard()
|
||||||
|
wc.EmptyClipboard()
|
||||||
|
wc.SetClipboardData(win32con.CF_UNICODETEXT, str)
|
||||||
|
wc.CloseClipboard()
|
||||||
|
|
||||||
|
|
||||||
|
data = getCopy()
|
||||||
|
# print(modified_data)
|
||||||
|
modified_data = re.sub(r"\((\d)\)",lambda x: "\\textcircled{"+x.group(1)+"}",data)
|
||||||
|
# print(modified_data)
|
||||||
|
modified_data = re.sub(r"\$\\textcircled\{\\scriptsize\{(\d)\}\}",lambda x: "\\textcircled{"+x.group(1)+"}$",modified_data)
|
||||||
|
modified_data = re.sub(r"\\textcircled\{\\scriptsize\{(\d)\}\}",lambda x: "\\textcircled{"+x.group(1)+"}",modified_data)
|
||||||
|
|
||||||
|
|
||||||
|
setCopy(modified_data)
|
||||||
|
|
||||||
|
with open("临时文件/outputfile.txt","w",encoding = "utf8") as f:
|
||||||
|
f.write(modified_data)
|
||||||
Reference in New Issue