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.

162 CLASSIFY MESSAGE ANNOYANCE-FILTER §191<br />

}<br />

}<br />

os ≪ Xfile ≪ "−Parser−Diagnostic:␣" ≪ parserDiagnostics .front ( ) ≪ transEndl ;<br />

messageTranscript .insert (p, os .str ( ));<br />

parserDiagnostics .pop( );<br />

This code is used in section 185.<br />

192. Here’s the little function which adds the most signficant words and their probabilities to either<br />

the parser diagnostics or the transcript. We break it out into a function to avoid duplicating the code.<br />

〈 Class implementations 11 〉 +≡<br />

void classifyMessage ::addSignificantWordDiagnostics (list〈string〉 &l,<br />

list〈string〉::iterator where , multimap〈double, string〉 &rtokens , string endLine )<br />

{<br />

unsigned int n = min (static cast〈multimap〈double, string〉::size type 〉(nExtremal ),<br />

rtokens .size ( ));<br />

}<br />

}<br />

multimap〈double, string〉::const reverse iterator rp = rtokens .rbegin ( );<br />

for (unsigned int i = 0; i < n; i++) {<br />

dictionary ::iterator dp = d ⃗ find (rp ⃗ second );<br />

double wp = ((dp ≡ d ⃗ end ( )) ∨ ((dp ⃗ second .getJunkProbability ( ) < 0))) ?<br />

unknownWordProbability : dp ⃗ second .getJunkProbability ( );<br />

ostringstream os ;<br />

os ≪ Xfile ≪ "−Significant−Word:␣" ≪ setw (3) ≪ setiosflags (ios ::right ) ≪ (i + 1) ≪<br />

"␣␣" ≪ setw (8) ≪ setprecision (5) ≪ setiosflags (ios ::left ) ≪ wp ≪ "␣␣\"" ≪ rp ⃗ second ≪<br />

"\"" ≪ endLine ;<br />

l.insert (where , os .str ( ));<br />

os .str ("");<br />

rp ++;

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

Saved successfully!

Ooh no, something went wrong!