Skip to content

Commit

Permalink
[#1270] Refactor gradoop-examples module (#1271)
Browse files Browse the repository at this point in the history
fixes #1270
  • Loading branch information
Kevin Gómez authored and ChrizZz110 committed May 23, 2019
1 parent 0bbeddc commit 69c67b0
Show file tree
Hide file tree
Showing 174 changed files with 800 additions and 9,912 deletions.
Expand Up @@ -17,6 +17,9 @@
<suppress checks="IllegalCatch"
files="PrintTableSink"
lines="90-100"/>
<suppress checks="LineLength"
files="SocialNetworkGraph.java"
lines="0-68"/>

<!-- less restrictive checkstyle for tests -->
<suppress checks="JavadocMethod"
Expand Down
90 changes: 90 additions & 0 deletions gradoop-examples/gradoop-examples-operators/pom.xml
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>gradoop-examples</artifactId>
<groupId>org.gradoop</groupId>
<version>0.5.0-SNAPSHOT</version>
</parent>

<artifactId>gradoop-examples-operators</artifactId>
<packaging>jar</packaging>

<name>Gradoop Examples Operators</name>
<description>Contains examples for a subset of Gradoop operators.</description>


<dependencies>
<dependency>
<groupId>org.gradoop</groupId>
<artifactId>gradoop-flink</artifactId>
</dependency>
<dependency>
<groupId>org.gradoop</groupId>
<artifactId>gradoop-common</artifactId>
</dependency>
<dependency>
<groupId>org.gradoop</groupId>
<artifactId>gradoop-data-integration</artifactId>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<!-- gradoop dependencies -->
<include>org.gradoop:gradoop-flink</include>
<include>org.gradoop:gradoop-common</include>
<include>org.gradoop:gradoop-data-integration</include>
<!-- libs that are not provided by flink binary -->
<include>org.apache.flink:flink-gelly_2.11</include>
<include>org.apache.flink:flink-java</include>
<!-- others -->
<include>org.apache.hbase:hbase-common</include>
<include>com.github.s1ck:gdl</include>
<include>org.antlr:antlr4-runtime</include>
<include>me.lemire.integercompression:*</include>
<!-- capf example dependencies -->
<include>org.opencypher:*</include>
<include>org.apache.flink:flink-table_2.11</include>
<include>org.parboiled:parboiled-scala_2.11</include>
<include>com.lihaoyi:ujson_2.11</include>
<include>com.lihaoyi:upickle_2.11</include>
<include>org.typelevel:cats-kernel_2.11</include>
<include>org.typelevel:cats-core_2.11</include>
<include>org.atnos:eff_2.11</include>
<include>org.parboiled:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Expand Up @@ -15,57 +15,55 @@
*/
package org.gradoop.examples.aggregation;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

import org.apache.flink.api.java.ExecutionEnvironment;
import org.gradoop.examples.aggregation.functions.AddPropertyMeanAgeToGraphHead;
import org.gradoop.examples.aggregation.functions.AggregateListOfNames;
import org.gradoop.examples.common.SocialNetworkGraph;
import org.gradoop.flink.model.impl.epgm.LogicalGraph;
import org.gradoop.flink.model.impl.functions.epgm.ByLabel;
import org.gradoop.flink.model.impl.operators.aggregation.functions.count.VertexCount;
import org.gradoop.flink.model.impl.operators.aggregation.functions.sum.SumVertexProperty;
import org.gradoop.flink.model.impl.operators.aggregation.functions.average.AverageVertexProperty;
import org.gradoop.flink.util.FlinkAsciiGraphLoader;
import org.gradoop.flink.util.GradoopFlinkConfig;

/**
* A self contained example on how to use the aggregate operator on Gradoop's LogicalGraph class.
* A self contained example on how to use the aggregate operator on Gradoop's {@link LogicalGraph}
* class.
*
* The example uses the graph in dev-support/social-network.pdf
* The example uses the graph in {@code dev-support/social-network.pdf}
*/
public class AggregationExample {

/**
* Path to the example data graph
* Property key {@code birthday}
*/
private static final String EXAMPLE_DATA_FILE =
AggregationExample.class.getResource("/data/gdl/sna.gdl").getFile();
private static final String PROPERTY_KEY_BIRTHDAY = "birthday";

/**
* Property key 'birthday'
* Property key {@code mean_age}
*/
private static final String PROPERTY_KEY_BIRTHDAY = "birthday";
private static final String PROPERTY_KEY_MEAN_AGE = "mean_age";

/**
* Property key 'person'
* Property key {@code Person}
*/
private static final String LABEL_PERSON = "Person";

/**
* Runs the program on the example data graph.
*
* The example provides an overview over the usage of the aggregate() method.
* The example provides an overview over the usage of the {@code aggregate()} method.
* It both showcases the application of aggregation functions that are already provided by
* Gradoop, as well as the definition of custom ones.
* Documentation for all available aggregation functions as well as a detailed description of the
* aggregate method can be found in the projects wiki.
*
* Using the social network graph in the resources directory, the program will:
* 1. extract a subgraph only containing vertices which are labeled "person"
* 2. concatenate the values of the vertex property "name" of each vertex in the subgraph
* 3. count the amount of vertices in the subgraph (aka the amount of persons)
* 4. sum up the values of the vertex property "birthday"
* 5. add the property "meanAge" to the graph head using a graph head transformation
* <ol>
* <li>extract a subgraph only containing vertices which are labeled "Person"</li>
* <li>concatenate the values of the vertex property "name" of each vertex in the subgraph</li>
* <li>calculate the mean value of the "birthday" property</li>
* </ol>
*
* @param args arguments
* @param args Command line arguments (unused).
*
* @see <a href="https://github.com/dbs-leipzig/gradoop/wiki/Unary-Logical-Graph-Operators">
* Gradoop Wiki</a>
Expand All @@ -79,8 +77,7 @@ public static void main(String[] args) throws Exception {
FlinkAsciiGraphLoader loader = new FlinkAsciiGraphLoader(GradoopFlinkConfig.createConfig(env));

// load data
loader.initDatabaseFromFile(
URLDecoder.decode(EXAMPLE_DATA_FILE, StandardCharsets.UTF_8.name()));
loader.initDatabaseFromString(SocialNetworkGraph.getGraphGDLString());

// get LogicalGraph representation of the social network graph
LogicalGraph networkGraph = loader.getLogicalGraph();
Expand All @@ -92,12 +89,8 @@ public static void main(String[] args) throws Exception {
// apply custom VertexAggregateFunction
.aggregate(
new AggregateListOfNames(),
// aggregate sum of vertices in order to obtain total amount of persons
new VertexCount(),
// sum up values of the vertex property "birthday"
new SumVertexProperty(PROPERTY_KEY_BIRTHDAY))
// add computed property "meanAge" to the graph head
.transformGraphHead(new AddPropertyMeanAgeToGraphHead());
// Calculate the average of the vertex property "birthday"
new AverageVertexProperty(PROPERTY_KEY_BIRTHDAY, PROPERTY_KEY_MEAN_AGE));

// print graph, which now contains the newly aggregated properties in the graph head
result.print();
Expand Down
@@ -0,0 +1,68 @@
/*
* Copyright © 2014 - 2019 Leipzig University (Database Research Group)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradoop.examples.common;

/**
* Class to provide a example graph used by gradoop examples.
*/
public class SocialNetworkGraph {

/**
* Private Constructor
*/
private SocialNetworkGraph() { }

/**
* Returns the SNA Graph as GDL String.
*
* @return gdl string of sna graph
*/
public static String getGraphGDLString() {

return
"db[" +
"(databases:tag {name:\"Databases\"})" +
"(graphs:Tag {name:\"Graphs\"})" +
"(hadoop:Tag {name:\"Hadoop\"})" +
"(gdbs:Forum {title:\"Graph Databases\"})" +
"(gps:Forum {title:\"Graph Processing\"})" +
"(alice:Person {name:\"Alice\", gender:\"f\", city:\"Leipzig\", birthday:20})" +
"(bob:Person {name:\"Bob\", gender:\"m\", city:\"Leipzig\", birthday:30})" +
"(carol:Person {name:\"Carol\", gender:\"f\", city:\"Dresden\", birthday:30})" +
"(dave:Person {name:\"Dave\", gender:\"m\", city:\"Dresden\", birthday:40})" +
"(eve:Person {name:\"Eve\", gender:\"f\", city:\"Dresden\", speaks:\"English\", birthday:35})" +
"(frank:Person {name:\"Frank\", gender:\"m\", city:\"Berlin\", locIP:\"127.0.0.1\", birthday:35})" +
"" +
"(eve)-[:hasInterest]->(databases)" +
"(alice)-[:hasInterest]->(databases)" +
"(frank)-[:hasInterest]->(hadoop)" +
"(dave)-[:hasInterest]->(hadoop)" +
"(gdbs)-[:hasModerator]->(alice)" +
"(gdbs)-[:hasMember]->(alice)" +
"(gdbs)-[:hasMember]->(bob)" +
"(gps)-[:hasModerator {since:2013}]->(dave)" +
"(gps)-[:hasMember]->(dave)" +
"(gps)-[:hasMember]->(carol)-[ckd]->(dave)" +
"(databases)<-[ghtd:hasTag]-(gdbs)-[ghtg1:hasTag]->(graphs)<-[ghtg2:hasTag]-(gps)-[ghth:hasTag]->(hadoop)" +
"(eve)-[eka:knows {since:2013}]->(alice)-[akb:knows {since:2014}]->(bob)" +
"(eve)-[ekb:knows {since:2015}]->(bob)-[bka:knows {since:2014}]->(alice)" +
"(frank)-[fkc:knows {since:2015}]->(carol)-[ckd:knows {since:2014}]->(dave)" +
"(frank)-[fkd:knows {since:2015}]->(dave)-[dkc:knows {since:2014}]->(carol)" +
"(alice)-[akb]->(bob)-[bkc:knows {since:2013}]->(carol)-[ckd]->(dave)" +
"(alice)<-[bka]-(bob)<-[ckb:knows {since:2013}]-(carol)<-[dkc]-(dave)" +
"]";
}
}
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
/**
* Contains functions used in benchmark programs
* Example SNA Data
*
* {@code dev-support/social-network.pdf}
*/
package org.gradoop.benchmark.sna.functions;
package org.gradoop.examples.common;
@@ -0,0 +1,78 @@
/*
* Copyright © 2014 - 2019 Leipzig University (Database Research Group)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradoop.examples.communities;

import org.apache.flink.api.java.ExecutionEnvironment;
import org.gradoop.examples.common.SocialNetworkGraph;
import org.gradoop.flink.algorithms.gelly.labelpropagation.GellyLabelPropagation;
import org.gradoop.flink.model.impl.epgm.LogicalGraph;
import org.gradoop.flink.util.FlinkAsciiGraphLoader;
import org.gradoop.flink.util.GradoopFlinkConfig;

/**
* A self contained example on how to use the {@link GellyLabelPropagation} operator.
*
* The example uses the graph in dev-support/social-network.pdf
*/
public class GellyCommunitiesExample {

/**
* Runs the program on the example data graph.
*
* The example provides an overview over the usage of the {@link GellyLabelPropagation} Operator.
* Documentation for all available gelly based operators can be found in the projects wiki.
*
* Using the social network graph {@link SocialNetworkGraph}, the program will:
* <ol>
* <li>create the logical graph from the social network gdl string</li>
* <li>prepare the initial community id by using a transformation function on each vertex</li>
* <li>calculate the communities using label propagation</li>
* <li>print the results</li>
* </ol>
*
* @param args arguments
* @see <a href="https://github.com/dbs-leipzig/gradoop/wiki/Unary-Logical-Graph-Operators">
* Gradoop Wiki</a>
* @throws Exception if something goes wrong
*/
public static void main(String[] args) throws Exception {

// create flink execution environment
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

// create loader
FlinkAsciiGraphLoader loader = new FlinkAsciiGraphLoader(GradoopFlinkConfig.createConfig(env));

// load data
loader.initDatabaseFromString(SocialNetworkGraph.getGraphGDLString());

// property key used for label propagation
final String communityKey = "comm_id";

// load the graph and set initial community id
LogicalGraph graph = loader.getLogicalGraph();
graph = graph.transformVertices((current, transformed) -> {
current.setProperty(communityKey, current.getId());
return current;
});

// apply label propagation to compute communities
graph = graph.callForGraph(new GellyLabelPropagation(5, communityKey));

// print results
graph.print();
}
}
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/
/**
* Contains example Gradoop programs that can be executed on a Flink cluster.
* Program to run parametrized Grouping on extended property graphs.
*/
package org.gradoop.benchmark;
package org.gradoop.examples.communities;

0 comments on commit 69c67b0

Please sign in to comment.