@Override public boolean filter(Tuple2<GradoopId, Edge> value) throws Exception { return value.f1.getGraphIds().contains(value.f0); } }
@Override public boolean filter(Tuple2<GradoopId, Edge> value) throws Exception { return value.f1.getGraphIds().contains(value.f0); } }
@Override public void flatMap( E e, Collector<Tuple2<GradoopId, GradoopIdSet>> collector) throws Exception { collector.collect(new Tuple2<>(e.getSourceId(), e.getGraphIds())); collector.collect(new Tuple2<>(e.getTargetId(), e.getGraphIds())); } }
@Override public void flatMap( E e, Collector<Tuple2<GradoopId, GradoopIdSet>> collector) throws Exception { collector.collect(new Tuple2<>(e.getSourceId(), e.getGraphIds())); collector.collect(new Tuple2<>(e.getTargetId(), e.getGraphIds())); } }
@Override public void flatMap(Edge edge, Collector<EdgeString> collector) throws Exception { GradoopId sourceId = edge.getSourceId(); GradoopId targetId = edge.getTargetId(); String edgeLabel = "[" + label(edge) + "]"; for (GradoopId graphId : edge.getGraphIds()) { collector.collect(new EdgeString(graphId, sourceId, targetId, edgeLabel)); } } }
@Override public void flatMap(Edge edge, Collector<EdgeString> collector) throws Exception { GradoopId sourceId = edge.getSourceId(); GradoopId targetId = edge.getTargetId(); String edgeLabel = "[" + edge.getId() + "]"; for (GradoopId graphId : edge.getGraphIds()) { collector.collect(new EdgeString(graphId, sourceId, targetId, edgeLabel)); } } }
@Override public void flatMap(Edge edge, Collector<EdgeString> collector) throws Exception { GradoopId sourceId = edge.getSourceId(); GradoopId targetId = edge.getTargetId(); String edgeLabel = "[" + edge.getId() + "]"; for (GradoopId graphId : edge.getGraphIds()) { collector.collect(new EdgeString(graphId, sourceId, targetId, edgeLabel)); } } }
@Override public void flatMap( E edge, Collector<Tuple4<GradoopId, GradoopId, GradoopId, GradoopId>> collector) { for (GradoopId graphId : edge.getGraphIds()) { collector.collect(new Tuple4<>( edge.getId(), edge.getSourceId(), edge.getTargetId(), graphId)); } } }
@Override public void flatMap(Edge edge, Collector<EdgeString> collector) throws Exception { GradoopId sourceId = edge.getSourceId(); GradoopId targetId = edge.getTargetId(); String edgeLabel = "[" + label(edge) + "]"; for (GradoopId graphId : edge.getGraphIds()) { collector.collect(new EdgeString(graphId, sourceId, targetId, edgeLabel)); } } }
@Override public void flatMap( E edge, Collector<Tuple4<GradoopId, GradoopId, GradoopId, GradoopId>> collector) { for (GradoopId graphId : edge.getGraphIds()) { collector.collect(new Tuple4<>( edge.getId(), edge.getSourceId(), edge.getTargetId(), graphId)); } } }
@Override public void flatMap( Tuple3<E, GradoopIdSet, GradoopIdSet> triple, Collector<E> collector) { GradoopIdSet sourceGraphs = triple.f1; GradoopIdSet targetGraphs = triple.f2; GradoopIdSet graphsToBeAdded = new GradoopIdSet(); boolean filter = false; for (GradoopId id : sourceGraphs) { if (targetGraphs.contains(id)) { graphsToBeAdded.add(id); filter = true; } } if (filter) { E edge = triple.f0; edge.getGraphIds().addAll(graphsToBeAdded); collector.collect(edge); } } }
@Override public void flatMap( Tuple3<E, GradoopIdSet, GradoopIdSet> triple, Collector<E> collector) { GradoopIdSet sourceGraphs = triple.f1; GradoopIdSet targetGraphs = triple.f2; GradoopIdSet graphsToBeAdded = new GradoopIdSet(); boolean filter = false; for (GradoopId id : sourceGraphs) { if (targetGraphs.contains(id)) { graphsToBeAdded.add(id); filter = true; } } if (filter) { E edge = triple.f0; edge.getGraphIds().addAll(graphsToBeAdded); collector.collect(edge); } } }
@Override public GraphTransaction map(GraphTransaction transaction) throws Exception { if (graphHeadTransFunc != null) { transaction.setGraphHead(graphHeadTransFunc.apply( transaction.getGraphHead(), graphHeadFactory.initGraphHead( transaction.getGraphHead().getId(), GradoopConstants.DEFAULT_GRAPH_LABEL))); } if (vertexTransFunc != null) { transaction.setVertices(transaction.getVertices().stream() .map(vertex -> vertexTransFunc.apply( vertex, vertexFactory.initVertex( vertex.getId(), GradoopConstants.DEFAULT_VERTEX_LABEL, vertex.getGraphIds()))) .collect(Collectors.toSet())); } if (edgeTransFunc != null) { transaction.setEdges(transaction.getEdges().stream() .map(edge -> edgeTransFunc.apply( edge, edgeFactory.initEdge( edge.getId(), GradoopConstants.DEFAULT_EDGE_LABEL, edge.getSourceId(), edge.getTargetId(), edge.getGraphIds()))) .collect(Collectors.toSet())); } return transaction; } }
@Override public Tuple2<GradoopIdSet, TripleWithCandidates<GradoopId>> map(E e) throws Exception { reuseTuple.f0 = e.getGraphIds(); reuseTuple.f1.setEdgeId(e.getId()); reuseTuple.f1.setSourceId(e.getSourceId()); reuseTuple.f1.setTargetId(e.getTargetId()); reuseTuple.f1.setCandidates(getCandidates(edgeCount, ElementMatcher.getMatches(e, queryEdges, DEFAULT_EDGE_LABEL))); return reuseTuple; } }
@Override public Tuple2<GradoopIdSet, TripleWithCandidates<GradoopId>> map(E e) throws Exception { reuseTuple.f0 = e.getGraphIds(); reuseTuple.f1.setEdgeId(e.getId()); reuseTuple.f1.setSourceId(e.getSourceId()); reuseTuple.f1.setTargetId(e.getTargetId()); reuseTuple.f1.setCandidates(getCandidates(edgeCount, ElementMatcher.getMatches(e, queryEdges, DEFAULT_EDGE_LABEL))); return reuseTuple; } }
@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); } } }
@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); } } }
@Override public CSVEdge map(Edge edge) throws Exception { csvEdge.setId(edge.getId().toString()); csvEdge.setGradoopIds(collectionToCsvString(edge.getGraphIds())); csvEdge.setSourceId(edge.getSourceId().toString()); csvEdge.setTargetId(edge.getTargetId().toString()); csvEdge.setLabel(StringEscaper.escape(edge.getLabel(), CSVConstants.ESCAPED_CHARACTERS)); csvEdge.setProperties(getPropertyString(edge, MetaDataSource.EDGE_TYPE)); return csvEdge; } }
@Override public CSVEdge map(Edge edge) throws Exception { csvEdge.setId(edge.getId().toString()); csvEdge.setGradoopIds(collectionToCsvString(edge.getGraphIds())); csvEdge.setSourceId(edge.getSourceId().toString()); csvEdge.setTargetId(edge.getTargetId().toString()); csvEdge.setLabel(StringEscaper.escape(edge.getLabel(), CSVConstants.ESCAPED_CHARACTERS)); csvEdge.setProperties(getPropertyString(edge, MetaDataSource.EDGE_TYPE)); return csvEdge; } }
@Test public void testUpdateFromStringWithVariables2() { AsciiGraphLoader<GraphHead, Vertex, Edge> asciiGraphLoader = AsciiGraphLoader.fromString("g[(a)-[e]->(b)]", config); validateCollections(asciiGraphLoader, 1, 2, 1); validateCaches(asciiGraphLoader, 1, 2, 1); asciiGraphLoader.appendFromString("g[(a)-[f]->(c)]"); validateCollections(asciiGraphLoader, 1, 3, 2); validateCaches(asciiGraphLoader, 1, 3, 2); GraphHead g = asciiGraphLoader.getGraphHeadByVariable("g"); Vertex c = asciiGraphLoader.getVertexByVariable("c"); Edge f = asciiGraphLoader.getEdgeByVariable("f"); assertTrue("Vertex not in graph", c.getGraphIds().contains(g.getId())); assertTrue("Edge not in graph", f.getGraphIds().contains(g.getId())); }