A Python library for e-filing systems.
Project description
libefiling
This library targets electronic filing data provided by the Japan Patent Office (JPO). Detailed documentation is written in Japanese, as the primary users are Japanese.
概要
libefiling は インターネット出願ソフトのアーカイブを扱う python パッケージです。
- インターネット出願ソフト: 日本国特許庁に特許など出願する際に使うアプリ
- アーカイブ: インターネット出願ソフトの「データ出力」で保存されるようなJWX(JPC,JWX)を本パッケージではそう呼んでる。
- データ出力でアーカイブと一緒に出力されるXMLを手続XMLと呼ぶことにする。
機能
- アーカイブの展開 -> XML, 画像ファイルが得られる
- 画像ファイルのフォーマット変換、サイズ変換
- XMLファイルの文字コード変換
- いまのところ 特許願(A163) だけが処理対象。
動作環境
- ubuntu bookworm
- python 3.14
- tesseract
必要アプリのインストール
apt-get update
apt-get install -y python3.14 tesseract-ocr tesseract-ocr-jpn
libefiling パッケージのインストール
pip install libefiling
使い方
from libefiling import parse_archive, ImageConvertParam, Source
params = [
ImageConvertParam(
width=300,
height=300,
suffix="-thumbnail",
format=".webp",
attributes=[{"key": "sizeTag", "value": "thumbnail"}],
),
ImageConvertParam(
width=600,
height=600,
suffix="-middle",
format=".webp",
attributes=[{"key": "sizeTag", "value": "middle"}],
),
ImageConvertParam(
width=800,
height=0,
suffix="-large",
format=".webp",
attributes=[{"key": "sizeTag", "value": "large"}],
),
]
SRC='202501010000123456_A163_____XXXXXXXXXX__99999999999_____AAA.JWX'
PROC='202501010000123456_A163_____XXXXXXXXXX__99999999999_____AFM.XML'
OUT='output'
### ocr 処理対象イメージの種類. 以下から選択
### OCR_TARGET = Literal[
### "chemical-formulas", "figures", "equations", "tables", "other-images", "ALL"
### ]
ocr_target = ["other-images"]
# src のハッシュ値や文書コードを生成して、処理するか判定する例
source = Source.create(SRC)
document_code = source.get_document_code()
if document_code not in ['A163', 'A151']:
raise ValueError(f"Unsupported document code: {document_code}")
if source.sha256 == '...'
print("Already processed")
else:
parse_archive(
SRC,
PROC,
OUT,
params,
ocr_target,
image_max_workers=0, # 0: CPU数に応じて自動
)
- generate_sha256 はアーカイブの内容に応じたハッシュ値を生成し、再処理判定用に使える。
- parse_archive は SRC,PROCを OUTに展開する。第4引数に、画像変換のパラメータを渡せる。 OUT に各種ファイルが展開される。第5引数はOCR処理対象の画像種別を選択する。第6引数 image_max_workers は画像処理の並列オプション。
- image_max_workers が None のとき: 従来どおりシリアル実行
- image_max_workers が 1 のとき: シリアル実行
- image_max_workers が 2 以上のとき: スレッド並列実行
- image_max_workers が 0 のとき: CPU数ベースで自動設定
- source = Source.create(SRC) の source は、manifest.json, xml/sources.xml の内容とおなじ。parse_archive するまえに、source.sha256 を得られるということ。
画像変換の高速化オプション
既定では Pillow でリサイズします。環境変数 LIBEFILING_RESIZER_BACKEND を指定すると、 cykooz_resizer が利用可能な環境ではそちらを使い、利用できなければ Pillow に自動フォールバックします。
# 既定(明示): Pillow
export LIBEFILING_RESIZER_BACKEND=pillow
# cykooz_resizer を優先(未導入/失敗時は Pillow にフォールバック)
export LIBEFILING_RESIZER_BACKEND=cykooz
# 既定(明示): Pillow-simd
export LIBEFILING_RESIZER_BACKEND=pillow-simd
# auto も同様に cykooz_resizer, pillow-simd の順に優先
export LIBEFILING_RESIZER_BACKEND=auto
cykooz_resizer を使う場合:
pip install cykooz_resizer
pillow-simd を使う場合:
pip install pillow-simd
注: cykooz_resizer は Rust ツールチェーンが必要です。環境によってはビルドできない場合があります。 pillow-simd は prerequistes が必要です。
手元で試した限りでは、pillow, pillow-simd, cykooz_resizer であまり差が出なかった。
出力ファイル
- manifest.json : 展開後のファイルの情報
- raw/ : SRC に含まれてたファイルが展展されてる。
- xml/ : raw/*.xml 、PROC を文字コード変換したxml, イメージ変換の対応を表したxml が保存されてる。
- images/ : raw の画像ファイルがparamsに従って変換された画像が保存されてる。
- ocr/ : raw の画像ファイルごとにOCR処理してえられたテキストが保存されてる。
注意事項
- テストは十分でないので、いろいろバグあるとおもう。
- 読み取り元のファイル(SRC,PROCに指定したファイル)や展開後のファイルは、どこかに送信されることはありません。ソースみてもらえば。
- 本アプリで何らかの損害を被っても本アプリ作者は責任を負いません。
ライセンス
MIT ライセンス
Reference
特許庁 日本国特許庁電子文書交換標準仕様XML編 (抜粋版) https://www.jpo.go.jp/system/patent/gaiyo/sesaku/document/touroku_jyohou_kikan/shomen-entry-02jpo-shiyosho.pdf
変更履歴
0.1.40
- manifest の形式変更
- xml, image の path を filename にした。
0.1.49
- manifest の形式変更
- xml_files の kind を追加
- get_document_code 関数を追加
0.1.51
- get_doc_id 関数を追加
0.1.54
- 画像リサイズをスレッド化した。
0.1.55
- 画像リサイズのために cykooze_resizer を選択できるようにした。
0.1.56
- 画像リサイズのために pillow-simd を選択できるようにした。
0.1.60
- get_document_code 関数は、manifest.jsonだけでなく、アーカイブパス・手続ファイルを与えても文書コードを返すようにした。
- manifest.json に 文書コードを含めた
0.2.0
- manifest.json の documents フィールドを sources フィールドに変更した。
- sources の子要素は配列でなく archive, procedure とした。
- sources.document_code フィールドは、文書コードを表す
- get_document_code 廃止,Source クラスの get_document_code で代替
- get_doc_id, generate_sha256 関数廃止, Source クラスの sha256 で代替
- xml/sources.xml をはき出すようにした. manifest.json の sources フィールドと同じ内容を表す。
0.2.1
- xml/images-information.xml をはき出すようにした. manifest.json の images フィールドと同じ内容 + ocr テキストを含んだxml
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 libefiling-0.2.2.tar.gz.
File metadata
- Download URL: libefiling-0.2.2.tar.gz
- Upload date:
- Size: 77.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac5d0ae7310dfc33d34ab958fc15f51a8f61bdbd2cf10c9976852848002f5bb9
|
|
| MD5 |
25d3997b919ce63cdeeaa42bf6bf4275
|
|
| BLAKE2b-256 |
53c94701d4344d37cc8a175c647f295474f3dea00362ed304ee7f33c484e4d7a
|
Provenance
The following attestation bundles were made for libefiling-0.2.2.tar.gz:
Publisher:
publish-pypi.yml on hyperion13th144m/libefiling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libefiling-0.2.2.tar.gz -
Subject digest:
ac5d0ae7310dfc33d34ab958fc15f51a8f61bdbd2cf10c9976852848002f5bb9 - Sigstore transparency entry: 1191051870
- Sigstore integration time:
-
Permalink:
hyperion13th144m/libefiling@f98314ea7bfb0f2237a6080a139327f7db0e518c -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/hyperion13th144m
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f98314ea7bfb0f2237a6080a139327f7db0e518c -
Trigger Event:
release
-
Statement type:
File details
Details for the file libefiling-0.2.2-py3-none-any.whl.
File metadata
- Download URL: libefiling-0.2.2-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9371886e7ea3af8aafccd3aec71aebbef7d3678501fd88033bf83bc3efef657
|
|
| MD5 |
da176c90c043a295b57a7488e41693df
|
|
| BLAKE2b-256 |
fab2bee30598b97388de4c2a4b74a370f7058563a3a27107ac47570dd8faebd5
|
Provenance
The following attestation bundles were made for libefiling-0.2.2-py3-none-any.whl:
Publisher:
publish-pypi.yml on hyperion13th144m/libefiling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libefiling-0.2.2-py3-none-any.whl -
Subject digest:
f9371886e7ea3af8aafccd3aec71aebbef7d3678501fd88033bf83bc3efef657 - Sigstore transparency entry: 1191051872
- Sigstore integration time:
-
Permalink:
hyperion13th144m/libefiling@f98314ea7bfb0f2237a6080a139327f7db0e518c -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/hyperion13th144m
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f98314ea7bfb0f2237a6080a139327f7db0e518c -
Trigger Event:
release
-
Statement type: