注: 以下の翻訳の正確性は検証されていません。AIPを利用して英語版の原文から機械的に翻訳されたものです。
Functions を使用すると、1個以上のオブジェクトを起点として、結果のグラフを返す複雑な関連検索関数を記述できます。これらの関数は、関連検索ツールバーメニュー、右クリックメニュー、または URL パラメーターを使用してグラフを作成するときに実行できます。各関数には、オントロジーのオブジェクトタイプまたはオントロジーのオブジェクトのリストを受け取る引数がちょうど1個必要です。また、以下で詳しく説明するように、関数の戻り値の型は IGraphSearchAroundResultV1 である必要があります。

ツールバーまたは右クリックメニューから使用する場合、関数には Integer、Double、Float、string、boolean、Timestamp、Date 型の引数を追加できます。これらの関連検索を実行すると、ユーザーがそれらのパラメーターを入力するためのフォームが生成されます。
関連検索関数は、TypeScript 関数リポジトリに記述します。詳細については、Functions のドキュメントを参照してください。
関連検索関数では、戻り値の型として IGraphSearchAroundResultV1 または Promise<IGraphSearchAroundResultV1> を宣言する必要があります。Vertex は戻り値の型の名前と構造を使用して関連検索関数を見つけるため、次のとおりに正確に宣言する必要があります。
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 25export interface IGraphSearchAroundResultV1 { directEdges?: IGraphSearchAroundResultDirectEdgeV1[]; intermediateEdges?: IGraphSearchAroundResultIntermediateEdgeV1[]; orphanObjectRids?: string[]; objectRidsToGroup?: string[][]; layout?: string; } export interface IGraphSearchAroundResultDirectEdgeV1 { sourceObjectRid: string; targetObjectRid: string; linkTypeRid?: string; label?: string; direction?: string; } export interface IGraphSearchAroundResultIntermediateEdgeV1 { sourceObjectRid: string; sourceToIntermediateLinkTypeRid?: string; intermediateObjectRid: string; intermediateToTargetLinkTypeRid?: string; targetObjectRid: string; label?: string; direction?: string; }
directEdges は、2個のオブジェクトを直接結ぶエッジとしてグラフ上に表現されます。このエッジがリンクに基づく場合、オントロジーにあるそのリンクの linkTypeRid を指定すると、エッジに沿ってリンクタイプの表示名を表示し、Vertex がエッジの方向を認識できるようになります。intermediateEdges を使用すると、イベントやほかの中間オブジェクトに基づいて、2個のオブジェクト間にエッジを作成できます。中間エッジは、2個のオブジェクト間のエッジとして表現され、中間オブジェクトはそのエッジにグループ化されます。同じ2個のオブジェクト間で多数の中間エッジが返された場合、すべての中間オブジェクトが1本のエッジにグループ化されます。直接エッジと同様に、表現される関係が1組のリンク(ソースオブジェクトから中間オブジェクトへのリンクと、中間オブジェクトから対象オブジェクトへのリンク)に基づく場合は、これらのリンクタイプの RID を指定できます。Vertex がオブジェクトをエッジにグループ化するのは、関数がそのオブジェクトをグラフに追加する場合のみです。そのため、関数への入力として渡すオブジェクトを含め、すでにグラフ上にあるオブジェクトは独立したノードのままになります。orphanObjectRids を使用すると、レスポンス内のほかのオブジェクトへのリンクがないオブジェクトを返すことができます。directEdges または intermediateEdges のいずれかのエッジに含まれるオブジェクトを、ここで返す必要はありません。objectRidsToGroup を使用すると、グループの配列を返すことで、オブジェクトを1個のノードにグループ化できます。各グループはオブジェクトの RID の配列です。注:同じ RID を複数のグループに追加すると、それらのグループは統合されます。label を使用すると、ソースオブジェクトと対象オブジェクトの間に生成される関数によるリンクにカスタムラベルを指定できます。direction を使用すると、関連検索関数が生成する関数によるリンクの方向性を変更できます。指定する値は、NONE、FORWARD、REVERSE のいずれかである必要があります。省略した場合、デフォルトは FORWARD です。linkTypeRid が指定されていることによって表示されるリンクは、direction の影響を受けません。layout を使用すると、結果のオブジェクトがグラフに追加される際に使用するレイアウトを変更できます。指定する値は、auto、auto-grid、grid、linear-row、linear-column、circular のいずれかである必要があります。省略した場合、デフォルトは階層レイアウトです。
1.0.0 などのセマンティックバージョンでタグを付ける必要があります。
次の例には、2つの関連検索関数が含まれています。
1つ目の関数 allFlights は、ルート上のすべてのフライトを返し、空港間の1本のエッジに統合します。たとえば、ルート「SAN -> FAT」に対して実行すると、次のようになります。

