文本转换处理 功能 新增转换字符串中的半角标点
This commit is contained in:
parent
d2f272114f
commit
2464746d17
|
|
@ -43,27 +43,32 @@ class Ui_Form(object):
|
||||||
font = QFont()
|
font = QFont()
|
||||||
font.setBold(True)
|
font.setBold(True)
|
||||||
self.pushButton_convert.setFont(font)
|
self.pushButton_convert.setFont(font)
|
||||||
self.widget = QWidget(Form)
|
self.layoutWidget = QWidget(Form)
|
||||||
self.widget.setObjectName(u"widget")
|
self.layoutWidget.setObjectName(u"layoutWidget")
|
||||||
self.widget.setGeometry(QRect(320, 120, 97, 74))
|
self.layoutWidget.setGeometry(QRect(320, 80, 91, 100))
|
||||||
self.verticalLayout = QVBoxLayout(self.widget)
|
self.verticalLayout = QVBoxLayout(self.layoutWidget)
|
||||||
self.verticalLayout.setObjectName(u"verticalLayout")
|
self.verticalLayout.setObjectName(u"verticalLayout")
|
||||||
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
|
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.radioButton_mathpix.setObjectName(u"radioButton_mathpix")
|
||||||
|
|
||||||
self.verticalLayout.addWidget(self.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.radioButton_textcircled.setObjectName(u"radioButton_textcircled")
|
||||||
|
|
||||||
self.verticalLayout.addWidget(self.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.radioButton_multiple.setObjectName(u"radioButton_multiple")
|
||||||
|
|
||||||
self.verticalLayout.addWidget(self.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)
|
self.retranslateUi(Form)
|
||||||
|
|
||||||
|
|
@ -80,5 +85,6 @@ class Ui_Form(object):
|
||||||
self.radioButton_mathpix.setText(QCoreApplication.translate("Form", u"Mathpix", None))
|
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_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_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
|
# retranslateUi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,7 @@ def generate_number_set(string,*thedict): #根据可能含有":"和","的题号
|
||||||
string = re.sub(r"[\n\s]","",string).strip()
|
string = re.sub(r"[\n\s]","",string).strip()
|
||||||
while not string[-1] in "0123456789":
|
while not string[-1] in "0123456789":
|
||||||
string = string[:-1]
|
string = string[:-1]
|
||||||
|
string = RefinePunctuations(string)
|
||||||
string_list = string.split(",")
|
string_list = string.split(",")
|
||||||
numbers_list = []
|
numbers_list = []
|
||||||
for s in string_list:
|
for s in string_list:
|
||||||
|
|
@ -1385,8 +1386,8 @@ def itemizeProblems(string): #将题号替换为\item
|
||||||
string = "\n".join(itemed_list)
|
string = "\n".join(itemed_list)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def RefinePuctuations(raw_string):
|
def RefinePunctuations(raw_string):
|
||||||
puctuationsfulltosemi = {" ": " ","。": ". ",".": ". ",",": ", ",":": ": ",";": "; ","(": "(",")": ")","?": "? ","“": "``","”": "''", "【": "[", "】": "]"}
|
puctuationsfulltosemi = {" ": " ","。": ". ",".": ". ",",": ", ",":": ": ",";": "; ","(": "(",")": ")","?": "? ","“": "``","”": "''", "【": "[", "】": "]", "!": "!"}
|
||||||
string = raw_string.strip()
|
string = raw_string.strip()
|
||||||
for s in puctuationsfulltosemi:
|
for s in puctuationsfulltosemi:
|
||||||
string = re.sub(s,puctuationsfulltosemi[s],string) #将部分全角标记替换为半角
|
string = re.sub(s,puctuationsfulltosemi[s],string) #将部分全角标记替换为半角
|
||||||
|
|
@ -2096,7 +2097,7 @@ def makedir(dirpath): #递归创建文件夹
|
||||||
|
|
||||||
def TitleIDStringtoTupleList(raw_string): #将类json的标题与题号对应变为(标题,题号字符串)的tuple之后组成list
|
def TitleIDStringtoTupleList(raw_string): #将类json的标题与题号对应变为(标题,题号字符串)的tuple之后组成list
|
||||||
corresponding_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() == ""]
|
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:
|
for raw_item in raw_list:
|
||||||
item = raw_item.replace('"','').replace(";","")
|
item = raw_item.replace('"','').replace(";","")
|
||||||
|
|
|
||||||
|
|
@ -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"\((\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)
|
||||||
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:
|
try:
|
||||||
dest_string = MultiplechoicetoBlankFilling(raw_string)
|
dest_string = MultiplechoicetoBlankFilling(raw_string)
|
||||||
except:
|
except:
|
||||||
dest_string = "转换失败"
|
dest_string = "转换失败"
|
||||||
|
elif self.radioButton_puctuations.isChecked():
|
||||||
|
dest_string = RefinePunctuations(raw_string)
|
||||||
self.plainTextEdit_dest.setPlainText(dest_string)
|
self.plainTextEdit_dest.setPlainText(dest_string)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,13 +89,13 @@
|
||||||
<string>转换</string>
|
<string>转换</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>320</x>
|
<x>320</x>
|
||||||
<y>120</y>
|
<y>80</y>
|
||||||
<width>97</width>
|
<width>91</width>
|
||||||
<height>74</height>
|
<height>100</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
|
@ -120,6 +120,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="radioButton_puctuations">
|
||||||
|
<property name="text">
|
||||||
|
<string>标点转半角</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
||||||
Reference in New Issue