final changes to spamfilter. most up todate working version with no bugs
authoradash <adash>
Sun, 15 Nov 2009 00:03:04 +0000 (00:03 +0000)
committeradash <adash>
Sun, 15 Nov 2009 00:03:04 +0000 (00:03 +0000)
Robust/src/Benchmarks/Distributed/SpamFilter/Mail.java
Robust/src/Benchmarks/Distributed/SpamFilter/SignatureComputer.java
Robust/src/Benchmarks/Distributed/SpamFilter/SpamFilter.java
Robust/src/Benchmarks/Distributed/SpamFilter/WhiplashSignature.java

index f813b596431c593bfa6f4e4ddeaebe8f88f66381..2027070f4c8a7c0425a142dd68a6f81e664c8476 100644 (file)
@@ -33,8 +33,7 @@ public class Mail {
 
   public Mail(String fileName)  // read a mail from file
   {
-    fileName = "emails/email41";
-    System.out.println("fileName= " + fileName);
+    //System.out.println("DEBUG: fileName= " + fileName);
 
     FileInputStream fileinput = new FileInputStream(fileName);
     String line;
@@ -65,7 +64,7 @@ public class Mail {
       {
         cc = (String)splittedLine.elementAt(1);
       }
-      else if(((String)(splittedLine.elementAt(0))).equals("Title:")) // Subject
+      else if(((String)(splittedLine.elementAt(0))).equals("Subject:")) // Subject
       {
         subject = (String)splittedLine.elementAt(1);
         break;
@@ -360,8 +359,6 @@ public class Mail {
     String tmpStr = new String();
     tmpStr += charArray[0];
 
-    //System.out.println("tmpStr= " + tmpStr);
-
     for(int i=1; i< noURLBody.length(); i++)
     {
       if((i % size) == 0) {
index 4a79caf067744d493c1eabf1035486bf02b53bee..4f98a2d0e47b861e4a8b73153b0baa26f69a2c26 100644 (file)
@@ -109,7 +109,9 @@ public class SignatureComputer {
         if (sig != null) {
           String hash = engineNo + ":" + sig;
           printableSigs.addElement(hash);
-          // System.out.println("mail= " +mail + " hash= " + hash);
+
+          //System.out.println("DEBUG: mail= " +mail + " hash= " + hash);
+
         } else {
           // we didn't produce a signature for the mail. 
         }
@@ -162,7 +164,6 @@ public class SignatureComputer {
     Vector getURLs = (Vector)(EmailParts.elementAt(1));
     for (int mailIndex = 0; mailIndex < getURLs.size(); mailIndex++) {
       String mail = (String) (getURLs.elementAt(mailIndex));
-      System.out.println("from GETURLS mail= " + mail);
 
       /*
        * Compute Sig for bodyparts that are cleaned.
index a4bc9e23fd44b2c9751df0f1c9516d32f4e73cca..1b248686ea73fcc4a3a3c0a1bb5178e81f4142fe 100644 (file)
@@ -43,7 +43,6 @@ public class SpamFilter extends Thread {
     }
 
     Random rand = new Random(thid);
-    Random myrand = new Random(0);
 
     for(int i=0; i<niter; i++) {
       correct =0;
@@ -80,13 +79,16 @@ public class SpamFilter extends Thread {
  //       System.out.println("userAnswer= " + userAnswer + " filterAnswer= " + filterAnswer);
 
         if(filterAnswer != userAnswer) {
+          /* wrong answer from the spam filter */
           wrong++;
           atomic {
-            sendFeedBack(signatures, userAnswer, thid);
+            sendFeedBack(signatures, userAnswer, thid, rand);
           }
         }
-        else 
+        else {
+          /* Correct answer from the spam filter */
           correct++;
+        }
       } //end num emails
       System.out.println((i+1)+"th iteration correct = " + correct + " Wrong = " + wrong + " percentage = " + ((float)correct/(float)nemails));
     }//end num iter
@@ -262,7 +264,7 @@ public class SpamFilter extends Thread {
    * spam database and trains the spam database to check future
    * emails and detect spam
    **/
-  public void sendFeedBack(Vector signatures, boolean isSpam, int id) {
+  public void sendFeedBack(Vector signatures, boolean isSpam, int id, Random myrand) {
 
     for(int i=0;i<signatures.size();i++) {
       String part = (String)(signatures.elementAt(i));
@@ -308,16 +310,29 @@ public class SpamFilter extends Thread {
 
       //System.out.println(fs.toString());
 
-      //TODO: Allow users to give incorrect feedback
-
-      //Increment spam or ham value 
-      if(isSpam) {
-        tmphe.stats.incSpamCount(id);
-        fs.increaseSpam();
+      //Allow users to give incorrect feedback
+      int pickemail = myrand.nextInt(100);
+      /* Randomly allow user to provide incorrect feedback */
+      if(pickemail < 95) {
+        //give correct feedback 95% of times
+        //Increment spam or ham value 
+        if(isSpam) {
+          tmphe.stats.incSpamCount(id);
+          fs.increaseSpam();
+        } else {
+          tmphe.stats.incHamCount(id);
+          fs.increaseHam();
+        }
       } else {
-        tmphe.stats.incHamCount(id);
-        fs.increaseHam();
-      }
+        // Give incorrect feedback 5% of times
+        if(isSpam) {
+          tmphe.stats.incHamCount(id);
+          fs.increaseHam();
+        } else {
+          tmphe.stats.incSpamCount(id);
+          fs.increaseSpam();
+        }
+      } //end of pickemail
     }
   }
 }
index 97a197701d418d506fd3e420a006e4cdee84d261..4a8b0bd859f2504e19115faec6ec9d2326c552c5 100644 (file)
@@ -19,7 +19,7 @@
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 
- $Id: WhiplashSignature.java,v 1.3 2009/11/14 02:10:08 adash Exp $
+ $Id: WhiplashSignature.java,v 1.4 2009/11/15 00:03:04 adash Exp $
  */
 public class WhiplashSignature {
   char[] b64table;
@@ -166,7 +166,7 @@ public class WhiplashSignature {
     Vector hosts = new Vector();
     String buf = new String(text);
 
-    System.out.println("DEBUG: extractHosts() string= " + buf);
+    //System.out.println("DEBUG: extractHosts() string= " + buf);
 
     /* Extract hosts from http:// links */
     int idx;
@@ -177,7 +177,7 @@ public class WhiplashSignature {
       buf = buf.subString(startidx);
       int endidx = buf.indexOf(strcom);
       String host = buf.subString(0, endidx);
-      System.out.println("http links extracted host= " + host);
+      //System.out.println("DEBUG: http links extracted host= " + host);
       hosts.addElement(host);
       buf = buf.subString(endidx+strcom.length());
     }
@@ -191,7 +191,7 @@ public class WhiplashSignature {
       buf = buf.subString(startidx);
       int endidx = buf.indexOf(strdot);
       String host = buf.subString(0, endidx);
-      System.out.println("email addr extracted host= " + host);
+      //System.out.println("DEBUG: email addr extracted host= " + host);
       hosts.addElement(host);
       buf = buf.subString(endidx+strdot.length());
     }