2つ目の関数 destinations では、ユーザーが距離を選択でき、起点の空港からそのフライト数以内で到達できるすべての空港を返します。たとえば、空港「[ADK] Adak + Adak Island, AK」に対して距離を2として実行すると、次のようになります。

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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90import { Function, Integer, OntologyObject } from "@foundry/functions-api" import { ExampleDataAirport, ExampleDataRoute } from "@foundry/ontology-api"; export interface IGraphSearchAroundResultV1 { directEdges?: IGraphSearchAroundResultDirectEdgeV1[]; intermediateEdges?: IGraphSearchAroundResultIntermediateEdgeV1[]; orphanObjectRids?: string[]; objectRidsToGroup?: string[][]; } export interface IGraphSearchAroundResultDirectEdgeV1 { sourceObjectRid: string; targetObjectRid: string; linkTypeRid?: string; } export interface IGraphSearchAroundResultIntermediateEdgeV1 { sourceObjectRid: string; sourceToIntermediateLinkTypeRid?: string; intermediateObjectRid: string; intermediateToTargetLinkTypeRid?: string; targetObjectRid: string; } export class VertexSearchArounds { @Function() public async allFlights(routes: ExampleDataRoute[]): Promise<IGraphSearchAroundResultV1> { const flights = await Promise.all(routes.map(route => route.flights.allAsync()); const intermediateEdges: IGraphSearchAroundResultIntermediateEdgeV1[] = []; for (let i = 0; i < routes.length; i++) { const route = routes[i]; const flightBetweenOriginAndDestination = flights[i]; const sourceObjectRid = route.departingAirport.get().rid!; const targetObjectRid = route.arrivingAirport.get().rid!; for (const flight of flightBetweenOriginAndDestination) { intermediateEdges.push({ sourceObjectRid, intermediateObjectRid: flight.rid!, targetObjectRid, }); } } const result: IGraphSearchAroundResultV1 = { intermediateEdges, }; return result; } @Function() public async destinations(airport: ExampleDataAirport, distance: Integer): Promise<IGraphSearchAroundResultV1> { let currentDistance = 0; let currentAirports = [airport]; const directEdges: IGraphSearchAroundResultDirectEdgeV1[] = []; while (currentDistance < distance) { let nextAirports = new Set<ExampleDataAirport>(); const routesByAirport = await Promise.all(currentAirports.map(airport => airport.routes.allAsync())); const destinationsByAirport = await Promise.all( routesByAirport.map(routes => Promise.all(routes.map(route => route.arrivingAirport.getAsync())) ) ); for (let i = 0; i < currentAirports.length; i++) { const airport = currentAirports[i]; const destinations = destinationsByAirport[i]; for (const destination of destinations) { directEdges.push({ sourceObjectRid: airport.rid!, targetObjectRid: destination!.rid!, }); } nextAirports.add(destination!); } currentAirports = Array.from(nextAirports); currentDistance++; } return { directEdges }; } }
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 40 41 42 43 44 45 46 47 48 49 50 51 52import { ObjectSet, Osdk } from "@osdk/client"; import { Integer } from "@osdk/functions"; import { ExampleDataAirport, ExampleDataRoute } from "@ontology/sdk"; export interface IGraphSearchAroundResultV1 { directEdges?: IGraphSearchAroundResultDirectEdgeV1[]; intermediateEdges?: IGraphSearchAroundResultIntermediateEdgeV1[]; orphanObjectRids?: string[]; objectRidsToGroup?: string[][]; } export interface IGraphSearchAroundResultDirectEdgeV1 { sourceObjectRid: string; targetObjectRid: string; linkTypeRid?: string; } export interface IGraphSearchAroundResultIntermediateEdgeV1 { sourceObjectRid: string; sourceToIntermediateLinkTypeRid?: string; intermediateObjectRid: string; intermediateToTargetLinkTypeRid?: string; targetObjectRid: string; } export async function allFlights( routes: ObjectSet<ExampleDataRoute>, ): Promise<IGraphSearchAroundResultV1> { const intermediateEdges: IGraphSearchAroundResultIntermediateEdgeV1[] = []; for await (const route of routes.asyncIter()) { const [departure] = await Array.fromAsync( route.$link.departingAirport.asyncIter(), ); const [arrival] = await Array.fromAsync( route.$link.arrivingAirport.asyncIter(), ); if (!departure || !arrival) continue; for await (const flight of route.$link.flights.asyncIter()) { intermediateEdges.push({ sourceObjectRid: departure.$rid!, intermediateObjectRid: flight.$rid!, targetObjectRid: arrival.$rid!, }); } } return { intermediateEdges }; } export default allFlights;