在 power query 中生成标签列表

Generate a tag list in power query

我在 ArticleList 中有一长串文章文本(1000 多条,每条 50 多字)

我在 TagList 中有一个标签列表(100 个项目,每个 1 个单词)

我想 return 中每个单词的匹配标签列表(来自 TagList) ]文章列表.

例如

文章列表 = {"the big yellow teapot"; "the small white cup"; "the medium brown pan"; "grey flask"}

TagList = {"the", "yellow", "teapot", "white", "pan"}

结果列表 = {"the, yellow, teapot"; "the, white"; "the, pan"; ""}

所以基本上所有不在 TagList 中的单词都会从 ArticleList[=58= 中删除]ResultsList 的顺序与原始 ArticleList.

注意:ArticleList 是干净的,包含 space 个分隔的单词,大小写不重要。

我想我通过将 ArticleList 拆分为 space 分隔符上的列表列表,找到了解决方案,但我不知道如何从那时起操纵嵌套列表。尝试使用 List.Transform(ListofLists,每个 List.Intersect({_,TagList}){0}?),但是它 return 是单个列表,而不是保持列表列表的完整性。

如果我有一个名为 ArticleList 的列表,使用此 M 代码创建:

let
    Source = {"the big yellow teapot", "the small white cup", "the medium brown pan", "grey flask"}
in
    Source

还有一个名为 TagList 的列表,使用此 M 代码创建:

let
    Source = {"the", "yellow", "teapot", "white", "pan"}
in
    Source

那我就可以用这个M代码来做你想做的事了:

let
    Source = List.Transform(List.Transform(ArticleList, each Text.Split(_," ")), each List.Intersect({_,TagList})),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Extracted Values" = Table.TransformColumns(#"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), ", "), type text})
in
    #"Extracted Values"