A Python package for phonetic Korean text matching with enhanced first-character weighting.
Project description
korean-text-matcher
A Python package for phonetic Korean text matching with enhanced first-character weighting. This package provides a custom similarity ratio function (korean_word_matching_ratio) specifically designed for comparing Korean strings, especially useful for names, product names (like drug names), or any text where phonetic similarity and initial character importance are key.
Features
- Korean Phonetic Decomposition: Internally decomposes Korean characters into their initial, medial, and final consonants (초성, 중성, 종성) for more granular and phonetically aware similarity comparison.
- Partial Ratio Calculation: Utilizes
difflib.SequenceMatcherto find the similarity of the most similar substring, making it robust for partial matches. - Enhanced First Character Weighting: Applies a custom weight adjustment based on whether the first meaningful character (Korean, English, or number) of the original strings matches. This is particularly useful for distinguishing between similar-sounding but different entries.
- Robust Handling: Designed to safely process various inputs, including mixed Korean/English/numeric strings and edge cases like empty inputs or unusual characters.
Installation
You can install this package via pip (once it's uploaded to PyPI):
pip install korean-text-matcher
# Usage
from korean_text_matcher import korean_word_matching_ratio
#Example 1: Similar Korean words
score1 = korean_word_matching_ratio("안녕하세요", "안녕하세용")
print(f"Similarity ('안녕하세요' vs '안녕하세용'): {score1}")
# Expected output: High score (e.g., ~90s)
# Example 2: Drug names with mixed characters
score2 = korean_word_matching_ratio("에페른정50mg", "이페른정50mg")
print(f"Similarity ('에페른정50mg' vs '이페른정50mg'): {score2}")
# Expected output: High score due to phonetic similarity of '에'/'이' and exact match of '페른정50mg'
score3 = korean_word_matching_ratio("에페른정50mg", "아피토정40mg")
print(f"Similarity ('에페른정50mg' vs '아피토정40mg'): {score3}")
# Expected output: Lower score due to significant differences, and potentially -5 first char weight
#Example 3: Different first characters
score4 = korean_word_matching_ratio("사과", "바나나")
print(f"Similarity ('사과' vs '바나나'): {score4}")
# Expected output: Very low score (likely 0 due to -5 first char weight)
#Example 4: English and numbers
score5 = korean_word_matching_ratio("Cefaclor 250mg", "Cefaclor 500mg")
print(f"Similarity ('Cefaclor 250mg' vs 'Cefaclor 500mg'): {score5}")
# Expected output: High score (e.g., ~80-90s)
Contribution
If you find any bugs or have suggestions for improvement, send e-mail to me
License
This project is licensed under the MIT License.
MIT License
Copyright (c) 2025 Kim Jeon-hee
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. If you find any bugs or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file korean_text_matcher-0.1.0.tar.gz.
File metadata
- Download URL: korean_text_matcher-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4db5cb401e70e01cb29c687166ca2697577374aa977f7b5fe69f7867c7bda339
|
|
| MD5 |
bf3e3c3ecd6436681cbe8396d5a13e26
|
|
| BLAKE2b-256 |
81ef2983087a1a0126f675a02ecb160d64ab03cec01a9d1718b24829e6ca1e9a
|
File details
Details for the file korean_text_matcher-0.1.0-py3-none-any.whl.
File metadata
- Download URL: korean_text_matcher-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c3d637a83b9ee0e47fe99baca77bdc1abeb8a9b6377836c0f222855d4d90943
|
|
| MD5 |
5291caa313ec188d8c823300ed6c6b12
|
|
| BLAKE2b-256 |
47d0ffbc59d8cc3e31b0059e7c2f2b90d6c670fc0c10f66d003df6aad135d17e
|