Skip to content

構造化ディレクトリパスの取得

ディレクトリとカスタム構造化処理の制約

ユーザー自身が、カスタム構造化処理を定義する際が、RdeInputDirPaths, RdeOutputResourcePathを引数で受け取れり可能な関数を定義しなければなりません。

1
2
3
def dataset(srcpaths: RdeInputDirPaths, resource_paths: RdeOutputResourcePath):
    # この関数内でユーザ自身が定義したクラスや関数を呼び出す
    ...

Reference

RdeInputDirPathsは、入力で扱われるディレクトリパスやファイルパス群を格納してます。ディレクトリパスは、pathlib.Pathオブジェクトで格納されています。

1
2
3
4
5
@dataclass
class RdeInputDirPaths:
    inputdata: Path
    invoice: Path
    tasksupport: Path

関数内ディレクトリパスにアクセスする場合、以下の定義でディレクトリパスを取得できます。

1
2
3
4
def dataset(srcpaths: RdeInputDirPaths, resource_paths: RdeOutputResourcePath):
    inputdata_dir = srcpaths.inputdata
    invoice_dir = srcpaths.invoice
    tasksupport = srcpaths.tasksupport

RdeOutputResourcePathでは、出力で扱われるディレクトリパス群を格納しています。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
@dataclass
class RdeOutputResourcePath:
    raw: Path
    rawfiles: tuple[Path, ...]
    struct: Path
    main_image: Path
    other_image: Path
    meta: Path
    thumbnail: Path
    logs: Path
    invoice: Path
    invoice_schema_json: Path
    invoice_org: Path
    temp: Path | None = None
    invoice_patch: Path | None = None
    attachment: Path | None = None
    nonshared_raw: Path | None = None

関数内ディレクトリパスにアクセスする場合、以下の定義でディレクトリパスを取得できます。

1
2
3
4
5
def dataset(srcpaths: RdeInputDirPaths, resource_paths: RdeOutputResourcePath):
    rawfiles = resource_paths.rawfiles
    raw_dir = resource_paths.raw
    struct_dir = resource_paths.struct
    main_image_dir = resource_paths.main_image