我正在从 2 个配置单元表中读取数据。令牌表中有需要与输入数据匹配的令牌。输入数据将具有描述列以及其他列。我需要拆分输入数据,并且需要将每个拆分的元素与令牌表中的所有元素进行比较。目前我正在使用 me.xdrop.fuzzywuzzy.FuzzySearch 库进行模糊匹配。
下面是我的代码片段-
val tokens = sqlContext.sql("select token from tokens")
val desc = sqlContext.sql("select description from desceriptiontable")
val desc_tokens = desc.flatMap(_.toString().split(" "))
现在我需要迭代 desc_tokens 并且 desc_tokens 的每个元素都应该与令牌的每个元素进行模糊匹配,并且它超过 85% 的匹配我需要用令牌中的元素替换 desc_tokens 中的元素。
例子 -
我的令牌列表是
hello
this
is
token
file
sample
我的输入描述是
helo this is input desc sampl
代码应该返回
hello this is input desc sample
因为hello和helo模糊匹配 > 85%,所以 helo 将被 hello 替换。样品也是如此。