12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

182 MAIN PROGRAM ANNOYANCE-FILTER §227<br />

227. <strong>The</strong> addFolder procedure reads a mail folder and adds the tokens it contains to the master<br />

dictionary dict with the specified category . <strong>The</strong> global messageCount for the given category is updated<br />

to reflect the number of messages added from the folder.<br />

〈 Utility functions 219 〉 +≡<br />

static void addFolder (const char ∗fname , dictionaryWord ::mailCategory cat )<br />

{<br />

if (verbose ) {<br />

cerr ≪ "Adding␣" ≪ (bsdFolder ? "BSD␣" : "") ≪ "folder␣" ≪ fname ≪ "␣as␣" ≪<br />

dictionaryWord ::categoryName (cat ) ≪ ":" ≪ endl ;<br />

}<br />

}<br />

mailFolder mf (fname , cat );<br />

mf .setBSDmode (bsdFolder );<br />

bsdFolder = false ; /∗ Reset BSD folder semantics ∗/<br />

tokenParser tp;<br />

tp.setSource (mf );<br />

tp.setTokenDefinition (isoToken , asciiToken );<br />

tp.setTokenLengthLimits (maxTokenLength , minTokenLength , streamMaxTokenLength ,<br />

streamMinTokenLength );<br />

if (pDiagFilename .length ( ) > 0) {<br />

tp.setSaveMessage (true );<br />

}<br />

dictionaryWord dw ;<br />

unsigned int ntokens = 0;<br />

while (tp.nextToken (dw )) {<br />

dict .add (dw , mf .getCategory ( ));<br />

ntokens ++;<br />

〈 Prune unique words from dictionary if autoPrune threshold is exceeded 228 〉;<br />

}<br />

messageCount [mf .getCategory ( )] += mf .getMessageCount ( );<br />

if (verbose ) {<br />

cerr ≪ "␣␣Added␣" ≪ mf .getMessageCount ( ) ≪ "␣messages,␣" ≪ ntokens ≪<br />

"␣tokens␣in␣" ≪ mf .getLineCount ( ) ≪ "␣lines." ≪ endl ;<br />

cerr ≪ "␣␣Dictionary␣contains␣" ≪ dict .size ( ) ≪ "␣unique␣tokens." ≪ endl ;<br />

cerr ≪ "␣␣Dictionary␣size␣" ≪ dict .estimateMemoryRequirement ( ) ≪ "␣bytes." ≪ endl ;<br />

}

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

Saved successfully!

Ooh no, something went wrong!