-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
937410c
commit 3d3d46e
Showing
12 changed files
with
79 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
build/ | ||
dist/ | ||
.venv/ | ||
.idea/ | ||
.pytest_cache/ | ||
*/**/__pycache__/ | ||
*.egg-info/ |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
twine |
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 |
---|---|---|
@@ -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) |
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,6 +1,6 @@ | ||
from hanzi_chaizi import HanziChaizi | ||
|
||
hc = HanziChaizi() | ||
result = hc.query('名') | ||
result = hc.query("名") | ||
|
||
print(result) | ||
print(result) |
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,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 |
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 |
---|---|---|
@@ -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] |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
pythonpath = . |
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,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, | ||
) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from hanzi_chaizi import HanziChaizi | ||
|
||
|
||
def test_query(): | ||
hc = HanziChaizi() | ||
result = hc.query("名") | ||
|
||
assert result == ["夕", "口"] |