Github user dkuppitz commented on a diff in the pull request:

    https://github.com/apache/tinkerpop/pull/531#discussion_r95639012
  
    --- Diff: docs/src/recipes/duplicate-edge.asciidoc ---
    @@ -0,0 +1,142 @@
    +////
    +Licensed to the Apache Software Foundation (ASF) under one or more
    +contributor license agreements.  See the NOTICE file distributed with
    +this work for additional information regarding copyright ownership.
    +The ASF licenses this file to You under the Apache License, Version 2.0
    +(the "License"); you may not use this file except in compliance with
    +the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +////
    +[[duplicate-edge]]
    +Duplicate Edge Detection
    +------------------------
    +
    +Whether part of a graph maintenance process or for some other analysis 
need, it is sometimes necessary to detect
    +if there is more than one edge between two vertices. The following 
examples will assume that an edge with the same
    +label and direction will be considered "duplicate".
    +
    +The "modern" graph does not have any duplicate edges that fit that 
definition, so the following example adds one
    +that is duplicative of the "created" edge between vertex "1" and "3".
    +
    +[gremlin-groovy,modern]
    +----
    +g.V(1).as("a").V(3).addE("created").from("a").iterate()
    +g.V(1).outE("created")
    +----
    +
    +One way to find the duplicate edges would be to do something like this:
    +
    +[gremlin-groovy,existing]
    +----
    +g.V().outE().
    +  project("a","b").                         <1>
    +    by().by(inV().path().by().by(label)).
    +  group().                                  <2>
    +    by(select("b")).
    +    by(select("a").fold()).
    +  unfold().                                 <3>
    +  select(values).                           <4>
    +  where(count(local).is(gt(1)))
    +----
    +
    +<1> The "a" and "b" from the `project` contain the edge and the path 
respectively. The path consists of a the outgoing
    +vertex, an edge, and the incoming vertex. The use of `by().by(label))` 
converts the edge to its label (recall that `by`
    +are applied in round-robin fashion), so the path will look something like: 
`[v[1],created,v[3]]`.
    +<2> Group by the path from "b" and construct a list of edges from "a". Any 
value in this `Map` that has a list of edges
    +greater than one means that there is more than one edge for that edge 
label between those two vertices (i.e. the `Map`
    +key).
    +<3> Unroll the key-value pairs in the `Map` of paths-edges.
    +<4> Only the values from the `Map` are needed and as mentioned earlier, 
those lists with more than one edge would
    +containa  duplicate.
    +
    +This method find the duplicates, but does require more memory than other 
approaches. A slightly more complex approach
    +that uses less memory might look like this:
    +
    +[gremlin-groovy,existing]
    +----
    +g.V().as("ov").
    --- End diff --
    
    Go home.........


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to