仅字符串部分的编辑距离 (Java)
我有一个在线网络应用程序,带有顶部菜单树,用于打开不同的小部件来执行不同的任务。随着应用程序变得越来越强大,该树变得越来越大并且难以导航。我实现了一个搜索功能,用户只需键入菜单名称或其一部分,然后我使用正则表达式来查找菜单树中与用户键入的内容相匹配的所有项目。我的正则表达式允许部分单词和交换单词,并且还将搜索限制为每个单词的开头。它不允许的一件事是拼写错误的单词。我知道,为了允许拼写错误的单词,最好不要使用正则表达式,而是使用字符串距离方法,但我仍然想允许部分单词和交换的单词。这可能吗?
例如,现在,如果菜单项是“Finance Rate Maintenance”,则以下任何一项都将与该菜单项匹配:“finance”、“finance ra”、“rate Finance”等。“inance rates”不会匹配,因为“inance”没有出现在该菜单项的任何单词的开头。我想要像“fnane rates”和“rate Maintenance”这样的搜索,它们的拼写略有错误以匹配。
I have an online web application with a top menu tree for opening different widgets for performing different tasks. As the app grows more powerful, that tree has become large and difficult to navigate. I've implemented a search feature, where users can just type the menu name or part of it and I use regex to find all items in the menu tree that match what the user types. My regex allows for partial words and swapped words, and also limits the search to the beginning of each word. The one thing it doesn't allow for is misspelled words. I understand that to allow for misspelled words it's best not to use regex and to use a string distance method instead, but I still want to allow for the partial word and swapped words. Is this possible?
For example, right now, if a menu item is "Finance Rate Maintenance", any of the following would match to that menu item: "finance", "finance ra", "rate finance" etc.. "inance rate" would not match because "inance" does not appear at the beginning of any of the words for that menu item. I want searches like "fnane rate" and "rate maintainance" which are slightly misspelled to match.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是将一个单词列表附加到每个选项,并同时维护一个包含其中所有单词的字典。然后,当用户输入查询时,程序将检查他们输入的每个单词是否都在字典中。如果不是,它会找到最接近的单词 via。字符串距离并纠正单词。
最后,它可以建议与校正的输入词有最多共同词的菜单选项。
拼写校正器的一个很好的例子(虽然是Python)位于 http://norvig.com/spell-正确.html
I would just attach a list of words to each option, and simultaneously maintain a dictionary with all of the words in it. Then, when the user types in their query, the program would check that every word that they enter is in the dictionary. If one is not, it would find the closest word via. string distance and correct the word.
Finally, it would could suggest the menu option with the most words in common with the corrected input words.
A good example of a spelling corrector (in python though) is at http://norvig.com/spell-correct.html