Skip to content

Commit

Permalink
perfect discard names logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikatr7 committed Jun 26, 2024
1 parent 9c420de commit 1ce55ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 20 additions & 1 deletion modules/common/gender_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def group_names(text, names_with_positions: list[tuple[str, int]], max_distance:
"ue"
]

blacklist = [
"contents",
]

grouped_names = []
i = 0
skip_next = False
Expand All @@ -99,6 +103,10 @@ def group_names(text, names_with_positions: list[tuple[str, int]], max_distance:
else:
current_name, current_pos = names_with_positions[i]
next_name, next_pos = names_with_positions[i + 1]

if(current_name in blacklist):
i += 1
continue

## Check if names are separated by spaces and are within the maximum distance.
separator = text[current_pos + len(current_name):next_pos]
Expand Down Expand Up @@ -162,7 +170,18 @@ def discard_non_names(names: list[str]) -> list[str]:

GenderUtil.genders = GenderUtil.load_genders()

new_names = [name for name in names if any(any(part in full_name for part in GenderUtil.honorific_stripper(name).split(' ')) for gender, gender_names in GenderUtil.genders.items() for full_name, _ in gender_names.items())]
new_names = [
name for name in names
if any(
any(
part == full_part
for part in GenderUtil.honorific_stripper(name).split(' ')
for full_part in full_name.split(' ')
)
for gender, gender_names in GenderUtil.genders.items()
for full_name, _ in gender_names.items()
)
]

if(GenderUtil.is_cote):
## known issues with cote
Expand Down
7 changes: 7 additions & 0 deletions modules/common/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ async def commence_translation(is_webgui:bool=False) -> None:
logging.info("External genders.json file found, overriding config...")
shutil.copy2(FileEnsurer.external_translation_genders_path, FileEnsurer.config_translation_genders_path)

if(not os.path.exists(FileEnsurer.external_translation_settings_path) and not is_webgui):
logging.info("External translation_settings.json file not found, using config...")
print("External translation_settings.json file not found, using config...")
time.sleep(2)

logging.debug(f"Translator Activated, Translation Method : {Translator.TRANSLATION_METHOD} "
f"Settings are as follows : ")

Expand All @@ -455,6 +460,8 @@ async def commence_translation(is_webgui:bool=False) -> None:
Translator.gender_context_insertion = bool(JsonHandler.current_translation_settings["base translation settings"]["gender_context_insertion"])
Translator.is_cote = bool(JsonHandler.current_translation_settings["base translation settings"]["is_cote"])

GenderUtil.is_cote = Translator.is_cote

Translator._semaphore = asyncio.Semaphore(Translator.num_concurrent_batches)

Translator.openai_model = JsonHandler.current_translation_settings["openai settings"]["openai_model"]
Expand Down

0 comments on commit 1ce55ed

Please sign in to comment.