Javascript 拼写检查方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6166206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript Spell Checking Methods
提问by danem
Hey, I'm making a Web Based anagram game for fun and practice. The game presents the player with a word and the player needs only to construct new words out of letters contained in the given word. Where I am running into trouble is spellchecking the submitted words for validation purposes.
嘿,我正在制作一个基于 Web 的字谜游戏,以供娱乐和练习。游戏向玩家展示一个单词,玩家只需要从给定单词中包含的字母中构造新单词。我遇到麻烦的地方是对提交的单词进行拼写检查以进行验证。
I initially thought that this would be fairly trivial, and my first solution was to just copy the dictionary file that is located at usr/share/dict and compare the submitted answers to the words in that file. This however fails when dealing with different forms of a word. For instance, the dictionary has the word "ask", but if the user were to enter the word "asks", it would be considered wrong.
我最初认为这相当简单,我的第一个解决方案是复制位于 usr/share/dict 的字典文件,并将提交的答案与该文件中的单词进行比较。然而,这在处理单词的不同形式时失败了。例如,字典中有“ask”这个词,但如果用户输入“asks”这个词,就会被认为是错误的。
Knowing that I can't hope to write a functional spellchecking algorithm (nor do I want to spend the time trying to tackle that) I thought that I may be able to use the browsers built in spell checking capabilities. But my searching for an answer to this hasn't produced any useful results.
知道我不能希望编写功能性拼写检查算法(我也不想花时间尝试解决这个问题),我认为我可以使用内置拼写检查功能的浏览器。但是我对此问题的寻找并没有产生任何有用的结果。
Is there a way to use the browsers spellchecking capabilities, perhaps using javascript or something? And if not, how might I best approach this problem?
有没有办法使用浏览器的拼写检查功能,也许使用 javascript 之类的?如果没有,我怎样才能最好地解决这个问题?
Thanks!
谢谢!
采纳答案by Eevee
JavaScript spell-checking libraries do exist. I ran across this a little while ago: http://www.chrisfinke.com/2011/03/31/announcing-typo-js-client-side-javascript-spellchecking/
JavaScript 拼写检查库确实存在。不久前我遇到了这个:http: //www.chrisfinke.com/2011/03/31/annoucing-typo-js-client-side-javascript-spellchecking/
回答by nickf
John Resig (of jQuery fame) recently wrote a series of blog posts about fast spell checking for a Javascript-based anagram game he's working on.
John Resig(因 jQuery 出名)最近写了一系列关于他正在开发的基于 Javascript 的字谜游戏的快速拼写检查的博客文章。
http://ejohn.org/blog/dictionary-lookups-in-javascript/
http://ejohn.org/blog/javascript-trie-performance-analysis/
http://ejohn.org/blog/revised-javascript-dictionary-search/
http://ejohn.org/blog/dictionary-lookups-in-javascript/
http://ejohn.org/blog/javascript-trie-performance-analysis/
http://ejohn.org/blog/revised-javascript-字典搜索/
You might be able to skip to the last one where he wraps up all his findings there. It is quite in depth, measuring up look-up speed, download time, initialization time..
你也许可以跳到最后一个,他在那里总结了他的所有发现。讲的很深入,查查速度,下载时间,初始化时间..
回答by Kon
I've used JSpell Evolutionbefore. Once you get past the annoying installation/setup process, it works pretty well.
我以前使用过JSpell Evolution。一旦你通过了烦人的安装/设置过程,它就会运行得很好。
回答by ITRob
There are plenty of free dictionaries online that include plurals, hyphenations etc.
网上有很多免费词典,包括复数、连字符等。
E.g. a quick Google search found these dictionarieswhich support the spell checking functions of OpenOffice.
例如,通过 Google 快速搜索发现这些词典支持 OpenOffice 的拼写检查功能。
Have a Google. You can always aggregate several dictionaries into a massive super-dictionary!
有一个谷歌。你可以随时将多本词典聚合成一个海量的超级词典!
Have fun.
玩得开心。
Rob.
抢。