Merge associations with the same keys, same in a sense by user's definition
Clash 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.
string-manipulation associations
add a comment |Â
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.
string-manipulation associations
Can you give example associations?
â J. M. is computer-lessâ¦
1 hour ago
@J.M.iscomputer-less Please see the update.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1 hour ago
add a comment |Â
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.
string-manipulation associations
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
string-manipulation associations
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
add a comment |Â
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
add a comment |Â
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|>
add a comment |Â
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|>
add a comment |Â
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|>
add a comment |Â
up vote
4
down vote
data = "effects" -> 4, 1, 3, 5;
Merge[KeyMap[WordStem]/@ data, mergeFunc]
<|"effect" -> 9, 1, 2, 3, 5|>
add a comment |Â
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|>
data = "effects" -> 4, 1, 3, 5;
Merge[KeyMap[WordStem]/@ data, mergeFunc]
<|"effect" -> 9, 1, 2, 3, 5|>
answered 38 mins ago
kglr
166k8188389
166k8188389
add a comment |Â
add a comment |Â
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|>
add a comment |Â
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|>
add a comment |Â
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|>
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|>
answered 40 mins ago
Henrik Schumacher
42.3k261125
42.3k261125
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Can you give example associations?
â J. M. is computer-lessâ¦
1 hour ago
@J.M.iscomputer-less Please see the update.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1 hour ago