1

我正在尝试使用最短路径函数来查找图中字符串之间的距离。问题是有时我想计算一些接近的比赛。例如,我希望“通信”算作“通信”或“网络设备”算作“网络设备”。有没有办法在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 ...

关于简单或快速的方法来做到这一点的任何想法?或者,也许是一种不同的方式来考虑接受紧密匹配的强项......或者当字符串不匹配时可能只是更好的错误处理?

4

1 回答 1

0

尝试使用 nltk WorldNetLemmatizer,它旨在提取词根。https://www.nltk.org/_modules/nltk/stem/wordnet.html

于 2019-11-01T13:15:36.153 回答