You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/08/28 18:08:47 UTC
[2/4] tinkerpop git commit: TINKERPOP-2006 Fixing GraphML
serialization with similar named property for edge and vertex
TINKERPOP-2006 Fixing GraphML serialization with similar named property for edge and vertex
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/41f2ab8a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/41f2ab8a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/41f2ab8a
Branch: refs/heads/master
Commit: 41f2ab8a5cd6bdb60a195489fce38ef38baaf232
Parents: cfc7ece
Author: Svante Schubert <Sv...@gmail.com>
Authored: Thu Aug 2 15:33:04 2018 +0200
Committer: Svante Schubert <Sv...@gmail.com>
Committed: Thu Aug 2 15:33:04 2018 +0200
----------------------------------------------------------------------
.../structure/io/graphml/GraphMLWriter.java | 44 ++++++++++----------
.../tinkerpop/gremlin/structure/io/IoTest.java | 8 +++-
.../io/graphml/tinkerpop-classic-normalized.xml | 4 ++
3 files changed, 33 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41f2ab8a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
index 26c5760..53c5c12 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
@@ -68,8 +68,8 @@ public final class GraphMLWriter implements GraphWriter {
private Collection<String> intersection;
private GraphMLWriter(final boolean normalize, final Map<String, String> vertexKeyTypes,
- final Map<String, String> edgeKeyTypes, final String xmlSchemaLocation,
- final String edgeLabelKey, final String vertexLabelKey) {
+ final Map<String, String> edgeKeyTypes, final String xmlSchemaLocation,
+ final String edgeLabelKey, final String vertexLabelKey) {
this.normalize = normalize;
this.vertexKeyTypes = Optional.ofNullable(vertexKeyTypes);
this.edgeKeyTypes = Optional.ofNullable(edgeKeyTypes);
@@ -214,25 +214,25 @@ public final class GraphMLWriter implements GraphWriter {
return writer;
} else
return utf8Writer;
- }
+ }
private void writeTypes(final Map<String, String> identifiedVertexKeyTypes,
- final Map<String, String> identifiedEdgeKeyTypes,
- final XMLStreamWriter writer) throws XMLStreamException {
+ final Map<String, String> identifiedEdgeKeyTypes,
+ final XMLStreamWriter writer) throws XMLStreamException {
// <key id="weight" for="edge" attr.name="weight" attr.type="float"/>
- Collection<String> vertexKeySet = getVertexKeysAndNormalizeIfRequired(identifiedVertexKeyTypes);
- Collection<String> edgeKeySet = getEdgeKeysAndNormalizeIfRequired(identifiedEdgeKeyTypes);
+ final Collection<String> vertexKeySet = getVertexKeysAndNormalizeIfRequired(identifiedVertexKeyTypes);
+ final Collection<String> edgeKeySet = getEdgeKeysAndNormalizeIfRequired(identifiedEdgeKeyTypes);
// in case vertex and edge may have the same attribute name, the key id in graphml have to be different
intersection = CollectionUtils.intersection(vertexKeySet, edgeKeySet);
// speeding-up later checks
- if(intersection.isEmpty()){
+ if (intersection.isEmpty()) {
intersection = null;
}
for (String key : vertexKeySet) {
writer.writeStartElement(GraphMLTokens.KEY);
- if(intersection != null && intersection.contains(key)){
+ if (intersection != null && intersection.contains(key)) {
writer.writeAttribute(GraphMLTokens.ID, key.concat(GraphMLTokens.VERTEX_SUFFIX));
- }else{
+ } else {
writer.writeAttribute(GraphMLTokens.ID, key);
}
writer.writeAttribute(GraphMLTokens.FOR, GraphMLTokens.NODE);
@@ -242,9 +242,9 @@ public final class GraphMLWriter implements GraphWriter {
}
for (String key : edgeKeySet) {
writer.writeStartElement(GraphMLTokens.KEY);
- if(intersection != null && intersection.contains(key)){
+ if (intersection != null && intersection.contains(key)) {
writer.writeAttribute(GraphMLTokens.ID, key.concat(GraphMLTokens.EDGE_SUFFIX));
- }else{
+ } else {
writer.writeAttribute(GraphMLTokens.ID, key);
}
writer.writeAttribute(GraphMLTokens.FOR, GraphMLTokens.EDGE);
@@ -275,9 +275,9 @@ public final class GraphMLWriter implements GraphWriter {
for (String key : keys) {
writer.writeStartElement(GraphMLTokens.DATA);
- if(intersection != null && intersection.contains(key)){
+ if (intersection != null && intersection.contains(key)) {
writer.writeAttribute(GraphMLTokens.KEY, key + GraphMLTokens.EDGE_SUFFIX);
- }else{
+ } else {
writer.writeAttribute(GraphMLTokens.KEY, key);
}
// technically there can't be a null here as gremlin structure forbids that occurrence even if Graph
@@ -303,9 +303,9 @@ public final class GraphMLWriter implements GraphWriter {
for (String key : edge.keys()) {
writer.writeStartElement(GraphMLTokens.DATA);
- if(intersection != null && intersection.contains(key)){
+ if (intersection != null && intersection.contains(key)) {
writer.writeAttribute(GraphMLTokens.KEY, key + GraphMLTokens.EDGE_SUFFIX);
- }else{
+ } else {
writer.writeAttribute(GraphMLTokens.KEY, key);
}
// technically there can't be a null here as gremlin structure forbids that occurrence even if Graph
@@ -332,9 +332,9 @@ public final class GraphMLWriter implements GraphWriter {
for (String key : keys) {
writer.writeStartElement(GraphMLTokens.DATA);
- if(intersection != null && intersection.contains(key)){
+ if (intersection != null && intersection.contains(key)) {
writer.writeAttribute(GraphMLTokens.KEY, key.concat(GraphMLTokens.VERTEX_SUFFIX));
- }else{
+ } else {
writer.writeAttribute(GraphMLTokens.KEY, key);
}
// technically there can't be a null here as gremlin structure forbids that occurrence even if Graph
@@ -383,7 +383,7 @@ public final class GraphMLWriter implements GraphWriter {
edgeKeySet = identifiedEdgeKeyTypes.keySet();
return edgeKeySet;
- }
+ }
private Collection<String> getVertexKeysAndNormalizeIfRequired(final Map<String, String> identifiedVertexKeyTypes) {
final Collection<String> keyset;
@@ -395,7 +395,7 @@ public final class GraphMLWriter implements GraphWriter {
keyset = identifiedVertexKeyTypes.keySet();
return keyset;
- }
+ }
private void writeXmlNsAndSchema(final XMLStreamWriter writer) throws XMLStreamException {
writer.writeAttribute(GraphMLTokens.XMLNS, GraphMLTokens.GRAPHML_XMLNS);
@@ -431,8 +431,8 @@ public final class GraphMLWriter implements GraphWriter {
for (String key : edge.keys()) {
if (!edgeKeyTypes.containsKey(key))
edgeKeyTypes.put(key, GraphMLWriter.getStringType(edge.property(key).value()));
+ }
}
- }
return edgeKeyTypes;
}
@@ -452,7 +452,7 @@ public final class GraphMLWriter implements GraphWriter {
return GraphMLTokens.BOOLEAN;
else
return GraphMLTokens.STRING;
- }
+ }
public static Builder build() {
return new Builder();
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41f2ab8a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
index 0221555..729ede7 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
@@ -98,6 +98,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat;
+
/**
* @author Joshua Shinavier (http://fortytwo.net)
* @author Stephen Mallette (http://stephen.genoprime.com)
@@ -238,8 +239,13 @@ public class IoTest {
public void shouldWriteNormalizedGraphML() throws Exception {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
final GraphMLWriter w = GraphMLWriter.build().normalize(true).create();
+ final Vertex v = graph.vertices().next();
+ // adding 'color' property to vertex
+ v.property(VertexProperty.Cardinality.single, "color", "#6495ed");
+ final Edge e = graph.edges().next();
+ // adding 'color' property to edge
+ e.property("color", "#ee0000");
w.writeGraph(bos, graph);
-
final String expected = streamToString(IoTest.class.getResourceAsStream(TestHelper.convertPackageToResourcePath(GraphMLResourceAccess.class) + "tinkerpop-classic-normalized.xml"));
assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", ""));
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41f2ab8a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-classic-normalized.xml
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-classic-normalized.xml b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-classic-normalized.xml
index 19896d9..45d63c1 100644
--- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-classic-normalized.xml
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-classic-normalized.xml
@@ -1,15 +1,18 @@
<?xml version="1.0" ?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="age" for="node" attr.name="age" attr.type="int"></key>
+ <key id="colorV" for="node" attr.name="color" attr.type="string"></key>
<key id="labelV" for="node" attr.name="labelV" attr.type="string"></key>
<key id="lang" for="node" attr.name="lang" attr.type="string"></key>
<key id="name" for="node" attr.name="name" attr.type="string"></key>
+ <key id="colorE" for="edge" attr.name="color" attr.type="string"></key>
<key id="labelE" for="edge" attr.name="labelE" attr.type="string"></key>
<key id="weight" for="edge" attr.name="weight" attr.type="float"></key>
<graph id="G" edgedefault="directed">
<node id="1">
<data key="labelV">vertex</data>
<data key="age">29</data>
+ <data key="colorV">#6495ed</data>
<data key="name">marko</data>
</node>
<node id="2">
@@ -51,6 +54,7 @@
</edge>
<edge id="7" source="1" target="2">
<data key="labelE">knows</data>
+ <data key="colorE">#ee0000</data>
<data key="weight">0.5</data>
</edge>
<edge id="8" source="1" target="4">