Skip to content

Commit

Permalink
Merge pull request #27 from kimsehwan96/master
Browse files Browse the repository at this point in the history
release v1.0.1
  • Loading branch information
kimsehwan96 authored Jul 5, 2021
2 parents ac8af92 + db5fd7c commit 75a3b83
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 57 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ print(Josa.get_josa("닭", "는")) # 은
print(Josa.get_josa("", "으로")) # 으로
print(Josa.get_josa("명예", "")) #
print(Josa.get_josa("", "")) # 이나
# 사람 이름 + 이가/가 를 구분하기 위해서는 조사부분에 '이가'를 입력합니다.
print(Josa.get_josa("예나", "이가")) #
print(Josa.get_josa("세환", "이가")) # 이가

print(Josa.get_full_string("철수", "")) # 철수는
print(Josa.get_full_string("오리", "")) # 오리를
print(Josa.get_full_string("", "")) # 닭은
print(Josa.get_full_string("", "으로")) # 산으로
print(Josa.get_full_string("명예", "")) # 명예와
print(Josa.get_full_string("", "")) # 물이나
# 사람 이름 + 이가/가 를 구분하기 위해서는 조사부분에 '이가'를 입력합니다.
print(Josa.get_josa("예나", "이가")) # 예나가
print(Josa.get_josa("세환", "이가")) # 세환이가

```

Expand Down
6 changes: 6 additions & 0 deletions docs/2_EXAMPLE/example1.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ print(Josa.get_josa("닭", "는")) # 은
print(Josa.get_josa("", "으로")) # 으로
print(Josa.get_josa("명예", "")) #
print(Josa.get_josa("", "")) # 이나
# 사람 이름 + 이가/가 를 구분하기 위해서는 조사부분에 '이가'를 입력합니다.
print(Josa.get_josa("예나", "이가")) #
print(Josa.get_josa("세환", "이가")) # 이가

print(Josa.get_full_string("철수", "")) # 철수는
print(Josa.get_full_string("오리", "")) # 오리를
print(Josa.get_full_string("", "")) # 닭은
print(Josa.get_full_string("", "으로")) # 산으로
print(Josa.get_full_string("명예", "")) # 명예와
print(Josa.get_full_string("", "")) # 물이나
# 사람 이름 + 이가/가 를 구분하기 위해서는 조사부분에 '이가'를 입력합니다.
print(Josa.get_josa("예나", "이가")) # 예나가
print(Josa.get_josa("세환", "이가")) # 세환이가
```
4 changes: 2 additions & 2 deletions docs/2_EXAMPLE/example2.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from pyjosa.josa import Josa
subject = '철수'
obj = ''

full_string = f'{Josa.get_full_string(subject, '')} {Josa.get_full_string(obj, '')} 간다'
full_string = f'{Josa.get_full_string(subject, "")} {Josa.get_full_string(obj, "")} 간다'

