変換モジュール
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
|
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_resultがdictでない場合(必要に応じて、文字列から読み込んだ後にチェックが行われます)。
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 |
dictCSV 形式に変換する辞書。 |
property_header |
strプロパティ列のヘッダー。
|
value_header |
str値列のヘッダー。
|
戻り値
CSV 形式の文字列のリスト。
戻り値の型
list
TIPCommon.transformation.get_unicode
TIPCommon.transformation.get_unicode(value)
値の Unicode を取得します。
| パラメータ | |
|---|---|
value |
AnyUnicode に変換する値。 |
戻り値
値の 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
|
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
文字列の分割に使用する区切り文字。 デフォルトは、 |
only_unique |
Optional
デフォルトは、 |
戻り値
値のリスト。
戻り値の型
list
さらにサポートが必要な場合 コミュニティ メンバーや Google SecOps のプロフェッショナルから回答を得ることができます。