1

假设我将这些短语存储在单词列表中:

** school education high support level -->    support education high school level support
** school education high support level -->    support education high school level level education
** school education high support level -->    education high school level support education school
** school education high support level -->    support education high school level support

比较列表列表的元素并选择与所有成员最相似的模式的最有效方法是什么?

[['support', 'education', 'high', 'school', 'level', 'support'],
['support', 'education', 'high', 'school', 'level', 'level', 'education'],
['education', 'high', 'school', 'level', 'support', 'education', 'school'],
['support', 'education', 'high', 'school', 'level', 'support']]

--- 产量

[支持、教育、高中、学校、水平]

更新

感谢您的意见和反馈。我含糊其辞,虽然我认为说这不是一个完全明确的问题会更准确。

(1) 绝对要保持词序

(2) 标准比仅仅保留存在的所有元素的集合要复杂一些(即 set(A) & set(B) 不是我真正想要的)

(3) 更像是“大部分存在的所有元素的集合”,这个词主要被定义为一些可调整的参数,比如在 60% 的情况下存在,或者 70% ......

我可以编写自己的函数(我确实做到了),但它很慢而且很麻烦。我认为必须有一些来自集合或 itertools 或类似模块的技巧才能更快地获取此解决方案。就像我了解了 Collections.Counter() 一样,我的函数切换并变得更快。我知道有一个 'bag' 或 'multiset' 选项,但没有用它来处理模糊集的概念,其中成员资格是由一个事物的许多示例中出现的概率定义的。

这就是为什么我要求提供反馈和对这些策略的见解。

4

0 回答 0