【问题标题】:how do I make my program guess for the correct word?如何让我的程序猜测正确的单词?
【发布时间】:2012-09-08 10:37:33
【问题描述】:

我有兴趣做一些人工智能/算法探索。所以我有这个想法,做一个简单的应用程序有点像吊人,我分配一个单词并留下一些字母作为线索。但是,我不想让用户猜测这个词,而是让我的应用程序尝试根据我留下的线索来弄清楚它。有谁知道我应该从哪里开始?谢谢。

【问题讨论】:

    标签: c# winforms algorithm artificial-intelligence solver


    【解决方案1】:

    创建所需语言的单词数据库(索引维基百科转储)。
    这可能不应该超过 100 万字。

    然后你可以简单地查询一个数据库:

    例如:fxxulxxs

    --> SELECT * FROM T_Words WHERE word LIKE f__ul__s

    --> 太棒了

    如果返回集中的单词超过 1 个,则需要返回统计上最常用的那个。

    另一种方法是查看 nhunspell

    如果您想进行更多分析,则需要找到一种统计方法来关联词干、词尾和词头,或者基本上是衡量单词相似度的方法。

    语言研究表明,当您只有开头和结尾时,您可以轻松阅读单词。如果你只有中间,那就很难了。

    【讨论】:

    • 对不起,我最近没上。我喜欢这种方法,因为它似乎更像是人工智能而不是算法。我有一个问题,你提到获得维基百科转储。我怎样才能做到这一点?谢谢。
    • 谢谢,如果我需要更多帮助,我会发布另一个问题。
    • 该图像和围绕它的“研究”不正确。令人烦恼的是,建议您查询具有 1,000,000 个条目的 SQL 数据库的答案是最好的。
    【解决方案2】:

    您可能想查看某种形式的算法来测量编辑距离,例如Damerau-Levenshtein distance (wikipedia)。这通常用于在几个单词中找到与其他给定单词最接近的一个单词。

    在处理 DNA 和蛋白质序列时,它经常用于搜索和比较,但在您的情况下也可能有用。

    【讨论】:

    • @Kjartan:只有一个问题:你如何使用它来比较一个单词和数据库中的 1'000'000 个单词?
    • @Quandary 简答:搜索了很久。我相信 BLAST 在搜索蛋白质或 DNA 匹配时使用类似于此的算法:en.wikipedia.org/wiki/BLAST#Algorithm。尝试在此搜索框中输入一些字母组​​合(代表蛋白质):blast.ncbi.nlm.nih.gov/…
    • @Kjartan:不,没关系,愚蠢的问题。您要么使用 C# 版本并将其放入 SQL Server CLR 函数(SQL Server、Oracle)中,要么使用 C 版本并编写扩展存储过程(PostGre/MySQL/Firebird)。
    【解决方案3】:

    第一步是构建一个包含所有有效单词的数据结构,并且可以轻松查询以检索与当前模式匹配的所有单词。然后使用这个匹配词列表,您可以计算最常见的字母以获得下一个候选词。另一种方法可能是找到将给出最小的下一个匹配词集的字母。

    next_guess(pattern, played_chars, dictionary)
      // find all the word matching the pattern and not containing letters played
      // not in the pattern
      words_set = find_words_matching(pattern, played_chars, dictionary)
    
      // build an array containing for each letter the frequency in the words set
      letter_freq = build_frequency_array(words_set)
    
      // build an array containing the size of the words set if ever the letter appears at least once
      // in the word (I name it its power)
      letter_power = build_power_array(words_set)
    
      // find the letter minimizing a function (the AI part ?)
      // the function could take last two arrays in account
      // this is the AI part.
      candidate = minimize(weighted_function, letter_freq, letter_power)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-04
      • 2011-06-28
      • 2022-11-09
      • 1970-01-01
      • 1970-01-01
      • 2021-02-13
      相关资源
      最近更新 更多