Skip to content

Commit

Permalink
move to 1.6.2, prevent spacy model from being loaded when it may not …
Browse files Browse the repository at this point in the history
…need to be or extra times
  • Loading branch information
Bikatr7 committed Jun 7, 2024
1 parent a0102a3 commit 7c3ad45
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies = [
]

name = "kairyou"
version = "v1.6.1"
version = "v1.6.2"
authors = [
{ name="Bikatr7", email="Bikatr7@proton.me" },
]
Expand Down
20 changes: 12 additions & 8 deletions src/kairyou/kairyou.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# -------------------start-of-Kairyou---------------------------------------------------------------------------------------------------------------------------------------------------------------------------


class Kairyou:

"""
Expand Down Expand Up @@ -53,13 +52,8 @@ class Kairyou:

#----------------------------/

## The spacy NER model used for enhanced replacement checking.
try:
_ner = spacy.load("ja_core_news_lg")
_ner:spacy.language.Language | None = None

except Exception:
raise SpacyModelNotFound

##-------------------start-of-_reset_globals()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@staticmethod
Expand Down Expand Up @@ -110,6 +104,16 @@ def preprocess(text_to_preprocess:str, replacement_json:typing.Union[dict,str],
"""


## The spacy NER model used for enhanced replacement checking.
try:

if(Kairyou._ner is None):
Kairyou._ner = spacy.load("ja_core_news_lg")

except Exception:
raise SpacyModelNotFound

## If the replacement json is blank, skip the preprocessing.
if(replacement_json == _kudasai_blank_json or replacement_json == _fukuin_blank_json):
return text_to_preprocess, "Skipped", ""
Expand Down Expand Up @@ -498,7 +502,7 @@ def _perform_enhanced_replace(jap:str, replacement:str) -> int:
while (i < len(_jap_lines)):
if (jap in _jap_lines[i]):

_sentence = Kairyou._ner(_jap_lines[i])
_sentence = Kairyou._ner(_jap_lines[i]) # type:ignore

for _entity in _sentence.ents:
if (_entity.text == jap and _entity.label_ == "PERSON"):
Expand Down
2 changes: 1 addition & 1 deletion src/kairyou/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
## Use of this source code is governed by an GNU Lesser General Public License v2.1
## license that can be found in the LICENSE file.

VERSION = "1.6.1"
VERSION = "1.6.2"
2 changes: 2 additions & 0 deletions tests/passing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def main():

if(KatakanaUtil.is_partially_english("テスト")):
raise ValueError("Test failed")

print("All tests passed")


if(__name__ == "__main__"):
Expand Down

0 comments on commit 7c3ad45

Please sign in to comment.