PyRIDF
Repository: https://github.com/yano404/PyRIDF
RIDFのPython Interface
作っている最中なので仕様変更多め.
Installation
パッケージのビルドには poetry を使う. インストールしていない場合は https://python-poetry.org/docs/#installation にしたがってインストールする.
まずcloneしてくる.
git clone https://github.com/yano404/PyRIDF.git
Buildしてインストールする.
cd PyRIDF
poetry build
pip install dist/pyridf-x.y.z-py3-none-any.whl
使い方
RIDFを読む
import pyridf
r = pyridf.read("/path/to/ridf")
Block Data
Block data は ridf.block
に詰められている.
ridf.block[n].children
で n 番目のblockに格納されている中身にアクセスできる.
>>> r.block[1].children
[<pyridf.element.block_number at 0x7f0720b9b1c0>,
<pyridf.element.event_ts at 0x7f0720b9a4d0>,
<pyridf.element.event_ts at 0x7f0720b9b700>,
<pyridf.element.event_ts at 0x7f0720b9b970>,
<pyridf.element.event_ts at 0x7f0720b9bbe0>,
<pyridf.element.event_ts at 0x7f0720b9be50>,
<pyridf.element.event_ts at 0x7f0720b9ada0>,
<pyridf.element.event_ts at 0x7f0720b9b040>,
<pyridf.element.event_ts at 0x7f0720b9ab00>,
<pyridf.element.event_ts at 0x7f0720b9a6b0>,
<pyridf.element.event_ts at 0x7f07eca92f20>,
<pyridf.element.event_ts at 0x7f0720bd8280>,
<pyridf.element.event_ts at 0x7f0720bd84f0>,
<pyridf.element.event_ts at 0x7f0720bd8760>,
<pyridf.element.event_ts at 0x7f0720bd89d0>,
<pyridf.element.event_ts at 0x7f0720bd8c40>,
<pyridf.element.event_ts at 0x7f0720bd8eb0>,
<pyridf.element.event_ts at 0x7f0720bd9120>,
<pyridf.element.event_ts at 0x7f0720bd9390>,
<pyridf.element.event_ts at 0x7f0720bd9600>,
<pyridf.element.event_ts at 0x7f0720bd9870>,
<pyridf.element.event_ts at 0x7f0720bd9ae0>,
<pyridf.element.event_ts at 0x7f0720bd9d50>,
<pyridf.element.event_ts at 0x7f0720bd9fc0>,
<pyridf.element.event_ts at 0x7f0720bda230>,
<pyridf.element.block_ender at 0x7f0720bda4a0>]
Event Data
Event data は ridf.event
に詰められている.
n番目のEvent に格納されているsegment dataには ridf.event[n].children
でアクセスできる.
>>> r.event[0]
<pyridf.element.event_ts at 0x7f0720b9a4d0>
>>> r.event[0].children
[<pyridf.element.segment at 0x7f0720b9ae60>,
<pyridf.element.segment at 0x7f0720b9b670>,
<pyridf.element.segment at 0x7f0720b9b6d0>,
<pyridf.element.segment at 0x7f0720b9a8f0>,
<pyridf.element.segment at 0x7f0720b9ae30>,
<pyridf.element.segment at 0x7f0720b9a710>,
<pyridf.element.segment at 0x7f0720b9ac20>,
<pyridf.element.segment at 0x7f0720b9abc0>,
<pyridf.element.segment at 0x7f0720b9b610>,
<pyridf.element.segment at 0x7f0720b9b640>,
<pyridf.element.segment at 0x7f0720b9b520>,
<pyridf.element.segment at 0x7f0720b9b6a0>]
RIDFファイルに書き込む
import pyridf
r = pyridf.ridf()
# r に何らかの処理を施す
pyridf.write("/path/to/ridf", r)