Skip to content
Browse files

deprecate josa

  • Loading branch information...
1 parent e3a0d53 commit 420230fa9ae2473e83120e3d0a9a6c9dd7174f50 @sublee committed
Showing with 52 additions and 59 deletions.
  1. +28 −38 josa.py
  2. +23 −21 setup.py
  3. +1 −0 test.py
View
66 josa.py
@@ -1,47 +1,37 @@
# -*- coding: utf-8 -*-
-from hangulize import hangulize
+import warnings
+from korean import Loanword, Noun, Particle, hangul, morphology
-INDO_EUROPEANS = {'nld': 1.7}
- #'spa': 1,
- #'ita': 0.3,
- #'por': 0.3,
- #'deu': 0.1,
-POSTPOSITIONS = [(u'', u''), (u'', u''), (u'', u''),
- (u'', u''), (u'이랑', u''), (u'이라', u''),
- (u'이면', u''), (u'이야', u''), (u'이다', u''),
- (u'이든', u''), (u'이던', u'')]
+
+warnings.warn('This library has been deprecated. Use "korean" instead.',
+ DeprecationWarning)
def has_jongseong(word, lang='eng'):
- if not word:
- raise ValueError('the empty word is given')
- elif lang == 'eng':
- return _has_jongseong_for_eng(word)
- elif lang != 'kor':
- word = hangulize(word, lang)
- return (ord(word[-1]) - 16) % 28 != 0
-
-
-def _has_jongseong_for_eng(word):
- point = 0
- for lang, accuracy in INDO_EUROPEANS.items():
- if has_jongseong(word, lang):
- point += accuracy
- else:
- point -= accuracy
- return point > 0
-
-
-def add_josa(after_jongseong, after_jungseong):
- POSTPOSITIONS.append(after_jongseong, after_jungseong)
-
-
-def josa(word, type, lang='eng'):
- for pp in POSTPOSITIONS:
- if type in pp:
- return pp[0] if has_jongseong(word, lang) else pp[1]
- raise ValueError('%s is not an available postposition' % type)
+ if lang == 'kor':
+ word = Noun(word)
+ else:
+ if lang == 'eng':
+ lang = 'nld'
+ word = Loanword(unicode(word), lang)
+ try:
+ return bool(hangul.get_final(word.read()[-1]))
+ except IndexError:
+ raise ValueError
+
+
+def josa(word, particle, lang='eng'):
+ if lang == 'kor':
+ word = Noun(word)
+ else:
+ if lang == 'eng':
+ lang = 'nld'
+ word = Loanword(unicode(word), lang)
+ try:
+ return morphology.pick_allomorph(Particle(particle), suffix_of=word)
+ except IndexError:
+ raise ValueError
def append(word, type, lang='eng', spacing=False):
View
44 setup.py
@@ -3,30 +3,32 @@
Josa
~~~~
-Appends the correct postposition to a given word by checking whether the word
-has jongseong (final consonant) or not.
+This library has been deprecated. Use `korean
+<http://pypi.python.org/pypi/korean`_ instead.
->>> print josa.append(u'false positive', u'를')
-false positive를
->>> print josa.append(u'deterministic', u'랑')
-deterministic이랑
->>> print josa.append(u'넥슨', u'와', lang='kor')
-넥슨과
->>> print josa.append(u'あなた', u'이', lang='jpn')
-あなた가
+The description of the past:
-Links
-`````
+ Appends the correct postposition to a given word by checking whether the word
+ has jongseong (final consonant) or not.
-* `GitHub repository <http://github.com/sublee/josa>`_
-* `development version
- <http://github.com/sublee/josa/zipball/master#egg=josa-dev>`_
+ >>> print josa.append(u'false positive', u'를')
+ false positive를
+ >>> print josa.append(u'deterministic', u'랑')
+ deterministic이랑
+ >>> print josa.append(u'넥슨', u'와', lang='kor')
+ 넥슨과
+ >>> print josa.append(u'あなた', u'이', lang='jpn')
+ あなた가
+
+ Links
+ `````
+
+ * `GitHub repository <http://github.com/sublee/josa>`_
+ * `development version
+ <http://github.com/sublee/josa/zipball/master#egg=josa-dev>`_
"""
-try:
- from setuptools import setup
-except ImportError:
- from distutils.core import setup
+from setuptools import setup
def run_tests():
@@ -36,7 +38,7 @@ def run_tests():
setup(
name='josa',
- version='0.0.7',
+ version='0.0.8',
license='BSD',
author='Heungsub Lee',
author_email='h@subl.ee',
@@ -44,7 +46,7 @@ def run_tests():
long_description=__doc__,
platforms='any',
py_modules=['josa'],
- install_requires=['hangulize'],
+ install_requires=['korean', 'hangulize'],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
View
1 test.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import unittest
+
import josa

0 comments on commit 420230f

Please sign in to comment.
Something went wrong with that request. Please try again.