-
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.
Merge pull request #27 from kimsehwan96/master
release v1.0.1
- Loading branch information
Showing
10 changed files
with
101 additions
and
57 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
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
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
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,25 +1,28 @@ | ||
#-*- coding: utf-8 -*- | ||
import re | ||
from pyjosa.exceptions import NotHangleException | ||
from pyjosa.exceptions import NotHangleException, JongsungInstantiationException | ||
|
||
START_HANGLE = 44032 | ||
J_IDX = 28 | ||
|
||
class Jongsung: | ||
# we will not instantiate this class because it's not really needed. | ||
def __init__(self): | ||
raise JongsungInstantiationException | ||
START_HANGLE = 44032 | ||
J_IDX = 28 | ||
|
||
def is_hangle(string: str) -> bool: | ||
last_char = string[-1] | ||
if re.match('.*[ㄱ-ㅎㅏ-ㅣ가-힣]+.*', last_char) is None: | ||
return False | ||
return True | ||
|
||
|
||
def has_jongsung(string: str) -> bool: | ||
if not is_hangle(string): | ||
raise NotHangleException | ||
|
||
last_char = string[-1] | ||
if (ord(last_char) - START_HANGLE) % J_IDX > 0: | ||
@staticmethod | ||
def is_hangle(string: str) -> bool: | ||
last_char = string[-1] | ||
if re.match('.*[ㄱ-ㅎㅏ-ㅣ가-힣]+.*', last_char) is None: | ||
return False | ||
return True | ||
return False | ||
|
||
# TODO: can we make above functions as Decorator? | ||
@classmethod | ||
def has_jongsung(cls, string: str) -> bool: | ||
if not cls.is_hangle(string): | ||
raise NotHangleException | ||
|
||
last_char = string[-1] | ||
if (ord(last_char) - cls.START_HANGLE) % cls.J_IDX > 0: | ||
return True | ||
return False |
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,40 +1,47 @@ | ||
from pyjosa.jonsung import has_jongsung | ||
from pyjosa.jonsung import Jongsung | ||
from pyjosa.exceptions import JosaTypeException | ||
|
||
class Josa: | ||
|
||
@staticmethod | ||
def get_josa(string, josa) -> str: | ||
def get_josa(string:str, josa:str) -> str: | ||
|
||
if (josa == '을') or (josa == '를'): | ||
return '을' if has_jongsung(string) else '를' | ||
return '을' if Jongsung.has_jongsung(string) else '를' | ||
elif (josa == '은') or (josa == '는'): | ||
return '은' if has_jongsung(string) else '는' | ||
return '은' if Jongsung.has_jongsung(string) else '는' | ||
elif (josa == '이') or (josa == '가'): | ||
return '이' if has_jongsung(string) else '가' | ||
return '이' if Jongsung.has_jongsung(string) else '가' | ||
elif (josa == '과') or (josa == '와'): | ||
return '과' if has_jongsung(string) else '와' | ||
return '과' if Jongsung.has_jongsung(string) else '와' | ||
elif (josa == '이나') or (josa == '나'): | ||
return '이나' if has_jongsung(string) else '나' | ||
return '이나' if Jongsung.has_jongsung(string) else '나' | ||
elif (josa == '으로') or (josa == '로'): | ||
return '으로' if has_jongsung(string) else '로' | ||
return '으로' if Jongsung.has_jongsung(string) else '로' | ||
elif josa == '이가': | ||
return '이가' if Jongsung.has_jongsung(string) else '가' | ||
else: | ||
raise JosaTypeException | ||
|
||
@staticmethod | ||
def get_full_string(string, josa) -> str: | ||
def get_full_string(string: str, josa: str) -> str: | ||
|
||
if (josa == '을') or (josa == '를'): | ||
return string + '을' if has_jongsung(string) else string + '를' | ||
return string + '을' if Jongsung.has_jongsung(string) else string + '를' | ||
elif (josa == '은') or (josa == '는'): | ||
return string + '은' if has_jongsung(string) else string + '는' | ||
return string + '은' if Jongsung.has_jongsung(string) else string + '는' | ||
elif (josa == '이') or (josa == '가'): | ||
return string + '이' if has_jongsung(string) else string + '가' | ||
return string + '이' if Jongsung.has_jongsung(string) else string + '가' | ||
elif (josa == '과') or (josa == '와'): | ||
return string + '과' if has_jongsung(string) else string + '와' | ||
return string + '과' if Jongsung.has_jongsung(string) else string + '와' | ||
elif (josa == '이나') or (josa == '나'): | ||
return string + '이나' if has_jongsung(string) else string + '나' | ||
return string + '이나' if Jongsung.has_jongsung(string) else string + '나' | ||
elif (josa == '으로') or (josa == '로'): | ||
return string + '으로' if has_jongsung(string) else string + '로' | ||
return string + '으로' if Jongsung.has_jongsung(string) else string + '로' | ||
elif josa == '이가': | ||
return string + '이가' if Jongsung.has_jongsung(string) else string + '가' | ||
else: | ||
raise JosaTypeException | ||
|
||
# TODO : Refactor pyjosa's architecture with oop. | ||
# TODO : need to remove duplicated codes with 'if ... elif...' (refactor) |
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