Python中的文本分类和搜索

Python中的文本分类和搜索,python,string,search,classification,distance,Python,String,Search,Classification,Distance,我正在做一个小项目,需要一些帮助来搜索字符串中的文本 假设我有一个主字符串1,例如:贷款协调员 假设我还有另外一条主线,比如:金融学生贷款协调员 假设我有另一个string3,比如:Loan Operator 假设我有另一个字符串4,例如:协调器 假设我还有另外一条线索,比如:财务助理 。 在Python中,找到与string1有关的所有字符串的最佳方法是什么? 例如: 字符串2必须处理字符串1,因为字符串中有文本Loan Coordinator 字符串3与单词Loan有关 字符串4有一些事情

我正在做一个小项目,需要一些帮助来搜索字符串中的文本

假设我有一个主字符串1,例如:贷款协调员

假设我还有另外一条主线,比如:金融学生贷款协调员

假设我有另一个string3,比如:Loan Operator

假设我有另一个字符串4,例如:协调器

假设我还有另外一条线索,比如:财务助理

在Python中,找到与string1有关的所有字符串的最佳方法是什么? 例如:

字符串2必须处理字符串1,因为字符串中有文本Loan Coordinator

字符串3与单词Loan有关

字符串4有一些事情要做,因为协调器这个词

字符串5与此无关,因此我不关心此字符串

2、3和4应该返回find或表示存在小匹配的内容


谢谢你的帮助

可以使用“设置交点”。在字符串中创建一组唯一的单词以进行比较。然后从每个其他字符串中获取与单词集的交点。保留任何具有非空交叉点的字符串

>>> s1 = 'Loan Coordinator'
>>> sList = ['Financial Student Loan Coordinator', 'Loan Operator', 'Coordinator', 'Financial Assistant']

>>> unique = set(s1.split())  # unique words in string 1

>>> [i for i in sList if unique & set(i.split())]
['Financial Student Loan Coordinator', 'Loan Operator', 'Coordinator']
运行代码:

~/string_matcher.py "Loan Coordinator" "Financial Student Loan Coordinator" "Loan Operator" "Coordinator" "Financial Assistant"
Financial Student Loan Coordinator matches because of coordinator, loan
Loan Operator matches because of loan
Coordinator matches because of coordinator
Financial Assistant doesnt match

你尝试了什么,也给出了预期的输入和预期的输出“钱”和“贷款协调员”有关系吗?“经理”怎么样?另一方面,“rdina”呢?我觉得你的要求有点不够具体。@hackaholic我没有尝试过任何东西,因为我不知道从哪里开始搜索字符串。我不是在要求python代码,只是关于从哪里开始的建议。
~/string_matcher.py "Loan Coordinator" "Financial Student Loan Coordinator" "Loan Operator" "Coordinator" "Financial Assistant"
Financial Student Loan Coordinator matches because of coordinator, loan
Loan Operator matches because of loan
Coordinator matches because of coordinator
Financial Assistant doesnt match