注: 以下の翻訳の正確性は検証されていません。AIPを利用して英語版の原文から機械的に翻訳されたものです。
このページでは、Example Restaurant オブジェクトタイプに基づいて、Python OSDK の汎用的なドキュメントを提供します。Developer Console では、オントロジーに固有のドキュメントを生成できます。
このページの例は Python OSDK 2.x を対象としています。1.x からアップグレードする場合は、必須の .object_type アクセサーなど、構文の変更について Python OSDK 移行ガイドをご覧ください。バージョン別のドキュメントは、プラットフォーム内の /workspace/developer-console/ にある Developer Console でも利用できます。
Example Restaurant オブジェクトタイプには、次のプロパティがあります。
| プロパティ | API名 | データ型 |
|---|---|---|
restaurant id(主キー) | restaurantId | 文字列 |
restaurant name(タイトル) | restaurantName | 文字列 |
address | address | 文字列 |
e mail | eMail | 文字列 |
number of reviews | numberOfReviews | Integer |
phone number | phoneNumber | 文字列 |
review summary | reviewSummary | 文字列 |
| セクション | 説明内容 |
|---|---|
| 前提条件 | SDK をインストールして、client を作成します。 |
| 1個のレストランを読み込む | 主キーで1個のオブジェクトを取得します。 |
| オブジェクトの RID にアクセスする | include_rid=True を指定して、読み込んだオブジェクトの RID を読み取ります。 |
| サンプルのレストランをページ単位で読み込む | page_size と page_token を使用してページングします。 |
| サンプルのレストランをすべて読み込む | すべてのオブジェクトを反復処理します。 |
| 取得オプション | プロパティの選択、プロパティ修飾子の適用、およびオブジェクトのメタデータの制御を行います。 |
| 並べ替えた結果を読み込む | order_by、asc、desc を使用して並べ替えます。 |
| ページングの一貫性とスナップショット | ページ間でデータが変更されたときの、読み込みメソッドごとの動作を説明します。 |
| 絞り込む | where を使用してオブジェクトセットを絞り込む方法と、利用可能な9種類の検索フィルターを説明します。 |
| 集計 | 要約統計量の計算方法と、利用可能な3種類の集計関数を説明します。 |
| グループ化の種類 | 集計結果をグループ化します。 |
| シナリオをスコープとするクライアントを使用する | シナリオを作成するか、シナリオにアタッチします。 |
このページのすべての例では、オントロジーにすでに接続されている client 変数と、ExampleRestaurant などの生成されたオブジェクトクラスがあることを前提としています。クライアントの作成方法は、コードの実行場所によって異なります。
Foundry の Python 関数、Code Workspaces のノートブック、またはモデルアダプターでは、ランタイムがホスト名と資格情報を提供するため、コンストラクターに引数は不要です。
Copied!1 2 3from ontology_sdk import FoundryClient client = FoundryClient()
Developer Console のアプリケーションの概要ページに表示される値を使用して SDK をインストールし、各 < > プレースホルダーを実際の値に置き換えます。Python OSDK は Python バージョン3.10から3.14をサポートしています。
Copied!1 2export FOUNDRY_TOKEN=<YOUR-TOKEN-FROM-GETTING-STARTED-PAGE> pip install <YOUR-PACKAGE-NAME> --upgrade --extra-index-url "https://:$FOUNDRY_TOKEN@<INDEX-URL>"
次に、ユーザートークン認証を使用してクライアントを作成します。
Copied!1 2 3 4 5 6import os from ontology_sdk import FoundryClient, UserTokenAuth auth = UserTokenAuth(token=os.environ["FOUNDRY_TOKEN"]) client = FoundryClient(auth=auth, hostname="<YOUR-FOUNDRY-URL>")
証明書のセットアップやトラブルシューティングを含む完全なウォークスルーについては、新しい OSDK Python アプリケーションをセットアップするをご覧ください。ユーザーとしてではなくアプリケーションとして認証するバックエンドサービスについては、Compute Modules でオントロジー SDK を使用するをご覧ください。
このページのほかの例を実行する前に、環境に合わせて作成した client を使用して、正常に動作することを確認します。
Copied!1 2restaurants = client.ontology.objects.ExampleRestaurant.take(1) print(restaurants)
これらの例では、ontology_sdk は Developer Console アプリケーション用に生成されたパッケージ名で、ExampleRestaurant はオブジェクトタイプの1つから生成されたクラスです。両方を実際の値に置き換えてください。パッケージ名は、アプリケーションの概要ページに表示されます。
パラメーター:
string:取得する Example Restaurant オブジェクトの主キーです。クエリの例:
Copied!1result = client.ontology.objects.ExampleRestaurant.get("primaryKey")
API レスポンスの例:
Copied!1 2 3 4 5 6 7 8 9 10 11{ "__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000", "__primaryKey": "Restaurant Id", "eMail": "E Mail", "restaurantId": "Restaurant Id", "address": "Address", "reviewSummary": "Review Summary", "phoneNumber": "Phone Number", "numberOfReviews": 123, "restaurantName": "Restaurant Name" }
デフォルトでは、読み込まれたオブジェクトのアクセス可能な属性に、オブジェクトの RID は含まれません。プログラムからオブジェクトの RID にアクセスするには、読み込みメソッドに include_rid=True を渡します。
Copied!1 2 3# RID にアクセスできる状態で1個のオブジェクトを読み込みます result = client.ontology.objects.ExampleRestaurant.get("primaryKey", include_rid=True) object_rid = result.rid
include_rid=True パラメーターは、ほかの読み込みメソッドでも使用できます。
Copied!1 2 3 4 5 6 7 8# RID にアクセスできる状態で反復処理します for restaurant in client.ontology.objects.ExampleRestaurant.iterate(include_rid=True): print(restaurant.rid) # RID にアクセスできる状態でページ単位で取得します result = client.ontology.objects.ExampleRestaurant.page(page_size=30, include_rid=True) for restaurant in result.data: print(restaurant.rid)
指定したページサイズのオブジェクトのリストを読み込みます。ページトークンが指定されている場合は、そのトークンの後から読み込みます。page_size は1ページのサイズを設定するものであり、オブジェクトの総数の上限ではありません。
ユーザーインターフェースで一度に表示できるオブジェクト数は限られているため、データがサンプルや表示のためだけに必要な場合は、1ページの読み込みが適していることがよくあります。最初にすべてのオブジェクトを読み込むのではなく、表示に収まるページを読み込み、ユーザーのスクロールに合わせて追加で取得します。
このエンドポイントは、オブジェクトタイプの基盤となるオブジェクト同期技術を使用します。Example Restaurant オブジェクトタイプが Object Storage V2 を使用している場合、リクエストの上限はありません。Object Storage V1 (Phonograph) を使用している場合、結果の件数は10,000件に制限されます。10,000個を超える Example Restaurant オブジェクトをリクエストすると、ObjectsExceededLimit エラーが返されます。
パラメーター:
integer(任意):リクエストするページのサイズで、最大10,000です。値を指定しない場合は、リクエストによって最大10,000個の Example Restaurant オブジェクトが読み込まれます。後続のページには、最初のページの pageSize が使用されます。string(任意):指定した場合、最初にリクエストしたページの pageSize 以下のサイズのページをリクエストします。list(任意):読み込むプロパティを、ExampleRestaurant.object_type.<property> 形式の参照で指定します。省略した場合、API はデフォルトのプロパティ選択を使用します。page() 自体はスナップショットをリクエストしませんが、関数の実行に対して設定されたスナップショットは引き続き適用されます。スナップショットが適用されない場合、ページ間の変更によって重複や欠落が発生する可能性があります。
クエリの例:
Copied!1 2 3 4 5 6 7 8 9 10 11 12from ontology_sdk.ontology.objects import ExampleRestaurant result = client.ontology.objects.ExampleRestaurant.page( page_size=30, page_token=None, properties=[ ExampleRestaurant.object_type.restaurant_name, ExampleRestaurant.object_type.address, ], ) page_token = result.next_page_token data = result.data
API レスポンスの例(一部省略):
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14{ "nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000", "data": [ { "__primaryKey": "Restaurant Id", "__apiName": "ExampleRestaurant", // 主キープロパティは、選択されていない場合でも常に返されます。 "restaurantId": "Restaurant Id", "address": "Address", "restaurantName": "Restaurant Name" } // ... ページの残り ] }
iterate() は、一致するすべてのオブジェクトが返されるまで、一貫したスナップショットからページを順次取得するイテレーターを返します。for restaurant in client.ontology.objects.ExampleRestaurant のように、オブジェクトセットを直接反復処理する場合も、同じように動作します。
一定数のオブジェクトをリストとして取得するには、代わりに take(n) を使用します。take(n) は最大 n 個のオブジェクトを返し、残りは通知せずに破棄するため、サンプルや表示用リストなど、一部の結果だけで問題ない場合にのみ使用してください。
すべてのオブジェクトを読み込む前に、次の点を検討してください。
take(n) を使用するか、1ページを読み込みます。properties を渡して、必要なプロパティのみを読み込みます。list(...) でラップするのではなく、オブジェクトが到着するたびにループ内で処理します。このエンドポイントは、オブジェクトタイプの基盤となるオブジェクト同期技術を使用します。Example Restaurant オブジェクトタイプが Object Storage V2 を使用している場合、リクエストの上限はありません。Object Storage V1 (Phonograph) を使用している場合、結果の件数は10,000件に制限されます。10,000個を超える Example Restaurant オブジェクトをリクエストすると、ObjectsExceededLimit エラーが返されます。
クエリの例:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22from ontology_sdk.ontology.objects import ExampleRestaurant # 読み取るプロパティのみを読み込み、オブジェクトが到着するたびに処理します for restaurant in client.ontology.objects.ExampleRestaurant.iterate( properties=[ ExampleRestaurant.object_type.restaurant_name, ExampleRestaurant.object_type.e_mail, ] ): send_newsletter(restaurant.e_mail, restaurant.restaurant_name) # コードですべてのオブジェクトが一度に必要な場合にのみ、リストにまとめます objects = list( client.ontology.objects.ExampleRestaurant.iterate( properties=[ExampleRestaurant.object_type.restaurant_name] ) ) # 最大100個に制限されたオブジェクトのサンプルを取得します sample = client.ontology.objects.ExampleRestaurant.take( 100, properties=[ExampleRestaurant.object_type.restaurant_name] )
API レスポンスの例(一部省略):
Copied!1 2 3 4 5 6 7 8 9 10 11 12{ "data": [ { "__primaryKey": "Restaurant Id", "__apiName": "ExampleRestaurant", // 主キープロパティは、選択されていない場合でも常に返されます。 "restaurantId": "Restaurant Id", "restaurantName": "Restaurant Name" } // ... データの残り ] }
Python OSDK の読み込みメソッドは、返されるプロパティとオブジェクトメタデータを制御するパラメーターを受け取ります。次のテーブルは同期メソッドの一覧です。対応する非同期メソッドも同じパラメーターを受け取ります。
| パラメーター | サポートされるメソッド | 説明 |
|---|---|---|
properties | get(), page(), iterate(), take() | リストに記載された、生成済みのプロパティ参照のみを返します。 |
apply_modifiers | get(), page(), iterate(), take() | 特定のプロパティについて、設定済みのリデューサーによって選択された値など、別の表現で返すようにリクエストします。 |
include_rid | get(), page(), iterate(), take() | 返されるオブジェクトの rid 属性に値を設定します。デフォルト値は False です。 |
load_property_securities | get(), page(), iterate(), take() | 返されるオブジェクトのプロパティレベルのセキュリティメタデータを読み込みます。デフォルト値は False です。 |
load_ontology_defined_derived_properties | get(), page(), iterate(), take() | properties を省略した場合に True に設定すると、オントロジー定義の派生プロパティも返されます。properties を指定した場合は効果がありません。 |
page_size | page() | 各ページの最大オブジェクト数を設定します。 |
page_token | page() | 以前のページイテレーターの next_page_token からページングを再開します。 |
num_items | take() | 返すオブジェクトの最大数を設定します。 |
返されるプロパティを制限するには、生成されたプロパティ参照を properties パラメーターに渡します。properties を省略するか空にすると、OSDK はベクトルプロパティを除く、オブジェクトタイプのネイティブプロパティを返します。オントロジー定義の派生プロパティはデフォルトでは返されず、明示的に選択する必要があります。次の例では、restaurant_id と restaurant_name のみを返します。
Copied!1 2 3 4 5 6 7result = client.ontology.objects.ExampleRestaurant.page( page_size=30, properties=[ ExampleRestaurant.object_type.restaurant_id, ExampleRestaurant.object_type.restaurant_name, ], )
配列プロパティを選択すると、Ontology Manager でプロパティリデューサーが設定されていても、リデューサーを適用していない完全な値が返されます。ネイティブプロパティとオントロジー定義の派生プロパティのどちらにも、同じ動作が適用されます。
プロパティは、後でコードが読み取るかどうかにかかわらず、リクエストの実行時に読み込まれます。大きなテキスト、配列、またはその他のデータ量の多いプロパティを持つオブジェクトタイプでは、不要なプロパティを読み込むと、読み取るプロパティだけを読み込む場合と比べて、処理が大幅に遅くなり、ネットワーク帯域幅の使用量が増えることがあります。コードが読み取るプロパティを properties に渡して、それらのプロパティだけを読み込みます。主キーのプロパティは、選択されていなくても API から返されます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21from ontology_sdk.ontology.objects import ExampleRestaurant # 非推奨:1個のプロパティを読み取るために、サイズが大きい可能性のあるレビューの概要を含め、コードで不要なプロパティを読み込みます names = {r.restaurant_name for r in client.ontology.objects.ExampleRestaurant.iterate()} # 推奨:読み取るプロパティのみを読み込みます names = { r.restaurant_name for r in client.ontology.objects.ExampleRestaurant.iterate( properties=[ExampleRestaurant.object_type.restaurant_name] ) } # properties は take() でも同じように機能します sample = client.ontology.objects.ExampleRestaurant.take( 100, properties=[ ExampleRestaurant.object_type.restaurant_name, ExampleRestaurant.object_type.number_of_reviews, ], )
オントロジー定義の派生プロパティを読み取るには、コードが読み取るほかのすべてのプロパティとともに、そのプロパティを properties に含めます。たとえば、Example Restaurant に、リンクされた Menu Item オブジェクトの数を数える、オントロジー定義の派生プロパティ menu_item_count があるとします。
Copied!1 2 3 4 5 6 7result = client.ontology.objects.ExampleRestaurant.take( 100, properties=[ ExampleRestaurant.object_type.restaurant_name, ExampleRestaurant.object_type.menu_item_count, ], )
オントロジー定義の派生プロパティは、クエリ時にリンクをたどるか、リンクされたオブジェクト全体を集計することで計算されます。明示的に選択する方式のため、後からオブジェクトタイプに派生プロパティが追加されても、既存のリクエストの遅延や計算コストが増えることはありません。
必要なプロパティをまだ列挙できない場合は、properties を省略したリクエストで load_ontology_defined_derived_properties=True を設定します。すると、レスポンスにはネイティブプロパティに加えて、オントロジー定義の派生プロパティが含まれます。
Copied!1 2 3 4result = client.ontology.objects.ExampleRestaurant.take( 100, load_ontology_defined_derived_properties=True, )
load_ontology_defined_derived_properties=True を設定すると、すべてのオントロジー定義の派生プロパティを計算するコストがリクエストごとに加わります。properties を指定した場合は、選択したプロパティのみが返されるため、この設定は効果がありません。
関数がパラメーターとして受け取るオブジェクトは、リクエストではなくプラットフォームによって読み込まれます。オブジェクトパラメーターで読み込まれるプロパティを確認してください。
Python OSDK のプロパティ修飾子は、開発のベータ版段階にあります。開発が進む中で、機能が変更される可能性があります。
サポート対象のプロパティ設定を持つ生成済みオブジェクトタイプには、それぞれ ApplyModifiers クラスが含まれます。このクラスのインスタンスを apply_modifiers に渡します。生成されたクラスは、各プロパティに指定できる修飾子を、そのオントロジー設定でサポートされるものに制限します。
"applyReducers":**リデューサーが設定された配列プロパティについて、配列全体ではなく、選択された配列要素を返します。"extractMainValue":メイン値が設定された構造体プロパティについて、メイン値のフィールドのみを返します。"applyReducersAndExtractMainValue":**両方の機能が設定された構造体配列について、リデューサーで1個の構造体を選択し、そのメイン値のフィールドを返します。properties も渡す場合は、apply_modifiers で指定したすべてのプロパティを含めます。含めないと、OSDK は ValueError を発生させます。
たとえば、Equipment オブジェクトタイプに、最新の日付を選択するリデューサーが設定された、null 許容の Date 配列型の maintenance_history プロパティがあるとします。apply_modifiers を指定せずにこのプロパティを選択すると、配列全体が返されます。
Copied!1 2 3 4 5 6 7 8 9 10 11equipment = client.ontology.objects.Equipment.get( "E-100", properties=[ Equipment.object_type.equipment_id, Equipment.object_type.maintenance_history, ], ) if equipment is not None: # list[date] | None full_maintenance_history = equipment.maintenance_history
リデューサーを適用した表現をリクエストするには、生成された EquipmentApplyModifiers クラスを使用します。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18from ontology_sdk.ontology.objects.equipment import EquipmentApplyModifiers equipment = client.ontology.objects.Equipment.get( "E-100", properties=[ Equipment.object_type.equipment_id, Equipment.object_type.maintenance_history, ], apply_modifiers=EquipmentApplyModifiers( maintenance_history="applyReducers", ), ) if equipment is not None and equipment.modified_properties is not None: # date | None most_recent_maintenance_date = ( equipment.modified_properties.maintenance_history )
修飾子を適用した場合は、modified_properties を通じて変換後の値にアクセスします。通常のプロパティ属性は None になります。この例では、equipment.modified_properties.maintenance_history には配列全体ではなく、リデューサーによって選択された1個の日付が格納されます。修飾子を適用しても、保存されたプロパティデータや派生プロパティのデータは変更されません。完全な値が必要な場合は、修飾子を省略して通常のプロパティ属性を読み取ります。
特定のプロパティの並べ替え方向を指定して、並べ替えた Example Restaurant オブジェクトのリストを読み込みます。API 経由で呼び出す場合は、fields 配列で並べ替え条件を指定します。SDK 経由で呼び出す場合は、複数の order_by 呼び出しを連結できます。文字列の並べ替えでは大文字と小文字が区別され、数字、大文字、小文字の順に並びます。たとえば、Cat は bat より前になります。
パラメーター:
string:並べ替えの基準にするプロパティです。SDK では、ExampleRestaurant.object_type.<property> として参照します。asc | desc:並べ替えの方向で、昇順または降順です。SDK では、プロパティアクセサーの asc() メソッドと desc() メソッドを使用します。クエリの例:
Copied!1 2 3 4 5 6 7 8from ontology_sdk.ontology.objects import ExampleRestaurant ordered_restaurants = ( client.ontology.objects.ExampleRestaurant .where(~ExampleRestaurant.object_type.restaurant_name.is_null()) .order_by(ExampleRestaurant.object_type.restaurant_name.asc()) .iterate(properties=[ExampleRestaurant.object_type.restaurant_name]) )
この例では、~ はその後に続くフィルターを否定するため、~ExampleRestaurant.object_type.restaurant_name.is_null() は restaurant name の値を持つオブジェクトにのみ一致します。フィルターで利用可能なほかのブール演算子については、Not フィルター、And フィルター、Or フィルターを参照してください。
API レスポンスの例(抜粋):
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20{ "nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000", "data": [ { "__primaryKey": "Object A", "__apiName": "ExampleRestaurant", // 主キープロパティは、選択されていない場合でも常に返されます。 "restaurantId": "Object A", "restaurantName": "A" }, { "__primaryKey": "Object B", "__apiName": "ExampleRestaurant", // 主キープロパティは、選択されていない場合でも常に返されます。 "restaurantId": "Object B", "restaurantName": "B" } // ...ページの残り ] }
複数のページにわたってオブジェクトを読み込む場合、リクエスト間でデータが変更される可能性があります。次のテーブルは、各読み込みメソッドが独自のスナップショットを要求するかどうかを示しています。関数実行用に設定されたスナップショットは、読み込みメソッドにかかわらず適用されます。
| メソッド | 独自のスナップショットのリクエスト | ページ間でデータが変更されたときの動作 |
|---|---|---|
iterate()、またはオブジェクトセットの直接の反復処理 | はい | すべてのページに同じ時点のデータが反映されるため、各オブジェクトは必ず1回だけ返されます。スナップショットを維持できない場合、リクエストは失敗します。これらの保証は、ストリーミング入力データソースを持つオブジェクトタイプには適用されません。 |
page() と take() | いいえ | スナップショットが適用されない場合、ページ間の変更によって重複や欠落が発生する可能性があります。 |
このテーブルは同期メソッドについて説明しています。ベータ版の非同期メソッドは、動作が異なる場合があります。たとえば、一部の SDK バージョンでは async_take() はスナップショットから読み取ります。
サービスがページ間の不整合を検出すると、走査が PagingInconsistencyDetected で失敗する場合があります。長時間実行される走査は、スナップショットの期限切れによって失敗する場合もあります。ストリーミングデータソースでは、一貫性のあるスナップショットは保証されません。iterate() では、スナップショットを使用しないように設定することはできません。
頻繁に更新されるオブジェクトタイプの全件走査がスナップショットエラーで失敗する場合は、ワークフローで許容できるトレードオフに応じて、次の方法から選択します。
properties を使用して読み込むプロパティを減らし、フィルターでオブジェクトセットを絞り込むことで、スナップショットの有効期限が切れる前に走査が完了するようにします。iterate() を呼び出す代わりに、page() が返すページを反復処理します。page() は独自のスナップショットを要求しませんが、関数実行用に設定されたスナップショットは引き続き適用されます。スナップショットが適用されていない場合、ページ間の変更によって重複や欠落が生じる可能性があります。次の例では、独自のスナップショットを要求せずにページを順次取得し、主キーがすでに処理済みのオブジェクトをスキップします。
Copied!1 2 3 4 5 6 7 8 9 10 11 12from ontology_sdk.ontology.objects import ExampleRestaurant seen = set() for page in client.ontology.objects.ExampleRestaurant.page( page_size=1000, properties=[ExampleRestaurant.object_type.restaurant_name], ): for restaurant in page: primary_key = restaurant.get_primary_key() if primary_key not in seen: seen.add(primary_key) # restaurant を処理します
スナップショットが適用されていない場合、ページ間の変更によってオブジェクトが欠落する可能性があります。重複排除では、欠落したオブジェクトを復元できません。
Python 関数内で OSDK を使用する場合は、関数自体の一貫性のあるスナップショットの設定も適用されます。OSDK クライアントが関数実行用のスナップショットを保持している場合、そのスナップショットは読み込みメソッドにかかわらず適用されます。
iterate() は独自の走査用のスナップショットを要求します。iterate() によるページングの不整合エラーは防げません。iterate() は関数の設定にかかわらず、独自のスナップショットを要求するためです。リンクの走査には、単一のオブジェクトのインスタンスから開始するか、オブジェクトセットから開始するかによって、2つの形式があります。以下の例では、Example Restaurant に多対一の city リンクと一対多の reviews リンクがあることを前提としています。お使いのオントロジーのリンクのAPI名に置き換えてください。
オブジェクトのインスタンスでは、各リンクは、リンクのAPI名をスネークケースにした名前のメソッドになります。一対一または多対一のリンクは、リンクされたオブジェクト、または None を返します。一対多または多対多のリンクはオブジェクトセットを返すため、すべてのオブジェクトセットメソッドを使用できます。
クエリの例:
Copied!1 2 3 4 5 6 7 8restaurant = client.ontology.objects.ExampleRestaurant.get("primaryKey") # 多対一リンクは、リンクされたオブジェクト、または None を返します。 city = restaurant.city() # 一対多リンクは、オブジェクトセットを返します。 for review in restaurant.reviews().iterate(): ...
オブジェクトセットでは、各リンクに対して search_around_<link_name>() メソッドが生成されます。このメソッドはリンク先のタイプのオブジェクトセットを返すため、走査を連鎖させたり、フィルターや集計と組み合わせたりできます。
クエリの例:
Copied!1reviews = client.ontology.objects.ExampleRestaurant.search_around_reviews()
リンクが実行時にしか判明しない場合、search_around() はリンクのAPI名を文字列として受け取り、対応する型付きメソッドに処理を振り分けます。リンクが判明している場合は、型付きの search_around_<link_name>() メソッドを優先して使用します。search_around() は、指定された名前がそのオブジェクトタイプで有効なリンクでない場合、RuntimeError を発生させます。
クエリの例:
Copied!1linked = client.ontology.objects.ExampleRestaurant.search_around("reviews")
実行できるフィルタリングの種類は、対象のオブジェクトタイプのプロパティのデータ型によって異なります。また、これらのフィルターをブール式で組み合わせて、より複雑なフィルターを作成することもできます。
このエンドポイントは、オブジェクトタイプの基盤となるオブジェクト同期技術を使用します。Example Restaurant オブジェクトタイプが Object Storage V2 を使用している場合、リクエストの上限はありません。Object Storage V1(Phonograph)を使用している場合、結果の上限は10,000件です。10,000個を超える Example Restaurant オブジェクトをリクエストすると、ObjectsExceededLimit エラーが返されます。
パラメーター:
SearchQuery(任意):特定のプロパティで絞り込みます。利用可能な演算は、プロパティのデータ型によって異なります。OrderByQuery(任意):特定のプロパティに基づいて結果を並べ替えます。SDK を使用している場合は、.where 呼び出しに .order_by 呼び出しをチェーンして、同じ結果を得ることができます。integer(任意):リクエストするページのサイズです。最大値は10,000です。値を指定しない場合は、リクエストによって最大10,000個の Example Restaurant オブジェクトが読み込まれます。後続のページでは、最初のページの pageSize が使用されます。SDK を使用している場合は、.where 呼び出しに .page メソッドをチェーンし、page_size キーワード引数を渡します。string(任意):指定した場合、最初にリクエストしたページの pageSize 以下のサイズのページをリクエストします。SDK を使用している場合は、.where 呼び出しに .page メソッドをチェーンし、page_token キーワード引数を渡します。クエリの例:
Copied!1 2 3 4 5 6 7from ontology_sdk.ontology.objects import ExampleRestaurant result = client.ontology.objects.ExampleRestaurant.where( ExampleRestaurant.object_type.restaurant_name.is_null() ).page(page_size=30) page_token = result.next_page_token data = result.data
API レスポンスの例:
Copied!1 2 3 4 5 6 7 8 9 10 11 12{ "nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000", "data": [ { "__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000", "__primaryKey": "Restaurant Id", "restaurantName": null // ... プロパティの残り } // ... ページの残り ] }
SearchQuery)絞り込み対象のプロパティのデータ型に応じて、次のフィルターを使用できます。
文字列プロパティにのみ適用されます。指定された値に含まれる空白区切りの単語のいずれかを、restaurantName が順序を問わず含む Example Restaurant オブジェクトを返します(大文字と小文字は区別しません)。
パラメーター:
string:使用するプロパティの名前です(例:restaurantName)。string:照合対象の空白区切りの単語です。たとえば、foo bar は bar baz に一致しますが、baz qux には一致しません。boolean:検索クエリで近似一致を使用できるようにします。クエリの例:
Copied!1 2 3from ontology_sdk.ontology.objects import ExampleRestaurant example_restaurant_object_set = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.contains_any_term(['foo bar']))
API レスポンスの例:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16{ "nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000", "data": [ { "__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000", "__primaryKey": "Restaurant Id", "restaurantName": "foo bar baz" // ... プロパティの残り }, { "__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000001", "restaurantName": "bar baz" // ... プロパティの残り } ] }
文字列プロパティにのみ適用されます。指定された値に含まれる空白区切りの単語を、restaurantName が順序を問わずすべて含む Example Restaurant オブジェクトを返します(大文字と小文字は区別しません)。
パラメーター:
string:使用するプロパティの名前です(例:restaurantName)。string:照合対象の空白区切りの単語です。たとえば、foo bar は hello foo baz bar に一致しますが、foo qux には一致しません。boolean:検索クエリで近似一致を使用できるようにします。クエリの例:
Copied!1 2 3from ontology_sdk.ontology.objects import ExampleRestaurant example_restaurant_object_set = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.contains_all_terms(['foo bar']))
API レスポンスの例:
Copied!1 2 3 4 5 6 7 8 9 10 11{ "nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000", "data": [ { "__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000", "__primaryKey": "Restaurant Id", "restaurantName": "hello foo baz bar" // ... プロパティの残り } ] }
文字列プロパティにのみ適用されます。restaurantName がすべての語句を指定された順序で互いに隣接する形で含む Example Restaurant オブジェクトを返します(大文字と小文字は区別しません)。
パラメーター:
string:使用するプロパティの名前です(例:restaurantName)。string:照合対象の空白区切りの単語です。たとえば、foo bar は hello foo bar baz に一致しますが、bar foo qux には一致しません。prefix_last_term boolean:最後の語句を単語全体ではなく前方一致で照合するには、True に設定します。デフォルトは False です。クエリの例:
Copied!1 2 3from ontology_sdk.ontology.objects import ExampleRestaurant example_restaurant_object_set = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.contains_all_terms_in_order(['foo'], prefix_last_term=True))
API レスポンスの例:
Copied!1 2 3 4 5 6 7 8 9 10 11{ "nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000", "data": [ { "__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000", "__primaryKey": "Restaurant Id", "restaurantName": "foo bar baz" // ... プロパティの残り } ] }
数値、文字列、DateTime プロパティにのみ適用されます。ExampleRestaurant.object_type.restaurant_name が指定の値より小さい Example Restaurant オブジェクトを返します。
パラメーター:
string:使用するプロパティの名前です(例:restaurantName)。string:restaurant name と比較する値です。比較の種類:
<><=>=クエリの例:
Copied!1 2 3from ontology_sdk.ontology.objects import ExampleRestaurant example_restaurant_object_set = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name < "Restaurant Name")
ブール、DateTime、数値、文字列プロパティにのみ適用されます。restaurantName が指定された値と等しい Example Restaurant オブジェクトを検索します。
パラメーター:
string:使用するプロパティの名前です(例:restaurantName)。string:restaurant name と等しいかどうかを確認する値です。クエリの例:
Copied!1 2 3from ontology_sdk.ontology.objects import ExampleRestaurant example_restaurant_object_set = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name == "Restaurant Name")
API レスポンスの例:
Copied!1 2 3 4 5 6 7 8 9 10 11{ "nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000", "data": [ { "__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000", "__primaryKey": "Restaurant Id", "restaurantName": "Restaurant Name" // ... プロパティの残り } ] }
配列、ブール、DateTime、数値、文字列プロパティにのみ適用されます。restaurantName の値が存在するかどうかに基づいて、Example Restaurant オブジェクトを検索します。
パラメーター:
string:使用するプロパティの名前です(例:restaurantName)。boolean:restaurant name が存在するかどうかです。Python SDK では、is_null() は引数を取りません。プロパティが設定されているオブジェクトを検索するには、~ExampleRestaurant.object_type.restaurant_name.is_null() のように、~ でフィルターを否定します。クエリの例:
Copied!1 2 3from ontology_sdk.ontology.objects import ExampleRestaurant example_restaurant_object_set = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.is_null())
クエリを満たさない Example Restaurant オブジェクトを返します。さらに、ほかのブールフィルター演算と組み合わせることができます。
パラメーター:
SearchQuery:反転する検索クエリです。クエリの例:
Copied!1 2 3from ontology_sdk.ontology.objects import ExampleRestaurant example_restaurant_object_set = client.ontology.objects.ExampleRestaurant.where(~ExampleRestaurant.object_type.restaurant_id.is_null())
すべてのクエリを満たす Example Restaurant オブジェクトを返します。さらに、ほかのブールフィルター演算と組み合わせることができます。
パラメーター:
SearchQuery[]:and で結合する検索クエリです。クエリの例:
Copied!1 2 3 4 5 6from ontology_sdk.ontology.objects import ExampleRestaurant example_restaurant_object_set = client.ontology.objects.ExampleRestaurant.where( ~ExampleRestaurant.object_type.restaurant_id.is_null() & (ExampleRestaurant.object_type.restaurant_id == '<primaryKey>') )
指定されたクエリのいずれかを満たす Example Restaurant オブジェクトを返します。さらに、ほかのブールフィルター演算と組み合わせることができます。
パラメーター:
SearchQuery[]:or で結合する検索クエリです。クエリの例:
Copied!1 2 3 4 5 6from ontology_sdk.ontology.objects import ExampleRestaurant example_restaurant_object_set = client.ontology.objects.ExampleRestaurant.where( ExampleRestaurant.object_type.restaurant_id.is_null() | (ExampleRestaurant.object_type.restaurant_id == '<primaryKey>') )
Example Restaurant オブジェクトに対して集計を実行します。
パラメーター:
Aggregation[](任意):実行する集計関数。SDK では、.where を使用して集計処理にさらに検索を連結できます。GroupBy[](任意):集計結果に対して作成するグループ化。SDK を使用する場合は、.group_by 呼び出しを連結します。SearchQuery(任意):特定のプロパティに対するフィルター。使用できる演算は、プロパティのデータ型によって異なります。クエリの例:
Copied!1 2 3 4 5 6 7 8 9from ontology_sdk.ontology.objects import ExampleRestaurant num_example_restaurant = ( client.ontology.objects.ExampleRestaurant .where(~ExampleRestaurant.object_type.restaurant_name.is_null()) .group_by(ExampleRestaurant.object_type.restaurant_name.exact()) .count() .compute() )
API レスポンスの例:
{
excludedItems: 0,
data: [{
group: {
"restaurantName": "Restaurant Name"
},
metrics: [
{
name: "count",
value: 100
}
]
}]
}
Aggregation)次の集計関数を利用できます。
restaurantName の一意の値の数を近似計算します。
パラメーター:
string:使用するプロパティの名前(たとえば、restaurantName)。string(任意):計算された件数のエイリアス。デフォルトは distinctCount です。クエリの例:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17from ontology_sdk.ontology.objects import ExampleRestaurant num_distinct_restaurant_names = ( client.ontology.objects.ExampleRestaurant .approximate_distinct(ExampleRestaurant.object_type.restaurant_name) .compute() ) num_distinct_restaurant_names = ( # これは前の例と同等ですが、名前として metric_name を # デフォルトの distinctCount の代わりに使用します。 client.ontology.objects.ExampleRestaurant .aggregate( {"metric_name": ExampleRestaurant.object_type.restaurant_name.approximate_distinct()} ) .compute() )
API レスポンスの例:
{
excludedItems: 0,
data: [{
group: {},
metrics: [
{
name: "distinctCount",
value: 100
}
]
}]
}
Example Restaurant オブジェクトの総数を計算します。
パラメーター:
string(任意):計算された件数のエイリアス。デフォルトは count です。クエリの例:
Copied!1 2 3 4 5num_example_restaurant = ( client.ontology.objects.ExampleRestaurant .count() .compute() )
API レスポンスの例:
{
excludedItems: 0,
data: [{
group: {},
metrics: [
{
name: "count",
value: 100
}
]
}]
}
数値型のプロパティにのみ適用されます。Example Restaurant オブジェクトの数値型のプロパティについて、最大値、最小値、合計、または平均を計算します。
パラメーター:
string:使用するプロパティの名前(たとえば、numberOfReviews)。string(任意):計算された値のエイリアス。デフォルトは avg です。集計の種類:
avg()max()min()sum()クエリの例:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17from ontology_sdk.ontology.objects import ExampleRestaurant avg_number_of_reviews = ( client.ontology.objects.ExampleRestaurant .avg(ExampleRestaurant.object_type.number_of_reviews) .compute() ) avg_number_of_reviews = ( # これは前の例と同等ですが、名前として metric_name を # デフォルトの avg の代わりに使用します。 client.ontology.objects.ExampleRestaurant .aggregate( {"metric_name": ExampleRestaurant.object_type.number_of_reviews.avg()} ) .compute() )
API レスポンスの例:
{
excludedItems: 0,
data: [{
group: {},
metrics: [
{
name: "avg",
value: 100
}
]
}]
}
GroupBy)プロパティの値が完全一致する集計結果をグループ化できます。
restaurantName の値が完全一致する Example Restaurant オブジェクトをグループ化します。
パラメーター:
string:使用するプロパティの名前(たとえば、restaurantName)。integer(任意):作成する restaurantName のグループの最大数。SDK を使用する場合は、これを exact メソッドに渡します。クエリの例:
Copied!1 2 3 4 5 6 7 8from ontology_sdk.ontology.objects import ExampleRestaurant num_example_restaurant = ( client.ontology.objects.ExampleRestaurant .group_by(ExampleRestaurant.object_type.restaurant_name.exact()) .count() .compute() )
API レスポンスの例:
{
excludedItems: 0,
data: [{
group: {
"restaurantName": "Restaurant Name"
},
metrics: [
{
name: "count",
value: 100
}
]
}]
}
多対一の関係では、with_properties を使用して、リンクされたオブジェクトの派生プロパティを実体化します。次に、実体化したプロパティでグループ化します。
次の例では、リンクされたオブジェクトのプロパティで Example Restaurant をグループ化し、レビュー数を合計します。linked_object と linked_property を、お使いのオントロジーのリンク名とプロパティ名に置き換えます。
派生プロパティはベータ機能です。with_properties と derived アクセサーを使用するには、ベータ機能で説明されている AllowBetaFeatures コンテキスト内でコードを実行します。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19from ontology_sdk.ontology.objects import ExampleRestaurant restaurants = client.ontology.objects.ExampleRestaurant result = ( restaurants.with_properties( linked_property= ExampleRestaurant.object_type.derived.linked_object().linked_property.get() ) .where( ~ExampleRestaurant.object_type.derived.property("linked_property").is_null() ) .group_by( ExampleRestaurant.object_type.derived.property("linked_property").exact() ) .aggregate({"sum": ExampleRestaurant.object_type.number_of_reviews.sum()}) .compute() .to_dict() )
主なステップ:
with_properties を使用し、derived アクセサーを介してリンクされたオブジェクトからプロパティを取得して追加します。group_by でそのプロパティをグループ化キーとして使用し、集計します。client.ontology.actions を使用してアクションを適用します。このセクションの例では、action_example や parameter_example などのプレースホルダー名を使用しています。お使いのオントロジーのAPI名に置き換えます。
ActionConfig は、アクションを検証するか、実行するか、その両方を行うか、および結果の編集内容をレスポンスに含めるかどうかを制御します。編集内容を利用する前に、response.validation.result を確認してください。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40from foundry_sdk_runtime.types import ( ActionConfig, ActionMode, ReturnEditsMode, SyncApplyActionResponse ) response: SyncApplyActionResponse = client.ontology.actions.action_example( action_config=ActionConfig( mode=ActionMode.VALIDATE_AND_EXECUTE, return_edits=ReturnEditsMode.ALL), parameter_example="value" ) if response.validation.result == "VALID": ... print(response) # 出力例: # SyncApplyActionResponse( # validation=ValidateActionResponse( # result='VALID', # submission_criteria=[], # parameters={} # ), # edits=ObjectEdits( # type='edits', # edits=[ # AddObject( # primary_key='value', # object_type='ExampleObjectType', # type='addObject' # ) # ], # added_object_count=1, # modified_objects_count=0, # deleted_objects_count=0, # added_links_count=0, # deleted_links_count=0 # ) # )
ValidationResult は Literal なので、上記のように文字列 "VALID" と比較します。foundry_sdk.v2.ontologies.models からインポートします。
client.ontology.batch_actions を使用して、1回の呼び出しで複数のパラメーターセットに同じアクションを適用します。バッチ適用は全件成功または全件不適用となります。バッチ内のいずれかのアクションが失敗すると、バッチ内の編集はどれも適用されません。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39from foundry_sdk_runtime.types import BatchActionConfig, BatchApplyActionResponse, ReturnEditsMode from ontology_sdk.ontology.action_types import ActionExampleBatchRequest response: BatchApplyActionResponse = client.ontology.batch_actions.action_example( batch_action_config=BatchActionConfig(return_edits=ReturnEditsMode.ALL), requests=[ ActionExampleBatchRequest( parameter_example="value_1" ), ActionExampleBatchRequest( parameter_example="value_2" ) ] ) print(response) # 出力例: # BatchApplyActionResponse( # edits=BatchActionObjectEdits( # type='edits', # edits=[ # AddObject( # primary_key='value_1', # object_type='ExampleObjectType', # type='addObject' # ), # AddObject( # primary_key='value_2', # object_type='ExampleObjectType', # type='addObject' # ) # ], # added_object_count=2, # modified_objects_count=0, # deleted_objects_count=0, # added_links_count=0, # deleted_links_count=0 # ) # )
client.ontology.queries を使用して、公開済みの関数を実行します。すべての引数はキーワード引数です。戻り値の型は関数の宣言によって異なり、以下の各形式は、生の識別子ではなくインスタンスとして返されます。
Copied!1 2 3 4 5result: Object = client.ontology.queries.query_object_output(object_id = 1) print(result) # 出力例: # Object(id = 1)
Copied!1 2 3 4 5result: ObjectSet = client.ontology.queries.query_object_set_output(object_id = 1) print(result) # 出力例: # ObjectSet(object_set_definition=...)
Copied!1 2 3 4 5result: Attachment = client.ontology.queries.query_attachment_output(object_id = 1) print(result) # 出力例: # Attachment(rid="ri.attachments.main.attachment.2c1432f8-0378-45f2-8280-55d858cb71fc")
Copied!1 2 3 4 5 6 7 8 9 10result: QueryTwoDimensionalAggregation = client.ontology.queries.query_two_dimensional_output() print(result) # 出力例: # QueryTwoDimensionalAggregation( # groups=[ # QueryAggregation(key='1', value=2.0), # QueryAggregation(key='2', value=3.0) # ] # )
内側のバケットは、両方の階層で groups キーの下に格納されます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22result: QueryThreeDimensionalAggregation = client.ontology.queries.query_three_dimensional_output() print(result) # 出力例: # QueryThreeDimensionalAggregation( # groups=[ # NestedQueryAggregation( # key='1', # groups=[ # QueryAggregation(key='ABC', value=2.0), # QueryAggregation(key='DEF', value=4.0) # ] # ), # NestedQueryAggregation( # key='2', # groups=[ # QueryAggregation(key='GHI', value=1.0), # QueryAggregation(key='JKL', value=1.0) # ] # ) # ] # )
Copied!1 2 3 4 5 6 7 8result: dict[Object, int] = client.ontology.queries.query_map_output(object_id = 1) print(result) # 出力例: # { # Object(id=1): 1, # Object(id=2): 3 # }
client.ontology.attachments を使用して、ファイルを添付ファイルとしてアップロードします。返される Attachment には、ファイルのメタデータを取得する get_metadata() と、内容を読み取る read() が用意されています。
アップロードから1時間以内に、適用されたアクションによってオブジェクトのプロパティに書き込まれなかった添付ファイルは、その内容とともに削除されます。添付ファイルを保持するには、返された RID を、添付ファイルプロパティに書き込むアクションに渡します。添付ファイルがオブジェクトに書き込まれるまでは、アップロードしたユーザーのみが読み取れます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21result: Attachment = client.ontology.attachments.upload( file_path="file.json", attachment_name="myFile" ) print(result) # Example output: # Attachment(rid=ri.attachments.main.attachment.00000000-0000-0000-0000-000000000000) print(result.get_metadata()) # Example output: # AttachmentMetadata( # rid='ri.attachments.main.attachment.00000000-0000-0000-0000-000000000000', # filename='myFile', # size_bytes=20, # media_type='*/*', # type='single' # ) print(result.read().getvalue()) # Example output: # b'My example file.\n'
マーキングとベクトルのプロパティはベータ機能です。ベータ機能で説明されている AllowBetaFeatures コンテキスト内で読み取ります。メディアプロパティは、以下に示すように直接読み取ります。
マーキングは、リソースへのアクセスを、適用されたすべてのマーキング基準を満たすユーザーに制限する強制的なセキュリティ制御を表す文字列です。
Copied!1 2 3 4 5 6 7 8 9 10 11 12from foundry_sdk_runtime import AllowBetaFeatures from foundry_sdk_runtime.markings import Marking my_object_set = client.ontology.objects.Object with AllowBetaFeatures(): my_object = my_object_set.get(1) print(my_object.marking_property) # 出力例: # Marking("MyMarking")
メディアプロパティからは、内容、メタデータ、および Media Reference を取得できます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37from foundry_sdk_runtime.media import Media my_object_set = client.ontology.objects.Object my_object = my_object_set.get(1) print(my_object.media_property) # 出力例: # Media("media_property") print(my_object.media_property.get_media_content()) # 出力例: # <_io.BytesIO object at 0x106ed32c0> print(my_object.media_property.get_media_metadata()) # 出力例: # MediaMetadata( # path='my_file.png' # size_bytes=1408 # media_type='image/png' # ) print(my_object.media_property.get_media_reference()) # 出力例: # MediaReference( # mime_type='image/png' # reference=MediaSetViewItemWrapper( # media_set_view_item=MediaSetViewItem( # media_set_rid='ri.mio.main.media-set.00000000-0000-0000-0000-000000000000', # media_set_view_rid='ri.mio.main.view.00000000-0000-0000-0000-000000000000', # media_item_rid='ri.mio.main.media-item.00000000-0000-0000-0000-000000000000', # token=None # ), # type='mediaSetViewItem' # ) # )
ベクトルプロパティは Float のリストで、最近傍フィルタリングに使用できます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16from foundry_sdk_runtime import AllowBetaFeatures from foundry_sdk_runtime.vectors import Vector from ontology_sdk.ontology.objects import Object my_object_set = client.ontology.objects.Object with AllowBetaFeatures(): my_object = my_object_set.get( 1, properties=[Object.object_type.vector_property] ) print(my_object.vector_property) # 出力例: # Vector([0.014408838003873825, ..., -0.012173213064670563])
オントロジーのシナリオサポートは、開発の試験的段階にあり、お使いのエンロールメントでは利用できない場合があります。開発が進む中で機能が変更される場合があります。
OSDK は、オントロジーのシナリオの作成や操作にも使用できます。シナリオを使用すると、メインのオントロジーを変更せずに What-if 分析を作成できます。シナリオスコープのクライアントを作成するか、RID を使用して既存のシナリオにアタッチします。Foundry は、このクライアントからの呼び出しを、シナリオの分離されたサンドボックスに対して評価します。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13from foundry_sdk_runtime import AllowBetaFeatures from osdk import ScenarioClient with AllowBetaFeatures(): # 新しいシナリオを作成します。これによりプラットフォームが呼び出され、シナリオが発行されます。 scenario_client = ScenarioClient.create(client) # または、RID を使用して既存のシナリオにアタッチします。 scenario_client = ScenarioClient( client, scenario_rid="ri.actions..scenario.0000-..." ) result = scenario_client.ontology.objects.ExampleRestaurant.get("primaryKey")
シナリオスコープのクライアントの追加機能やバージョン要件については、OSDK でシナリオを使用するを参照してください。