Skip to content

Commit

Permalink
search optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dyang886 committed Oct 18, 2024
1 parent a0d34de commit 115efa2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import shutil
import stat
import string
import subprocess
import sys
import threading
Expand All @@ -23,6 +24,7 @@
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWidgets import QApplication, QCheckBox, QComboBox, QDialog, QHBoxLayout, QLabel, QMessageBox, QPushButton, QVBoxLayout, QWidget
import requests
import zhon
ts = None

from config import *
Expand Down Expand Up @@ -648,7 +650,8 @@ def arabic_to_roman(self, num):

def sanitize(self, text):
text = re.sub(r'\d+', lambda x: self.arabic_to_roman(int(x.group())), text)
return re.sub(r"[\-\s\"'‘’“”::.。,,()()<>《》;;!!??@#$%^&™®_+*=~`|]", "", text).lower()
all_punctuation = string.punctuation + zhon.hanzi.punctuation
return ''.join(char for char in text if char not in all_punctuation and not char.isspace()).lower()

def symbol_replacement(self, text):
return text.replace(': ', ' - ').replace(':', '-').replace("/", "_").replace("?", "")
Expand Down Expand Up @@ -1119,7 +1122,7 @@ def translate_keyword(self, keyword):
trainer_details = self.load_json_content("xgqdetail.json")
if trainer_details:
for trainer in trainer_details:
if keyword in trainer.get("keyw", ""):
if self.sanitize(keyword) in self.sanitize(trainer.get("keyw", "")):
translations.append(trainer.get("en_name", ""))

elif self.initialize_translator():
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ python-Levenshtein
requests
tendo
translators
zhon

0 comments on commit 115efa2

Please sign in to comment.