我有一些数据,其中“X”列包含字符串。我正在使用 pyspark 编写一个函数,其中传递了一个 search_word,并且过滤掉了列 'X' 字符串中不包含子字符串 search_word 的所有行。该函数还必须允许单词的拼写错误,即模糊匹配。我已将数据加载到 pyspark 数据帧中,并使用 NLTK 和 Fuzzywuzzy python 库编写了一个函数,如果字符串包含 search_word,则返回 True 或 False。
我的问题是我无法将函数正确映射到数据帧。我是否错误地处理了这个问题?我应该尝试通过某种 SQL 查询进行模糊匹配,还是使用 RDD?
我是 pyspark 的新手,所以我觉得这个问题以前肯定已经回答过,但我在任何地方都找不到答案。我从未用 SQL 做过任何 NLP,也从未听说过 SQL 能够模糊匹配子字符串。
更新 #1
该函数看起来像:
wf = WordFinder(search_word='some_substring')
result1 = wf.find_word_in_string(string_to_search='string containing some_substring or misspelled some_sibstrung')
result2 = wf.find_word_in_string(string_to_search='string not containing the substring')
Run Code Online (Sandbox Code Playgroud)
结果 1 为真
结果 2 为假