Merge associations with the same keys, same in a sense by user's definition

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I know that it is the standard functionality of Merge to combine the values of the same keys among associations.



Now I would like to deal with a situation in which, in my associations, the keys are strings (English words). And I want to define the sameness as two words having the same result from WordStem so that "effects" and "effect" are the same key.



So is it possible for Merge to accept such a same test function for the keys, e.g., Equal@@WordStem[##]&, to determine what keys should be considered the same and be merged?




A MWE goes as below:



mergeFunc = x [Function] Total[#], Union[Flatten@#2] & @@ (x[Transpose]);

Merge["effects" -> 4, 1, 3, 5, mergeFunc]

Merge[>, <, mergeFunc]



<|"effect" -> 5, 2, 3, "effects" -> 4, 1, 3, 5|>

<|"effect" -> 9, 1, 2, 3, 5|>



The second result is desired.










share|improve this question























  • Can you give example associations?
    – J. M. is computer-less♦
    1 hour ago










  • @J.M.iscomputer-less Please see the update.
    – Î‘λέξανδρος Ζεγγ
    1 hour ago














up vote
3
down vote

favorite












I know that it is the standard functionality of Merge to combine the values of the same keys among associations.



Now I would like to deal with a situation in which, in my associations, the keys are strings (English words). And I want to define the sameness as two words having the same result from WordStem so that "effects" and "effect" are the same key.



So is it possible for Merge to accept such a same test function for the keys, e.g., Equal@@WordStem[##]&, to determine what keys should be considered the same and be merged?




A MWE goes as below:



mergeFunc = x [Function] Total[#], Union[Flatten@#2] & @@ (x[Transpose]);

Merge["effects" -> 4, 1, 3, 5, mergeFunc]

Merge[>, <, mergeFunc]



<|"effect" -> 5, 2, 3, "effects" -> 4, 1, 3, 5|>

<|"effect" -> 9, 1, 2, 3, 5|>



The second result is desired.










share|improve this question























  • Can you give example associations?
    – J. M. is computer-less♦
    1 hour ago










  • @J.M.iscomputer-less Please see the update.
    – Î‘λέξανδρος Ζεγγ
    1 hour ago












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I know that it is the standard functionality of Merge to combine the values of the same keys among associations.



Now I would like to deal with a situation in which, in my associations, the keys are strings (English words). And I want to define the sameness as two words having the same result from WordStem so that "effects" and "effect" are the same key.



So is it possible for Merge to accept such a same test function for the keys, e.g., Equal@@WordStem[##]&, to determine what keys should be considered the same and be merged?




A MWE goes as below:



mergeFunc = x [Function] Total[#], Union[Flatten@#2] & @@ (x[Transpose]);

Merge["effects" -> 4, 1, 3, 5, mergeFunc]

Merge[>, <, mergeFunc]



<|"effect" -> 5, 2, 3, "effects" -> 4, 1, 3, 5|>

<|"effect" -> 9, 1, 2, 3, 5|>



The second result is desired.










share|improve this question















I know that it is the standard functionality of Merge to combine the values of the same keys among associations.



Now I would like to deal with a situation in which, in my associations, the keys are strings (English words). And I want to define the sameness as two words having the same result from WordStem so that "effects" and "effect" are the same key.



So is it possible for Merge to accept such a same test function for the keys, e.g., Equal@@WordStem[##]&, to determine what keys should be considered the same and be merged?




A MWE goes as below:



mergeFunc = x [Function] Total[#], Union[Flatten@#2] & @@ (x[Transpose]);

Merge["effects" -> 4, 1, 3, 5, mergeFunc]

Merge[>, <, mergeFunc]



<|"effect" -> 5, 2, 3, "effects" -> 4, 1, 3, 5|>

<|"effect" -> 9, 1, 2, 3, 5|>



The second result is desired.







string-manipulation associations






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 54 mins ago

























asked 1 hour ago









Αλέξανδρος Ζεγγ

2,8091827




2,8091827











  • Can you give example associations?
    – J. M. is computer-less♦
    1 hour ago










  • @J.M.iscomputer-less Please see the update.
    – Î‘λέξανδρος Ζεγγ
    1 hour ago
















  • Can you give example associations?
    – J. M. is computer-less♦
    1 hour ago










  • @J.M.iscomputer-less Please see the update.
    – Î‘λέξανδρος Ζεγγ
    1 hour ago















Can you give example associations?
– J. M. is computer-less♦
1 hour ago




Can you give example associations?
– J. M. is computer-less♦
1 hour ago












@J.M.iscomputer-less Please see the update.
– Î‘λέξανδρος Ζεγγ
1 hour ago




@J.M.iscomputer-less Please see the update.
– Î‘λέξανδρος Ζεγγ
1 hour ago










2 Answers
2






active

oldest

votes

















up vote
4
down vote













 data = "effects" -> 4, 1, 3, 5;
Merge[KeyMap[WordStem]/@ data, mergeFunc]



<|"effect" -> 9, 1, 2, 3, 5|>







share|improve this answer



























    up vote
    2
    down vote













    What about this?



    data = <|"effect" -> 5, 2, 3, "effects" -> 4, 1, 3, 5|>;
    Merge[
    KeyValueMap[key, value [Function] WordStem[key] -> value, data],
    mergeFunc
    ]



    <|"effect" -> 9, 1, 2, 3, 5|>







    share|improve this answer




















      Your Answer




      StackExchange.ifUsing("editor", function ()
      return StackExchange.using("mathjaxEditing", function ()
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      );
      );
      , "mathjax-editing");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "387"
      ;
      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',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184219%2fmerge-associations-with-the-same-keys-same-in-a-sense-by-users-definition%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      4
      down vote













       data = "effects" -> 4, 1, 3, 5;
      Merge[KeyMap[WordStem]/@ data, mergeFunc]



      <|"effect" -> 9, 1, 2, 3, 5|>







      share|improve this answer
























        up vote
        4
        down vote













         data = "effects" -> 4, 1, 3, 5;
        Merge[KeyMap[WordStem]/@ data, mergeFunc]



        <|"effect" -> 9, 1, 2, 3, 5|>







        share|improve this answer






















          up vote
          4
          down vote










          up vote
          4
          down vote









           data = "effects" -> 4, 1, 3, 5;
          Merge[KeyMap[WordStem]/@ data, mergeFunc]



          <|"effect" -> 9, 1, 2, 3, 5|>







          share|improve this answer












           data = "effects" -> 4, 1, 3, 5;
          Merge[KeyMap[WordStem]/@ data, mergeFunc]



          <|"effect" -> 9, 1, 2, 3, 5|>








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 38 mins ago









          kglr

          166k8188389




          166k8188389




















              up vote
              2
              down vote













              What about this?



              data = <|"effect" -> 5, 2, 3, "effects" -> 4, 1, 3, 5|>;
              Merge[
              KeyValueMap[key, value [Function] WordStem[key] -> value, data],
              mergeFunc
              ]



              <|"effect" -> 9, 1, 2, 3, 5|>







              share|improve this answer
























                up vote
                2
                down vote













                What about this?



                data = <|"effect" -> 5, 2, 3, "effects" -> 4, 1, 3, 5|>;
                Merge[
                KeyValueMap[key, value [Function] WordStem[key] -> value, data],
                mergeFunc
                ]



                <|"effect" -> 9, 1, 2, 3, 5|>







                share|improve this answer






















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  What about this?



                  data = <|"effect" -> 5, 2, 3, "effects" -> 4, 1, 3, 5|>;
                  Merge[
                  KeyValueMap[key, value [Function] WordStem[key] -> value, data],
                  mergeFunc
                  ]



                  <|"effect" -> 9, 1, 2, 3, 5|>







                  share|improve this answer












                  What about this?



                  data = <|"effect" -> 5, 2, 3, "effects" -> 4, 1, 3, 5|>;
                  Merge[
                  KeyValueMap[key, value [Function] WordStem[key] -> value, data],
                  mergeFunc
                  ]



                  <|"effect" -> 9, 1, 2, 3, 5|>








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 40 mins ago









                  Henrik Schumacher

                  42.3k261125




                  42.3k261125



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184219%2fmerge-associations-with-the-same-keys-same-in-a-sense-by-users-definition%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      Installing NextGIS Connect into QGIS 3?

                      One-line joke