将字符串列表与可用的词典/同义词库进行比较

问题描述:

我有一个程序(C#),该程序生成字符串列表(原始字符串的排列).大多数字符串都是按预期方式对原始字母进行随机分组的(即etam,aemt,team).我想以编程方式在列表中找到一个字符串,它是一个实际的英语单词.我需要一个词库/词典来查找和比较每个字符串.任何人都知道可用的资源.我在C#中使用VS2008.

I have a program (C#) that generates a list of strings (permutations of an original string). Most of the strings are random grouping of the original letters as expected (ie etam,aemt, team). I wanna find the one string in the list that is an actual English word, programatically. I need a thesaurus/dictionary to look up and compare each string to. Any one know of a resource available. Im using VS2008 in C#.

您可以从网上下载单词列表(例如,此处提到的文件之一:

You could download a list of words from the web (say one of the files mentioned here: http://www.outpost9.com/files/WordLists.html), then then do a quick:

// Read words from file.
string [] words = ReadFromFile();

Dictionary<String, List<String>> permuteDict = new Dictionary<String, List<String>>(StringComparer.OrdinalIgnoreCase);

foreach (String word in words) {
    String sortedWord = new String(word.ToArray().Sort());
    if (!permuteDict.ContainsKey(sortedWord)) {
        permuteDict[sortedWord] = new List<String>();
    }
    permuteDict[sortedWord].Add(word);
}

// To do a lookup you can just use

String sortedWordToLook = new String(wordToLook.ToArray().Sort());

List<String> outWords;
if (permuteDict.TryGetValue(sortedWordToLook, out outWords)) {
    foreach (String outWord in outWords) {
        Console.WriteLine(outWord);
    }
}