0

キーワードのリストがあるとしましょう

free numerology compatibility
numerology calculator free
free numerology report
numerology reading
free numerology reading
etc...

次の結果を取得したいときに、さらに調査できるように、どのC#アルゴリズムまたはそれが何と呼ばれているのでしょうか?

6 instances of "numerology"
3 instances of "free numerology"
2 instances of "numerology reading"
1 instance of "numerology compatibility"
1 instance of "numerology calculator"
etc...
4

2 に答える 2

0

単語の配列をループして、辞書を使用してカウントを保存できます。

例えば

Dictionary d = new Dictionary<string, int>();

foreach (string word in wordList)
{
    if (d.ContainsKey(word))
    {
       d[word]++;
    }
    else
    {
       d[word] = 1;
    }
}
于 2012-10-24T15:09:32.123 に答える
0

あなたが探している主題は、用語頻度分析または単語頻度分析の名前で行きます.次のコードは、各単語の頻度を与えることができます. 特定のフレーズの頻度を見つけることも非常に簡単ですが、ドキュメント全体を分析して、頻度が 1 を超える用語のシーケンスを見つけるのは少し複雑です。

void Analyze(ref String InputText, ref Dictionary<string, int> WordFreq)
{
    string []Words = InputText.Split(' ');

    for (int i = 0; i < Words.Length; i++)
    {
        if (WordFreq.ContainsKey(Words[i]) == false)
            WordFreq.Add(Words[i], 1);
        else
        {
             WordFreq[Words[i]]++;
        }
    }
}

void DoWork()
{
    string InputText = "free numerology compatibility numerology calculator free free numerology report numerology reading free numerology reading";
    Dictionary<string, int> WordFreq = new Dictionary<string,int>();

    Analyze(ref InputText,ref WordFreq);

    string result = null;
    foreach (KeyValuePair<string, int> pair in WordFreq)
    {
        result += pair.Value + " Instances of " + pair.Key + "\r\n";
    }

    MessageBox.Show(result);
}

private void Form1_Load(object sender, EventArgs e)
{
    DoWork();
}
于 2012-10-24T17:10:40.200 に答える