Skip to content

Commit

Permalink
upgrade to v0.2: code maintaining
Browse files Browse the repository at this point in the history
  • Loading branch information
howl-anderson committed Oct 17, 2024
1 parent 937410c commit 3d3d46e
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 51 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build/
dist/
.venv/
.idea/
.pytest_cache/
*/**/__pycache__/
*.egg-info/
1 change: 1 addition & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
twine
23 changes: 23 additions & 0 deletions dev_scripts/prase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pickle
import pathlib

WORKSPACE_DIR = pathlib.Path(__file__).parent.parent

data = {}

for i in [
WORKSPACE_DIR / "chaizi/chaizi-ft.txt",
WORKSPACE_DIR / "chaizi/chaizi-jt.txt",
]:
with open(i, "rt") as fd:
for line in fd:
item_list = line.strip().split("\t")
key = item_list[0]
value = [i.strip().split() for i in item_list[1:]]

data[key] = value

output_file = WORKSPACE_DIR / "hanzi_chaizi/data/data.pkl"

with open(output_file, "wb") as fd:
pickle.dump(data, fd)
4 changes: 2 additions & 2 deletions example_code.py → example_code/example_code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from hanzi_chaizi import HanziChaizi

hc = HanziChaizi()
result = hc.query('名')
result = hc.query("名")

print(result)
print(result)
23 changes: 1 addition & 22 deletions hanzi_chaizi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
import pickle

import pkg_resources


class HanziChaizi(object):
def __init__(self):
data_file = pkg_resources.resource_filename(__name__, "data/data.pkl")

with open(data_file, 'rb') as fd:
self.data = pickle.load(fd)

def query(self, input_char, default=None):
result = self.data.get(input_char, default)
return result[0]


if __name__ == "__main__":
hc = HanziChaizi()
result = hc.query('名')

print(result)
from .hanzi_chaizi import HanziChaizi
15 changes: 15 additions & 0 deletions hanzi_chaizi/hanzi_chaizi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pickle

import pkg_resources


class HanziChaizi(object):
def __init__(self):
data_file = pkg_resources.resource_filename(__name__, "data/data.pkl")

with open(data_file, "rb") as fd:
self.data = pickle.load(fd)

def query(self, input_char, default=None):
result = self.data.get(input_char, default)
return result[0]
8 changes: 8 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pkg_build:
python setup.py bdist_wheel
pkg_upload:
twine upload dist/*
pkg_clean:
rm -rf build dist *.egg-info
test:
pytest
18 changes: 0 additions & 18 deletions prase.py

This file was deleted.

2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
pythonpath = .
20 changes: 11 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from setuptools import setup

setup(
name='hanzi_chaizi',
version='0.1',
packages=['hanzi_chaizi'],
url='',
license='',
author='Xiaoquan Kong',
author_email='[email protected]',
description='',
include_package_data=True
name="hanzi_chaizi",
version="0.2",
packages=["hanzi_chaizi"],
url="https://github.com/howl-anderson/hanzi_chaizi",
license="",
author="Xiaoquan Kong",
author_email="[email protected]",
description="""
The hanzi_chaizi package provides tools for breaking down Chinese characters into basic structural units, such as strokes and components. This decomposition reveals structural similarities between characters with similar shapes. These features can be used in deep learning models to capture character-based attributes, particularly shape-related ones, for applications like natural language processing or character recognition.
""".strip(),
include_package_data=True,
)
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest
8 changes: 8 additions & 0 deletions tests/test_hanzi_chaizi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from hanzi_chaizi import HanziChaizi


def test_query():
hc = HanziChaizi()
result = hc.query("名")

assert result == ["夕", "口"]

0 comments on commit 3d3d46e

Please sign in to comment.