01.04.2015 Views

1FfUrl0

1FfUrl0

1FfUrl0

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6<br />

First, we define a range of frequent emoticons and their replacements in a dictionary.<br />

Although we could find more distinct replacements, we go with obvious positive or<br />

negative words to help the classifier:<br />

emo_repl = {<br />

# positive emoticons<br />

"&lt;3": " good ",<br />

":d": " good ", # :D in lower case<br />

":dd": " good ", # :DD in lower case<br />

"8)": " good ",<br />

":-)": " good ",<br />

":)": " good ",<br />

";)": " good ",<br />

"(-:": " good ",<br />

"(:": " good ",<br />

# negative emoticons:<br />

":/": " bad ",<br />

":&gt;": " sad ",<br />

":')": " sad ",<br />

":-(": " bad ",<br />

":(": " bad ",<br />

":S": " bad ",<br />

":-S": " bad ",<br />

}<br />

# make sure that e.g. :dd is replaced before :d<br />

emo_repl_order = [k for (k_len,k) in reversed(sorted([(len(k),k) for k<br />

in emo_repl.keys()]))]<br />

Then, we define abbreviations as regular expressions together with their expansions<br />

(\b marks the word boundary):<br />

re_repl = {<br />

r"\br\b": "are",<br />

r"\bu\b": "you",<br />

r"\bhaha\b": "ha",<br />

r"\bhahaha\b": "ha",<br />

r"\bdon't\b": "do not",<br />

r"\bdoesn't\b": "does not",<br />

r"\bdidn't\b": "did not",<br />

r"\bhasn't\b": "has not",<br />

r"\bhaven't\b": "have not",<br />

r"\bhadn't\b": "had not",<br />

r"\bwon't\b": "will not",<br />

[ 137 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!