Skip to content

Commit

Permalink
4.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunwoongko authored and hyunwoongko committed May 16, 2023
1 parent 4c0e640 commit f3ba148
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
2 changes: 1 addition & 1 deletion kss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from kss._modules.summarization.summarize_sentences import summarize_sentences

__ALL__ = [split_sentences, split_morphemes, summarize_sentences]
__version__ = "4.5.1"
__version__ = "4.5.2"
25 changes: 10 additions & 15 deletions kss/_modules/sentences/sentence_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from kss._utils.const import (
alphabet_with_quotes,
numbers_with_quotes,
url_pattern,
email_pattern,
backup_normal,
Expand All @@ -19,12 +18,6 @@ class SentenceProcessor:
_all_s_poses_wo_qtn = ("SP", "SF", "SY", "SE", "SSC", "QTC", "EMOJI", "JAMO")

_heavy_backup = {}
_heavy_backup.update(
{
k: {_v: str(abs(hash(_v))) for _v in v}
for k, v in numbers_with_quotes.items()
}
)
_heavy_backup.update(
{
k: {_v: str(abs(hash(_v))) for _v in v}
Expand Down Expand Up @@ -58,21 +51,23 @@ def _add_url_or_email(self, text):
}
self._normal_backup.update(_url_or_email)

def _backup_or_restore_heavy(self, target: str, check: str, restore: bool = False):
for source, purpose_dict in self._heavy_backup.items():
if source in check:
target = self._replace(target, purpose_dict, restore=restore)
return target

@lru_cache(100)
def backup(self, inputs: str):
self._add_url_or_email(inputs)
inputs = self._replace(inputs, self._normal_backup)
inputs = self._backup_or_restore_heavy(inputs, inputs)

for source, purpose_dict in self._heavy_backup.items():
if source in inputs:
inputs = self._replace(inputs, purpose_dict, restore=False)

return inputs

@lru_cache(100)
def restore(self, outputs: str, inputs: str):
outputs = self._replace(outputs, self._normal_backup, restore=True)
outputs = self._backup_or_restore_heavy(outputs, inputs, restore=True)

for source, purpose_dict in self._heavy_backup.items():
if source in inputs:
outputs = self._replace(outputs, purpose_dict, restore=True)

return outputs
10 changes: 0 additions & 10 deletions kss/_utils/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,6 @@
]


# inch: 3'2 inch
# time: 06'30
# year: '60s
numbers_with_quotes = {}
for num in numbers:
numbers_with_quotes[num] = set()
numbers_with_quotes[num].update({f"{num}{q}" for q in ["'", "’"]})
numbers_with_quotes[num].update({f"{q}{num}" for q in ["'", "’"]})


# apostrophe: I`m, You’re, ...
alphabet_with_quotes = {}
for alpha in alphabets:
Expand Down

0 comments on commit f3ba148

Please sign in to comment.