如何在 C/C 中实现字典++具有自动更正、自动完成、拼写检查功能
我必须为具有以下功能的字典实现编写 C/C++ 代码:
单词基本上有定义(1 个或多个)。
1) 插入
2) 搜索(尽可能快)
3) 自动完成
4) 自动更正
5) 拼写检查
所以我需要知道如何做?
哪种数据结构应该是最有效的? Trie 或 hast 表或其他
什么使用哪种搜索技术...?
如何有效地实现自动完成和拼写检查......?
I have to write a C/C++ Code for a dictionary implementation with the following features:
There are basically definitions (1 or more) for words.
1) Insertion
2) Searching (As fast as possible)
3) Auto Complete
4) Auto Correct
5) Spell Check
So I need to know HOW TO DO SO?
Which data structures should be the most efficient? Trie or hast table or something else
Which searching technique to use...?
How to implement auto-complete and spell Checking effectively..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您通常会使用一棵单词树,根据彼此之间的编辑距离排列,例如BK 树。
IIRC,其想法是拥有一个平衡树,每个单词通过根据编辑距离编号的边链接。如果你想找到一个单词的最近匹配,你可以计算它到根单词的编辑距离,然后沿着根单词的相同编号的链接,重复这个过程,直到到达一个叶子节点,它要么是相同的单词,或最接近的匹配。
编辑:事后看来,我链接的那篇文章比我更好地解释了这一点。我只是建议通读它以获得对该方法的良好解释。
You would typically use a tree of words, arranged according to edit distance from one another, such as a BK tree.
IIRC, the idea is to have a balanced tree with each word linked through edges numbered according to edit distance. If you want to find the nearest match for a word, you compute it's edit distance to the root word, then follow the root word's link of the same number, and repeat the process until you reach a leaf node which is either the same word, or the closest match.
EDIT: in hindsight, that article I linked does a much better job of explaining it than I did. I'd just recommend reading through it for a good explanation of the approach.
当然,您需要一个包含单词列表的数据库,然后您需要将文本拆分为单词并查看它们是否存在于数据库中。
对于自动完成,您只需检查到目前为止输入的文本是否与字典中的单词匹配(使用 LIKE txt+'%' 子句),通过 AJAX 调用实现。
Certainly you need a database with a list of words, then you need to split your text up into words and see if they exist in the database.
For Autocomplete you can just check that the text entered so far matches words in the dictionary (with a LIKE txt+'%' clause), implemented with an AJAX call.