Gremlin graph traversal that uses previous edge property value to filter later edges












6















In a graph traversal I only want to consider edges that have a property that is equal to the property of one of the edges visited in a previous step in the traversal.



I found http://tinkerpop.apache.org/docs/current/recipes/#traversal-induced-values but this appears to only work for a single object, in my case I need the value to change as I traverse. For example starting at V1 that has the outbound edges (E1, E2, E3...) I want to traverse out E1 to V2 and then traverse along any edge from V2 where edge.property(x) == E1.property(x), and do the same for all edges out of V1 (E2, E3, ...)



I can't find any documentation that supports a way to do this in Gremlin, is it possible?










share|improve this question





























    6















    In a graph traversal I only want to consider edges that have a property that is equal to the property of one of the edges visited in a previous step in the traversal.



    I found http://tinkerpop.apache.org/docs/current/recipes/#traversal-induced-values but this appears to only work for a single object, in my case I need the value to change as I traverse. For example starting at V1 that has the outbound edges (E1, E2, E3...) I want to traverse out E1 to V2 and then traverse along any edge from V2 where edge.property(x) == E1.property(x), and do the same for all edges out of V1 (E2, E3, ...)



    I can't find any documentation that supports a way to do this in Gremlin, is it possible?










    share|improve this question



























      6












      6








      6


      2






      In a graph traversal I only want to consider edges that have a property that is equal to the property of one of the edges visited in a previous step in the traversal.



      I found http://tinkerpop.apache.org/docs/current/recipes/#traversal-induced-values but this appears to only work for a single object, in my case I need the value to change as I traverse. For example starting at V1 that has the outbound edges (E1, E2, E3...) I want to traverse out E1 to V2 and then traverse along any edge from V2 where edge.property(x) == E1.property(x), and do the same for all edges out of V1 (E2, E3, ...)



      I can't find any documentation that supports a way to do this in Gremlin, is it possible?










      share|improve this question
















      In a graph traversal I only want to consider edges that have a property that is equal to the property of one of the edges visited in a previous step in the traversal.



      I found http://tinkerpop.apache.org/docs/current/recipes/#traversal-induced-values but this appears to only work for a single object, in my case I need the value to change as I traverse. For example starting at V1 that has the outbound edges (E1, E2, E3...) I want to traverse out E1 to V2 and then traverse along any edge from V2 where edge.property(x) == E1.property(x), and do the same for all edges out of V1 (E2, E3, ...)



      I can't find any documentation that supports a way to do this in Gremlin, is it possible?







      gremlin graph-traversal






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 20 '16 at 22:37







      Chris Reeves

















      asked Oct 20 '16 at 22:18









      Chris ReevesChris Reeves

      313




      313
























          1 Answer
          1






          active

          oldest

          votes


















          6














          We can use the modern toy graph that ships with TinkerPop:



          gremlin> graph = TinkerFactory.createModern()
          ==>tinkergraph[vertices:6 edges:6]
          gremlin> g = graph.traversal()
          ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]


          This graph already contains 6 edges of which two have a weight of 1.0:



          gremlin> g.E().valueMap()
          ==>[weight:0.5]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:0.2]


          We use one of these two edges with a weight of 1.0 to get the other edge with the same weight. By traversing the first of these two edges, we land at a vertex that has two outgoing edges:



          gremlin> g.V(1).outE().has('weight',1.0).inV().outE()
          ==>e[10][4-created->5]
          ==>e[11][4-created->3]
          gremlin> g.V(1).outE().has('weight',1.0).inV().outE().valueMap()
          ==>[weight:1.0]
          ==>[weight:0.4]


          One of these edges is the other one with the weight of 1.0. So, we only have to filter these edges based on the weight of the first edge:



          gremlin> g.V(1).outE().has('weight',1.0).
          as('firstEdge'). // save the first edge
          inV().outE().
          where(eq('firstEdge')). // compare with the first edge
          by('weight') // use only the 'weight' property for the equality check
          ==>e[10][4-created->5]





          share|improve this answer





















          • 1





            Is there any way to accomplish this without the match() step? Microsoft Azure's CosmosDB supports the gremlin query language, expect it can't handle the match() step yet :(

            – SnoopDougg
            Nov 14 '18 at 14:08











          • Thanks for asking about the match() step. While reading my answer again, I noticed that it isn't really necessary to use match() here. I edited my answer to solve the problem without using match() which makes it much more readable in my opinion.

            – Florian Hockmann
            Nov 21 '18 at 17:00











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40165426%2fgremlin-graph-traversal-that-uses-previous-edge-property-value-to-filter-later-e%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6














          We can use the modern toy graph that ships with TinkerPop:



          gremlin> graph = TinkerFactory.createModern()
          ==>tinkergraph[vertices:6 edges:6]
          gremlin> g = graph.traversal()
          ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]


          This graph already contains 6 edges of which two have a weight of 1.0:



          gremlin> g.E().valueMap()
          ==>[weight:0.5]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:0.2]


          We use one of these two edges with a weight of 1.0 to get the other edge with the same weight. By traversing the first of these two edges, we land at a vertex that has two outgoing edges:



          gremlin> g.V(1).outE().has('weight',1.0).inV().outE()
          ==>e[10][4-created->5]
          ==>e[11][4-created->3]
          gremlin> g.V(1).outE().has('weight',1.0).inV().outE().valueMap()
          ==>[weight:1.0]
          ==>[weight:0.4]


          One of these edges is the other one with the weight of 1.0. So, we only have to filter these edges based on the weight of the first edge:



          gremlin> g.V(1).outE().has('weight',1.0).
          as('firstEdge'). // save the first edge
          inV().outE().
          where(eq('firstEdge')). // compare with the first edge
          by('weight') // use only the 'weight' property for the equality check
          ==>e[10][4-created->5]





          share|improve this answer





















          • 1





            Is there any way to accomplish this without the match() step? Microsoft Azure's CosmosDB supports the gremlin query language, expect it can't handle the match() step yet :(

            – SnoopDougg
            Nov 14 '18 at 14:08











          • Thanks for asking about the match() step. While reading my answer again, I noticed that it isn't really necessary to use match() here. I edited my answer to solve the problem without using match() which makes it much more readable in my opinion.

            – Florian Hockmann
            Nov 21 '18 at 17:00
















          6














          We can use the modern toy graph that ships with TinkerPop:



          gremlin> graph = TinkerFactory.createModern()
          ==>tinkergraph[vertices:6 edges:6]
          gremlin> g = graph.traversal()
          ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]


          This graph already contains 6 edges of which two have a weight of 1.0:



          gremlin> g.E().valueMap()
          ==>[weight:0.5]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:0.2]


          We use one of these two edges with a weight of 1.0 to get the other edge with the same weight. By traversing the first of these two edges, we land at a vertex that has two outgoing edges:



          gremlin> g.V(1).outE().has('weight',1.0).inV().outE()
          ==>e[10][4-created->5]
          ==>e[11][4-created->3]
          gremlin> g.V(1).outE().has('weight',1.0).inV().outE().valueMap()
          ==>[weight:1.0]
          ==>[weight:0.4]


          One of these edges is the other one with the weight of 1.0. So, we only have to filter these edges based on the weight of the first edge:



          gremlin> g.V(1).outE().has('weight',1.0).
          as('firstEdge'). // save the first edge
          inV().outE().
          where(eq('firstEdge')). // compare with the first edge
          by('weight') // use only the 'weight' property for the equality check
          ==>e[10][4-created->5]





          share|improve this answer





















          • 1





            Is there any way to accomplish this without the match() step? Microsoft Azure's CosmosDB supports the gremlin query language, expect it can't handle the match() step yet :(

            – SnoopDougg
            Nov 14 '18 at 14:08











          • Thanks for asking about the match() step. While reading my answer again, I noticed that it isn't really necessary to use match() here. I edited my answer to solve the problem without using match() which makes it much more readable in my opinion.

            – Florian Hockmann
            Nov 21 '18 at 17:00














          6












          6








          6







          We can use the modern toy graph that ships with TinkerPop:



          gremlin> graph = TinkerFactory.createModern()
          ==>tinkergraph[vertices:6 edges:6]
          gremlin> g = graph.traversal()
          ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]


          This graph already contains 6 edges of which two have a weight of 1.0:



          gremlin> g.E().valueMap()
          ==>[weight:0.5]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:0.2]


          We use one of these two edges with a weight of 1.0 to get the other edge with the same weight. By traversing the first of these two edges, we land at a vertex that has two outgoing edges:



          gremlin> g.V(1).outE().has('weight',1.0).inV().outE()
          ==>e[10][4-created->5]
          ==>e[11][4-created->3]
          gremlin> g.V(1).outE().has('weight',1.0).inV().outE().valueMap()
          ==>[weight:1.0]
          ==>[weight:0.4]


          One of these edges is the other one with the weight of 1.0. So, we only have to filter these edges based on the weight of the first edge:



          gremlin> g.V(1).outE().has('weight',1.0).
          as('firstEdge'). // save the first edge
          inV().outE().
          where(eq('firstEdge')). // compare with the first edge
          by('weight') // use only the 'weight' property for the equality check
          ==>e[10][4-created->5]





          share|improve this answer















          We can use the modern toy graph that ships with TinkerPop:



          gremlin> graph = TinkerFactory.createModern()
          ==>tinkergraph[vertices:6 edges:6]
          gremlin> g = graph.traversal()
          ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]


          This graph already contains 6 edges of which two have a weight of 1.0:



          gremlin> g.E().valueMap()
          ==>[weight:0.5]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:1.0]
          ==>[weight:0.4]
          ==>[weight:0.2]


          We use one of these two edges with a weight of 1.0 to get the other edge with the same weight. By traversing the first of these two edges, we land at a vertex that has two outgoing edges:



          gremlin> g.V(1).outE().has('weight',1.0).inV().outE()
          ==>e[10][4-created->5]
          ==>e[11][4-created->3]
          gremlin> g.V(1).outE().has('weight',1.0).inV().outE().valueMap()
          ==>[weight:1.0]
          ==>[weight:0.4]


          One of these edges is the other one with the weight of 1.0. So, we only have to filter these edges based on the weight of the first edge:



          gremlin> g.V(1).outE().has('weight',1.0).
          as('firstEdge'). // save the first edge
          inV().outE().
          where(eq('firstEdge')). // compare with the first edge
          by('weight') // use only the 'weight' property for the equality check
          ==>e[10][4-created->5]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 16:59

























          answered Oct 21 '16 at 7:24









          Florian HockmannFlorian Hockmann

          1,439717




          1,439717








          • 1





            Is there any way to accomplish this without the match() step? Microsoft Azure's CosmosDB supports the gremlin query language, expect it can't handle the match() step yet :(

            – SnoopDougg
            Nov 14 '18 at 14:08











          • Thanks for asking about the match() step. While reading my answer again, I noticed that it isn't really necessary to use match() here. I edited my answer to solve the problem without using match() which makes it much more readable in my opinion.

            – Florian Hockmann
            Nov 21 '18 at 17:00














          • 1





            Is there any way to accomplish this without the match() step? Microsoft Azure's CosmosDB supports the gremlin query language, expect it can't handle the match() step yet :(

            – SnoopDougg
            Nov 14 '18 at 14:08











          • Thanks for asking about the match() step. While reading my answer again, I noticed that it isn't really necessary to use match() here. I edited my answer to solve the problem without using match() which makes it much more readable in my opinion.

            – Florian Hockmann
            Nov 21 '18 at 17:00








          1




          1





          Is there any way to accomplish this without the match() step? Microsoft Azure's CosmosDB supports the gremlin query language, expect it can't handle the match() step yet :(

          – SnoopDougg
          Nov 14 '18 at 14:08





          Is there any way to accomplish this without the match() step? Microsoft Azure's CosmosDB supports the gremlin query language, expect it can't handle the match() step yet :(

          – SnoopDougg
          Nov 14 '18 at 14:08













          Thanks for asking about the match() step. While reading my answer again, I noticed that it isn't really necessary to use match() here. I edited my answer to solve the problem without using match() which makes it much more readable in my opinion.

          – Florian Hockmann
          Nov 21 '18 at 17:00





          Thanks for asking about the match() step. While reading my answer again, I noticed that it isn't really necessary to use match() here. I edited my answer to solve the problem without using match() which makes it much more readable in my opinion.

          – Florian Hockmann
          Nov 21 '18 at 17:00




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40165426%2fgremlin-graph-traversal-that-uses-previous-edge-property-value-to-filter-later-e%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini