Transcript of "21 spam"

1.
Hadley Wickham
Stat405String processing
Thursday, 4 November 2010

2.
Next project
Poster presentation: last week of class or
ﬁnals week?
Nov 23: Tracy Volz will be presenting on
how to do a good poster
You need to pick your own dataset. Ideas
here: http://www.delicious.com/hadley/
data. Start thinking now!
Thursday, 4 November 2010

3.
Motivation
Want to try and classify spam vs. ham
(non-spam) email.
Need to process character vectors
containing complete contents of email.
Eventually, will create variables that will be
useful for classiﬁcation.
Same techniques very useful for data
cleaning.
Thursday, 4 November 2010

6.
...
Date: Sun, 11 Nov 2001 11:55:05 -0500
Message-Id: <200503101247.j2ACloAq014654@host.high-host.com>
To: benrobinson13@shaw.ca
Subject: LETS DO THIS TOGTHER
From: ben1 <ben_1_wills@yahoo.com.au>
X-Priority: 3 (Normal)
CC:
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: RLSP Mailer
Dear Friend,
Firstly, not to caurse you embarrassment, I am Barrister Benson Wills, a Solicitor at law and the
personal attorney to late Mr. Mark Michelle a National of France, who used to be a private
contractor with the Shell Petroleum Development Company in Saudi Arabia, herein after shall be
referred to as my client. On the 21st of April 2001, him and his wife with their three children were
involved in an auto crash, all occupants of the vehicle unfortunately lost their lives.
Since then, I have made several enquiries with his country's embassies to locate any of my clients
extended relatives, this has also proved unsuccessful. After these several unsuccessful attempts, I
decided to contact you with this business partnership proposal. I have contacted
you to assist in repatriating a huge amount of money left behind by my client before they get
confiscated or declared unserviceable by the Finance/Security Company where these huge deposit was
lodged.
The deceased had a deposit valued presently at £30milion Pounds Sterling and the Company has issued
me a notice to provide his next of kin or Beneficiary by Will otherwise have the account confiscated
within the next thirty official working days.
Since I have been unsuccessful in locating the relatives for over two years now, I seek your consent
to present you as the next of kin/Will Beneficiary to the deceased so that the proceeds of this
Thursday, 4 November 2010

7.
Structure of an email
Headers give metadata
Empty line
Body of email
Other major complication is attachments
and alternative content, but we’ll ignore
those for class
Thursday, 4 November 2010

14.
Displaying strings
print() will display quoted form.
cat() will display actual contents (but
need to add a newline to the end).
(But generally better to use message() if
you want to send a message to the user
of your function)
Thursday, 4 November 2010

15.
Your turn
Create a string for each of the following
strings:
:-
(^_^")
@_'-'
m/
Create a multiline string.
Compare the output from print and cat
Thursday, 4 November 2010

18.
Header vs. content
Need to split the string into two pieces,
based on the the location of double line
break:
str_locate(string, pattern)
Splitting = creating two substrings, one to
the right, one to the left:
str_sub(string, start, end)
Thursday, 4 November 2010

25.
Your turn
Write a small function that given a single
header ﬁeld splits it into name and
contents.
Do you want to use str_split(), or
str_locate() & str_sub()?
Remember to get the algorithm working
before you write the function
Thursday, 4 November 2010

27.
We split the content into header and
body. And split up the header into ﬁelds.
Both of these tasks used ﬁxed strings.
What if the pattern we need to match is
more complicated?
Next time
Thursday, 4 November 2010