public double tfidf(int linenumber, string word) { double tf = 0; double idf = 0; Aux_SentenceInfo temp = Data.ListofSentenceInfo[linenumber]; foreach (var item in temp.ListofWordsInfo) { if (item.word == word) { int count = 0; foreach (var p in temp.ListofWordsInfo) { count += p.count; } tf = (double)item.count / (double)count; break; } } idf = Math.Log10((double)Data.totalines / (double)Data.DicofWords[word].Count); return(tf * idf); }
private void GetAllSentenceInfo(List <string> ListofFileInfo) { int linenum = 0; foreach (var path in ListofFileInfo) { StreamReader sr = new StreamReader(path, Encoding.UTF8); String line; while ((line = sr.ReadLine()) != null) { totalines++; ListofSentences.Add(line); Aux_SentenceInfo temp = new Aux_SentenceInfo(linenum++); foreach (var item in GetIndependentWord(line)) { bool judge = true; foreach (var p in temp.ListofWordsInfo) { if (p.word == item) { p.count++; judge = false; break; } } if (judge) { Aux_WordsInfo st = new Aux_WordsInfo(item); temp.ListofWordsInfo.Add(st); } } ListofSentenceInfo.Add(temp); } } }