java 检查字典中的单词
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2032064/
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
checking words in a dictionary
提问by David Hoffman
I need to determine if an unknown 5 or 6 letter string is a valid word, i.e. is in the dictionary. I could submit the string/word to an online dictionary, but I need to check this string/word, which will be different each time, for about 100 to 150 times. This seems to be a bit time consuming.
我需要确定一个未知的 5 或 6 个字母的字符串是否是有效单词,即是否在字典中。我可以将字符串/单词提交到在线词典,但我需要检查这个字符串/单词,每次都会不同,大约 100 到 150 次。这似乎有点耗时。
My next thought would be to try to get a dictionary program of my own. It would need to be in Java as my program is written in Java. Does the Java API already have a class for doing this? Can I get a descent one that someone has already coded, and all I have to do is submit the string/word to it?
我的下一个想法是尝试获得我自己的字典程序。因为我的程序是用 Java 编写的,所以它需要使用 Java。Java API 是否已经有一个用于执行此操作的类?我可以得到一个有人已经编码的下降,我所要做的就是向它提交字符串/单词吗?
My program is not being used for spell checking. I want to write a program for unscrambling the Jumbled Word Puzzles when I get stuck on a scrambled word. Thanks for your suggestions.
我的程序没有用于拼写检查。我想编写一个程序,当我被一个打乱的单词卡住时,它可以解开混乱的单词拼图。感谢您的建议。
回答by wallyk
You could use one of the open source dictionaries and load it into a database: ftp://ftp.cerias.purdue.edu/pub/dict/and ftp://ftp.ox.ac.uk/pub/wordlists/
您可以使用其中一个开源词典并将其加载到数据库中:ftp: //ftp.cerias.purdue.edu/pub/dict/和ftp://ftp.ox.ac.uk/pub/wordlists/
回答by trashgod
For scrambled words, you might want to look at the Jumble algorithm, an implementation of which is seen here.
回答by Chad Okere
If you don't need spell checking this would be really easy. Just load all your words into a HashSet and then check to see if that set contains the word you want to test. There are tons of word listsavailable.
如果您不需要拼写检查,这将非常容易。只需将所有单词加载到 HashSet 中,然后检查该集合是否包含您要测试的单词。有大量可用的单词列表。
If you do need a spell checker, then check out aspell or other free APIs.
如果您确实需要拼写检查器,请查看 aspell 或其他免费 API。
回答by duffymo
Maybe you could try Peter Norvig's spelling checker. I think it's an elegant way to get 80-90% accuracy.
也许你可以试试Peter Norvig 的拼写检查器。我认为这是获得 80-90% 准确率的优雅方式。
回答by SpliFF
回答by Mark Elliot
回答by Yin Zhu
Maybe you can check some wordlist: http://wordlist.sourceforge.net/
也许你可以检查一些词表:http://wordlist.sourceforge.net/
This page has some word lists in text format, so you can process in Java yourself, most easily using a HashSet. You need to use more efficient data structures if efficiency is important.
这个页面有一些文本格式的单词列表,所以你可以自己用 Java 处理,最容易使用 HashSet。如果效率很重要,您需要使用更高效的数据结构。

