根据包含的关键词将指定列按关键词指定顺序排列
例题描述和简单分析
有 Excel 文件 book1.xlsx,数据如下所示:
A |
B |
|
1 |
Parent Column |
Modifier (Column) |
2 |
Jack lives in the village |
Rose |
3 |
As mentioned by jack |
Village |
4 |
Rose already spoke to jack about last night |
Jack |
5 |
Rose left the village |
|
6 |
rose was their yesterday |
A列(Parent Column)需要根据包含的关键词按照关键单词列表 (Modifier (Column)) 的顺序排序,结果如下:
A |
B |
|
1 |
Parent Column |
Modifier (Column) |
2 |
Rose already spoke to jack about last night |
Rose |
3 |
Rose left the village |
Village |
4 |
rose was their yesterday |
Jack |
5 |
Jack lives in the village |
|
6 |
As mentioned by jack |
解法及简要说明
在集算器中编写脚本 p1.dfx,如下所示:
A |
|
1 |
Jack lives in the village… |
2 |
Rose… |
3 |
=A1.import@i() |
4 |
=A2.import@i().(lower(~)) |
5 |
=A3.sort((X=lower(~).words(),X.min(A4.pselect(~:X.~)))) |
6 |
=A5.export() |
简要说明:
A1 复制 Excel 中的 A 列数据(不含表头)
A2 复制 Excel 中的 B 列数据(不含表头)
A3 将 A1 串读成序列
A4 将 A2 串读成序列,转为小写
A5 A3的每个成员(句子)转为小写后,拆成单词序列,在单词序列中找出每个单词在 A4 中对应的位置序号,并取每个句子的最小值(优先级最高的单词),A3 按照该顺序排序
A6 A5拼成串(行间用回车符)
执行程序后,在集算器中选中 A6 单元格,再点击右侧对应的“copy data”按钮。在 Excel 中,点击 A2 单元格,按 Ctrl+V 就可以把计算结果粘贴过来。
英文版