12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

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.

§23 ANNOYANCE-FILTER DICTIONARY 27<br />

23. We import a dictionary from a CSV file by importing successive records into a dictionaryWord,<br />

which is then appended to the dictionary. When the pseudo-word containing the number of mail and junk<br />

messages used to assemble the dictionary is encountered, those quantities are added to the running totals.<br />

Note that the CSV input file may be in any order—it need not be sorted in the order exportCSV creates,<br />

nor need the message count pseudo-word be the first record of the file.<br />

〈 Class implementations 11 〉 +≡<br />

void dictionary ::importCSV (istream &is )<br />

{<br />

if (verbose ) {<br />

cerr ≪ "Importing␣dictionary␣from␣CSV␣file." ≪ endl ;<br />

}<br />

}<br />

dictionaryWord dw ;<br />

while (dw .importCSV (is )) {<br />

if (dw .getJunkProbability ( ) ≡ −1 ∧ (dw .get ( ) ≡ pseudoCountsWord )) {<br />

messageCount [dictionaryWord ::Mail ] += dw .n mail ( );<br />

messageCount [dictionaryWord ::Junk ] += dw .n junk ( );<br />

}<br />

else if (dw .getJunkProbability ( ) ≥ −1) {<br />

include (dw ) ;<br />

}<br />

else {<br />

if (verbose ) {<br />

cerr ≪ "Ill−formed␣record␣in␣CSV␣import:␣\"" ≪ dw .get ( ) ≪ "\"" ≪ endl ;<br />

}<br />

}<br />

}

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

Saved successfully!

Ooh no, something went wrong!