python - 列表中的短语相似度
问题描述
嗨,假设我有 2 个列表:
names = ['Daniel', 'Mario', 'Mandy', 'Jolene', 'Fabio']
places = ['on top of the table', 'France', 'valley of the kings']
和一个带有一些句子的数据框,例如:
数据框
Index | Sent
0 | Mandy went to France on the Eiffel Tower
1 | Daniele was dancing on top of the box
2 | I am eating on top of the table
3 | Maria went to the valley of the kings
我想使用像 difflib 这样的距离度量来扫描句子并将短语与具有确定偏移量的列表进行比较。希望这样做的结果是:
Index | Sent | Result
0 | Mandy went to France on the Eiffel Tower | Mandy
1 | Daniele was dancing on top of the box | Daniel
2 | I am eating on top of the table | on top of the table
3 | Maria went to the valley of the kings | Mario, valley of the kings
如果不使用大量循环来获取短语匹配,您将如何处理它?
解决方案
推荐阅读
- java - 在 Java 中使 JSON 漂亮的最佳方法
- python - 在函数中调用函数时会出现什么问题?
- python - 将具有阻塞请求的库重写为异步请求
- c - 在 C 程序中,我无法跟踪使用循环生成从 1 到 1000 的罗马数字的代码?
- swift - 斯威夫特:小数精度正确吗?
- google-sheets - 获取 Google 表格列中的最后一个非空单元格(不包括公式)
- java - 将 documentSnapshot 转换为自定义对象时出现问题
- python - 每 N 个数字加 0 - 列表推导
- javascript - 使 html 选择元素成为必需
- python - 熊猫数据框将所有数据列归为一列