Skip to content

Unary Graph Collection Operators

Rascat edited this page Aug 15, 2018 · 9 revisions

This section provides an overview of unary graph collection operators, which operate on a single GraphCollection and return a subset or transformation of the input collection.

Unary Graph Collection Operators
Selection
Matching
Limit
Distinct

Selection

Given a collection, the select operator filters all contained graphs based on their associated graph head and return a collection with logical graphs that fulfill the predicate.

Method Expects Returns
select Predicate function (FilterFunction<GraphHead>) for a graph head GraphCollection which contains all logical graphs that fulfill the predicate.

Selection example

Consider the Social Network example graph, which contains multiple logical graphs with different relations. This example takes a single graph collection and selects a subset of logical graphs that fulfill the predicate function.
In order to select all graphs that contain edges labeled 'hasMember', we would do the following:

  1. aggregate the property hasEdgeLabel_hasMember for each graph in the collection
  2. use the select method to retrieve graphs for which the newly set property is true
FlinkAsciiGraphLoader loader = getSocialNetworkLoader();
GraphCollection collection = loader.getGraphCollectionByVariables("g0", "g1", "g2", "g3");

// create aggregation function
HasEdgeLabel hasLabelHasMember = new HasEdgeLabel("hasMember");

// apply aggregation
collection = collection.apply(new ApplyAggregation(hasLabelHasMember));

// select graphs
GraphCollection result = collection.select(hasLabelHasMember);

The graph collection result now contains the logical graph g3:Forum, since it is the only one which contains edges labeled 'hasMember'. Or to be more precise: it is the only one with a property 'hasEdgeLabel_hasMember' that is set to true after we applied the aggregation.

Matching

tbd.

Limit

Given a collection, the limit operator return the first n arbitrary logical graphs contained in that collection.

Method Expects Returns
limit Positive integer limit which defines the number of graphs to return from the collection Subset of the graph collection

Limit example

Using the limit operator is fairly straight forward. We define some limit n of graphs that are being returned by the method. If n is greater or equal than the total amount of graphs contained in the initial collection, then every graph will be contained in the resulting GraphCollection. Using the Social Network example graph, one could apply the limit operator as follows:

FlinkAsciiGraphLoader loader = getSocialNetworkLoader();
GraphCollection collection = loader.getGraphCollectionByVariables("g0", "g1", "g2", "g3");

// define some limit
int limit = 2;

// apply limit
GraphCollection result = collection.limit(limit);

The resulting graph collection result contains the first two arbitrary logical graphs, which are g0 and g1.

Distinct

tbd.