注: 以下の翻訳の正確性は検証されていません。AIPを利用して英語版の原文から機械的に翻訳されたものです。
Vertex に表示するために、ツリー状の構造のルートオブジェクトからツリー全体を取得するにはどうすればよいですか?
このコードは、ツリー状のオブジェクト構造のルートオブジェクトから幅優先探索を実行します。その後、このツリーを Vertex に表示するための IGraphSearchAroundResultV1 を返します。
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 86import { Function, Integer, OntologyObject } from "@foundry/functions-api" import { ExampleObjectType } 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; } class Queue<T> { private items: T[]; constructor() { this.items = []; } enqueue(item: T): void { this.items.push(item); } dequeue(): T | undefined { return this.items.shift(); } isEmpty(): boolean { return this.items.length === 0; } } export class VertexSearchArounds { @Function() public async fullBomTree(exampleObject: ExampleObjectType): Promise<IGraphSearchAroundResultV1> { var directEdges: IGraphSearchAroundResultDirectEdgeV1[] = []; if (exampleObject.parent.all().length == 0) { const visited: ExampleObjectType[] = []; const queue: Queue<ExampleObjectType> = new Queue<ExampleObjectType>(); visited.push(exampleObject); queue.enqueue(exampleObject); while (!queue.isEmpty()) { const currentNode = queue.dequeue(); if (currentNode !== undefined) { const children = exampleObject.child.all(); if (children) { for (const child of children) { if (!visited.includes(child)) { visited.push(child); queue.enqueue(child); directEdges.push({ sourceObjectRid: currentNode.rid!, targetObjectRid: child.rid! }) } } } } } } const result: IGraphSearchAroundResultV1 = { directEdges }; return result; } }
graph, typescript, searcharound, breadth-first search, vertexツリーやグラフのように構造化されたオブジェクトの子と孫を取得するにはどうすればよいですか?
このコードは、入力ノードのリストを受け取り、親ノードから関連検索を行って、入力ノードの子と孫を含むオブジェクトセットを返す関数を定義します。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14@Function() // 指定された1個の入力ノードの子と孫を取得します。 private async getGrandChildrenAndChildrenViaList(item: ItemStructure[]): Promise<ObjectSet<ItemStructure>> { if(item.length === 0){ // 空のセットを返します return Objects.search().itemStructure([]); } else { // 入力されたオブジェクトのリストからオブジェクトセットを定義します var itemSet: ObjectSet<ItemStructure>; itemSet = Objects.search().itemStructure(item); // これらのオブジェクトの関連検索を行います return itemSet.searchAroundItemStructureParent().union(itemSet.searchAroundItemStructureParent().searchAroundItemStructureParent()); } }
functions on objects, foo, typescript, searcharound