変換モジュール

TIPCommon.transformation.add_prefix_to_dict

TIPCommon.transformation.add_prefix_to_dict(given_dict: dict, prefix: str) → dict

指定された辞書のキーに接頭辞を追加します。

パラメータ

パラメータ
given_dict dict

接頭辞を追加する辞書。

prefix str

辞書キーに適用される接頭辞。

戻り値

キーに接頭辞が追加された辞書。

戻り値の型

dict

TIPCommon.transformation.add_prefix_to_dict_keys

TIPCommon.transformation.add_prefix_to_dict_keys(target_dict: dict, prefix: str) → dict

指定された辞書のキーに接頭辞を追加します。

パラメータ

パラメータ
target_dict dict

接頭辞を追加する辞書。

prefix str

辞書キーに適用される接頭辞。

戻り値

キーに接頭辞が追加された辞書。

戻り値の型

dict

TIPCommon.transformation.adjust_to_csv

TIPCommon.transformation.adjust_to_csv(value)

CSV に含めるのに適した値に調整します。

パラメータ
value Any

調整する値。

戻り値

調整後の値。

戻り値の型

str

TIPCommon.transformation.construct_csv

TIPCommon.transformation.construct_csv(list_of_dicts)

辞書のリストから CSV を構築します。

パラメータ
list_of_dicts list[dict]

CSV に追加する辞書のリスト。

戻り値

CSV 形式のリスト。

戻り値の型

list[str]

TIPCommon.transformation.convert_comma_separated_to_list

TIPCommon.transformation.convert_comma_separated_to_list(comma_separated, delimiter=',')

カンマ区切りの文字列を値のリストに変換します。

パラメータ
delimiter 文字列を解析する区切り文字。
デフォルトは ',' です。
comma_separated str

変換するカンマ区切りの文字列。

戻り値

値のリスト。

戻り値の型

list

TIPCommon.transformation.convert_dict_to_json_result_dict

TIPCommon.transformation.convert_dict_to_json_result_dict(json_result, title_key='Entity', results_key='EntityResult')

key, value JSON の結果を JSON 結果オブジェクト リストに変換し、エンティティ JSON 結果オブジェクトを設定された形式に編成します。

dict が JSON 結果に変換される例は次のとおりです。

{k1: v1, k2:v2, ...} =>
[
   {
       title_key: k1,
       result_key: v1
   },
   {
       title_key: k2,
       result_key: v1
   }
   ...
]
パラメータ
json_result dict[str, Any] | str

key, value JSON の結果。

title_key str

各キーの名前の基になるキー。

result_key str

各値の名前の基になるキー。

エンティティ結果の JSON 形式のデフォルトの例(title_key='Entity'results_key='EntityResult')は次のとおりです。

[
   {
       'Entity': 'key1 in json_result',
       'EntityResult: {
           json_result['key1']
       }
   },
   {
       'Entity': 'key2 in json_result',
       'EntityResult: {
           json_result['key2']
       }
   }
]

戻り値

(list[dict[str, Any]]) エンティティ JSON 結果オブジェクトのリスト

発生

  • InternalJSONDecoderError - json_result が文字列であり、json.loads() を使用して辞書に解析できない場合。
  • ValueError - json_resultdict でない場合(必要に応じて、文字列から読み込んだ後にチェックが行われます)。

TIPCommon.transformation.convert_list_to_comma_string

TIPCommon.transformation.convert_list_to_comma_string(values_list, delimiter=',')

値のリストをカンマ区切りの文字列に変換します。

パラメータ
delimiter 文字列で使用する区切り文字。
デフォルトは ',' です。
values_list list

変換する値のリスト。

戻り値

カンマ区切りの文字列。

戻り値の型

str

TIPCommon.transformation.dict_to_flat

TIPCommon.transformation.dict_to_flat(target_dict)

ネストされたディクショナリを受け取り、フラットなディクショナリとして返します。

パラメータ
target_dict dict

フラット化する辞書。

戻り値

フラット化された辞書。

戻り値の型

dict

TIPCommon.transformation.flat_dict_to_csv

TIPCommon.transformation.flat_dict_to_csv(flat_dict, property_header='Property', value_header='Value')

フラットな辞書を CSV 形式の文字列のリストに変換します。

property_header 引数と value_header 引数は、CSV ヘッダーをカスタマイズするために使用されます。

パラメータ
flat_dict dict

CSV 形式に変換する辞書。

property_header str

プロパティ列のヘッダー。
デフォルトは [プロパティ] です。

value_header str

値列のヘッダー。
デフォルトは Value です。

戻り値

CSV 形式の文字列のリスト。

戻り値の型

list

TIPCommon.transformation.get_unicode

TIPCommon.transformation.get_unicode(value)

値の Unicode を取得します。

パラメータ
value Any

Unicode に変換する値。

戻り値

値の Unicode 表現。

戻り値の型

unicode (unicode)

TIPCommon.transformation.removeprefix

TIPCommon.transformation.removeprefix(string: str, prefix: str) → str

Python 3.9 以降に存在する str.removeprefix() の自己実装。

文字列が接頭辞文字列で始まる場合、メソッドは string[len(prefix):] を返します。それ以外の場合は、元の文字列のコピーを返します。

パラメータ
string str

プレフィックスを削除する文字列。

prefix str

文字列から削除する接頭辞。

戻り値

結果の文字列。

TIPCommon.transformation.removesuffix

TIPCommon.transformation.removesuffix(string: str, suffix: str) → str

Python 3.9 以降に存在する str.removesuffix() の自己実装。

文字列が接尾辞文字列で終わる場合、メソッドは string[:-len(prefix)] を返します。それ以外の場合は、元の文字列のコピーを返します。

パラメータ
string str

接尾辞を削除する文字列。

suffix str

文字列から削除する接尾辞。

戻り値

結果の文字列。

TIPCommon.transformation.rename_dict_key

TIPCommon.transformation.rename_dict_key(a_dict: dict, current_key: Hashable,new_key: Hashable) → None

ディクショナリ内のキーの名前を変更します。

パラメータ
a_dict dict

キーの名前を変更する辞書。

current_key Hashable

a_dict で名前を変更するキー。

new_key Hashable

名前が変更されたキー。

TIPCommon.transformation.string_to_multi_value

TIPCommon.transformation.string_to_multi_value(string_value, delimiter=',', only_unique=False)

値のカンマ区切りリストを含む文字列を値のリストに変換します。

パラメータ
string_value str

変換する文字列。

delimiter Optional

str

文字列の分割に使用する区切り文字。

デフォルトは、',' です。

only_unique Optional

bool

True に設定すると、パラメータには返されたリスト内の一意の値のみが含まれます。

デフォルトは、False です。

戻り値

値のリスト。

戻り値の型

list

さらにサポートが必要な場合 コミュニティ メンバーや Google SecOps のプロフェッショナルから回答を得ることができます。