@Override public DataSet<WithCount<T>> execute(LogicalGraph graph) { return compute(graph.getVertices()); } }
@Override protected DataSet<Tuple2<Tuple2<String, String>, Set<PropertyValue>>> extractValuePairs( LogicalGraph graph) { return graph.getVertices().flatMap(new ExtractPropertyValuesByLabel<>()); } }
/** * 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())); }
/** * Initializes the debug mappings between vertices/edges and their debug id. * * @param graph data graph */ private void initDebugMappings(LogicalGraph graph) { vertexMapping = graph.getVertices() .map(new PairElementWithPropertyValue<>("id")); edgeMapping = graph.getEdges() .map(new PairElementWithPropertyValue<>("id")); } }
/** * Initializes the debug mappings between vertices/edges and their debug id. * * @param graph data graph */ private void initDebugMappings(LogicalGraph graph) { vertexMapping = graph.getVertices() .map(new PairElementWithPropertyValue<>("id")); edgeMapping = graph.getEdges() .map(new PairElementWithPropertyValue<>("id")); } }
/** * 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()); }
@Override public DataSet<Boolean> isEmpty() { return getVertices() .map(new True<>()) .distinct() .union(getConfig().getExecutionEnvironment().fromElements(false)) .reduce(new Or()) .map(new Not()); }
@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()); }
/** * {@inheritDoc} */ @Override public DataSet<Boolean> isEmpty() { return getVertices() .map(new True<>()) .distinct() .union(getConfig().getExecutionEnvironment().fromElements(false)) .reduce(new Or()) .map(new Not()); }
@Override public DataSet<WithCount<GradoopId>> execute(LogicalGraph graph) { return new EdgeValueDistribution<>(new SourceId<>()).execute(graph) .rightOuterJoin(graph.getVertices().map(new Id<>())) .where(0).equalTo("*") .with(new SetOrCreateWithCount()); }
@Override public DataSet<WithCount<GradoopId>> execute(LogicalGraph graph) { return new EdgeValueDistribution<>(new SourceId<>()).execute(graph) .rightOuterJoin(graph.getVertices().map(new Id<>())) .where(0).equalTo("*") .with(new SetOrCreateWithCount()); } }
@Override public void validateGraphProperties(LogicalGraph graph) throws Exception { List<Vertex> vertices = graph.getVertices().collect(); for (Vertex v : vertices) { assertTrue("No local value stored in vertex: " + v.getId().toString(), v.hasProperty(ClusteringCoefficientBase.PROPERTY_KEY_LOCAL)); } } }
@Override public DataSet<WithCount<Tuple2<String, String>>> execute(LogicalGraph graph) { return Count.groupBy(graph.getVertices() .map(new ToIdWithLabel<>()) .join(graph.getEdges().map(new ToTargetIdWithLabel<>())) .where(0).equalTo(0) .with(new BothLabels())) .map(new Tuple2ToWithCount<>()); }
@Override public DataSet<WithCount<Tuple2<String, String>>> execute(LogicalGraph graph) { return Count.groupBy(graph.getVertices() .map(new ToIdWithLabel<>()) .join(graph.getEdges().map(new ToSourceIdWithLabel<>())) .where(0).equalTo(0) .with(new BothLabels())) .map(new Tuple2ToWithCount<>()); }
/** * Check PageRank for excluded "zero-degree" vertices * * @throws Exception If the execution fails. */ @Test public void testPageRankWithoutZeroDegrees() throws Exception { LogicalGraph resultGraph = new PageRank(propertyKey, 0.3, 20) .execute(testGraph); checkPageRankProperty(resultGraph); assertEquals(resultGraph.getVertices().count(), 3L); }
@Override public void testNonConnectedGraph() throws Exception { validateGraphProperties(nonConnectedGraph); List<Vertex> vertices = nonConnectedGraph.getVertices().collect(); for (Vertex v : vertices) { assertEquals( "Wrong local value for not connected vertex: " + v.getId().toString() + ", should be 0", 0d, v.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_LOCAL).getDouble(), 0.0); } }
@Override public void testNonConnectedGraph() throws Exception { validateGraphProperties(nonConnectedGraph); List<Vertex> vertices = nonConnectedGraph.getVertices().collect(); for (Vertex v : vertices) { assertEquals( "Wrong local value for not connected vertex: " + v.getId().toString() + ", should be 0", 0d, v.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_LOCAL).getDouble(), 0.0); } }
@Override public LogicalGraph executeInGelly(Graph<GradoopId, NullValue, NullValue> graph) throws Exception { DataSet<Vertex> newVertices = new org.apache.flink.graph.library.linkanalysis.PageRank<GradoopId, NullValue, NullValue>( dampingFactor, iterations).setIncludeZeroDegreeVertices(includeZeroDegrees).run(graph) .join(currentGraph.getVertices()) .where(new PageRankResultKey()).equalTo(new Id<>()) .with(new PageRankToAttribute(propertyKey)); return currentGraph.getConfig().getLogicalGraphFactory().fromDataSets( currentGraph.getGraphHead(), newVertices, currentGraph.getEdges()); }
@Override public void testFullyConnectedGraph() throws Exception { validateGraphProperties(fullGraph); List<Vertex> vertices = fullGraph.getVertices().collect(); for (Vertex v : vertices) { assertEquals("Wrong local value for clique-vertex '" + v.getId().toString() + "', should be 1", 1d, v.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_LOCAL).getDouble(), 0.0); } }
@Override public void testFullyConnectedGraph() throws Exception { validateGraphProperties(fullGraph); List<Vertex> vertices = fullGraph.getVertices().collect(); for (Vertex v : vertices) { assertEquals( "Wrong local value for clique-vertex '" + v.getId().toString() + "', should be 1", 1d, v.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_LOCAL).getDouble(), 0.0); } }