26.10.5.5 コレクション・フィルタからのサブグラフの作成

サブグラフは、頂点またはエッジ・コレクション・フィルタを使用して取得できます。

次のコードに示すように、頂点コレクション・フィルタからサブグラフを作成できます。

// Obtain a vertex collection from an algorithm, query execution or any other way
opg4j> VertexCollection<?> vertexCollection = ...
// Define a filter from the collection
opg4j> var vertexFilter = VertexFilter.fromCollection(vertexCollection)
// Create a subgraph of g containing the matched vertices in the vertex collection and the edges that connect them if any.
opg4j> var newGraph = g.filter(vertexFilter)
// Obtain a vertex collection from an algorithm, query execution or any other way
VertexCollection<?> vertexCollection = ...
// Define a filter from the collection
VertexFilter vertexFilter = VertexFilter.fromCollection(vertexCollection);
// Create a subgraph of g containing the matched vertices in the vertex collection and the edges that connect them if any.
PgxGraph newGraph = g.filter(vertexFilter);

次のコードに示すように、エッジ・コレクション・フィルタからサブグラフを作成できます。

// Obtain an edge collection from an algorithm, query execution or any other way
opg4j> EdgeCollection edgeCollection = ...
// Define a filter from the collection
opg4j> var edgeFilter = EdgeFilter.fromCollection(edgeCollection)
// Create a subgraph of g containing the matched edges in the collection and their corresponding source and destination vertices.
opg4j> var newGraph = g.filter(edgeFilter)
// Obtain an edge collection from an algorithm, query execution or any other way
EdgeCollection edgeCollection = ...
// Define a filter from the collection
EdgeFilter edgeFilter = EdgeFilter.fromCollection(edgeCollection);
// Create a subgraph of g containing the matched edges in the collection and their corresponding source and destination vertices.
PgxGraph newGraph = g.filter(edgeFilter);