Skip to main content

kanachain

任意のバイト列を、ブロックをまたいでつながる日本語のしりとりへ可逆変換します。 符号方式は Kana Chain Block Code / 仮名チェーンブロック符号(KCBC)、 現在のフォーマット識別子は A1/D1 です。依存パッケージはありません。

pip install kanachain

CLI

kanachain serialize --text "こんにちは、KCBC"
kanachain serialize --input photo.png --output photo.kana
kanachain deserialize --input photo.kana --output restored.png
kanachain info

API

符号化と復号のメソッド名は、しりとりの「尻」にかけて serialize / deserialize としています。

from kanachain import create_kana_chain_block_code

codec = create_kana_chain_block_code()

serialized = codec.serialize("こんにちは")
print(serialized.text)
# CRC付きブロックごとに改行されたしりとり

deserialized = codec.deserialize(serialized.text)
print(deserialized.data.decode("utf-8"))  # こんにちは

strを渡すとUTF-8、UTF-16LE、それぞれのDEFLATE表現を比較し、出力語数が最少に なるものを採用します。bytesを渡した場合は任意バイナリとしてrawとDEFLATEだけを 比較します。復号結果のdataは常にbytesです。

出力の改行は正式なブロック境界ですが、改行のない単語列からも35語ごとに境界を 復元できます。復号時はひらがなとカタカナを区別しません。

同じ符号表を使うJavaScript実装(npm: kanachain)と相互運用できます。 両実装はvectors/a1d1.jsonの同じテストベクタを検証します。

仕様と辞書

フォーマット仕様、辞書の生成パイプライン、採用根拠は リポジトリにあります。

ライセンス

コードはMIT。同梱するcodebook.jsonは国立国語研究所のCC BY 4.0データに由来します。 NOTICE.mdを参照してください。

Download files

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

Source Distribution

kanachain-1.0.0.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kanachain-1.0.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file kanachain-1.0.0.tar.gz.

File metadata

  • Download URL: kanachain-1.0.0.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kanachain-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4f20e112fb4d632963607455430ee8d26086642dc286448b7455313bcbe972e2
MD5 d50bfb09cb02818180f26f9d91588793
BLAKE2b-256 63da8d0d402efffd401d49961253b61739dc266a80816f873442940a3b6231f8

See more details on using hashes here.

File details

Details for the file kanachain-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: kanachain-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kanachain-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f220ca1595151b039849b933d5537f47797e5d9abd7382bb245fe8f803167fe
MD5 0f088c25ee0562b89ab9fb5b410085d7
BLAKE2b-256 86c9200f1516e8a5f76a5c4ed351edbda4660a2702afde17b16949d4f4754ce0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page