我正在尝试使用最短路径函数来查找图中字符串之间的距离。问题是有时我想计算一些接近的匹配项。例如,我希望“通信”算作“通信”或“网络设备”算作“网络设备”。有没有办法在 python 中做到这一点? (例如,提取词根,或计算字符串距离,或者可能是一个已经具有词形关系(如复数/动名词/拼写错误/等)的Python库)我现在的问题是,我的过程仅在存在与我的数据库中的每个项目完全匹配,这很难保持干净。
例如:
List_of_tags_in_graph = ['A', 'list', 'of', 'tags', 'in', 'graph']
given_tag = 'lists'
if min_fuzzy_string_distance_measure(given_tag, List_of_tags_in_graph) < threshold :
index_of_min = index_of_min_fuzzy_match(given_tag, List_of_tags_in_graph)
given_tag = List_of_tags_in_graph[index_of_min]
#... then use given_tag in the graph calculation because now I know it matches ...
有什么简单或快速的方法可以做到这一点吗?或者,也许是一种不同的方式来考虑接受接近匹配的强项......或者也许只是在字符串不匹配时更好的错误处理?
最佳答案
尝试使用 nltk WorldNetLemmatizer,它旨在提取词根。 https://www.nltk.org/_modules/nltk/stem/wordnet.html
关于python - 在 python 函数中使用字符串时接受 "close matches"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58659733/