For IntelliJ IDEA,
Android Studio or Eclipse



@Override public IdWithLabel map(E edge) throws Exception { reuseTuple.setId(edge.getTargetId()); reuseTuple.setLabel(edge.getLabel()); return reuseTuple; } }
/** * Drop edge properties. * * @param current current edge * @param transformed copy of current except label and properties * @return current edge without properties */ private static Edge dropEdgeProperties(Edge current, Edge transformed) { transformed.setLabel(current.getLabel()); return transformed; }
@Test public void getEdgesByLabel() throws Exception { TxCollectionLayout layout = new TxCollectionLayout( getExecutionEnvironment().fromElements(tx0, tx1)); GradoopTestUtils.validateEPGMGraphElementCollections( tx0.getEdges().stream().filter(e -> e.getLabel().equals("a")).collect(Collectors.toList()), layout.getEdgesByLabel("a").collect()); }
@Override public CSVEdge map(Edge edge) throws Exception { csvEdge.setId(edge.getId().toString()); csvEdge.setSourceId(edge.getSourceId().toString()); csvEdge.setTargetId(edge.getTargetId().toString()); csvEdge.setLabel(edge.getLabel()); csvEdge.setProperties(getPropertyString(edge)); return csvEdge; } }
@Override public void join(Edge edge, Vertex vertex, Collector<Edge> collector) throws Exception { if (vertex == null) { collector.collect(edge); } else if (edge != null) { REUSABLE_EDGE.setId(GradoopId.get()); REUSABLE_EDGE.setSourceId(isSourceNow ? vId : edge.getSourceId()); REUSABLE_EDGE.setTargetId(isSourceNow ? edge.getTargetId() : vId); REUSABLE_EDGE.setProperties(edge.getProperties()); REUSABLE_EDGE.setLabel(edge.getLabel()); REUSABLE_EDGE.setGraphIds(edge.getGraphIds()); collector.collect(REUSABLE_EDGE); } } }
@Test public void testEdgeInducedSubgraph() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); loader.appendToDatabaseFromString("expected[" + "(databases)<-[ghtd]-(gdbs)-[ghtg1]->(graphs)" + "(graphs)<-[ghtg2]-(gps)-[ghth]->(hadoop)" + "]"); LogicalGraph input = loader.getDatabase().getDatabaseGraph(); LogicalGraph expected = loader.getLogicalGraphByVariable("expected"); LogicalGraph output = input.edgeInducedSubgraph( e -> e.getLabel().equals("hasTag")); collectAndAssertTrue(output.equalsByElementData(expected)); }
@Test public void testGetEdges() throws Exception { AsciiGraphLoader<GraphHead, Vertex, Edge> asciiGraphLoader = AsciiGraphLoader.fromString("[()-->()]", config); validateCollections(asciiGraphLoader, 1, 2, 1); validateCaches(asciiGraphLoader, 0, 0, 0); for (Edge edge : asciiGraphLoader.getEdges()) { assertEquals("Edge has wrong label", GradoopConstants.DEFAULT_EDGE_LABEL, edge.getLabel()); } }
/** * Extracts a subgraph which is empty. * * @throws Exception */ @Test public void testEmptySubgraph() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); loader.appendToDatabaseFromString("expected[]"); LogicalGraph input = loader.getDatabase().getDatabaseGraph(); LogicalGraph expected = loader.getLogicalGraphByVariable("expected"); LogicalGraph output = input.subgraph( v -> v.getLabel().equals("User"), e -> e.getLabel().equals("friendOf")); collectAndAssertTrue(output.equalsByElementData(expected)); }
@Override public LabeledGraphStringString map(GraphTransaction transaction) throws Exception { LabeledGraphStringString outGraph = LabeledGraphStringString.getEmptyOne(); Map<String, Integer> labelMap = Maps.newHashMap(); Map<GradoopId, Integer> vertexIdMap = Maps.newHashMap(); for (Vertex vertex : transaction.getVertices()) { vertexIdMap.put(vertex.getId(), outGraph.addVertex(vertex.getLabel())); } labelMap.clear(); for (Edge edge : transaction.getEdges()) { int sourceId = vertexIdMap.get(edge.getSourceId()); int targetId = vertexIdMap.get(edge.getTargetId()); outGraph.addEdge(sourceId, edge.getLabel(), targetId); } return outGraph; } }
/** * 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()) .aggregate(new EdgeCount()); }
@Override public void flatMap(GraphTransaction graph, Collector<WithCount<String>> out) throws Exception { Set<String> edgeLabels = Sets.newHashSet(); for (Edge edge : graph.getEdges()) { edgeLabels.add(edge.getLabel()); } for (String label : edgeLabels) { reuseTuple.setObject(label); out.collect(reuseTuple); } } }
/** * Returns set of all edges with the given label. * * @param transaction the graph transaction containing the edges * @param label the label to be searched on * @return set of edges with the given label */ private Set<Edge> getEdgesByLabel(GraphTransaction transaction, String label) { Set<Edge> edges = Sets.newHashSet(); for (Edge edge : transaction.getEdges()) { if (edge.getLabel().equals(label)) { edges.add(edge); } } return edges; }
@Override public PropertyValue getEdgeIncrement(Edge edge) { return PropertyValue.create(edge.getLabel().equals(label)); }
@Override public IdWithLabel map(E edge) throws Exception { reuseTuple.setId(edge.getSourceId()); reuseTuple.setLabel(edge.getLabel()); return reuseTuple; } }
@Override public void flatMap(GraphTransaction graphTransaction, Collector<String> collector) throws Exception { for (Edge edge : graphTransaction.getEdges()) { collector.collect(edge.getLabel()); } } }