Skip to content
Permalink
Browse files

[#1258] Fix print for graph collections (#1259)

fixes #1258
  • Loading branch information...
timo95 authored and galpha committed May 10, 2019
1 parent 8365cb7 commit 0bbeddcd3ab5651d7078c1f7749cf06062e18f07
Showing with 29 additions and 20 deletions.
  1. +29 −20 gradoop-flink/src/main/java/org/gradoop/flink/io/impl/gdl/GDLEncoder.java
@@ -144,8 +144,8 @@ public String getGDLString() {
boolean containedInGraph = v.getGraphIds().contains(gh.getId());
boolean firstOccurrence = !usedVertexIds.contains(v.getId());

if (containedInGraph && firstOccurrence) {
String vertexString = vertexToGDLString(v, idToVertexName);
if (containedInGraph) {
String vertexString = vertexToGDLString(v, idToVertexName, firstOccurrence);
usedVertexIds.add(v.getId());
verticesString.append(vertexString).append(System.lineSeparator());
}
@@ -163,7 +163,8 @@ public String getGDLString() {
result
.append(graphHeadToGDLString(gh, idToGraphHeadName))
.append(GRAPH_ELEMENTS_DEFINITION_START).append(System.lineSeparator())
.append(verticesString).append(System.lineSeparator())
.append(verticesString)
.append(edgesString.length() > 0 ? System.lineSeparator() : "")
.append(edgesString)
.append(GRAPH_ELEMENTS_DEFINITION_END)
.append(System.lineSeparator()).append(System.lineSeparator());
@@ -237,48 +238,56 @@ private String graphHeadToGDLString(GraphHead g, Map<GradoopId, String> idToGrap
* Returns the gdl formatted vertex including the properties and the label on first occurrence
* or otherwise just the variable name.
*
* @param v The vertex that should be formatted.
* @param vertex The vertex that should be formatted.
* @param idToVertexName Maps GradoopId of a vertex to a string that represents the gdl
* variable name
* @param firstOccurrence Is it the first occurrence of the vertex in all graphs?
* @return A GDL formatted vertex string.
*/
private String vertexToGDLString(Vertex v, Map<GradoopId, String> idToVertexName) {
return String.format("(%s:%s %s)",
idToVertexName.get(v.getId()),
v.getLabel(),
propertiesToGDLString(v.getProperties()));
private String vertexToGDLString(
Vertex vertex,
Map<GradoopId, String> idToVertexName,
boolean firstOccurrence) {
if (firstOccurrence) {
return String.format("(%s:%s %s)",
idToVertexName.get(vertex.getId()),
vertex.getLabel(),
propertiesToGDLString(vertex.getProperties()));
} else {
return String.format("(%s)", idToVertexName.get(vertex.getId()));
}
}

/**
* Returns the GDL formatted edge, including the properties and the label on first occurrence
* or otherwise just the variable name.
*
* @param e The edge to be formatted.
* @param edge The edge to be formatted.
* @param idToVertexName Maps GradoopId of a vertex to a string that represents the GDL
* variable name
* @param idToEdgeName Maps GradoopId of an edge to a string that represents the GDL variable
* name.
* @param firstOccurrence Is it the first occurrence of the vertex in all graphs?
* @param firstOccurrence Is it the first occurrence of the edge in all graphs?
* @return A GDL formatted edge string.
*/
private String edgeToGDLString(
Edge e,
Edge edge,
Map<GradoopId, String> idToVertexName,
Map<GradoopId, String> idToEdgeName,
boolean firstOccurrence) {
String result;
if (firstOccurrence) {
result = String.format("(%s)-[%s:%s%s]->(%s)",
idToVertexName.get(e.getSourceId()),
idToEdgeName.get(e.getId()),
e.getLabel(),
propertiesToGDLString(e.getProperties()),
idToVertexName.get(e.getTargetId()));
idToVertexName.get(edge.getSourceId()),
idToEdgeName.get(edge.getId()),
edge.getLabel(),
propertiesToGDLString(edge.getProperties()),
idToVertexName.get(edge.getTargetId()));
} else {
result = String.format("(%s)-[%s]->(%s)",
idToVertexName.get(e.getSourceId()),
idToEdgeName.get(e.getId()),
idToVertexName.get(e.getTargetId()));
idToVertexName.get(edge.getSourceId()),
idToEdgeName.get(edge.getId()),
idToVertexName.get(edge.getTargetId()));
}
return result;
}

0 comments on commit 0bbeddc

Please sign in to comment.
You can’t perform that action at this time.