mirror of
https://github.com/illian64/llm-translate.git
synced 2026-04-28 03:39:51 +00:00
skip numeric-only parts
This commit is contained in:
parent
5daec3927a
commit
05019cebf3
2 changed files with 17 additions and 8 deletions
|
|
@ -140,15 +140,16 @@ class AppCore(JaaCore):
|
|||
def cache_read(self, req: Request, parts: list[Part]):
|
||||
if self.cache_params.enabled and req.translator_plugin not in self.cache_params.disable_for_plugins:
|
||||
for part in parts:
|
||||
cached_translate = self.cache.get(req, part.text)
|
||||
if cached_translate:
|
||||
part.cache_found = True
|
||||
part.translate = cached_translate
|
||||
else:
|
||||
part.cache_found = False
|
||||
if part.need_to_translate():
|
||||
cached_translate = self.cache.get(req, part.text)
|
||||
if cached_translate:
|
||||
part.cache_found = True
|
||||
part.translate = cached_translate
|
||||
else:
|
||||
part.cache_found = False
|
||||
|
||||
def cache_write(self, req: Request, parts: list[Part]):
|
||||
if self.cache_params.enabled and req.translator_plugin not in self.cache_params.disable_for_plugins:
|
||||
for part in parts:
|
||||
if not part.cache_found:
|
||||
if part.need_to_translate() and not part.cache_found:
|
||||
self.cache.put(req, part.text, part.translate)
|
||||
|
|
|
|||
|
|
@ -22,8 +22,16 @@ class Part:
|
|||
paragraph_end: bool
|
||||
cache_found: bool
|
||||
|
||||
def is_numeric_or_empty(self):
|
||||
processed_text = (self.text
|
||||
.replace(" ", "")
|
||||
.replace(",", "")
|
||||
.replace(".", ""))
|
||||
|
||||
return processed_text.isnumeric() or len(processed_text) == 0
|
||||
|
||||
def need_to_translate(self):
|
||||
return not self.cache_found and self.text and self.text != ""
|
||||
return not self.cache_found and self.text and self.text != "" and not self.is_numeric_or_empty()
|
||||
|
||||
def __init__(self, text: str, paragraph_end: bool):
|
||||
self.text = text
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue