与占位符最接近的字符串匹配

问题描述

我需要将输入字符串与包含占位符的预定义字符串之一匹配。

Input String: create randomtext

Predefined String:
 1. create note $0
 2. create reminder $0
 3. create task $0 $1
where $0 $1 are placeholders

Expected output:

 1. create note randomtext
 2. create reminder randomtext
 3. create task randomtext

字符串差异算法,例如 Diff match 替换预定义的字符串。 sample fiddle

Input: create tsk0
Predefined string: create task $0

Output: create task $0

Expected output: create task tsk0

我能想到的解决方案是

  1. 使用 levenshtein-distance 预测最近的字符串
  2. 使用 Myer 算法并修改/扩展它,使其更喜欢在占位符中删除/插入

是否有更好的方法解决方案?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)