删除单词以及出现频率 [英] Removing Words along with there frequancy

查看:120
本文介绍了删除单词以及出现频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码来生成单词的频率并按照更高的频率排列它们……它完全可以正常工作,但是有些单词与"and","or","a","the"无关.我想删除它们以及那里的频率.需要一些帮助..

I have this code to generate frequency of words and arrange them according to the higher frequency... it works completely fine but some of the words like "and" "or" "a" "the" are irrelevant. i want to delete them along with there frequency. Need some assistance..

String[] arr = targetListBox.Text.Split(' ');
Dictionary<string, int> dic = new Dictionary<string, int>();
dic = mkCount(arr, dic);
StringBuilder sb = new StringBuilder();
var sortedDict = (from entry in dic orderby entry.Value descending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
//richTextBox1.Text="Most Frequent Terms in the File: " + targetListBox.Text + " ";
foreach (KeyValuePair<string, int> pair in sortedDict)
{

    // Output the most frequently occurring words and the associated word counts
    sb.AppendLine(pair.Key + " " + pair.Value + " ");
    richTextBox1.Text = sb.ToString();


}

推荐答案

在代码工作之前将其添加. :)
adding this before code worked. :)
string[] arrToCheck = new string[] {"and","or","a" };
                StringBuilder input = new StringBuilder(targetListBox.Text);
                foreach (string word in arrToCheck )
                {
                    input.Replace(word, string.Empty);
                }
                targetTextBox2.Text = input.ToString();


这篇关于删除单词以及出现频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