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 2016/06/08 20:32:03 UTC

[8/8] incubator-tinkerpop git commit: if there is no edge label in the GraphML file, then use Edge.DEFAULT

if there is no edge label in the GraphML file, then use Edge.DEFAULT


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/dea0b622
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/dea0b622
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/dea0b622

Branch: refs/heads/graphml-no-edge-label
Commit: dea0b6223ecff547da3535ba3a34a012ad7b3841
Parents: 8753407
Author: Serge Vilvovsky <se...@ll.mit.edu>
Authored: Tue Jun 7 13:17:55 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jun 8 16:30:10 2016 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../structure/io/graphml/GraphMLReader.java     |  3 +-
 .../tinkerpop/gremlin/structure/io/IoTest.java  | 40 ++++++++++++++++++++
 .../io/graphml/tinkerpop-no-edge-labels.xml     | 25 ++++++++++++
 4 files changed, 68 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/dea0b622/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 10f91a0..3cad6ad 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -1247,6 +1247,7 @@ TinkerPop 3.0.0.M2 (Release Date: September 23, 2014)
 * Moved `GiraphGraph.getOutputGraph()` to `GiraphHelper`.
 * Changed `GIRAPH_GREMLIN_HOME` to `GIRAPH_GREMLIN_LIB` to reference directory where jars are to be loaded.
 * Updated README with release instructions.
+* if there is no edge label in the GraphML file, then use Edge.DEFAULT
 
 TinkerPop 3.0.0.M1 (Release Date: August 12, 2014)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/dea0b622/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
index d45d411..e161ba7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLReader.java
@@ -187,7 +187,8 @@ public final class GraphMLReader implements GraphReader {
                     } else if (elementName.equals(GraphMLTokens.EDGE)) {
                         final Object[] propsAsArray = edgeProps.entrySet().stream().flatMap(e -> Stream.of(e.getKey(), e.getValue())).toArray();
                         final Object[] propsReady = edgeFeatures.willAllowId(edgeId) ? ElementHelper.upsert(propsAsArray, T.id, edgeId) : propsAsArray;
-                        edgeOutVertex.addEdge(edgeLabel, edgeInVertex, propsReady);
+                        
+			edgeOutVertex.addEdge(null == edgeLabel ? Edge.DEFAULT_LABEL : edgeLabel, edgeInVertex, propsReady);
 
                         if (supportsTx && counter.incrementAndGet() % batchSize == 0)
                             graphToWriteTo.tx().commit();

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/dea0b622/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 2bf0485..2673f4d 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
@@ -112,6 +112,17 @@ public class IoTest {
         @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES)
         @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES)
         @FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES)
+        public void shouldReadGraphMLWithNoEdgeLabels() throws IOException {
+            readGraphMLIntoGraph(graph, "tinkerpop-no-edge-labels.xml");
+            assertNoEdgeGraph(graph, false, true);
+        }
+
+        @Test
+        @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+        @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+        @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES)
+        @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES)
+        @FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES)
         public void shouldReadGraphMLUnorderedElements() throws IOException {
             readGraphMLIntoGraph(graph, "tinkerpop-classic-unordered.xml");
             assertClassicGraph(graph, false, true);
@@ -724,6 +735,35 @@ public class IoTest {
         assertToyGraph(g1, assertDouble, lossyForId, false);
     }
 
+    public static void assertNoEdgeGraph(final Graph g1, final boolean assertDouble, final boolean lossyForId) {
+        assertEquals(2, IteratorUtils.count(g1.vertices()));
+        assertEquals(1, IteratorUtils.count(g1.edges()));
+
+        final Vertex v1 = g1.traversal().V().has("name", "marko").next();
+        assertEquals(29, v1.<Integer>value("age").intValue());
+        assertEquals(2, v1.keys().size());
+        assertEquals(Vertex.DEFAULT_LABEL, v1.label());
+        assertId(g1, lossyForId, v1, 1);
+
+        final List<Edge> v1Edges = IteratorUtils.list(v1.edges(Direction.BOTH));
+        assertEquals(1, v1Edges.size());
+        v1Edges.forEach(e -> {
+        	System.out.println("SERGE: e.inVertex().value(\"name\") : " + e.inVertex().value("name").equals("vadas"));
+
+            if (e.inVertex().value("name").equals("vadas")) {
+                assertEquals(Edge.DEFAULT_LABEL, e.label());
+                if (assertDouble)
+                    assertWeightLoosely(0.5d, e);
+                else
+                    assertWeightLoosely(0.5f, e);
+                assertEquals(1, e.keys().size());
+                assertId(g1, lossyForId, e, 7);
+            } else {
+                fail("Edge not expected");
+            }
+        });
+    }
+
     public static void assertModernGraph(final Graph g1, final boolean assertDouble, final boolean lossyForId) {
         assertToyGraph(g1, assertDouble, lossyForId, true);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/dea0b622/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-no-edge-labels.xml
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-no-edge-labels.xml b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-no-edge-labels.xml
new file mode 100644
index 0000000..feba7d4
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-no-edge-labels.xml
@@ -0,0 +1,25 @@
+<?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="labelV" for="node" attr.name="labelV" attr.type="string"></key>
+	<key id="name" for="node" attr.name="name" attr.type="string"></key>
+	<key id="lang" for="node" attr.name="lang" attr.type="string"></key>
+	<key id="age" for="node" attr.name="age" attr.type="int"></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="name">marko</data>
+			<data key="age">29</data>
+		</node>
+		<node id="2">
+			<data key="labelV">vertex</data>
+			<data key="name">vadas</data>
+			<data key="age">27</data>
+		</node>
+		<edge id="7" source="1" target="2">
+			<data key="weight">0.5</data>
+		</edge>
+	</graph>
+</graphml>