/** * {@inheritDoc} */ @Override public LogicalGraph execute(LogicalGraph graph) { DataSet<GraphHead> newGraphHead = graph .aggregate(new VertexCount(), new EdgeCount()) .getGraphHead() .map(new CalculateDensity(SamplingEvaluationConstants.PROPERTY_KEY_DENSITY)); return graph.getConfig().getLogicalGraphFactory() .fromDataSets(newGraphHead, graph.getVertices(), graph.getEdges()); }
@Override public DataSet<Tuple3<String, Long, Long>> execute(LogicalGraph graph) { LogicalGraph graphWithWccIds = graph.callForGraph(new AnnotateWeaklyConnectedComponents( propertyKey, maxIterations, annotateEdges)); graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccVertices(propertyKey)); if (annotateEdges) { graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccEdges(propertyKey)); } return graphWithWccIds.getGraphHead().flatMap( new GetConnectedComponentDistributionFlatMap(propertyKey, annotateEdges)); }
/** * {@inheritDoc} */ @Override public GraphCollection query(String query, String constructionPattern, boolean attachData, MatchStrategy vertexStrategy, MatchStrategy edgeStrategy, GraphStatistics graphStatistics) { return callForCollection(new CypherPatternMatching(query, constructionPattern, attachData, vertexStrategy, edgeStrategy, graphStatistics)); }
/** * Default transformation from a Gradoop Graph to a Gelly Graph. * * @param graph Gradoop Graph. * @return Gelly Graph. */ public Graph<GradoopId, VV, EV> transformToGelly(LogicalGraph graph) { DataSet<Vertex<GradoopId, VV>> gellyVertices = graph.getVertices().map(toGellyVertex); DataSet<Edge<GradoopId, EV>> gellyEdges = graph.getEdges().map(toGellyEdge); return Graph.fromDataSet(gellyVertices, gellyEdges, graph.getConfig().getExecutionEnvironment()); }
/** * Creates the meta data for the given graph. * * @param graph logical graph * @return meta data information */ default DataSet<Tuple3<String, String, String>> tuplesFromGraph(LogicalGraph graph) { return tuplesFromElements(graph.getVertices()) .union(tuplesFromElements(graph.getEdges())); }
.subgraph( vertex -> vertex.getLabel().toLowerCase().equals(person), edge -> edge.getLabel().toLowerCase().equals(knows)) .transform( }) .callForGraph(new GellyLabelPropagation(maxIterations, label)) .splitBy(label) .groupBy(Lists.newArrayList(city, gender)) .aggregate(new VertexCount(), new EdgeCount());
@Override public GraphCollection execute(LogicalGraph graph) { LogicalGraph graphWithWccIds = graph.callForGraph(new AnnotateWeaklyConnectedComponents( propertyKey, maxIterations)); GraphCollection split = graphWithWccIds.splitBy(propertyKey); return graph.getConfig().getGraphCollectionFactory().fromDataSets( split.getGraphHeads(), split.getVertices().map(new PropertyRemover<>(propertyKey)), split.getEdges().map(new PropertyRemover<>(propertyKey))); }
/** * Test HasVertexLabel with a single graph and result false. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasVertexLabelFalse() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasVertexLabel hasNotExistent = new HasVertexLabel("LabelDoesNotExist"); graph = graph.aggregate(hasNotExistent); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasVertexLabel_LabelDoesNotExist not set", graphHead.hasProperty(hasNotExistent.getAggregatePropertyKey())); assertFalse("Property hasVertexLabel_LabelDoesNotExist is true, should be false", graphHead.getPropertyValue(hasNotExistent.getAggregatePropertyKey()).getBoolean()); }
@Override public DataSet<Boolean> isEmpty() { return getVertices() .map(new True<>()) .distinct() .union(getConfig().getExecutionEnvironment().fromElements(false)) .reduce(new Or()) .map(new Not()); }
graph = graph.transformVertices((current, transformed) -> { current.setProperty(communityKey, current.getId()); return current; graph = graph.callForGraph(new GellyLabelPropagation(10, communityKey)); LogicalGraph communities = graph.groupBy(singletonList(communityKey), // vertex grouping keys singletonList(new Count("count")), // vertex aggregate functions .vertexInducedSubgraph((vertex) -> vertex.getPropertyValue("count").getLong() > 10);
/** * {@inheritDoc} */ @Override public LogicalGraph sample(SamplingAlgorithm algorithm) { return callForGraph(algorithm); }
/** * The actual computation. * * @param socialNetwork social network graph * @return summarized, aggregated graph */ private static LogicalGraph execute(LogicalGraph socialNetwork) { return socialNetwork .subgraph( vertex -> vertex.getLabel().equals("Person"), edge -> edge.getLabel().equals("knows")) .groupBy(Arrays.asList("gender", "city")) .aggregate(new VertexCount(), new EdgeCount()); }
/** * {@inheritDoc} */ @Override public GraphCollection query(String query, String constructionPattern, GraphStatistics graphStatistics) { return query(query, constructionPattern, true, MatchStrategy.HOMOMORPHISM, MatchStrategy.ISOMORPHISM, graphStatistics); }
@Override public void validateGraphProperties(LogicalGraph graph) throws Exception { GraphHead head = graph.getGraphHead().collect().get(0); assertTrue("No global value stored in graph head", head.hasProperty(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL)); } }
@Override public LogicalGraph groupBy( List<String> vertexGroupingKeys, List<AggregateFunction> vertexAggregateFunctions, List<String> edgeGroupingKeys, List<AggregateFunction> edgeAggregateFunctions, GroupingStrategy groupingStrategy) { Objects.requireNonNull(vertexGroupingKeys, "missing vertex grouping key(s)"); Objects.requireNonNull(groupingStrategy, "missing vertex grouping strategy"); Grouping.GroupingBuilder builder = new Grouping.GroupingBuilder(); builder.addVertexGroupingKeys(vertexGroupingKeys); builder.setStrategy(groupingStrategy); if (edgeGroupingKeys != null) { builder.addEdgeGroupingKeys(edgeGroupingKeys); } if (vertexAggregateFunctions != null) { vertexAggregateFunctions.forEach(builder::addVertexAggregateFunction); } if (edgeAggregateFunctions != null) { edgeAggregateFunctions.forEach(builder::addEdgeAggregateFunction); } return callForGraph(builder.build()); }
/** * Prints the logical graph to the standard output. * * @param logicalGraph The logical graph that is supposed to be printed. * @throws Exception Forwarded from flink execute. */ public static void print(LogicalGraph logicalGraph) throws Exception { GraphCollectionFactory collectionFactory = logicalGraph.getConfig().getGraphCollectionFactory(); GraphCollection graphCollection = collectionFactory.fromGraph(logicalGraph); print(graphCollection); }
/** * Test using multiple vertex aggregation functions in one call. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphWithMultipleVertexAggregationFunctions() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraph(); SumVertexProperty sumVertexProperty = new SumVertexProperty("age"); MaxVertexProperty maxVertexProperty = new MaxVertexProperty("age"); LogicalGraph expected = graph.aggregate(sumVertexProperty).aggregate(maxVertexProperty); LogicalGraph output = graph.aggregate(sumVertexProperty, maxVertexProperty); collectAndAssertTrue(expected.equalsByData(output)); }
@Override LogicalGraph applyGrouping(LogicalGraph graph, List<String> groupingKeys) { return graph.groupBy(groupingKeys, vertexAggregateFunctions, edgeGroupingKeys, edgeAggregateFunctions, strategy); }
@Override public DataSet<WithCount<GradoopId>> execute(LogicalGraph graph) { return new EdgeValueDistribution<>(new TargetId<>()).execute(graph) .rightOuterJoin(graph.getVertices().map(new Id<>())) .where(0).equalTo("*") .with(new SetOrCreateWithCount()); }
socialNetwork.subgraph(v -> v.getLabel().equals("person"), e -> e.getLabel().equals("knows")); LogicalGraph transformed = subgraph.transformVertices((current, modified) -> { LocalDate birthDayDate = current.getPropertyValue("birthday").getDate(); current.setProperty("yob", birthDayDate.getYear()); LogicalGraph summary = transformed.groupBy( Collections.singletonList("decade"), Arrays.asList( summary = summary.transformVertices((current, modified) -> { current.setLabel(current.getPropertyValue("decade").toString()); return current;