Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# file GENERATED by distutils, do NOT edit
setup.py
pinyin/pinyin.py
pinyin/data/word.data
1 change: 1 addition & 0 deletions pinyin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .pinyin import PinYin
File renamed without changes.
27 changes: 8 additions & 19 deletions pinyin.py → pinyin/pinyin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,35 @@
"""
Author:cleverdeng
E-mail:[email protected]
Modified by [email protected]
"""

__version__ = '0.9'
__all__ = ["PinYin"]

import os.path
import pkgutil


class PinYin(object):
def __init__(self, dict_file='word.data'):
def __init__(self):
__package__ = 'pinyin'
self.word_dict = {}
self.dict_file = dict_file

self.data = pkgutil.get_data(__package__, 'data/word.data')

def load_word(self):
if not os.path.exists(self.dict_file):
raise IOError("NotFoundFile")

with file(self.dict_file) as f_obj:
for f_line in f_obj.readlines():
try:
line = f_line.split(' ')
self.word_dict[line[0]] = line[1]
except:
line = f_line.split(' ')
self.word_dict[line[0]] = line[1]

for line in self.data.split('\n'):
self.word_dict[line[:5].strip()] = line[8:]

def hanzi2pinyin(self, string=""):
result = []
if not isinstance(string, unicode):
string = string.decode("utf-8")

for char in string:
key = '%X' % ord(char)
result.append(self.word_dict.get(key, char).split()[0][:-1].lower())

return result


def hanzi2pinyin_split(self, string="", split=""):
result = self.hanzi2pinyin(string=string)
if split == "":
Expand Down
42 changes: 21 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
"""
Author:cleverdeng
E-mail:[email protected]
Modified by [email protected]
"""
from distutils.core import setup
from pinyin import __version__ as version

setup(
name='pinyin',
version=version,
description='hanzi -> pinyin,With Python',
author='cleverdeng',
author_email='[email protected]',
url='http://github.com/cleverdeng/pinyin.py',
py_modules=['pinyin'],
license='MIT License',
platforms=['any'],
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules'
]
)
name='pinyin',
version='0.9.1',
description='hanzi -> pinyin,With Python',
author='cleverdeng',
author_email='[email protected]',
url='http://github.com/cleverdeng/pinyin.py',
packages=['pinyin'],
package_data={'pinyin': ['data/word.data']},
license='MIT License',
platforms=['any'],
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules'
]
)