Search in sources :

Example 1 with Project4To0And3AndSwitch

use of org.gradoop.flink.model.impl.operators.matching.transactional.function.Project4To0And3AndSwitch in project gradoop by dbs-leipzig.

the class TransactionalPatternMatching method findEmbeddings.

/**
 * Finds all embeddings in the given graph and constructs a new graph
 * collection consisting of these embeddings.
 * @param collection input graph collection
 * @param graphs graphs with candidates of their elements
 * @return collection of found embeddings
 */
private GC findEmbeddings(GC collection, DataSet<GraphWithCandidates> graphs) {
    // --------------------------------------------------------------------------
    // run the matching algorithm
    // --------------------------------------------------------------------------
    DataSet<Tuple4<GradoopId, GradoopId, GradoopIdSet, GradoopIdSet>> embeddings = graphs.flatMap(new FindEmbeddings(algorithm, query));
    // --------------------------------------------------------------------------
    // create new graph heads
    // --------------------------------------------------------------------------
    DataSet<G> newHeads = embeddings.map(new Project4To0And1<>()).map(new InitGraphHeadWithLineage<>(collection.getFactory().getGraphHeadFactory()));
    // --------------------------------------------------------------------------
    // update vertex graphs
    // --------------------------------------------------------------------------
    DataSet<Tuple2<GradoopId, GradoopIdSet>> verticesWithGraphs = embeddings.map(new Project4To0And2AndSwitch<>()).flatMap(new ExpandFirstField<>()).groupBy(0).reduceGroup(new MergeSecondField<>());
    DataSet<V> newVertices = verticesWithGraphs.join(collection.getVertices()).where(0).equalTo(new Id<>()).with(new AddGraphsToElements<>());
    // --------------------------------------------------------------------------
    // update edge graphs
    // --------------------------------------------------------------------------
    DataSet<Tuple2<GradoopId, GradoopIdSet>> edgesWithGraphs = embeddings.map(new Project4To0And3AndSwitch<>()).flatMap(new ExpandFirstField<>()).groupBy(0).reduceGroup(new MergeSecondField<>());
    DataSet<E> newEdges = edgesWithGraphs.join(collection.getEdges()).where(0).equalTo(new Id<>()).with(new AddGraphsToElements<>());
    // --------------------------------------------------------------------------
    return collection.getFactory().fromDataSets(newHeads, newVertices, newEdges);
}
Also used : Project4To0And3AndSwitch(org.gradoop.flink.model.impl.operators.matching.transactional.function.Project4To0And3AndSwitch) FindEmbeddings(org.gradoop.flink.model.impl.operators.matching.transactional.function.FindEmbeddings) Tuple4(org.apache.flink.api.java.tuple.Tuple4) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Project4To0And1(org.gradoop.flink.model.impl.functions.tuple.Project4To0And1) Id(org.gradoop.flink.model.impl.functions.epgm.Id) GradoopId(org.gradoop.common.model.impl.id.GradoopId) Project4To0And2AndSwitch(org.gradoop.flink.model.impl.operators.matching.transactional.function.Project4To0And2AndSwitch)

Aggregations

Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 Tuple4 (org.apache.flink.api.java.tuple.Tuple4)1 GradoopId (org.gradoop.common.model.impl.id.GradoopId)1 Id (org.gradoop.flink.model.impl.functions.epgm.Id)1 Project4To0And1 (org.gradoop.flink.model.impl.functions.tuple.Project4To0And1)1 FindEmbeddings (org.gradoop.flink.model.impl.operators.matching.transactional.function.FindEmbeddings)1 Project4To0And2AndSwitch (org.gradoop.flink.model.impl.operators.matching.transactional.function.Project4To0And2AndSwitch)1 Project4To0And3AndSwitch (org.gradoop.flink.model.impl.operators.matching.transactional.function.Project4To0And3AndSwitch)1