annofabapi.parser module#
- class annofabapi.parser.FullAnnotationDirParser(json_file_path: Path)[source]#
Fullアノテーションzipを展開した、ティレクトリのParser
- Parameters:
json_file_path – パースするJSONファイルのパス
Examples
JSONファイルをパースする:
p = FullAnnotationDirParser(Path("task_id/input_data_id.json")) annotation = p.parse()
- property input_data_id: str#
JSONファイルから決まる、input_data_id
- property json_file_path: str#
パースするJSONファイルのパス。
- open_outer_file(data_uri: str)[source]#
外部ファイル(塗りつぶし画像など)を開き、対応するファイルオブジェクトを返す。 JSONファイルと同階層にある、”JSONファイルの拡張子を除いた名前”のディレクトリ配下を探します。
- Parameters:
data_uri – 外部ファイルのパス
- Returns:
外部ファイルのファイルオブジェクト
- Raises:
AnnotationOuterFileNotFoundError – 外部ファイルが存在しないときに、例外を発生します。
- parse(convert_detail_data_func: Callable[[Dict[str, Any]], Any] | None = None) FullAnnotation #
JSONファイルをパースする
- Parameters:
convert_detail_data_func – FullAnnotationDetailクラスのdataプロパティを変換する関数を指定します。 dictからdataclassに変換する際に使います。
- Returns:
FullAnnotationインスタンス
- property task_id: str#
JSONファイルの親ディレクトリ名から決まる task_id
- class annofabapi.parser.FullAnnotationParser(json_file_path: str)[source]#
Full Annotationのparser
以下のフォルダ構成であることを期待します。:
├── {task_id}/ │ ├── {input_data_id}.json │ ├── {input_data_id}/ │ │ ├── {annotation_id}
- Parameters:
json_file_path – パースするJSONファイルのパス。
- property input_data_id: str#
JSONファイルから決まる、input_data_id
- property json_file_path: str#
パースするJSONファイルのパス。
- abstract open_outer_file(data_uri: str)[source]#
外部ファイル(塗りつぶし画像など)を開き、対応するファイルオブジェクトを返す。 JSONファイルと同階層にある、”JSONファイルの拡張子を除いた名前”のディレクトリ配下を探します。
- Parameters:
data_uri – 外部ファイルのパス
- Returns:
外部ファイルのファイルオブジェクト
- Raises:
AnnotationOuterFileNotFoundError – 外部ファイルが存在しないときに、例外を発生します。
- parse(convert_detail_data_func: Callable[[Dict[str, Any]], Any] | None = None) FullAnnotation [source]#
JSONファイルをパースする
- Parameters:
convert_detail_data_func – FullAnnotationDetailクラスのdataプロパティを変換する関数を指定します。 dictからdataclassに変換する際に使います。
- Returns:
FullAnnotationインスタンス
- property task_id: str#
JSONファイルの親ディレクトリ名から決まる task_id
- class annofabapi.parser.FullAnnotationZipParser(zip_file: ZipFile, json_file_path: str)[source]#
AnnotationのzipファイルのParser
- Parameters:
zip_file – ZipFileオブジェクト。
json_file_path – パースするJSONファイルのパス。
Examples
JSONファイルをパースする:
with zipfile.ZipFile('annotation.zip', 'r') as zip_file: p = FullAnnotationZipParser(zip_file, "task_id/input_data_id.json") annotation = p.parse()
- property input_data_id: str#
JSONファイルから決まる、input_data_id
- property json_file_path: str#
パースするJSONファイルのパス。
- open_outer_file(data_uri: str)[source]#
外部ファイル(塗りつぶし画像など)を開き、対応するファイルオブジェクトを返す。 JSONファイルと同階層にある、”JSONファイルの拡張子を除いた名前”のディレクトリ配下を探します。
- Parameters:
data_uri – 外部ファイルのパス
- Returns:
外部ファイルのファイルオブジェクト
- Raises:
AnnotationOuterFileNotFoundError – 外部ファイルが存在しないときに、例外を発生します。
- parse(convert_detail_data_func: Callable[[Dict[str, Any]], Any] | None = None) FullAnnotation #
JSONファイルをパースする
- Parameters:
convert_detail_data_func – FullAnnotationDetailクラスのdataプロパティを変換する関数を指定します。 dictからdataclassに変換する際に使います。
- Returns:
FullAnnotationインスタンス
- property task_id: str#
JSONファイルの親ディレクトリ名から決まる task_id
- class annofabapi.parser.SimpleAnnotationDirParser(json_file_path: Path)[source]#
Simpleアノテーションzipを展開した、ティレクトリのParser
- Parameters:
json_file_path – パースするJSONファイルのパス
Examples
JSONファイルをパースする:
p = SimpleAnnotationDirParser(Path("annotation/task_id/input_data_id.json")) annotation = p.parse()
- property input_data_id: str#
JSONファイルから決まるinput_data_id.
- property json_file_path: str#
パースするJSONファイルのパス。
- open_outer_file(data_uri: str)[source]#
外部ファイル(塗りつぶし画像など)を開き、対応するファイルオブジェクトを返す。 JSONファイルと同階層にある、”JSONファイルの拡張子を除いた名前”のディレクトリ配下を探します。
- Parameters:
data_uri – 外部ファイルのパス
- Returns:
外部ファイルのファイルオブジェクト
- Raises:
AnnotationOuterFileNotFoundError – 外部ファイルが存在しないときに、例外を発生します。
- parse(convert_detail_data_func: Callable[[Dict[str, Any]], Any] | None = None) SimpleAnnotation #
JSONファイルをパースする
- Parameters:
convert_detail_data_func – SimpleAnnotationDetailクラスのdataプロパティを変換する関数を指定します。 dictからdataclassに変換する際に使います。
- Returns:
SimpleAnnotationインスタンス
- property task_id: str#
JSONファイルの親ディレクトリ名から決まる task_id
- class annofabapi.parser.SimpleAnnotationDirParserByTask(task_dir_path: Path)[source]#
Simple Annotation zipを展開したディレクトリのparserをタスクごとにまとめたもの。
- Parameters:
task_id – Simple Annotation zipのzipfileオブジェクト
task_id – タスクID
json_path_list – タスク配下のJSONパスのリスト。パスにはtask_idを含む。
Examples
JSONファイルをパースする:
with zipfile.ZipFile("simple-annotation.zip", "r") as zip_file: p = SimpleAnnotationZipParserByTask(zip_file, "task1", ["task1/input1.json","task1/input2.json"])
- get_parser(json_file_path: str) SimpleAnnotationParser [source]#
JSONファイルパスから、Simple Annotation parserを取得する。
- Parameters:
json_file_path – パースするJSONファイルのパス。
json_file_path_list
に含まれる値を指定すること。- Returns:
Simple Annotation parser
- Raises:
ValueError –
json_file_path
の値がjson_file_path_list
に含まれていないとき
- property json_file_path_list: List[str]#
パースするJSONファイルパスのリスト
- class annofabapi.parser.SimpleAnnotationParser(json_file_path: str)[source]#
Simple Annotationのparser
以下のフォルダ構成であることを期待します。:
├── {task_id}/ │ ├── {input_data_id}.json │ ├── {input_data_id}/ │ │ ├── {annotation_id}
- Parameters:
json_file_path – パースするJSONファイルのパス。
- property input_data_id: str#
JSONファイルから決まるinput_data_id.
- property json_file_path: str#
パースするJSONファイルのパス。
- abstract open_outer_file(data_uri: str)[source]#
外部ファイル(塗りつぶし画像など)を開き、対応するファイルオブジェクトを返す。 JSONファイルと同階層にある、”JSONファイルの拡張子を除いた名前”のディレクトリ配下を探します。
- Parameters:
data_uri – 外部ファイルのパス
- Returns:
外部ファイルのファイルオブジェクト
- Raises:
AnnotationOuterFileNotFoundError – 外部ファイルが存在しないときに、例外を発生します。
- parse(convert_detail_data_func: Callable[[Dict[str, Any]], Any] | None = None) SimpleAnnotation [source]#
JSONファイルをパースする
- Parameters:
convert_detail_data_func – SimpleAnnotationDetailクラスのdataプロパティを変換する関数を指定します。 dictからdataclassに変換する際に使います。
- Returns:
SimpleAnnotationインスタンス
- property task_id: str#
JSONファイルの親ディレクトリ名から決まる task_id
- class annofabapi.parser.SimpleAnnotationParserByTask(task_id: str)[source]#
Simple Annotationのparserをタスクごとにまとめたもの。
- Parameters:
task_id – タスクID
- abstract get_parser(json_file_path: str) SimpleAnnotationParser [source]#
JSONファイルパスから、Simple Annotation parserを取得する。
- Parameters:
json_file_path – パースするJSONファイルのパス。
json_file_path_list
に含まれる値を指定すること。- Returns:
Simple Annotation parser
- Raises:
ValueError –
json_file_path
の値がjson_file_path_list
に含まれていないとき
- abstract property json_file_path_list: List[str]#
パースするJSONファイルパスのリスト
- class annofabapi.parser.SimpleAnnotationZipParser(zip_file: ZipFile, json_file_path: str)[source]#
Simple AnnotationのzipファイルのParser
- Parameters:
zip_file – ZipFileオブジェクト。
json_file_path – パースするJSONファイルのパス。
Examples
JSONファイルをパースする:
with zipfile.ZipFile('annotation.zip', 'r') as zip_file: p = SimpleAnnotationZipParser(zip_file, "task_id/input_data_id.json") annotation = p.parse()
- property input_data_id: str#
JSONファイルから決まるinput_data_id.
- property json_file_path: str#
パースするJSONファイルのパス。
- open_outer_file(data_uri: str)[source]#
外部ファイル(塗りつぶし画像など)を開き、対応するファイルオブジェクトを返す。 JSONファイルと同階層にある、”JSONファイルの拡張子を除いた名前”のディレクトリ配下を探します。
- Parameters:
data_uri – 外部ファイルのパス
- Returns:
外部ファイルのファイルオブジェクト
- Raises:
AnnotationOuterFileNotFoundError – 外部ファイルが存在しないときに、例外を発生します。
- parse(convert_detail_data_func: Callable[[Dict[str, Any]], Any] | None = None) SimpleAnnotation #
JSONファイルをパースする
- Parameters:
convert_detail_data_func – SimpleAnnotationDetailクラスのdataプロパティを変換する関数を指定します。 dictからdataclassに変換する際に使います。
- Returns:
SimpleAnnotationインスタンス
- property task_id: str#
JSONファイルの親ディレクトリ名から決まる task_id
- class annofabapi.parser.SimpleAnnotationZipParserByTask(zip_file: ZipFile, task_id: str, json_path_list: List[str] | None = None)[source]#
Simple Annotation zipのparserをタスクごとにまとめたもの。
- Parameters:
zip_file – Simple Annotation zipのzipfileオブジェクト
task_id – タスクID
json_path_list – パースするJSONパスのリスト。 Noneの場合は、
zipfile.ZipFile.infolist()
関数を呼び出して、JSONパスのリストを生成します。
Examples
JSONファイルをパースする:
with zipfile.ZipFile("simple-annotation.zip", "r") as zip_file: p = SimpleAnnotationZipParserByTask(zip_file, "task1")
- get_parser(json_file_path: str) SimpleAnnotationParser [source]#
JSONファイルパスから、Simple Annotation parserを取得する。
- Parameters:
json_file_path – パースするJSONファイルのパス。
json_file_path_list
に含まれる値を指定すること。- Returns:
Simple Annotation parser
- Raises:
ValueError –
json_file_path
の値がjson_file_path_list
に含まれていないとき
- property json_file_path_list: List[str]#
パースするJSONファイルパスのリスト
- annofabapi.parser.lazy_parse_full_annotation_dir(annotation_dir_path: Path) Iterator[SimpleAnnotationParser] [source]#
Fullアノテーションzipを展開したディレクトリ内を探索し、各annotationをparse可能なオブジェクトの列を返します。
- Parameters:
annotation_dir_path – annofabからダウンロードしたsimple annotationのzipファイルを展開したディレクトリ
- Yields:
annotationの遅延Parseが可能なインスタンス列。
- annofabapi.parser.lazy_parse_full_annotation_zip(zip_file_path: Path) Iterator[FullAnnotationParser] [source]#
引数のFullアノテーションzipファイル内を探索し、各annotationをparse可能なオブジェクトの列を返します。
大量のファイルを含むzipファイルを展開せず、task_idなどを確認して最小限のデータのみをparseすることを目的としたユーティリティです。
- Parameters:
zip_file_path – annofabからダウンロードしたsimple annotationのzipファイルへのパス
- Yields:
annotationの遅延Parseが可能なインスタンス列。 順番は(多分)zipファイル内のエントリー順です
- annofabapi.parser.lazy_parse_simple_annotation_dir(annotation_dir_path: Path) Iterator[SimpleAnnotationParser] [source]#
Simpleアノテーションzipを展開したディレクトリ内を探索し、各annotationをparse可能なオブジェクトの列を返します。
- Parameters:
annotation_dir_path – annofabからダウンロードしたsimple annotationのzipファイルを展開したディレクトリ
- Yields:
annotationの遅延Parseが可能なインスタンス列。
- annofabapi.parser.lazy_parse_simple_annotation_dir_by_task(annotation_dir_path: Path) Iterator[SimpleAnnotationParserByTask] [source]#
Simpleアノテーションzipを展開したディレクトリ内を探索し、タスクごとに各annotationをparse可能なオブジェクトの列を返します。
- Parameters:
annotation_dir_path – annofabからダウンロードしたsimple annotationのzipファイルを展開したディレクトリ
- Yields:
対象タスク内の、annotationの遅延Parseが可能なインスタンス列
- annofabapi.parser.lazy_parse_simple_annotation_zip(zip_file_path: Path) Iterator[SimpleAnnotationParser] [source]#
Simpleアノテーションzipファイル内を探索し、各annotationをparse可能なオブジェクトの列を返します。
- Parameters:
zip_file_path – annofabからダウンロードしたsimple annotationのzipファイルへのパス
- Yields:
annotationの遅延Parseが可能なインスタンス列。 順番は(多分)zipファイル内のエントリー順です
- annofabapi.parser.lazy_parse_simple_annotation_zip_by_task(zip_file_path: Path) Iterator[SimpleAnnotationParserByTask] [source]#
Simpleアノテーションzipファイル内を探索し、タスクごとに各annotationをparse可能なオブジェクトの列を返します。
- Parameters:
zip_file_path – annofabからダウンロードしたsimple annotationのzipファイルへのパス
- Yields:
対象タスク内の、annotationの遅延Parseが可能なインスタンス列