From: adash Date: Fri, 30 Oct 2009 17:55:44 +0000 (+0000) Subject: more files X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d7eb746f75d5af6bb454b040d98bb028c49f27ba;p=IRC.git more files --- diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/FilterResult.java b/Robust/src/Benchmarks/Distributed/SpamFilter/FilterResult.java new file mode 100644 index 00000000..25a98ac4 --- /dev/null +++ b/Robust/src/Benchmarks/Distributed/SpamFilter/FilterResult.java @@ -0,0 +1,54 @@ +/** + * A FilterResult encapsulates the result of a filter made by checking a mail. + **/ +public class FilterResult { + /** + * This value is used if type is ERROR or UNKNOWN. + */ + public double NO_RESULT; + + /** + * A result value greater or equal this value indicates that the filter has + * decided on spam. + */ + public double SPAM_THRESHOLD; + public double ABSOLUTE_SPAM; + public double ABSOLUTE_HAM; + + //TODO decide a good way of deciding + public double result; // the result, a value between 0 (ham) and 1 (spam), negative values for "error", "unknown" etc. + + //public HashMap properties = new HashMap(); // additional properties of the filter (mainly for statistics) + + // ----------------------------------------------------------------------------- + + public FilterResult(double result) { + SPAM_THRESHOLD=0.5; + ABSOLUTE_SPAM=1.0; + ABSOLUTE_HAM=0.0; + NO_RESULT=-1; + this.result = result; + } + + public double getResult() { + return result; + } + + public boolean isSpam() { + return result >= SPAM_THRESHOLD; + } + + /* + public void addProperty(String key, String value) { + properties.put(key,value); + } + + public String getProperty(String key) { + return properties.get(key); + } + + public HashMap getProperties() { + return properties; + } + */ +} diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/Mail.java b/Robust/src/Benchmarks/Distributed/SpamFilter/Mail.java new file mode 100644 index 00000000..44be4827 --- /dev/null +++ b/Robust/src/Benchmarks/Distributed/SpamFilter/Mail.java @@ -0,0 +1,194 @@ +/** + * This class is a container for all data contained in an Email Message. + **/ +public class Mail { + + String header; // the full header + //String sentOn; // time the message was sent + //String receivedOn; // time when the message arrived + String from; // the "from" field + String to; // the "to" field + String cc; + String subject; + String body; + String sourceCode; + boolean hasAttachement; + //String encoding; //rich text, plain, html + + String messageID; // cached message ID for reuse (takes a lot of memory and is used all over the place) + //same as hashcode of a class + + public Mail() { + messageID=null; + } + + // ------------------------------------------------------- + + public void setHeader(String header) { + this.header = header; + } + + public String getHeader() { + return header; + } + + public void setSentOn(String sentOn) { + this.sentOn = sentOn; + } + + public String getSentOn() { + return sentOn; + } + + /* + public Date getSentOnAsDate() { + String sentOn = getSentOn(); + return parseDate(sentOn); + } + + public void setReceivedOn(String receivedOn) { + this.receivedOn = receivedOn; + } + + public String getReceivedOn() { + return receivedOn; + } + + public Date getReceivedOnAsDate() { + String receivedOn = getReceivedOn(); + return parseDate(receivedOn); + } + */ + + /** + * Parses a given Date-String in into a real Date-Object + * + * @param stringDate the string in format dd.mm.yyyy hh:mm + * @return a Date containing the info of the string or the actual date and time if something fails. + */ + /* + public Date parseDate(String stringDate) { + // date is in this format: dd.mm.yyyy hh:mm + if (stringDate == null || "N/A".equals(stringDate)) { + return new Date(); + } + try { + synchronized (MAIL_TIME_FORMAT) { + return MAIL_TIME_FORMAT.parse(stringDate); + } + } catch (Throwable e) { + return new Date(); + } + } + */ + + public void setFrom(String from) { + this.from = from; + } + + public String getFrom() { + return from; + } + + public void setTo(String to) { + this.to = to; + } + + public String getTo() { + return to; + } + + public void setCc(String cc) { + this.cc = cc; + } + + public String getCc() { + return cc; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getSubject() { + return subject; + } + + public void setBody(String body) { + this.body = body; + } + + public String getBody() { + return body; + } + + public void setSourceCode(String sourceCode) { + this.sourceCode = sourceCode; + } + + public String getSourceCode() { + return sourceCode; + } + + // TODO: String? Is this a boolean, a number, or can be both? + public void setHasAttachement(boolean hasAttachement) { + this.hasAttachement = hasAttachement; + } + + public boolean getHasAttachement() { + return hasAttachement; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + public String getEncoding() { + return encoding; + } + + public boolean isTextEncoding() { + return getEncoding().toLowerCase().indexOf("plain") >= 0; + } + + public boolean isHTMLEncoding() { + return getEncoding().toLowerCase().indexOf("html") >= 0; + } + + public String toString() { + return getBody() + "," + getCc() + "," + getEncoding() + "," + getFrom() + "," + getHasAttachement() + "," + getHeader() + "," + getReceivedOn() + "," + getSentOn() + "," + getSourceCode() + "," + getSubject() + "," + getTo(); + } + + /* + public String getID() { + if (messageID == null) { // no cached version + // Take the message-ID header as ID (if present) + String[] messageIDs = getHeaderField("Message-ID"); + if ((messageIDs != null) && (messageIDs.length > 0)) { + messageID = messageIDs[0]; + } else { // otherwise, hash header and body as ID + return String.valueOf(getHeader().hashCode() + getBody().hashCode()); + } + } + + return messageID; + } + */ + + public String[] getHeaderField(String fieldName) { + + } + + public String extractEMailAddress() { + + } + + public boolean equals(Object o) { + if (o instanceof Mail) { + Mail mail = (Mail)o; + return this.getID().equals(mail.getID()); + } + + return false; + } +} diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/SpamFilter.java b/Robust/src/Benchmarks/Distributed/SpamFilter/SpamFilter.java new file mode 100644 index 00000000..f65ba8ba --- /dev/null +++ b/Robust/src/Benchmarks/Distributed/SpamFilter/SpamFilter.java @@ -0,0 +1,124 @@ +public class SpamFilter extends Thread { + DistributedHashMap mydhmap; + int id; //thread id + int numiter; + int numemail; + /** + * Total number of threads + **/ + int nthreads; + + public SpamFilter() { + + } + + public SpamFilter(int numiter, int numemail,int threadid) { + this.numiter=numiter; + this.numemail=numemail; + this.id = id; + } + + public void run() { + int niter; + int nemails + atomic { + niter=numiter; + nemails=numemails; + } + + Random rand = new Random(0); + + for(int i=0; i -e -t \n"); + System.out.println( " -n : num iterations"); + System.out.println( " -e : number of emails"); + System.out.println( " -t : number of threads"); + } + + /** + * Returns signatures to the Spam filter + **/ + public FilterResult[] checkMail(Mail mail) { + //Preprocess emails + //StringBuffer[] mailStrings = createMailStrings(); + //Compute signatures + //CommunicationEngine checkEngine = getCheckEngine(); + //SignatureComputer sigComp = new SignatureComputer(); + //check with global data structure + + //return results + FilterResult[] filterResults = new FilterResult[mailStrings.length]; + + return filterResults; + } +}