hanja-tools 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hanja_tools-0.1.0/LICENSE +21 -0
- hanja_tools-0.1.0/PKG-INFO +78 -0
- hanja_tools-0.1.0/README.md +53 -0
- hanja_tools-0.1.0/hanja-tools-PLAN.md +374 -0
- hanja_tools-0.1.0/hanja_tools/__init__.py +20 -0
- hanja_tools-0.1.0/hanja_tools/data/inmyong_hanja.json +1 -0
- hanja_tools-0.1.0/hanja_tools/data/stroke_count.json +1 -0
- hanja_tools-0.1.0/hanja_tools/db.py +140 -0
- hanja_tools-0.1.0/hanja_tools/inmyong.py +54 -0
- hanja_tools-0.1.0/hanja_tools/ohaeng.py +75 -0
- hanja_tools-0.1.0/hanja_tools/search.py +132 -0
- hanja_tools-0.1.0/hanja_tools/stroke.py +44 -0
- hanja_tools-0.1.0/pyproject.toml +45 -0
- hanja_tools-0.1.0/scripts/build_inmyong_db.py +54 -0
- hanja_tools-0.1.0/scripts/build_stroke_db.py +60 -0
- hanja_tools-0.1.0/tests/conftest.py +10 -0
- hanja_tools-0.1.0/tests/test_inmyong.py +48 -0
- hanja_tools-0.1.0/tests/test_ohaeng.py +59 -0
- hanja_tools-0.1.0/tests/test_search.py +94 -0
- hanja_tools-0.1.0/tests/test_stroke.py +53 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hanja-tools contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hanja-tools
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Korean Hanja utilities: stroke count, five-elements (ohaeng), and personal-name character filter
|
|
5
|
+
Project-URL: Homepage, https://github.com/hyun/hanja-tools
|
|
6
|
+
Project-URL: Repository, https://github.com/hyun/hanja-tools
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: chinese-characters,hanja,inmyong,korean,ohaeng,stroke
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: hanja>=0.14.0
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
23
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# hanja-tools
|
|
27
|
+
|
|
28
|
+
한국 한자(漢字) 관련 기능을 통합한 Python 패키지입니다.
|
|
29
|
+
`suminb/hanja`가 제공하지 않는 **획수·오행·인명용 필터·검색** 기능을 추가합니다.
|
|
30
|
+
|
|
31
|
+
## 설치
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install hanja-tools
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 빠른 시작
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from hanja_tools import HanjaDB
|
|
41
|
+
|
|
42
|
+
db = HanjaDB()
|
|
43
|
+
|
|
44
|
+
db.get_eum('松') # '송' — 한글 음 (suminb/hanja 기반)
|
|
45
|
+
db.get_stroke('松') # 8 — 획수 (Unihan kTotalStrokes)
|
|
46
|
+
db.get_ohaeng('松') # '金' — 오행 (수리오행법: 8획 끝자리 8 → 金)
|
|
47
|
+
db.is_inmyong('松') # True — 인명용 한자 여부 (대법원 기준)
|
|
48
|
+
db.info('松')
|
|
49
|
+
# {'char': '松', 'eum': '송', 'stroke': 8, 'ohaeng': '金', 'inmyong': True}
|
|
50
|
+
|
|
51
|
+
# 검색
|
|
52
|
+
db.search_by_eum('송') # ['松', '誦', '頌', ...]
|
|
53
|
+
db.search_by_stroke(8) # 8획 한자 목록
|
|
54
|
+
db.search_by_ohaeng('木') # 木 오행 한자 목록
|
|
55
|
+
db.search(eum='송', inmyong=True) # 복합 조건
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 오행 분류표 (수리오행법)
|
|
59
|
+
|
|
60
|
+
| 획수 끝자리 | 오행 |
|
|
61
|
+
|---|---|
|
|
62
|
+
| 1, 2 | 木 |
|
|
63
|
+
| 3, 4 | 火 |
|
|
64
|
+
| 5, 6 | 土 |
|
|
65
|
+
| 7, 8 | 金 |
|
|
66
|
+
| 9, 0 | 水 |
|
|
67
|
+
|
|
68
|
+
## 데이터 출처
|
|
69
|
+
|
|
70
|
+
| 데이터 | 출처 | 라이선스 |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| 한자→음 | `suminb/hanja` table.yml (27,497자) | CC0 |
|
|
73
|
+
| 획수 | Unicode Unihan Database `kTotalStrokes` | Unicode License |
|
|
74
|
+
| 인명용 한자 | `rutopio/Korean-Name-Hanja-Charset` data-gov.csv | MIT |
|
|
75
|
+
|
|
76
|
+
## 라이선스
|
|
77
|
+
|
|
78
|
+
MIT
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# hanja-tools
|
|
2
|
+
|
|
3
|
+
한국 한자(漢字) 관련 기능을 통합한 Python 패키지입니다.
|
|
4
|
+
`suminb/hanja`가 제공하지 않는 **획수·오행·인명용 필터·검색** 기능을 추가합니다.
|
|
5
|
+
|
|
6
|
+
## 설치
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install hanja-tools
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 빠른 시작
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from hanja_tools import HanjaDB
|
|
16
|
+
|
|
17
|
+
db = HanjaDB()
|
|
18
|
+
|
|
19
|
+
db.get_eum('松') # '송' — 한글 음 (suminb/hanja 기반)
|
|
20
|
+
db.get_stroke('松') # 8 — 획수 (Unihan kTotalStrokes)
|
|
21
|
+
db.get_ohaeng('松') # '金' — 오행 (수리오행법: 8획 끝자리 8 → 金)
|
|
22
|
+
db.is_inmyong('松') # True — 인명용 한자 여부 (대법원 기준)
|
|
23
|
+
db.info('松')
|
|
24
|
+
# {'char': '松', 'eum': '송', 'stroke': 8, 'ohaeng': '金', 'inmyong': True}
|
|
25
|
+
|
|
26
|
+
# 검색
|
|
27
|
+
db.search_by_eum('송') # ['松', '誦', '頌', ...]
|
|
28
|
+
db.search_by_stroke(8) # 8획 한자 목록
|
|
29
|
+
db.search_by_ohaeng('木') # 木 오행 한자 목록
|
|
30
|
+
db.search(eum='송', inmyong=True) # 복합 조건
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 오행 분류표 (수리오행법)
|
|
34
|
+
|
|
35
|
+
| 획수 끝자리 | 오행 |
|
|
36
|
+
|---|---|
|
|
37
|
+
| 1, 2 | 木 |
|
|
38
|
+
| 3, 4 | 火 |
|
|
39
|
+
| 5, 6 | 土 |
|
|
40
|
+
| 7, 8 | 金 |
|
|
41
|
+
| 9, 0 | 水 |
|
|
42
|
+
|
|
43
|
+
## 데이터 출처
|
|
44
|
+
|
|
45
|
+
| 데이터 | 출처 | 라이선스 |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| 한자→음 | `suminb/hanja` table.yml (27,497자) | CC0 |
|
|
48
|
+
| 획수 | Unicode Unihan Database `kTotalStrokes` | Unicode License |
|
|
49
|
+
| 인명용 한자 | `rutopio/Korean-Name-Hanja-Charset` data-gov.csv | MIT |
|
|
50
|
+
|
|
51
|
+
## 라이선스
|
|
52
|
+
|
|
53
|
+
MIT
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
# hanja-tools 프로젝트 기획서
|
|
2
|
+
|
|
3
|
+
> **목적**: 한국 한자(漢字) 관련 기능을 통합한 독립 Python 패키지
|
|
4
|
+
> **배경**: ho-namer(서예 호 작명 앱) 개발 중 발견한 공백 — `suminb/hanja`는 음(音) 변환만 제공하며 획수·오행·인명용 필터가 없음
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. 문제 정의
|
|
9
|
+
|
|
10
|
+
### suminb/hanja 패키지의 현황과 한계
|
|
11
|
+
|
|
12
|
+
`pip install hanja`로 설치하는 기존 패키지(`suminb/hanja`, CC0 라이선스)는 내부적으로 `table.yml` 하나로 동작한다.
|
|
13
|
+
|
|
14
|
+
**내부 구조**
|
|
15
|
+
```
|
|
16
|
+
hanja 패키지 (522KB)
|
|
17
|
+
├── table.yml ← 핵심: 한자 유니코드 문자 → 한글 음 1글자 매핑 (27,497자)
|
|
18
|
+
├── __init__.py ← translate(), is_hanja(), split_hanja() 공개 API
|
|
19
|
+
├── impl.py ← 두음법칙 포함 번역 로직
|
|
20
|
+
├── hangul.py ← 두음법칙 처리 (dooeum 함수)
|
|
21
|
+
└── table.py ← table.yml YAML 로더
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**table.yml 구조** (키: 한자 문자 자체, 값: 한글 음 1음절)
|
|
25
|
+
```yaml
|
|
26
|
+
'松': '송'
|
|
27
|
+
'山': '산'
|
|
28
|
+
'水': '수'
|
|
29
|
+
'靑': '청'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**블록별 커버리지**
|
|
33
|
+
|
|
34
|
+
| 유니코드 블록 | 범위 | 수록 자수 |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| CJK Unified Ideographs | U+4E00~U+9FFF | 20,902자 |
|
|
37
|
+
| CJK Extension-A | U+3400~U+4DBF | 6,582자 |
|
|
38
|
+
| CJK Compatibility | U+F900~U+FAFF | 13자 |
|
|
39
|
+
| **합계** | | **27,497자** |
|
|
40
|
+
|
|
41
|
+
음(音) 종류: 546개 / 가장 많은 음: 구(349자), 수(306자), 기(300자)
|
|
42
|
+
|
|
43
|
+
**제공 기능과 공백**
|
|
44
|
+
|
|
45
|
+
| 기능 | suminb/hanja | 비고 |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| 한자 → 한글 음 변환 | ✅ | CC0, 두음법칙 포함 |
|
|
48
|
+
| 한자 여부 판별 `is_hanja()` | ✅ | |
|
|
49
|
+
| 한자/비한자 분리 `split_hanja()` | ✅ | |
|
|
50
|
+
| **획수(劃數) 조회** | ❌ 없음 | 별도 구현 필요 |
|
|
51
|
+
| **오행(五行) 분류** | ❌ 없음 | 획수 기반 계산 |
|
|
52
|
+
| **인명용 한자 필터** | ❌ 없음 | 대법원 9,389자 |
|
|
53
|
+
| **한자 검색** (음/획수/오행별) | ❌ 없음 | |
|
|
54
|
+
| **한자 의미** | ❌ 없음 | |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 2. 프로젝트 목표
|
|
59
|
+
|
|
60
|
+
`suminb/hanja`의 공백을 채우는 **독립 Python 패키지**를 만든다.
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
pip install hanja-tools
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 핵심 기능
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from hanja_tools import HanjaDB
|
|
70
|
+
|
|
71
|
+
db = HanjaDB()
|
|
72
|
+
|
|
73
|
+
# 한자 → 음 (suminb/hanja 기반)
|
|
74
|
+
db.get_eum('松') # → '송'
|
|
75
|
+
|
|
76
|
+
# 획수 조회 (Unihan kTotalStrokes)
|
|
77
|
+
db.get_stroke('松') # → 8
|
|
78
|
+
|
|
79
|
+
# 오행 계산 (수리오행법: 획수 끝자리)
|
|
80
|
+
db.get_ohaeng('松') # → '木' (8획 → 끝자리 8 → 金... 아님 → 정확한 분류법 적용)
|
|
81
|
+
|
|
82
|
+
# 인명용 한자 여부 (대법원 9,389자)
|
|
83
|
+
db.is_inmyong('松') # → True
|
|
84
|
+
|
|
85
|
+
# 검색
|
|
86
|
+
db.search_by_eum('송') # → ['松', '誦', '頌', ...]
|
|
87
|
+
db.search_by_stroke(8) # → ['松', '杰', ...]
|
|
88
|
+
db.search_by_ohaeng('木') # → [...]
|
|
89
|
+
db.search(eum='송', stroke=8) # → 복합 조건
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 3. 데이터 소스
|
|
95
|
+
|
|
96
|
+
### 3-1. 한자 → 음 매핑
|
|
97
|
+
|
|
98
|
+
- **출처**: `suminb/hanja` 내장 `table.yml`
|
|
99
|
+
- **라이선스**: CC0 (상업적 사용 포함 제한 없음)
|
|
100
|
+
- **수량**: 27,497자
|
|
101
|
+
- **처리**: 그대로 활용 또는 의존성으로 설치
|
|
102
|
+
|
|
103
|
+
### 3-2. 획수 데이터
|
|
104
|
+
|
|
105
|
+
- **출처**: Unicode Consortium — **Unihan Database** `kTotalStrokes` 필드
|
|
106
|
+
- **파일**: `Unihan_IRGSources.txt` (Unicode.org 무료 제공)
|
|
107
|
+
- **라이선스**: Unicode License (무료, 재배포 가능)
|
|
108
|
+
- **URL**: `https://www.unicode.org/Public/UCD/latest/ucd/Unihan.zip`
|
|
109
|
+
- **처리**: 1회 파싱 스크립트 → `data/stroke_count.json` 저장
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
# Unihan 파싱 예시
|
|
113
|
+
# Unihan_IRGSources.txt 형식:
|
|
114
|
+
# U+677E kTotalStrokes 8
|
|
115
|
+
# U+5C71 kTotalStrokes 3
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 3-3. 인명용 한자 목록
|
|
119
|
+
|
|
120
|
+
- **출처 A**: 나무위키 인명용 한자표 (대법원 원본 기반)
|
|
121
|
+
- URL: `https://namu.wiki/w/한자/인명용%20한자표`
|
|
122
|
+
- 텍스트 파일: 대법원 PDF 첨부 `AppendixA-ListofHanjaforUseinPersonalNames.txt`
|
|
123
|
+
- **출처 B**: `rutopio/Korean-Name-Hanja-Charset` (GitHub, MIT 라이선스)
|
|
124
|
+
- `data-gov.csv` — 대법원 크롤링 결과 10,163자
|
|
125
|
+
- `data-naver.csv` — 네이버 사전 크롤링 결과 8,957자
|
|
126
|
+
- **최신 기준**: 2024년 6월 개정 — 총 **9,389자**
|
|
127
|
+
|
|
128
|
+
### 3-4. 오행 분류
|
|
129
|
+
|
|
130
|
+
성명학에서 사용하는 **수리오행법** (획수 끝자리 기준):
|
|
131
|
+
|
|
132
|
+
| 획수 끝자리 | 오행 |
|
|
133
|
+
|---|---|
|
|
134
|
+
| 1, 2 | 木 |
|
|
135
|
+
| 3, 4 | 火 |
|
|
136
|
+
| 5, 6 | 土 |
|
|
137
|
+
| 7, 8 | 金 |
|
|
138
|
+
| 9, 0 | 水 |
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 4. 기술 스택
|
|
143
|
+
|
|
144
|
+
| 항목 | 선택 | 비고 |
|
|
145
|
+
|---|---|---|
|
|
146
|
+
| 언어 | Python 3.11+ | |
|
|
147
|
+
| 의존성 | `suminb/hanja`, `pyyaml` | 최소화 |
|
|
148
|
+
| 데이터 형식 | JSON | 런타임 로드 |
|
|
149
|
+
| 테스트 | pytest | |
|
|
150
|
+
| 패키지 관리 | pyproject.toml (uv) | |
|
|
151
|
+
| 배포 | PyPI | `hanja-tools` |
|
|
152
|
+
| 라이선스 | MIT | |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 5. 디렉토리 구조
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
hanja-tools/
|
|
160
|
+
├── pyproject.toml
|
|
161
|
+
├── README.md
|
|
162
|
+
├── LICENSE
|
|
163
|
+
│
|
|
164
|
+
├── hanja_tools/
|
|
165
|
+
│ ├── __init__.py # 공개 API
|
|
166
|
+
│ ├── db.py # HanjaDB 메인 클래스
|
|
167
|
+
│ ├── stroke.py # 획수 조회
|
|
168
|
+
│ ├── ohaeng.py # 오행 계산
|
|
169
|
+
│ ├── inmyong.py # 인명용 한자 필터
|
|
170
|
+
│ ├── search.py # 검색 기능
|
|
171
|
+
│ └── data/
|
|
172
|
+
│ ├── stroke_count.json # Unihan kTotalStrokes 파싱 결과
|
|
173
|
+
│ └── inmyong_hanja.json # 대법원 인명용 한자 9,389자
|
|
174
|
+
│
|
|
175
|
+
├── scripts/
|
|
176
|
+
│ ├── build_stroke_db.py # Unihan 파싱 → stroke_count.json 생성
|
|
177
|
+
│ └── build_inmyong_db.py # 대법원/나무위키 → inmyong_hanja.json 생성
|
|
178
|
+
│
|
|
179
|
+
└── tests/
|
|
180
|
+
├── test_stroke.py
|
|
181
|
+
├── test_ohaeng.py
|
|
182
|
+
├── test_inmyong.py
|
|
183
|
+
└── test_search.py
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 6. 빌드 스크립트 설계
|
|
189
|
+
|
|
190
|
+
### `scripts/build_stroke_db.py`
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
"""
|
|
194
|
+
Unicode Unihan Database에서 kTotalStrokes를 파싱해
|
|
195
|
+
data/stroke_count.json을 생성하는 1회성 빌드 스크립트
|
|
196
|
+
"""
|
|
197
|
+
import urllib.request, zipfile, io, json
|
|
198
|
+
|
|
199
|
+
UNIHAN_URL = "https://www.unicode.org/Public/UCD/latest/ucd/Unihan.zip"
|
|
200
|
+
|
|
201
|
+
def fetch_stroke_count():
|
|
202
|
+
print("Unihan.zip 다운로드...")
|
|
203
|
+
with urllib.request.urlopen(UNIHAN_URL) as r:
|
|
204
|
+
data = r.read()
|
|
205
|
+
|
|
206
|
+
stroke_map = {}
|
|
207
|
+
with zipfile.ZipFile(io.BytesIO(data)) as z:
|
|
208
|
+
with z.open("Unihan_IRGSources.txt") as f:
|
|
209
|
+
for line in f:
|
|
210
|
+
line = line.decode('utf-8').strip()
|
|
211
|
+
if '\tkTotalStrokes\t' in line:
|
|
212
|
+
parts = line.split('\t')
|
|
213
|
+
codepoint = parts[0] # 'U+677E'
|
|
214
|
+
stroke = int(parts[2])
|
|
215
|
+
char = chr(int(codepoint[2:], 16))
|
|
216
|
+
stroke_map[char] = stroke
|
|
217
|
+
|
|
218
|
+
print(f"총 {len(stroke_map)}자 획수 데이터 수집")
|
|
219
|
+
return stroke_map
|
|
220
|
+
|
|
221
|
+
if __name__ == '__main__':
|
|
222
|
+
result = fetch_stroke_count()
|
|
223
|
+
with open('hanja_tools/data/stroke_count.json', 'w', encoding='utf-8') as f:
|
|
224
|
+
json.dump(result, f, ensure_ascii=False, indent=None)
|
|
225
|
+
print("저장 완료: hanja_tools/data/stroke_count.json")
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### `scripts/build_inmyong_db.py`
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
"""
|
|
232
|
+
rutopio/Korean-Name-Hanja-Charset의 data-gov.csv 또는
|
|
233
|
+
대법원 txt 파일을 파싱해 inmyong_hanja.json을 생성
|
|
234
|
+
"""
|
|
235
|
+
import csv, json, urllib.request
|
|
236
|
+
|
|
237
|
+
# rutopio/Korean-Name-Hanja-Charset (MIT)
|
|
238
|
+
CSV_URL = "https://raw.githubusercontent.com/rutopio/Korean-Name-Hanja-Charset/main/data-gov.csv"
|
|
239
|
+
|
|
240
|
+
def build():
|
|
241
|
+
chars = set()
|
|
242
|
+
with urllib.request.urlopen(CSV_URL) as r:
|
|
243
|
+
reader = csv.DictReader(r.read().decode('utf-8').splitlines())
|
|
244
|
+
for row in reader:
|
|
245
|
+
ch = row.get('character', '').strip()
|
|
246
|
+
if ch:
|
|
247
|
+
chars.add(ch)
|
|
248
|
+
print(f"인명용 한자 {len(chars)}자 수집")
|
|
249
|
+
return sorted(chars)
|
|
250
|
+
|
|
251
|
+
if __name__ == '__main__':
|
|
252
|
+
result = build()
|
|
253
|
+
with open('hanja_tools/data/inmyong_hanja.json', 'w', encoding='utf-8') as f:
|
|
254
|
+
json.dump(result, f, ensure_ascii=False)
|
|
255
|
+
print("저장 완료: hanja_tools/data/inmyong_hanja.json")
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## 7. 공개 API 설계
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
from hanja_tools import HanjaDB, stroke, ohaeng, search
|
|
264
|
+
|
|
265
|
+
# === 단일 한자 조회 ===
|
|
266
|
+
db = HanjaDB()
|
|
267
|
+
|
|
268
|
+
db.get_eum('松') # '송' — 한글 음
|
|
269
|
+
db.get_stroke('松') # 8 — 획수
|
|
270
|
+
db.get_ohaeng('松') # '金' — 오행 (수리오행법)
|
|
271
|
+
db.is_inmyong('松') # True — 인명용 여부
|
|
272
|
+
db.info('松') # {'char':'松','eum':'송','stroke':8,'ohaeng':'金','inmyong':True}
|
|
273
|
+
|
|
274
|
+
# === 검색 ===
|
|
275
|
+
db.search_by_eum('송') # ['松','誦','頌',...] 음으로 검색
|
|
276
|
+
db.search_by_stroke(8) # 8획 한자 전체
|
|
277
|
+
db.search_by_ohaeng('木') # 木 오행 한자 전체
|
|
278
|
+
db.search(eum='송', inmyong=True) # 복합 조건
|
|
279
|
+
db.search(stroke=8, ohaeng='金', inmyong=True)
|
|
280
|
+
|
|
281
|
+
# === 오행 계산 (독립 함수) ===
|
|
282
|
+
from hanja_tools.ohaeng import calc_ohaeng_by_stroke
|
|
283
|
+
calc_ohaeng_by_stroke(8) # '金'
|
|
284
|
+
calc_ohaeng_by_stroke(13) # '火' (끝자리 3)
|
|
285
|
+
|
|
286
|
+
# === 획수 (독립 함수) ===
|
|
287
|
+
from hanja_tools.stroke import get_stroke
|
|
288
|
+
get_stroke('松') # 8
|
|
289
|
+
get_stroke('山') # 3
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## 8. 테스트 계획
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
tests/
|
|
298
|
+
├── test_stroke.py
|
|
299
|
+
│ ├── test_known_strokes() # 松=8, 山=3, 水=4 등 검증
|
|
300
|
+
│ ├── test_stroke_not_found() # 없는 한자 → None 반환
|
|
301
|
+
│ └── test_stroke_count_range() # 1~64획 범위 내
|
|
302
|
+
│
|
|
303
|
+
├── test_ohaeng.py
|
|
304
|
+
│ ├── test_ohaeng_mok() # 1,2획 → 木
|
|
305
|
+
│ ├── test_ohaeng_hwa() # 3,4획 → 火
|
|
306
|
+
│ ├── test_ohaeng_to() # 5,6획 → 土
|
|
307
|
+
│ ├── test_ohaeng_geum() # 7,8획 → 金
|
|
308
|
+
│ └── test_ohaeng_su() # 9,0획 → 水
|
|
309
|
+
│
|
|
310
|
+
├── test_inmyong.py
|
|
311
|
+
│ ├── test_inmyong_true() # 松 → True
|
|
312
|
+
│ ├── test_inmyong_false() # 일반 한자 → False
|
|
313
|
+
│ └── test_inmyong_count() # 9,000자 이상
|
|
314
|
+
│
|
|
315
|
+
└── test_search.py
|
|
316
|
+
├── test_search_by_eum()
|
|
317
|
+
├── test_search_by_stroke()
|
|
318
|
+
├── test_search_by_ohaeng()
|
|
319
|
+
└── test_search_compound()
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## 9. ho-namer와의 관계
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
[hanja-tools] → pip install hanja-tools
|
|
328
|
+
↓
|
|
329
|
+
[ho-namer]
|
|
330
|
+
core/hanja.py 에서 import
|
|
331
|
+
Phase 6 (음양 배열·한자 DB) 에 활용
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
ho-namer의 `core/hanja.py`는 `hanja-tools`를 의존성으로 설치해 사용한다.
|
|
335
|
+
hanja-tools가 완성되기 전까지는 ho-namer 내부에 임시 구현(`core/hanja_local.py`)을 두고 진행한다.
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## 10. 참조 레포
|
|
340
|
+
|
|
341
|
+
| 레포 | 역할 | 라이선스 |
|
|
342
|
+
|---|---|---|
|
|
343
|
+
| `suminb/hanja` | 한자→음 table.yml (27,497자) | CC0 |
|
|
344
|
+
| `rutopio/Korean-Name-Hanja-Charset` | 대법원 인명용 한자 크롤링 데이터 | MIT |
|
|
345
|
+
| `byung-u/EdenNaming` | 작명 도메인 로직 참조 | MIT |
|
|
346
|
+
| Unicode Unihan DB | kTotalStrokes 획수 데이터 | Unicode License |
|
|
347
|
+
| 나무위키 인명용 한자표 | 대법원 원본 기반 텍스트 목록 | — |
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## 11. 개발 순서 (권장)
|
|
352
|
+
|
|
353
|
+
```
|
|
354
|
+
Phase 0 프로젝트 초기화 (pyproject.toml, 디렉토리)
|
|
355
|
+
↓
|
|
356
|
+
Phase 1 scripts/build_stroke_db.py → data/stroke_count.json 생성
|
|
357
|
+
↓
|
|
358
|
+
Phase 2 scripts/build_inmyong_db.py → data/inmyong_hanja.json 생성
|
|
359
|
+
↓
|
|
360
|
+
Phase 3 stroke.py + test_stroke.py (획수 조회)
|
|
361
|
+
↓
|
|
362
|
+
Phase 4 ohaeng.py + test_ohaeng.py (오행 계산)
|
|
363
|
+
↓
|
|
364
|
+
Phase 5 inmyong.py + test_inmyong.py (인명용 필터)
|
|
365
|
+
↓
|
|
366
|
+
Phase 6 db.py + search.py + test_search.py (통합 클래스 + 검색)
|
|
367
|
+
↓
|
|
368
|
+
Phase 7 PyPI 배포 (twine, pyproject.toml 완성)
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
*작성일: 2026-06-24*
|
|
374
|
+
*관련 프로젝트: ho-namer (서예 호 작명 FastAPI 앱)*
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
hanja_tools — Korean Hanja utilities
|
|
3
|
+
|
|
4
|
+
Public API:
|
|
5
|
+
HanjaDB : unified access class
|
|
6
|
+
get_stroke, calc_ohaeng_by_stroke : convenience re-exports
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from hanja_tools.db import HanjaDB
|
|
10
|
+
from hanja_tools.stroke import get_stroke
|
|
11
|
+
from hanja_tools.ohaeng import calc_ohaeng_by_stroke, get_ohaeng
|
|
12
|
+
from hanja_tools.inmyong import is_inmyong
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"HanjaDB",
|
|
16
|
+
"get_stroke",
|
|
17
|
+
"calc_ohaeng_by_stroke",
|
|
18
|
+
"get_ohaeng",
|
|
19
|
+
"is_inmyong",
|
|
20
|
+
]
|