How to delete the redundant parts of each association according to the corresponding intersection of parts in the key list.
Select[<|{x1,
x2} -> {{"a", "t"}, {"h", "k"}, {"h", "t"}, {"r", "t"}, {"s",
"w"}}, {x2,
x6} -> {{"t", "t"}, {"h", "k"}, {"k", "u"}, {"r", "t"}}, {x3, x6,
x1} -> {{"t", "t", "a"}, {"h", "u", "r"}, {"a", "t", "l"}}|>, f]
That is to realize the calculation results in the figure below:
In the end, all parts of each key do not contain different values. What can I do to achieve this goal?
Further explanation of this problem:
First, we take the intersection of the values corresponding to the associated key:
assoc = <|{x1,
x2} -> {{"a", "t"}, {"h", "k"}, {"h", "t"}, {"r", "t"}, {"s",
"w"}}, {x2,
x6} -> {{"t", "t"}, {"h", "k"}, {"k", "u"}, {"r", "t"}}, {x3, x6,
x1} -> {{"t", "t", "a"}, {"h", "u", "r"}, {"a", "t", "l"}}|>
Merge[KeyValueMap[Thread[#1 -> #2\[Transpose]] &, assoc],
Intersection @@ # &]
The result of the above code is <|x1->{"a", "r"},x2->{"k", "t"},x6->{"t", "u"},x3->{"a", "h", "t"}|>.
so we know that x1 should be selected from {"a", "r"}, x2 should be selected from {"k", "t"}, x3 should be selected from {"a", "h", "t"}, x6 should be selected from {"t", "u"}.
Taking the first group of association selection as an example, only {"a","t"} or {"r","t"} of the values of the key {x1, x2} meet the above selection rules at the same time. Therefore, x2 can only take "t". Further analysis shows that x6 can only take "t". In the third group of relationships, only {"t", "t", "a"} can satisfy the requirement that x1 can only take "a" or "t", x6 can only take "t" and x3 can only be selected from {"a", "H", "t"} in the same time. So the end result is <|{x1, x2} -> {"a", "t"}, {x2, x6} -> {"t", "t"},
{x3, x6, x1} -> {"t", "t", "a"}|>.
But I can't implement this process in code coherently. I need help.
Add:
Thank you very much for kglr's help, but when I applied your code to this problem, a small problem occurred.
When I reassign x as following:
assoc = Association[
s1 = Merge[
Map[Rule[{x1, x2}, #] &,
Flatten[StringCases[DictionaryLookup["w" ~~ _ ~~ "is" ~~ _],
"w" ~~ x1_ ~~ "is" ~~ x2_ :> {x1, x2}], 1]], Identity],
s2 = Merge[
Map[Rule[{x1, x3, x4, x8}, #] &,
Flatten[StringCases[DictionaryLookup[_ ~~ _ ~~ _ ~~ "l" ~~ _],
x1_ ~~ x3_ ~~ x4_ ~~ "l" ~~ x8_ :> {x1, x3, x4, x8}], 1]],
Identity],
s3 = Merge[
Map[Rule[{x2, x6}, #] &,
Flatten[StringCases[DictionaryLookup[_ ~~ "o" ~~ _],
x2_ ~~ "o" ~~ x6_ :> {x2, x6}], 1]], Identity],
s4 = Merge[
Map[Rule[{x4, x5, x6}, #] &,
Flatten[StringCases[DictionaryLookup[_ ~~ "n" ~~ _ ~~ _ ~~ _],
x4_ ~~ "n" ~~ x5_ ~~ x6_ :> {x4, x5, x6}], 1]], Identity],
s5 = Merge[
Map[Rule[{x7, x8, x9}, #] &,
Flatten[StringCases[DictionaryLookup[_ ~~ _ ~~ "c" ~~ _],
x7_ ~~ x8_ ~~ "c" ~~ x9_ :> {x7, x8, x9}], 1]], Identity]]
solution =
Association[
First@Solve[
And @@ Or @@@
KeyValueMap[
Map[Apply[And]@*Thread]@
Thread[Unevaluated@Equal[##], List, {2}] &]@#,
Union @@ Keys[#]]] &;
solution@assoc
I can't get the result after running the above code.



Firston the association: i.e.,assoc = <|{x1, x2} -> {{"a", "t"}, {"h", "k"}, {"h", "t"}, {"r", "t"}, {"s", "w"}}, {x2, x6} -> {{"t", "t"}, {"h", "k"}, {"k", "u"}, {"r", "t"}}, {x3, x6, x1} -> {{"t", "t", "a"}, {"h", "u", "r"}, {"a", "t", "l"}}|>; First /@ assoc? – kglr Mar 25 '20 at 08:02assoc = <|{x1, x2} -> {{"a", "t"}, {"h", "k"}, {"h", "t"}, {"r", "t"}, {"s", "w"}}, {x2, x6} -> {{"t", "t"}, {"h", "k"}, {"k", "u"}, {"r", "t"}}, {x3, x6, x1} -> {{"h", "u", "r"}, {"t", "t", "a"}, {"a", "t", "l"}}|>, the result is still<|{x1,x2}->{a,t},{x2,x6}->{t,t},{x3,x6,x1}->{t,t,a}|>. – A little mouse on the pampas Mar 25 '20 at 08:52