Skip to main content

chanoma is Characters Normalization library.文字列正規化処理用のライブラリです。

Project description

chanoma

chanoma is Characters Normalization library. 文字列正規化処理用のライブラリです。

Rust 版 の Python バインディングです。

使い方

from chanoma import Chanoma

def main():
    chanoma = Chanoma(preset=True)
    print(chanoma.normalize("ハンカクカナは全角カタカナに変換されます"))

if __name__ == '__main__':
    main()

インストール

pip install chanoma

設定ファイル

chanoma は設定ファイルを配置することで、結果を調整することが可能です。 設定ファイルを読み込ませるための方法は二種類あります。

  • 環境変数 CHANOMARC に設定ファイルのパスを指定する。
  • 以下のパスのうちのどこかにファイルを配置する。
    • $HOME/.config/chanoma/chanomarc.{ext}
    • $HOME/.config/chanoma/.chanomarc.{ext}
    • $HOME/chanomarc.{ext}
    • $HOME/.chanomarc.{ext}
    • $PWD/chanomarc.{ext}
    • $PWD/.chanomarc.{ext}

上記のどちらの場合でも、.{ext} に指定可能な拡張子は .csv, .yaml (.yml) のどれかです。

CSV ファイルの場合のフォーマット

CSV ファイルでは、一文字から一文字の置換のみ設定が可能です。 最初の列に 置換したい文字、次の列に 置換後の文字 を記述します。

from,to
&,&

YAML ファイルの場合のフォーマット

Yaml ファイルでは、一文字から一文字の置換と、Modifier を指定する二種類の方法があります。

一文字から一文字の置換

ルートキーに items を記述し、配列指定で from キーの値に 置換したい文字to キーの値に 置換後の文字 を記述します。

items:
  - from: "a"
    to: "A"

Modifier を指定する

ルートキーに modifiers を記述し、一段インデントして Modifier をキーとして記述します。 指定できる Modifire は以下です。

  • character_converter : 一文字から一文字の置換を設定します。キーに 置換したい文字、値に 置換後の文字 を記述します。( items と同様の処理になります。)
  • character_eliminator : 指定した文字を削除します。
  • consecutive_character_reducer : 指定した連続する同じ文字を一つにします。
  • dotted_space_eliminator : 『「半角英数字」と「半角英数字」の間の半角スペース』以外の半角スペースを削除します。
  • ligature_translator : 指定した合字をくっつけて一文字にします。
  • trim : 先頭と末尾の半角スペースを削除します。
  • neologdn : neologdn と同様の結果になる処理をします。
modifiers:
  character_converter:
    a: A
    b: B
  character_eliminator: ["~", , , , , ]
  consecutive_character_reducer: 
  dotted_space_eliminator:
  ligature_translator:
    ハ゜: 
  trim:
  neologdn:

Development

docker-compose build chanoma
docker-compose run --rm chanoma bash
cd /app/bindings/python3
python3 ./setup.py develop
./run-test.sh

Build

docker-compose run --rm build-wheels-for-python ./build-wheels.sh

Publish

docker-compose run --rm chanoma ./bindings/python3/publish_to_pypi.sh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chanoma-0.1.2.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distributions

chanoma-0.1.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.24+ x86-64 manylinux: glibc 2.28+ x86-64

chanoma-0.1.2-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64 manylinux: glibc 2.28+ x86-64

chanoma-0.1.2-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64 manylinux: glibc 2.28+ x86-64

chanoma-0.1.2-cp37-cp37m-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64 manylinux: glibc 2.28+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page