-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e392fb6
commit 9670fe0
Showing
4 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
This code is generally borrown from under-maintained pkg `japandas` | ||
and used to turn 「全角」strings to 「半角」strings. | ||
""" | ||
|
||
__version__ = 0.1 | ||
|
||
from unicodedata import normalize | ||
|
||
# soundmarks require special handlings | ||
_ZALPHA = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' | ||
'abcdefghijklmnopqrstuvwxyz') | ||
_ZSYMBOL = '!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ ' | ||
_ZDIGIT = '0123456789' | ||
|
||
# mapping from full-width to half-width | ||
_ALPHA_MAPPER = {c: normalize('NFKC', c) for c in _ZALPHA} | ||
_DIGIT_MAPPER = {c: normalize('NFKC', c) for c in _ZDIGIT} | ||
_SYMBOL_MAPPER = {c: normalize('NFKC', c) for c in _ZSYMBOL} | ||
|
||
# adding symbols that un-normalizable | ||
# https://www.utf8-chartable.de/unicode-utf8-table.pl?start=12224&names=-&utf8=string-literal | ||
_ZSYMBOL_MAPPER = {"〜": "~", } | ||
_SYMBOL_MAPPER.update(_ZSYMBOL_MAPPER) | ||
|
||
|
||
def _ord_dict(dict): | ||
return {ord(k): v for k, v in dict.items()} | ||
|
||
|
||
# for unicode.translate | ||
_Z2H_ALPHA = _ord_dict(_ALPHA_MAPPER) | ||
_Z2H_DIGIT = _ord_dict(_DIGIT_MAPPER) | ||
_Z2H_SYMBOL = _ord_dict(_SYMBOL_MAPPER) | ||
|
||
mapper = dict() | ||
mapper.update(_Z2H_ALPHA) | ||
mapper.update(_Z2H_DIGIT) | ||
mapper.update(_Z2H_SYMBOL) | ||
|
||
|
||
def str_z2h(string: str, ): | ||
try: | ||
res = string.translate(mapper) | ||
return res | ||
except AttributeError: | ||
return string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.0.3.2' | ||
__version__ = '0.0.4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters