Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Yet Another Fast Japanese String Converter

License

NotificationsYou must be signed in to change notification settings

Hizuru3/python-habachen

Repository files navigation

Read in English

Habachen

日本語の全角/半角とひらがな/カタカナの相互変換をサポートする高速で省メモリな文字列変換モジュールです。

License

MIT License

Installation

pip install habachen

Usage

# habachenモジュールをインポート>>>importhabachen# 半角から全角>>>habachen.han_to_zen('abc!?012ハンカクモジ')'abc!?012ハンカクモジ'# 半角カタカナのみを変換>>>text='abc!?012ハンカクモジ'>>>habachen.han_to_zen(text,ascii=False,digit=False,kana=True)'abc!?012ハンカクモジ'# 全角から半角>>>habachen.zen_to_han('abc!?012ゼンカクモジ')'abc!?012ゼンカクモジ'# 全角カタカナの変換を行わない>>>text='abc!?012ゼンカクモジ'>>>habachen.zen_to_han(text,kana=False)'abc!?012ゼンカクモジ'# ひらがなをカタカナに変換>>>habachen.to_katakana('もじれつの変換')'モジレツノ変換'# 指定したひらがなを無視>>>habachen.to_katakana('あいうえおかきくけこ',ignore='あか')'あイウエオかキクケコ'# ひらがなを半角カタカナに変換>>>habachen.to_katakana('もじれつの変換',hankaku=True)'モジレツノ変換'# 全角カタカナをひらがなに変換>>>habachen.to_hiragana('モジレツノ変換')'もじれつの変換'# 指定したカタカナを無視>>>habachen.to_hiragana('テストデス',ignore='ス')'てスとでス'

Benchmarks

使用した文章

夢野久作『ドグラ・マグラ』
http://www.aozora.gr.jp/cards/000096/files/2093_ruby_28087.zip

Python のバージョン

Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux

ライブラリのバージョン

habachen-0.3.0
mojimoji-0.0.12
jaconv-0.3.4

結果(短文 140文字)

habachenmojimojijaconv
全角→半角1.319 µs11.92 µs11.22 µs
半角→全角1.147 µs10.15 µs26.49 µs
ひらがな→カタカナ0.3674 µs11.22 µs
カタカナ→ひらがな0.3542 µs10.97 µs

結果(全文 468996文字)

habachenmojimojijaconv
全角→半角2.607 ms55.07 ms40.36 ms
半角→全角1.832 ms33.89 ms57.16 ms
ひらがな→カタカナ0.711 ms38.72 ms
カタカナ→ひらがな0.755 ms40.36 ms

検証に用いたスクリプトはこちら

Links

ドキュメント:https://hizuru3.github.io/python-habachen/

Qiita 記事:https://qiita.com/Hizuru/items/6b91d00fbe13ebb43867

About

Yet Another Fast Japanese String Converter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp