Java 字谜解算器

发布于 2024-08-29 23:32:53 字数 89 浏览 20 评论 0原文

我可以弄清楚如何创建字符串的字谜词,但我不知道如何将它们与真实单词的字典进行比较,以检查字谜词是否是真实的单词。 Java API 中是否有一个类包含整个英语词典?

I can work out how to create anagrams of a string but I don't know how I can compare them to a dictionary of real words to check if the anagram is a real word. Is there a class in the Java API that contains the entire English dictionary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

北座城市 2024-09-05 23:32:53

不,但是您可以从各个地方获取单词列表< /a>.从那里,您可以将单词列表文件读入列表中:

List<String> lines = new ArrayList<String>();
BufferedReader in = new BufferedReader(new FileReader("wordlist.txt"));
String line = null;
while (null!=(line=in.readLine()))
{
   lines.add(line);
}
in.close();

最后二分搜索使用lines.contains()作为您的候选单词。

No, but you can get a wordlist from various places. From there, you could read the wordlist file into a list:

List<String> lines = new ArrayList<String>();
BufferedReader in = new BufferedReader(new FileReader("wordlist.txt"));
String line = null;
while (null!=(line=in.readLine()))
{
   lines.add(line);
}
in.close();

And finally binary search use lines.contains() for your candidate word.

莫相离 2024-09-05 23:32:53

确定一组字符是否是单词的字谜词的一种方法涉及使用素数。为每个字母指定一个素数,例如,a=2、b=3、c=5、d=7。现在预先计算字典中每个单词的素数乘积。例如,'add' = 2*7*7 = 98,或 'bad' = 3*2*7 = 42。

现在可以通过计算以下值来确定一组字母是否是字典中任何单词的字谜词:字母集的值。例如,字母“abd”= 2*3*7 = 42 =“坏”。只需检查预先计算的字典中是否存在字母的计算值即可。对于任何 anagram,您只需要进行一次计算,而不是尝试生成每个可能的 anagram。但请注意,此方法仅适用于相对较小的单词,否则您将遇到溢出问题并需要使用 BigInteger。

One method of determining whether a set of characters is an anagram of a word involves using prime numbers. Assign each letter a prime number, for example, a=2, b=3, c=5, d=7. Now precompute the product of primes for each word in your dictionary. For example, 'add' = 2*7*7 = 98, or 'bad' = 3*2*7 = 42.

Now determining if a set of letters is an anagram of any word in a dictionary can be done by computing the value of the set of letters. For example, the letters 'abd'= 2*3*7 = 42 = 'bad'. Just check whether the computed value for the letters exists in your precomputed dictionary. For any anagram, you need only do this computation once versus trying to generate every possible anagram. Note however this method will only work well for relatively small words, otherwise you will run into overflow issues and need to use BigInteger.

回忆躺在深渊里 2024-09-05 23:32:53

不,您必须使用外部库,例如 JWNL,它是 WordNet 的包装器 - - 按含义组织的机器可读词汇数据库,几乎包含所有英语单词。

No, you have to use an external library, such as JWNL, which is a wrapper for WordNet -- a machine-readable lexical database organized by meanings, that contains pretty much every English word.

谎言月老 2024-09-05 23:32:53

也许 jazzy 中的英语词典可以帮助您。

Maybe the English dictionary in jazzy can help you.

岁月染过的梦 2024-09-05 23:32:53

标准 Java 库中没有这样的专门类,但您可以使用您喜欢的 设置界面并通过加载您选择的单词(从无数的 单词列表您可以在很多地方找到(只需仔细检查您选择的单词列表的许可证是否与您的预期应用程序兼容,例如,它是否允许商业用途、闭源应用程序如果这就是您的要求,等等)。

There's no such specialized class in the standard Java library, but you can use any implementation you like of the Set interface and initialize it by loading it up with words of your choosing, picked from any of the innumerable word lists you can find in many places (just check out carefully that the license for the word list you choose is compatible with your intended application, e.g., does it allow commercial use, closed-source apps if that's what you require, and so forth).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文