compile errors fixed
authoradash <adash>
Mon, 2 Nov 2009 01:52:02 +0000 (01:52 +0000)
committeradash <adash>
Mon, 2 Nov 2009 01:52:02 +0000 (01:52 +0000)
Robust/src/Benchmarks/Distributed/SpamFilter/FilterResult.java
Robust/src/Benchmarks/Distributed/SpamFilter/FilterStatistic.java
Robust/src/Benchmarks/Distributed/SpamFilter/HashEntry.java
Robust/src/Benchmarks/Distributed/SpamFilter/HashStat.java
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/makefile [new file with mode: 0644]

index 9eb03c52a310586ce9a70982ea0a67946b896bab..2a8a2bf211546bd46cdb4c019e9e82111954fdf5 100644 (file)
@@ -25,7 +25,7 @@ public class FilterResult {
     ABSOLUTE_SPAM=1000;
     ABSOLUTE_HAM=0;
     NO_RESULT=-1;
-    this.result = result;
+    //this.result = result;
   }
 
   public FilterResult() {
@@ -35,14 +35,6 @@ public class FilterResult {
     NO_RESULT=-1;
   }
 
-  public double getResult() {
-    return result;
-  }
-
-  public boolean isSpam() {
-    return result >= SPAM_THRESHOLD;
-  }
-
   public boolean getResult(int[] confidenceVals) {
     int[] res = new int[3];
     for(int i=0; i<confidenceVals; i++) {
@@ -61,11 +53,11 @@ public class FilterResult {
         max = i;
       }
     }
-    if(i==0)
+    if(max==0)
       return false;
-    if(i==1)
+    if(max==1)
       return false;
-    if(i==2)
+    if(max==2)
       return true;
 
     System.out.println("Err: getResult() Shouldn't come here\n");
index c50b7023e79a30fc7860c687cf0493d39f5bf1fd..e4fbac544539fa720f39a6de8741667c156ee41c 100644 (file)
@@ -6,7 +6,9 @@ public class FilterStatistic {
   // -------------------------------------------------------
 
   public FilterStatistic() {
-    this(0,0,0);
+    this.spam = 0;
+    this.ham = 0;
+    this.unknown = 0;
   }
 
   public FilterStatistic(int spam, int ham, int unknown) {
@@ -27,10 +29,6 @@ public class FilterStatistic {
     return spam;
   }
 
-  public String getName() {
-    return name;
-  }
-
   public void setHam(int i) {
     ham = i;
   }
@@ -58,8 +56,4 @@ public class FilterStatistic {
   public void increaseUnknown() {
     setUnknown(getUnknown() + 1);
   }
-
-  public void setName(String name) {
-    this.name = name;
-  }
 }
index 95cfe40ab966fed40d7b490dfbec378c5498705e..6b49e9c86e16cd34bf66d9489cc28384d690b94d 100644 (file)
@@ -28,7 +28,7 @@ public class HashEntry {
   }
 
   public void setsig(String signature) {
-    this.setsig=signature;
+    this.signature=signature;
   }
 
   public String getEngine() {
@@ -39,7 +39,7 @@ public class HashEntry {
     return signature;
   }
 
-  public Stat getStats() {
+  public HashStat getStats() {
     return stats;
   }
 
@@ -47,9 +47,9 @@ public class HashEntry {
     if(o.getType()!=getType())
       return false;
     HashEntry he = (HashEntry)o;
-    if(!(he.getEngine().equals(Engine)))
+    if(!(he.getEngine().equals(engine)))
       return false;
-    if(!(he.getSignature().equals(Signature)))
+    if(!(he.getSignature().equals(signature)))
       return false;
     //if(!(he.getStats().equals(stats)))
     //  return false;
@@ -57,10 +57,10 @@ public class HashEntry {
   }
 
   public int askForSpam() {
-    Vector users = stats.getUsers();
+    int[] users = stats.getUsers();
     int spamConfidence=0;
-    for(int i=0; i<users.size(); i++) {
-      int userid = (int) (users.elementAt(i));
+    for(int i=0; i<users.length; i++) {
+      int userid = users[i];
       spamConfidence += stats.userstat[userid].getChecked();
     }
     return spamConfidence;
index a11004161aa2c64d4d0e6af090e90ac527844785..92143eebb155a45f5e9f9e3663576e24558313b4 100644 (file)
@@ -1,7 +1,7 @@
 public class HashStat {
   int[] userid;
   FilterStatistic[] userstat; 
-  Vector listofusers;
+  int[] listofusers;
   public HashStat() {
     userid = new int[8]; //max users for our system=8
     userstat = new FilterStatistic[8];
@@ -26,17 +26,21 @@ public class HashStat {
   }
 
   public int gethamcount(int userid) {
-    return userstat[userid].getham();
+    return userstat[userid].getHam();
   }
 
   public int getunknowncount(int userid) {
     return userstat[userid].getUnknown();
   }
 
-  public Vector getUsers() {
+  public int[] getUsers() {
+    int nusers = numUsers();
+    listofusers = new int[nusers];
+    int j=0;
     for(int i=0; i<8; i++) {
       if(userid[i] == 1) {
-        listofusers.addElement(i);
+        listofusers[j]=i;
+        j++;
       }
     }
     return listofusers;
@@ -47,7 +51,6 @@ public class HashStat {
     for(int i=0; i<8; i++) {
       if(userid[i] == 1) {
         count++;
-        listofusers.addElement(i);
       }
     }
     return count;
index bf26fdc1abaeb3719c650ee1818568ec0cdfa1ca..ffb84ffb22cf5e41565ade1058be7b9bcc788ca9 100644 (file)
@@ -61,7 +61,6 @@ public class Mail {
     {
       body += line;
     }
-
   }
 
        // -------------------------------------------------------
@@ -74,6 +73,7 @@ public class Mail {
                return header;
        }
 
+    /*
        public void setSentOn(String sentOn) {
                this.sentOn = sentOn;
        }
@@ -82,7 +82,6 @@ public class Mail {
                return sentOn;
        }
 
-    /*
        public Date getSentOnAsDate() {
                String sentOn = getSentOn();
                return parseDate(sentOn);
@@ -225,6 +224,7 @@ public class Mail {
 
        }
 
+    /*
        public boolean equals(Object o) {
                if (o instanceof Mail) {
                        Mail mail = (Mail)o;
@@ -233,6 +233,7 @@ public class Mail {
 
                return false;
        }
+    */
   
   public Vector createMailStringsWithURL()
   {
@@ -246,8 +247,10 @@ public class Mail {
     String[] splittedBody = body.split();
 
     // add URL and email in the body
-    for(String segment : splittedBody)
+    for(int i=0; i<splittedBody.length; i++) 
+    //for(String segment : splittedBody)
     {
+      String segment = splittedBody[i];
       if(segment.startsWith("http://"))  // URL
       {
         returnStrings.addElement(segment);
@@ -326,6 +329,8 @@ public class Mail {
     return isSpam;
   }
 
+  /* For tests only */
+  /*
   public static void main(String[] args)
   {
     Mail mail = new Mail("./emails/email1");
@@ -337,4 +342,5 @@ public class Mail {
       System.out.println(b);
     }
   }
+  */
 }
index 2f5ab98107b0f8a1363f66e23ffc714352e0014f..ab9caae81633440d542b0b4dd114963369586b84 100644 (file)
@@ -75,7 +75,7 @@ public class SignatureComputer {
 
     Vector printableSigs = new Vector(); // vector of strings
     for (int mailIndex = 0; mailIndex < EmailParts.size(); mailIndex++) {
-      String mail = EmailParts.elementAt(mailIndex);
+      String mail = (String) (EmailParts.elementAt(mailIndex));
 
       if (mail == null) continue;
 
@@ -85,7 +85,17 @@ public class SignatureComputer {
       for (int engineIndex = 0; engineIndex < enginesToUseForCheck.length; engineIndex++) {
         int engineNo = enginesToUseForCheck[engineIndex];
         String sig = null;
+        if(engineNo==4) {
+          sig = computeSignature(engineNo,mail);
+        }
+        if(engineNo==8) {
+          sig = computeSignature(engineNo,mail);
+        }
+        if(engineNo!=4 || engineNo!=8) {
+          System.out.println("Couldn't find the signature engine\n");
+        }
 
+        /*
         switch (engineNo) {
           case 4:
             sig = computeSignature(engineNo,mail);
@@ -98,10 +108,11 @@ public class SignatureComputer {
             //sig = computeSignature(engineNo,curPart.getCleaned());
             break;
         }//switch engineNo
+        */
 
-        if (sig != null && sig.length > 0) {
-          String hash = engineNo + ":" + sig[curSigIndex];
-          printableSigs.add(hash);
+        if (sig != null && sig.length() > 0) {
+          String hash = engineNo + ":" + sig;
+          printableSigs.addElement(hash);
         } else {
           /* we didn't produce a signature for the mail. */
         }
@@ -116,6 +127,20 @@ public class SignatureComputer {
    * @return
    */
   private String computeSignature(int engineNo, String mail) {
+    if(engineNo==4) {
+      String s1 = this.sig4.computeSignature(mail);
+      //return new String { this.sig4.computeSignature(mail) };
+    }
+
+    if(engineNo==8) {
+        //String cleanedButKeepHTML = Preprocessor.preprocess(mail,Preprocessor.ConfigParams.NO_DEHTML);
+        //return this.sig8.computeSignature(cleanedButKeepHTML);
+      return this.sig8.computeSignature(mail);
+    }
+
+    return null;
+
+    /*
     switch (engineNo) {
       case 4:
         return new String { this.sig4.computeSignature(mail) };
@@ -126,5 +151,6 @@ public class SignatureComputer {
       default:
         return null;
     }
+    */
   }
 }
index d690f25300f6d7f1525c07b6799f187bba2c5686..600dcea6c679e0bf236ee8b90abc819198685344 100644 (file)
@@ -24,7 +24,7 @@ public class SpamFilter extends Thread {
     int thid;
     atomic {
       niter=numiter;
-      nemails=numemails;
+      nemails=numemail;
       thid = id;
     }
 
@@ -33,17 +33,19 @@ public class SpamFilter extends Thread {
     for(int i=0; i<niter; i++) {
       for(int j=0; j<nemails; j++) {
         int pickemail = rand.nextInt(100);
+        Mail email = new Mail();
         //Mail email = getEmail(pickemail);
         boolean filterAnswer = checkMail(email, thid);
         boolean userAnswer = email.getIsSpam();
         if(filterAnswer != userAnswer) {
-          sendFeedBack(email);
+          //sendFeedBack(email);
         }
       }
     }
   }
 
   public static void main(String[] args) {
+   /* 
     int nthreads;
     int[] mid = new int[8];
     mid[0] = (128<<24)|(195<<16)|(136<<8)|162; //dc-1.calit2
@@ -56,21 +58,21 @@ public class SpamFilter extends Thread {
     mid[7] = (128<<24)|(195<<16)|(136<<8)|169; //dc-8.calit2
 
 
-    /**
-     * Read options from command prompt
-     **/
+    
+     //Read options from command prompt
     SpamFilter sf = new SpamFilter();
     SpamFilter.parseCmdLine(args, sf);
 
-    /**
-     * Create Global data structure 
-     **/
+    
+    //Create Global data structure 
+    
     DistributedHashMap dhmap;
     atomic {
       dhmap = global new DistributedHashMap(500, 0.75f);
     }
     //3. N times iteration of work that needs to be done
     //     by each client
+    */
 
   }
 
@@ -90,7 +92,7 @@ public class SpamFilter extends Thread {
         }
       } else if(arg.equals("-t")) { //num of threads
         if(i < args.length) {
-          sf.threshold = new Integer(args[i++]).intValue();
+          sf.nthreads = new Integer(args[i++]).intValue();
         }
       } else if(arg.equals("-h")) {
         sf.usage();
@@ -116,7 +118,7 @@ public class SpamFilter extends Thread {
    **/
   public boolean checkMail(Mail mail, int userid) {
     //Preprocess emails
-    //Vector partsOfMailStrings = createMailStrings(mail);
+    Vector partsOfMailStrings = mail.createMailStringsWithURL();
 
     //Compute signatures
     SignatureComputer sigComp = new SignatureComputer();
@@ -127,7 +129,7 @@ public class SpamFilter extends Thread {
 
     //---- create and  return results --------
     FilterResult filterResult = new FilterResult();
-    boolean spam = filterResult.getResult();
+    boolean spam = filterResult.getResult(confidenceVals);
 
     return spam;
   } 
@@ -154,7 +156,7 @@ public class SpamFilter extends Thread {
         mydhmap.put(myhe, fs);
       } else {
         // ----- now connect to global data structure and ask query -----
-        confidenceVals[i] = tmphe.askForSpam(numparts);
+        confidenceVals[i] = tmphe.askForSpam();
       }
     }
 
diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/makefile b/Robust/src/Benchmarks/Distributed/SpamFilter/makefile
new file mode 100644 (file)
index 0000000..8491ee7
--- /dev/null
@@ -0,0 +1,24 @@
+MAINCLASS=SpamFilter
+SRC=${MAINCLASS}.java \
+     DistributedHashMap.java \
+     Mail.java \
+     FilterResult.java \
+     HashEntry.java \
+     HashStat.java \
+     SignatureComputer.java \
+     FilterStatistic.java \
+     EphemeralSignature.java \
+     WhiplashSignature.java
+
+FLAGS1=-dsm -optimize -mainclass ${MAINCLASS}
+FLAGS2=-dsm -dsmcaching -optimize -mainclass ${MAINCLASS}
+FLAGS3=-dsm -dsmcaching -prefetch -optimize -mainclass ${MAINCLASS}
+
+default:
+       ../../../buildscript ${FLAGS1} -o ${MAINCLASS}NPNC ${SRC}
+#      ../../../buildscript ${FLAGS2} -o ${MAINCLASS}NPC ${SRC}
+#      ../../../buildscript ${FLAGS3} -o ${MAINCLASS}RangeN ${SRC}
+
+clean:
+       rm -rf tmpbuilddirectory
+       rm *.bin