Ignoring a property within Cypher Query OR alternative: how count relationship sequences





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















the following Cypher statements give me the graph output (see image) below the code. And also the text output below the image. My problem is the text output.



I will try to explain the problem clearly: I am interested in the same sequences of two nodes, with respect to a specific property (here: personName). E.g. as you can see in the picture (or from the create statement) Bob comes after May twice. I wanted to capture this via apoc.coll.frequencies(pairsOfActs) AS giveBackFrequencyOfPairs
RETURN giveBackFrequencyOfPairs. However, the 'time' property is in the way. Is there a way to ignore the time property? I have been trying with operations on lists and also with deleting the time property (then my sequence is gone), but nothing is working. Any suggestions? Or is this approach wrong entirely, or is there even a predefined function for counting specific node sequences that I am missing?



CREATE
(a: Action {personName: 'Tom', time: 1}),
(b: Action {personName: 'May', time: 2}),
(c: Action {personName: 'Bob', time: 3}),
(d: Action {personName: 'Alex', time: 4}),
(e: Action {personName: 'Zac', time: 5}),
(f: Action {personName: 'Jill', time: 6}),
(g: Action {personName: 'May', time: 7}),
(h: Action {personName: 'Bob', time: 8})


MATCH (act: Action)
WITH act ORDER BY act.time ASC
WITH COLLECT(act) AS acts
FOREACH (n IN RANGE(0, size(acts)-2) |
FOREACH (curr IN [acts[n]] |
FOREACH (next IN [acts[n+1]] |
MERGE (curr)-[:NEXT]-> (next))))
WITH apoc.coll.pairsMin(acts) as pairsOfActs
UNWIND pairsOfActs as unwoundPairsOfActs
WITH apoc.coll.frequencies(unwoundPairsOfActs) AS giveBackFrequencyOfPairs
RETURN giveBackFrequencyOfPairs


enter image description hereenter image description here










