如何将文件夹里的文本文件变成数组,满足double[] IDF(string text,string []texts)里的参数
IDF方法里的2个参数(text, [ ]texts) 第一个text我已经知道,第二个参数 string[ ] texts 的意思是文件夹里的所有文本文件,想用button7里面的texts1表示第二个参数 [ ]texts ,应该怎么写button7里的 string[ ]texts1 满足IDF里的第二个参数...
CLASS1:
public double[] IDF(string text,string []texts)
{
Dictionary<string, int> dictionary = GetWordsFrequnce(text);
double[] idf = new double[dictionary.Keys.Count];
//int total_file = text.Length;//文件总数
int []file_num = new int[dictionary.Keys.Count]; //含有该词组的文件数
int flag = 0;
foreach(string word in dictionary.Keys)
{
file_num[flag] = 0;
for (int j=0; j < texts.Length; j++)
{
if (texts[j].Contains(word)) //在指定文件夹里所有文本文件中找到与text文件相同词的文件
{
file_num[flag]++;
}
}
idf[flag] = Math.Log( texts.Length / file_num[flag],2)+1;
flag++;
}
return idf;
}
Form:
public void button7_Click(object sender, EventArgs e)
{
FolderBrowserDialog browse = new FolderBrowserDialog();
if(browse.ShowDialog()==DialogResult.OK )
{
this.textBox4.Text = browse.SelectedPath;
string[] texts1 = Directory.GetDirectories(browse.SelectedPath);
Class1 C1=new Class1();
double[] idf = C1.IDF(result, texts1);
}
}