From 2464746d1700f1f777b8ccfc839d6aea6c4a71e8 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Mon, 4 Mar 2024 20:28:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=9C=AC=E8=BD=AC=E6=8D=A2=E5=A4=84?= =?UTF-8?q?=E7=90=86=20=E5=8A=9F=E8=83=BD=20=E6=96=B0=E5=A2=9E=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=B8=AD=E7=9A=84=E5=8D=8A?= =?UTF-8?q?=E8=A7=92=E6=A0=87=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/Ui_文本转换处理.py | 20 +++++++++++++------- 工具v2/database_tools.py | 7 ++++--- 工具v2/文本转换处理.py | 4 +++- 工具v2/文本转换处理.ui | 15 +++++++++++---- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/工具v2/Ui_文本转换处理.py b/工具v2/Ui_文本转换处理.py index d776009a..4707f004 100644 --- a/工具v2/Ui_文本转换处理.py +++ b/工具v2/Ui_文本转换处理.py @@ -43,27 +43,32 @@ class Ui_Form(object): font = QFont() font.setBold(True) self.pushButton_convert.setFont(font) - self.widget = QWidget(Form) - self.widget.setObjectName(u"widget") - self.widget.setGeometry(QRect(320, 120, 97, 74)) - self.verticalLayout = QVBoxLayout(self.widget) + self.layoutWidget = QWidget(Form) + self.layoutWidget.setObjectName(u"layoutWidget") + self.layoutWidget.setGeometry(QRect(320, 80, 91, 100)) + self.verticalLayout = QVBoxLayout(self.layoutWidget) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(0, 0, 0, 0) - self.radioButton_mathpix = QRadioButton(self.widget) + self.radioButton_mathpix = QRadioButton(self.layoutWidget) self.radioButton_mathpix.setObjectName(u"radioButton_mathpix") self.verticalLayout.addWidget(self.radioButton_mathpix) - self.radioButton_textcircled = QRadioButton(self.widget) + self.radioButton_textcircled = QRadioButton(self.layoutWidget) self.radioButton_textcircled.setObjectName(u"radioButton_textcircled") self.verticalLayout.addWidget(self.radioButton_textcircled) - self.radioButton_multiple = QRadioButton(self.widget) + self.radioButton_multiple = QRadioButton(self.layoutWidget) self.radioButton_multiple.setObjectName(u"radioButton_multiple") self.verticalLayout.addWidget(self.radioButton_multiple) + self.radioButton_puctuations = QRadioButton(self.layoutWidget) + self.radioButton_puctuations.setObjectName(u"radioButton_puctuations") + + self.verticalLayout.addWidget(self.radioButton_puctuations) + self.retranslateUi(Form) @@ -80,5 +85,6 @@ class Ui_Form(object): self.radioButton_mathpix.setText(QCoreApplication.translate("Form", u"Mathpix", None)) self.radioButton_textcircled.setText(QCoreApplication.translate("Form", u"\u5706\u5708\u6570\u5b57", None)) self.radioButton_multiple.setText(QCoreApplication.translate("Form", u"\u591a\u9009\u8f6c\u586b\u7a7a", None)) + self.radioButton_puctuations.setText(QCoreApplication.translate("Form", u"\u6807\u70b9\u8f6c\u534a\u89d2", None)) # retranslateUi diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 610a48d2..0e02cdc3 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -150,6 +150,7 @@ def generate_number_set(string,*thedict): #根据可能含有":"和","的题号 string = re.sub(r"[\n\s]","",string).strip() while not string[-1] in "0123456789": string = string[:-1] + string = RefinePunctuations(string) string_list = string.split(",") numbers_list = [] for s in string_list: @@ -1385,8 +1386,8 @@ def itemizeProblems(string): #将题号替换为\item string = "\n".join(itemed_list) return string -def RefinePuctuations(raw_string): - puctuationsfulltosemi = {" ": " ","。": ". ",".": ". ",",": ", ",":": ": ",";": "; ","(": "(",")": ")","?": "? ","“": "``","”": "''", "【": "[", "】": "]"} +def RefinePunctuations(raw_string): + puctuationsfulltosemi = {" ": " ","。": ". ",".": ". ",",": ", ",":": ": ",";": "; ","(": "(",")": ")","?": "? ","“": "``","”": "''", "【": "[", "】": "]", "!": "!"} string = raw_string.strip() for s in puctuationsfulltosemi: string = re.sub(s,puctuationsfulltosemi[s],string) #将部分全角标记替换为半角 @@ -2096,7 +2097,7 @@ def makedir(dirpath): #递归创建文件夹 def TitleIDStringtoTupleList(raw_string): #将类json的标题与题号对应变为(标题,题号字符串)的tuple之后组成list corresponding_list = [] - raw_string = RefinePuctuations(raw_string).replace("{","").replace("}","") + raw_string = RefinePunctuations(raw_string).replace("{","").replace("}","") raw_list = [re.sub(r"(?:(?:\s)|(?:,\s*$))","",t) for t in raw_string.split("\n") if not t.strip() == ""] for raw_item in raw_list: item = raw_item.replace('"','').replace(";","") diff --git a/工具v2/文本转换处理.py b/工具v2/文本转换处理.py index 43a2b074..6dfe2f2f 100644 --- a/工具v2/文本转换处理.py +++ b/工具v2/文本转换处理.py @@ -18,11 +18,13 @@ class MyWindow(QWidget,Ui_Form): dest_string = re.sub(r"\((\d)\)",lambda x: "\\textcircled{"+x.group(1)+"}",raw_string) #替换所有的小括号包围的单个数字为圆圈包围的 dest_string = re.sub(r"\$\\textcircled\{\\scriptsize\{(\d)\}\}",lambda x: "\\textcircled{"+x.group(1)+"}$",dest_string) dest_string = re.sub(r"\\textcircled\{\\scriptsize\{(\d)\}\}",lambda x: "\\textcircled{"+x.group(1)+"}",dest_string) - else: + elif self.radioButton_multiple.isChecked(): try: dest_string = MultiplechoicetoBlankFilling(raw_string) except: dest_string = "转换失败" + elif self.radioButton_puctuations.isChecked(): + dest_string = RefinePunctuations(raw_string) self.plainTextEdit_dest.setPlainText(dest_string) diff --git a/工具v2/文本转换处理.ui b/工具v2/文本转换处理.ui index 0b48f163..17698267 100644 --- a/工具v2/文本转换处理.ui +++ b/工具v2/文本转换处理.ui @@ -89,13 +89,13 @@ 转换 - + 320 - 120 - 97 - 74 + 80 + 91 + 100 @@ -120,6 +120,13 @@ + + + + 标点转半角 + + +