2eab89ccab223647285a82579b6c374cdd08c47c
[IRC.git] / Robust / src / Benchmarks / Distributed / SpamFilter / FilterResult.java
1 /**
2  * A FilterResult encapsulates the result of a filter made by checking a mail.
3  **/
4 public class FilterResult {
5   /**
6    * This value is used if type is ERROR or UNKNOWN.
7    */
8   public double NO_RESULT;
9
10   /**
11    * A result value greater or equal this value indicates that the filter has
12    * decided on spam.
13    */
14   public int SPAM_THRESHOLD;
15   public int ABSOLUTE_SPAM;
16   public int ABSOLUTE_HAM;
17
18   //public double result; // the result, a value between -1 (ham) and 1000 (spam), 
19   // negative values for "error", "unknown" etc.
20
21   // -----------------------------------------------------------------------------
22
23   public FilterResult(double result) {
24     SPAM_THRESHOLD=500;
25     ABSOLUTE_SPAM=1000;
26     ABSOLUTE_HAM=0;
27     NO_RESULT=-1;
28     //this.result = result;
29   }
30
31   public FilterResult() {
32     SPAM_THRESHOLD=500;
33     ABSOLUTE_SPAM=1000;
34     ABSOLUTE_HAM=0;
35     NO_RESULT=-1;
36   }
37
38   public boolean getResult(int[] confidenceVals) {
39     int[] res = new int[3];
40     for(int i=0; i<confidenceVals.length; i++) {
41        if(confidenceVals[i] < 0)
42          res[0]+=1; //unknown
43        if(confidenceVals[i] >= 0 && confidenceVals[i] < 500)
44          res[1]+=1; //ham
45        if(confidenceVals[i] > SPAM_THRESHOLD)
46          res[2]+=1;//spam
47     }
48     int maxVotes=0;
49     int max;
50     for(int i=0; i<3;i++) {
51       if(res[i] > maxVotes) {
52         maxVotes = res[i];
53         max = i;
54       }
55     }
56     if(max==0)
57       return false;
58     if(max==1)
59       return false;
60     if(max==2)
61       return true;
62
63     System.out.println("Err: getResult() Control shouldn't come here\n");
64     return false;
65   }
66
67   /*
68      public void addProperty(String key, String value) {
69      properties.put(key,value);
70      }
71
72      public String getProperty(String key) {
73      return properties.get(key);
74      }
75
76      public HashMap<String,String> getProperties() {
77      return properties;
78      }
79    */
80 }