├── .idea
├── four_corner_method.iml
├── misc.xml
├── modules.xml
└── workspace.xml
├── MANIFEST.in
├── Makefile
├── README.md
├── data
├── .DS_Store
├── html
│ ├── #IDXHDR
│ ├── #ITBITS
│ ├── #STRINGS
│ ├── #SYSTEM
│ ├── #TOPICS
│ ├── #URLSTR
│ ├── #URLTBL
│ ├── #WINDOWS
│ ├── 四角号码检字表(勘误版).hhc
│ └── 四角号码检字表(勘误版).htm
└── raw
│ └── 四角号码检字表(勘误版).CHM
├── dev_requirements.txt
├── example_code.py
├── four_corner_method
├── __init__.py
└── data
│ └── data.pkl
├── parse.py
├── query.py
└── setup.py
/.idea/four_corner_method.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 | 1543401248355
158 |
159 |
160 | 1543401248355
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 | print(section['class'])
194 | Python
195 | EXPRESSION
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include four_corner_method/data/data.pkl
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: clean clean-test clean-pyc clean-build docs help
2 | .DEFAULT_GOAL := help
3 |
4 | define BROWSER_PYSCRIPT
5 | import os, webbrowser, sys
6 |
7 | from urllib.request import pathname2url
8 |
9 | webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
10 | endef
11 | export BROWSER_PYSCRIPT
12 |
13 | define PRINT_HELP_PYSCRIPT
14 | import re, sys
15 |
16 | for line in sys.stdin:
17 | match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
18 | if match:
19 | target, help = match.groups()
20 | print("%-20s %s" % (target, help))
21 | endef
22 | export PRINT_HELP_PYSCRIPT
23 |
24 | BROWSER := python -c "$$BROWSER_PYSCRIPT"
25 |
26 | help:
27 | @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
28 |
29 | clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
30 |
31 | clean-build: ## remove build artifacts
32 | rm -fr build/
33 | rm -fr dist/
34 | rm -fr .eggs/
35 | find . -name '*.egg-info' -exec rm -fr {} +
36 | find . -name '*.egg' -exec rm -f {} +
37 |
38 | clean-pyc: ## remove Python file artifacts
39 | find . -name '*.pyc' -exec rm -f {} +
40 | find . -name '*.pyo' -exec rm -f {} +
41 | find . -name '*~' -exec rm -f {} +
42 | find . -name '__pycache__' -exec rm -fr {} +
43 |
44 | clean-test: ## remove test and coverage artifacts
45 | rm -fr .tox/
46 | rm -f .coverage
47 | rm -fr htmlcov/
48 | rm -fr .pytest_cache
49 |
50 | formatter: ## format code inplace with balck
51 | black corpusflow tests
52 |
53 | lint: ## check style with flake8 and black
54 | flake8 corpusflow tests
55 | black --check corpusflow tests
56 |
57 | types: ## check typine issue with pytype
58 | pytype --keep-going seq2annotation
59 |
60 | test: ## run tests quickly with the default Python
61 | pytest
62 |
63 | test-all: ## run tests on every Python version with tox
64 | tox
65 |
66 | coverage: ## check code coverage quickly with the default Python
67 | coverage run --source corpusflow -m pytest
68 | coverage report -m
69 | coverage html
70 | $(BROWSER) htmlcov/index.html
71 |
72 | docs: ## generate Sphinx HTML documentation, including API docs
73 | rm -f docs/corpusflow.rst
74 | rm -f docs/modules.rst
75 | sphinx-apidoc -o docs/ corpusflow
76 | $(MAKE) -C docs clean
77 | $(MAKE) -C docs html
78 | $(BROWSER) docs/_build/html/index.html
79 |
80 | servedocs: docs ## compile the docs watching for changes
81 | watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
82 |
83 | release: dist ## package and upload a release
84 | twine upload dist/*
85 |
86 | dist: clean ## builds source and wheel package
87 | python setup.py sdist
88 | python setup.py bdist_wheel
89 | ls -l dist
90 |
91 | install: clean ## install the package to the active Python's site-packages
92 | python setup.py install
93 |
94 | .PHONY: test_install
95 | test_install:
96 | pip install -r test_requirements.txt
97 |
98 | .PHONY: dev_install
99 | dev_install:
100 | pip install -r dev_requirements.txt
101 |
102 | .PHONY: update_minor_version
103 | update_minor_version:
104 | bumpversion minor
105 |
106 | .PHONY: update_patch_version
107 | update_patch_version:
108 | bumpversion patch
109 |
110 | .PHONY: update_major_version
111 | update_major_version:
112 | bumpversion major
113 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 中文「四角号码」数据与工具
2 |
3 | > 四角号码,汉语词典常用检字方法之一,用最多5个阿拉伯数字来对汉字进行归类。
4 |
5 | 四角号码最重要的特定之一是字型相似的字具有相同或者相似的编码。比如 `门` 和 `闫` 比较相似,它们都编码成了 `37001`。`闩` 和它们两个也比较接近,被编码成 `37101`
6 |
7 | **这种特性可以被深度学习模型用来作为字的特征之一:字形的特征。**
8 |
9 | ## 使用
10 | ```bash
11 | python ./query.py 民
12 | ```
13 |
14 | or
15 |
16 | ```python
17 | from four_corner_method import FourCornerMethod
18 |
19 | fcm = FourCornerMethod()
20 | result = fcm.query('名')
21 |
22 | print(result)
23 | ```
24 |
25 | 输出
26 |
27 | ```text
28 | 77747
29 | ```
30 |
31 |
32 |
33 | ## 从原始数据生成
34 | ### 数据来源
35 | 数据来自于 [资料共享——最全的《四角号码检字表》chm](http://bbs.unispim.com/forum.php?mod=viewthread&tid=31674)
36 |
37 | ### chmlib 将 CHM 文件 提取成 HTML
38 | TODO
39 |
40 | ### 解析
41 | ```bash
42 | pytohn ./parse.py
43 | ```
44 |
45 | ## 致谢
46 | 四角号码数据来自于 [wangyanhan](http://bbs.unispim.com/home.php?mod=space&uid=59433) AT [资料共享——最全的《四角号码检字表》chm](http://bbs.unispim.com/forum.php?mod=viewthread&tid=31674)
47 |
48 |
--------------------------------------------------------------------------------
/data/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/.DS_Store
--------------------------------------------------------------------------------
/data/html/#IDXHDR:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/#IDXHDR
--------------------------------------------------------------------------------
/data/html/#ITBITS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/#ITBITS
--------------------------------------------------------------------------------
/data/html/#STRINGS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/#STRINGS
--------------------------------------------------------------------------------
/data/html/#SYSTEM:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/#SYSTEM
--------------------------------------------------------------------------------
/data/html/#TOPICS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/#TOPICS
--------------------------------------------------------------------------------
/data/html/#URLSTR:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/#URLSTR
--------------------------------------------------------------------------------
/data/html/#URLTBL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/#URLTBL
--------------------------------------------------------------------------------
/data/html/#WINDOWS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/#WINDOWS
--------------------------------------------------------------------------------
/data/html/四角号码检字表(勘误版).hhc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/四角号码检字表(勘误版).hhc
--------------------------------------------------------------------------------
/data/html/四角号码检字表(勘误版).htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/html/四角号码检字表(勘误版).htm
--------------------------------------------------------------------------------
/data/raw/四角号码检字表(勘误版).CHM:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/data/raw/四角号码检字表(勘误版).CHM
--------------------------------------------------------------------------------
/dev_requirements.txt:
--------------------------------------------------------------------------------
1 | bumpversion
2 | twine
3 | wheel
4 | black
5 | flake8
6 | pytype
7 |
--------------------------------------------------------------------------------
/example_code.py:
--------------------------------------------------------------------------------
1 | from four_corner_method import FourCornerMethod
2 |
3 | fcm = FourCornerMethod()
4 | result = fcm.query('名')
5 |
6 | print(result)
--------------------------------------------------------------------------------
/four_corner_method/__init__.py:
--------------------------------------------------------------------------------
1 | import pickle
2 |
3 | import pkg_resources
4 |
5 |
6 | class FourCornerMethod(object):
7 | def __init__(self):
8 | data_file = pkg_resources.resource_filename(__name__, "data/data.pkl")
9 |
10 | with open(data_file, 'rb') as fd:
11 | self.data = pickle.load(fd)
12 |
13 | def query(self, input_char, default=None):
14 | return self.data.get(input_char, default)
15 |
16 |
17 | if __name__ == "__main__":
18 | fcm = FourCornerMethod()
19 | result = fcm.query('名')
20 |
21 | print(result)
22 |
--------------------------------------------------------------------------------
/four_corner_method/data/data.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howl-anderson/four_corner_method/fc7223237baa0a80e8262dab9cd8c9a959111324/four_corner_method/data/data.pkl
--------------------------------------------------------------------------------
/parse.py:
--------------------------------------------------------------------------------
1 | import pickle
2 |
3 | from bs4 import BeautifulSoup
4 |
5 | soup = BeautifulSoup(open('data/html/四角号码检字表(勘误版).htm', encoding='gb18030'))
6 |
7 | section = soup.body.div
8 |
9 | print(section['class'])
10 |
11 | # get printable text, instead of using element for more quickly
12 | raw_data = section.text
13 |
14 | data_list = raw_data.split()
15 |
16 | print(len(data_list))
17 |
18 | clean_data_list = [i for i in data_list if i.startswith('*')]
19 |
20 | print(len(clean_data_list))
21 |
22 | print('-' * 20)
23 |
24 | dict_data = {}
25 |
26 | duplicate_coding_char = []
27 |
28 | for item in clean_data_list:
29 | try:
30 | raw_code, chars = item.split(':')
31 |
32 | assert raw_code.startswith('*')
33 | assert len(chars)
34 | assert ' ' not in chars
35 |
36 | code = raw_code[1:]
37 |
38 | char_list = [i for i in chars]
39 | assert len(char_list)
40 |
41 | for char in char_list:
42 | if char in dict_data:
43 | duplicate_coding_char.append(char)
44 |
45 | dict_data[char] = code
46 |
47 | print((code, char_list))
48 | except:
49 | print('*' * 20)
50 | print(item)
51 | raise
52 |
53 | with open('data.pkl', 'wb') as fd:
54 | pickle.dump(dict_data, fd)
55 |
56 | print('{} has at least two different coding'.format(duplicate_coding_char))
57 |
--------------------------------------------------------------------------------
/query.py:
--------------------------------------------------------------------------------
1 | import pickle
2 | import sys
3 |
4 |
5 | def query(input_char):
6 | with open('four_corner_method/data/data.pkl', 'rb') as fd:
7 | data = pickle.load(fd)
8 |
9 | return data.get(input_char)
10 |
11 |
12 | if __name__ == "__main__":
13 | input_char = sys.argv[1]
14 |
15 | result = query(input_char)
16 |
17 | print(result)
18 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup
2 |
3 | setup(
4 | name='four_corner_method',
5 | version='0.1',
6 | packages=['four_corner_method'],
7 | url='',
8 | license='',
9 | author='Xiaoquan Kong',
10 | author_email='u1mail2me@gmail.com',
11 | description='',
12 | include_package_data=True
13 | )
14 |
--------------------------------------------------------------------------------