Use dict comprehension in auto replace processing
This commit is contained in:
@@ -495,12 +495,10 @@ class Tokenizer(ABC):
|
|||||||
def doPreProcessing(self) -> None:
|
def doPreProcessing(self) -> None:
|
||||||
"""Run pre-processing jobs before the text is tokenized."""
|
"""Run pre-processing jobs before the text is tokenized."""
|
||||||
# Process the user's auto-replace dictionary
|
# Process the user's auto-replace dictionary
|
||||||
if autoReplace := self._project.data.autoReplace:
|
if entry := self._project.data.autoReplace:
|
||||||
repDict = {}
|
replace = {f"<{k}>": v for k, v in entry.items()}
|
||||||
for aKey, aVal in autoReplace.items():
|
rxRep = re.compile("|".join([re.escape(k) for k in replace]), flags=re.DOTALL)
|
||||||
repDict[f"<{aKey}>"] = aVal
|
self._text = rxRep.sub(lambda x: replace[x.group(0)], self._text)
|
||||||
xRep = re.compile("|".join([re.escape(k) for k in repDict.keys()]), flags=re.DOTALL)
|
|
||||||
self._text = xRep.sub(lambda x: repDict[x.group(0)], self._text)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def tokenizeText(self) -> None:
|
def tokenizeText(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user