share|improve this question































    0















    the following Cypher statements give me the graph output (see image) below the code. And also the text output below the image. My problem is the text output.



    I will try to explain the problem clearly: I am interested in the same sequences of two nodes, with respect to a specific property (here: personName). E.g. as you can see in the picture (or from the create statement) Bob comes after May twice. I wanted to capture this via apoc.coll.frequencies(pairsOfActs) AS giveBackFrequencyOfPairs
    RETURN giveBackFrequencyOfPairs. However, the 'time' property is in the way. Is there a way to ignore the time property? I have been trying with operations on lists and also with deleting the time property (then my sequence is gone), but nothing is working. Any suggestions? Or is this approach wrong entirely, or is there even a predefined function for counting specific node sequences that I am missing?



    CREATE
    (a: Action {personName: 'Tom', time: 1}),
    (b: Action {personName: 'May', time: 2}),
    (c: Action {personName: 'Bob', time: 3}),
    (d: Action {personName: 'Alex', time: 4}),
    (e: Action {personName: 'Zac', time: 5}),
    (f: Action {personName: 'Jill', time: 6}),
    (g: Action {personName: 'May', time: 7}),
    (h: Action {personName: 'Bob', time: 8})


    MATCH (act: Action)
    WITH act ORDER BY act.time ASC
    WITH COLLECT(act) AS acts
    FOREACH (n IN RANGE(0, size(acts)-2) |
    FOREACH (curr IN [acts[n]] |
    FOREACH (next IN [acts[n+1]] |
    MERGE (curr)-[:NEXT]-> (next))))
    WITH apoc.coll.pairsMin(acts) as pairsOfActs
    UNWIND pairsOfActs as unwoundPairsOfActs
    WITH apoc.coll.frequencies(unwoundPairsOfActs) AS giveBackFrequencyOfPairs
    RETURN giveBackFrequencyOfPairs


    enter image description hereenter image description here










    share|improve this question



























      0












      0








      0








      the following Cypher statements give me the graph output (see image) below the code. And also the text output below the image. My problem is the text output.



      I will try to explain the problem clearly: I am interested in the same sequences of two nodes, with respect to a specific property (here: personName). E.g. as you can see in the picture (or from the create statement) Bob comes after May twice. I wanted to capture this via apoc.coll.frequencies(pairsOfActs) AS giveBackFrequencyOfPairs
      RETURN giveBackFrequencyOfPairs. However, the 'time' property is in the way. Is there a way to ignore the time property? I have been trying with operations on lists and also with deleting the time property (then my sequence is gone), but nothing is working. Any suggestions? Or is this approach wrong entirely, or is there even a predefined function for counting specific node sequences that I am missing?



      CREATE
      (a: Action {personName: 'Tom', time: 1}),
      (b: Action {personName: 'May', time: 2}),
      (c: Action {personName: 'Bob', time: 3}),
      (d: Action {personName: 'Alex', time: 4}),
      (e: Action {personName: 'Zac', time: 5}),
      (f: Action {personName: 'Jill', time: 6}),
      (g: Action {personName: 'May', time: 7}),
      (h: Action {personName: 'Bob', time: 8})


      MATCH (act: Action)
      WITH act ORDER BY act.time ASC
      WITH COLLECT(act) AS acts
      FOREACH (n IN RANGE(0, size(acts)-2) |
      FOREACH (curr IN [acts[n]] |
      FOREACH (next IN [acts[n+1]] |
      MERGE (curr)-[:NEXT]-> (next))))
      WITH apoc.coll.pairsMin(acts) as pairsOfActs
      UNWIND pairsOfActs as unwoundPairsOfActs
      WITH apoc.coll.frequencies(unwoundPairsOfActs) AS giveBackFrequencyOfPairs
      RETURN giveBackFrequencyOfPairs


      enter image description hereenter image description here










      share|improve this question
















      the following Cypher statements give me the graph output (see image) below the code. And also the text output below the image. My problem is the text output.



      I will try to explain the problem clearly: I am interested in the same sequences of two nodes, with respect to a specific property (here: personName). E.g. as you can see in the picture (or from the create statement) Bob comes after May twice. I wanted to capture this via apoc.coll.frequencies(pairsOfActs) AS giveBackFrequencyOfPairs
      RETURN giveBackFrequencyOfPairs. However, the 'time' property is in the way. Is there a way to ignore the time property? I have been trying with operations on lists and also with deleting the time property (then my sequence is gone), but nothing is working. Any suggestions? Or is this approach wrong entirely, or is there even a predefined function for counting specific node sequences that I am missing?



      CREATE
      (a: Action {personName: 'Tom', time: 1}),
      (b: Action {personName: 'May', time: 2}),
      (c: Action {personName: 'Bob', time: 3}),
      (d: Action {personName: 'Alex', time: 4}),
      (e: Action {personName: 'Zac', time: 5}),
      (f: Action {personName: 'Jill', time: 6}),
      (g: Action {personName: 'May', time: 7}),
      (h: Action {personName: 'Bob', time: 8})


      MATCH (act: Action)
      WITH act ORDER BY act.time ASC
      WITH COLLECT(act) AS acts
      FOREACH (n IN RANGE(0, size(acts)-2) |
      FOREACH (curr IN [acts[n]] |
      FOREACH (next IN [acts[n+1]] |
      MERGE (curr)-[:NEXT]-> (next))))
      WITH apoc.coll.pairsMin(acts) as pairsOfActs
      UNWIND pairsOfActs as unwoundPairsOfActs
      WITH apoc.coll.frequencies(unwoundPairsOfActs) AS giveBackFrequencyOfPairs
      RETURN giveBackFrequencyOfPairs


      enter image description hereenter image description here







      neo4j cypher sequence frequency neo4j-apoc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 21:19







      CodeIsland

















      asked Jan 3 at 21:12









      CodeIslandCodeIsland

      276




      276
























          1 Answer
          1






          active

          oldest

          votes


















          0














          For your stated problem, there is no need to create the NEXT relationships, so this answer does not bother to create them. You can modify this answer to add that back in, if that is actually needed for some reason.



          This query should return the frequency of each pair of names (that appear in your time sequence):



          MATCH (act: Action) 
          WITH act ORDER BY act.time ASC
          RETURN apoc.coll.frequencies(apoc.coll.pairsMin(COLLECT(act.personName))) AS giveBackFrequencyOfPairs


          The output, with your sample data, would be:



          ╒══════════════════════════════════════════════════════════════════════╕
          │"giveBackFrequencyOfPairs" │
          ╞══════════════════════════════════════════════════════════════════════╡
          │[{"count":1,"item":["Tom","May"]},{"count":2,"item":["May","Bob"]},{"c│
          │ount":1,"item":["Bob","Alex"]},{"count":1,"item":["Alex","Zac"]},{"cou│
          │nt":1,"item":["Zac","Jill"]},{"count":1,"item":["Jill","May"]}] │
          └──────────────────────────────────────────────────────────────────────┘





          share|improve this answer


























            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%2f54029871%2fignoring-a-property-within-cypher-query-or-alternative-how-count-relationship-s%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









            0














            For your stated problem, there is no need to create the NEXT relationships, so this answer does not bother to create them. You can modify this answer to add that back in, if that is actually needed for some reason.



            This query should return the frequency of each pair of names (that appear in your time sequence):



            MATCH (act: Action) 
            WITH act ORDER BY act.time ASC
            RETURN apoc.coll.frequencies(apoc.coll.pairsMin(COLLECT(act.personName))) AS giveBackFrequencyOfPairs


            The output, with your sample data, would be:



            ╒══════════════════════════════════════════════════════════════════════╕
            │"giveBackFrequencyOfPairs" │
            ╞══════════════════════════════════════════════════════════════════════╡
            │[{"count":1,"item":["Tom","May"]},{"count":2,"item":["May","Bob"]},{"c│
            │ount":1,"item":["Bob","Alex"]},{"count":1,"item":["Alex","Zac"]},{"cou│
            │nt":1,"item":["Zac","Jill"]},{"count":1,"item":["Jill","May"]}] │
            └──────────────────────────────────────────────────────────────────────┘





            share|improve this answer






























              0














              For your stated problem, there is no need to create the NEXT relationships, so this answer does not bother to create them. You can modify this answer to add that back in, if that is actually needed for some reason.



              This query should return the frequency of each pair of names (that appear in your time sequence):



              MATCH (act: Action) 
              WITH act ORDER BY act.time ASC
              RETURN apoc.coll.frequencies(apoc.coll.pairsMin(COLLECT(act.personName))) AS giveBackFrequencyOfPairs


              The output, with your sample data, would be:



              ╒══════════════════════════════════════════════════════════════════════╕
              │"giveBackFrequencyOfPairs" │
              ╞══════════════════════════════════════════════════════════════════════╡
              │[{"count":1,"item":["Tom","May"]},{"count":2,"item":["May","Bob"]},{"c│
              │ount":1,"item":["Bob","Alex"]},{"count":1,"item":["Alex","Zac"]},{"cou│
              │nt":1,"item":["Zac","Jill"]},{"count":1,"item":["Jill","May"]}] │
              └──────────────────────────────────────────────────────────────────────┘





              share|improve this answer




























                0












                0








                0







                For your stated problem, there is no need to create the NEXT relationships, so this answer does not bother to create them. You can modify this answer to add that back in, if that is actually needed for some reason.



                This query should return the frequency of each pair of names (that appear in your time sequence):



                MATCH (act: Action) 
                WITH act ORDER BY act.time ASC
                RETURN apoc.coll.frequencies(apoc.coll.pairsMin(COLLECT(act.personName))) AS giveBackFrequencyOfPairs


                The output, with your sample data, would be:



                ╒══════════════════════════════════════════════════════════════════════╕
                │"giveBackFrequencyOfPairs" │
                ╞══════════════════════════════════════════════════════════════════════╡
                │[{"count":1,"item":["Tom","May"]},{"count":2,"item":["May","Bob"]},{"c│
                │ount":1,"item":["Bob","Alex"]},{"count":1,"item":["Alex","Zac"]},{"cou│
                │nt":1,"item":["Zac","Jill"]},{"count":1,"item":["Jill","May"]}] │
                └──────────────────────────────────────────────────────────────────────┘





                share|improve this answer















                For your stated problem, there is no need to create the NEXT relationships, so this answer does not bother to create them. You can modify this answer to add that back in, if that is actually needed for some reason.



                This query should return the frequency of each pair of names (that appear in your time sequence):



                MATCH (act: Action) 
                WITH act ORDER BY act.time ASC
                RETURN apoc.coll.frequencies(apoc.coll.pairsMin(COLLECT(act.personName))) AS giveBackFrequencyOfPairs


                The output, with your sample data, would be:



                ╒══════════════════════════════════════════════════════════════════════╕
                │"giveBackFrequencyOfPairs" │
                ╞══════════════════════════════════════════════════════════════════════╡
                │[{"count":1,"item":["Tom","May"]},{"count":2,"item":["May","Bob"]},{"c│
                │ount":1,"item":["Bob","Alex"]},{"count":1,"item":["Alex","Zac"]},{"cou│
                │nt":1,"item":["Zac","Jill"]},{"count":1,"item":["Jill","May"]}] │
                └──────────────────────────────────────────────────────────────────────┘






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 4 at 0:09

























                answered Jan 3 at 21:45









                cybersamcybersam

                41k53353




                41k53353
































                    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%2f54029871%2fignoring-a-property-within-cypher-query-or-alternative-how-count-relationship-s%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







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas