public void Store(string filepath) { StreamWriter fs = new StreamWriter(filepath, false); string csvStr = ""; Int64 avg = count / corpus.Count + 2; int csvC = 0; foreach (var entry in corpus) { nGramDist ngd = entry.Value; if (ngd.isSalient && ngd.total > avg) { csvStr = "'" + entry.Key + "',"; csvStr += ngd.negCnt + ","; csvStr += ngd.posCnt + ","; csvStr += ngd.nutCnt + ","; csvStr += ngd.bias + ","; csvStr += ngd.objective + ","; csvStr += ngd.total; csvC++; fs.WriteLine(csvStr); } } Console.WriteLine(csvC); fs.Close(); }
public double score(string line) { double score = 0.0; line = line.ToLower(); line = line.Replace(",", ""); line = line.Replace(".", ""); line = line.Replace("!", ""); line = line.Replace("?", ""); line = line.Replace("\"", ""); line = line.Replace("'", ""); line = line.Replace("#", ""); string[] ngrams = NGramify(line); double negS = 0.0000001, posS = 0.0000001, objS = 0.0000001; foreach (string ng in ngrams) { if (corpus.ContainsKey(ng)) { nGramDist ngd = corpus[ng]; //if (ngd.isSalient) { if (ngd.objective > 0.5) { objS += ngd.objective; } else { double bias = ngd.bias; if (bias < 0) { negS -= bias; } else { posS += bias; } } } } } if (objS > negS && objS > posS) { return(0); } if (negS > posS) { return(-negS / (negS + posS + objS)); } else if (negS < posS) { return(posS / (negS + posS + objS)); } score = (posS - negS) / (negS + posS + objS); return(score); }