ABSOLUTE_SPAM=1000;
ABSOLUTE_HAM=0;
NO_RESULT=-1;
- this.result = result;
+ //this.result = result;
}
public 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++) {
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");
// -------------------------------------------------------
public FilterStatistic() {
- this(0,0,0);
+ this.spam = 0;
+ this.ham = 0;
+ this.unknown = 0;
}
public FilterStatistic(int spam, int ham, int unknown) {
return spam;
}
- public String getName() {
- return name;
- }
-
public void setHam(int i) {
ham = i;
}
public void increaseUnknown() {
setUnknown(getUnknown() + 1);
}
-
- public void setName(String name) {
- this.name = name;
- }
}
}
public void setsig(String signature) {
- this.setsig=signature;
+ this.signature=signature;
}
public String getEngine() {
return signature;
}
- public Stat getStats() {
+ public HashStat getStats() {
return stats;
}
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;
}
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;
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];
}
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;
for(int i=0; i<8; i++) {
if(userid[i] == 1) {
count++;
- listofusers.addElement(i);
}
}
return count;
{
body += line;
}
-
}
// -------------------------------------------------------
return header;
}
+ /*
public void setSentOn(String sentOn) {
this.sentOn = sentOn;
}
return sentOn;
}
- /*
public Date getSentOnAsDate() {
String sentOn = getSentOn();
return parseDate(sentOn);
}
+ /*
public boolean equals(Object o) {
if (o instanceof Mail) {
Mail mail = (Mail)o;
return false;
}
+ */
public Vector createMailStringsWithURL()
{
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);
return isSpam;
}
+ /* For tests only */
+ /*
public static void main(String[] args)
{
Mail mail = new Mail("./emails/email1");
System.out.println(b);
}
}
+ */
}
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;
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);
//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. */
}
* @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) };
default:
return null;
}
+ */
}
}
int thid;
atomic {
niter=numiter;
- nemails=numemails;
+ nemails=numemail;
thid = id;
}
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
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
+ */
}
}
} 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();
**/
public boolean checkMail(Mail mail, int userid) {
//Preprocess emails
- //Vector partsOfMailStrings = createMailStrings(mail);
+ Vector partsOfMailStrings = mail.createMailStringsWithURL();
//Compute signatures
SignatureComputer sigComp = new SignatureComputer();
//---- create and return results --------
FilterResult filterResult = new FilterResult();
- boolean spam = filterResult.getResult();
+ boolean spam = filterResult.getResult(confidenceVals);
return spam;
}
mydhmap.put(myhe, fs);
} else {
// ----- now connect to global data structure and ask query -----
- confidenceVals[i] = tmphe.askForSpam(numparts);
+ confidenceVals[i] = tmphe.askForSpam();
}
}
--- /dev/null
+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