/
BaseProb.cs
64 lines (61 loc) · 1.7 KB
/
BaseProb.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sentiment_Console
{
class BaseProb
{
public Dictionary<string, double> d = new Dictionary<string, double>();
public double total = 0.0;
public int none = 0;
public bool exists(string key) { return d.Keys.Contains(key); }
public double getsum() { return total; }
public void get(string key, out bool para1, out double para2)
{
if (!exists(key))
{
para1 = false; para2 = none;
}
else
{
para1 = true;para2 = d[key];
}
}
public double freq(string key)
{
bool para1;
double para2;
get(key, out para1, out para2);
return para2 / total;
}
//def samples(self):
// return self.d.keys()
}
class AddOneProb : BaseProb
{
//public Dictionary<string, double> d = new Dictionary<string, double>();
//public double total = 0.0;
//public int none = 1;
public void add(string key, int value)
{
total += value;
if (!exists(key))
{
d.Add(key, 1);
total += 1;
}
d[key] += value;
}
public void DPrint()
{
Console.WriteLine(d.Count);
Console.ReadKey();
foreach (var key in d.Keys)
{
Console.WriteLine(key+" : "+d[key].ToString());
}
}
}
}