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.

154 TOKEN PARSER ANNOYANCE-FILTER §181<br />

181. If we’re assembling phrases, we take each token parsed (which has already been stored into the<br />

dictionaryWord argument d in canonical form) and place it on the phraseQueue queue, removing<br />

the element at the tail if the queue is longer than phraseMax . <strong>The</strong>n, if the queue contains phraseMin<br />

elements or more, iterate over the range of phrase lengths we wish to generate, creating phrases and<br />

storing them onto pendingPhrases for subsequent return.<br />

〈 Class implementations 11 〉 +≡<br />

void tokenParser ::assembleAllPhrases (dictionaryWord &d)<br />

{<br />

phraseQueue .push back (d.text );<br />

if (phraseQueue .size ( ) > phraseMax ) {<br />

phraseQueue .pop front ( );<br />

assert(phraseQueue .size ( ) ≡ phraseMax );<br />

}<br />

for (unsigned int p = phraseMin ; p ≤ phraseMax ; p++) {<br />

if (p ≤ phraseQueue .size ( )) {<br />

deque〈string〉::const reverse iterator wp = phraseQueue .rbegin ( );<br />

}<br />

}<br />

}<br />

string phrase = "";<br />

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

phrase = (∗wp) + ((phrase ≡ "") ? "" : "␣") + phrase ;<br />

wp ++;<br />

}<br />

if ((phraseLimit ≡ 0) ∨ (phrase .length ( ) ≤ phraseLimit )) {<br />

pendingPhrases .push back (phrase );<br />

}

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

Saved successfully!

Ooh no, something went wrong!