print(full_string) # 철수는 산을 오른다
```
Expand All @@ -18,6 +18,6 @@ subjects = ['철수', '세환', '길동']
obj = ['', '바다', '']

for i, v in enumerate(subjects):
print(f'{Josa.get_full_string(v, '')} {Josa.get_full_string(obj[i], '')} 간다')
print(f'{Josa.get_full_string(v, "")} {Josa.get_full_string(obj[i], "")} 간다')

```
46 changes: 29 additions & 17 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.0.3.5)
activesupport (6.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
coffee-script (2.4.1)
coffee-script-source
Expand All @@ -16,22 +16,34 @@ GEM
colorator (1.1.0)
commonmarker (0.17.13)
ruby-enum (~> 0.5)
concurrent-ruby (1.1.8)
dnsruby (1.61.5)
concurrent-ruby (1.1.9)
dnsruby (1.61.7)
simpleidn (~> 0.1)
em-websocket (0.5.2)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
ethon (0.12.0)
ffi (>= 1.3.0)
ethon (0.14.0)
ffi (>= 1.15.0)
eventmachine (1.2.7)
execjs (2.7.0)
faraday (1.3.0)
execjs (2.8.1)
faraday (1.5.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-patron (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-net_http (1.0.1)
ffi (1.15.0)
faraday-net_http_persistent (1.1.0)
faraday-patron (1.0.0)
ffi (1.15.3)
forwardable-extended (2.6.0)
gemoji (3.0.1)
github-pages (209)
Expand Down Expand Up @@ -203,7 +215,7 @@ GEM
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (4.0.3)
listen (3.4.1)
listen (3.5.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.3.6)
Expand All @@ -213,24 +225,24 @@ GEM
jekyll-seo-tag (~> 2.1)
minitest (5.14.4)
multipart-post (2.1.1)
nokogiri (1.11.2-x86_64-darwin)
nokogiri (1.11.7-x86_64-darwin)
racc (~> 1.4)
octokit (4.20.0)
octokit (4.21.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (3.1.1)
racc (1.5.2)
rb-fsevent (0.10.4)
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
rexml (3.2.4)
rexml (3.2.5)
rouge (3.23.0)
ruby-enum (0.9.0)
i18n
ruby2_keywords (0.0.4)
rubyzip (2.3.0)
rubyzip (2.3.1)
safe_yaml (1.0.5)
sass (3.7.4)
sass-listen (~> 4.0.0)
Expand Down Expand Up @@ -263,4 +275,4 @@ DEPENDENCIES
jekyll-rtd-theme (~> 2.0.6)

BUNDLED WITH
2.2.14
2.2.21
6 changes: 6 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ print(Josa.get_josa("닭", "는")) # 은
print(Josa.get_josa("", "으로")) # 으로
print(Josa.get_josa("명예", "")) #
print(Josa.get_josa("", "")) # 이나
# 사람 이름 + 이가/가 를 구분하기 위해서는 조사부분에 '이가'를 입력합니다.
print(Josa.get_josa("예나", "이가")) #
print(Josa.get_josa("세환", "이가")) # 이가

print(Josa.get_full_string("철수", "")) # 철수는
print(Josa.get_full_string("오리", "")) # 오리를
print(Josa.get_full_string("", "")) # 닭은
print(Josa.get_full_string("", "으로")) # 산으로
print(Josa.get_full_string("명예", "")) # 명예와
print(Josa.get_full_string("", "")) # 물이나
# 사람 이름 + 이가/가 를 구분하기 위해서는 조사부분에 '이가'를 입력합니다.
print(Josa.get_josa("예나", "이가")) # 예나가
print(Josa.get_josa("세환", "이가")) # 세환이가
```

## 깃허브 주소
Expand Down
6 changes: 5 additions & 1 deletion pyjosa/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ def __init__(self):

class JosaTypeException(Exception):
def __init__(self):
super().__init__("메서드의 인자로 주어진 조사가 올바르지 않습니다.")
super().__init__("메서드의 인자로 주어진 조사가 올바르지 않습니다.")

class JongsungInstantiationException(Exception):
def __init__(self):
super().__init__("종성 클래스는 인스턴스화 할 필요가 없습니다.")
39 changes: 21 additions & 18 deletions pyjosa/jonsung.py
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
37 changes: 22 additions & 15 deletions pyjosa/josa.py
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)
6 changes: 3 additions & 3 deletions pyjosa/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyjosa.jonsung import is_hangle, has_jongsung
from pyjosa.jonsung import Jongsung
import unittest


Expand All @@ -21,10 +21,10 @@ def setUp(self):

def test_line_count(self):
for v in self.kor:
self.assertTrue(is_hangle(v))
self.assertTrue(Jongsung.is_hangle(v))

for v in self.not_kor:
self.assertFalse(is_hangle(v))
self.assertFalse(Jongsung.is_hangle(v))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name = 'pyjosa',
version = '1.0.0',
version = '1.0.1',
description = '한국어 조사 처리 패키지',
author = 'sehwan.kim',
author_email = 'sehwan.kim@ingkle.com',
Expand Down

0 comments on commit 75a3b83

Please sign in to comment.