<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ITPindia &#187; Java</title>
	<atom:link href="http://itp.nyu.edu/~ia303/thunk/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://itp.nyu.edu/~ia303/thunk</link>
	<description>India’s ITP blog</description>
	<lastBuildDate>Fri, 10 Apr 2009 06:20:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Markov bookshelf</title>
		<link>http://itp.nyu.edu/~ia303/thunk/2009/03/31/markov-bookshelf/</link>
		<comments>http://itp.nyu.edu/~ia303/thunk/2009/03/31/markov-bookshelf/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 12:59:12 +0000</pubDate>
		<dc:creator>India</dc:creator>
				<category><![CDATA[A2Z]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[homework]]></category>

		<guid isPermaLink="false">http://itp.nyu.edu/~ia303/thunk/?p=573</guid>
		<description><![CDATA[Oh, well. We&#8217;re back to kill-me-now territory.
This week&#8217;s assignment was
Get some XML from a web service. Extract some interesting information from the XML and use it as input to one of your homework assignments from previous weeks.
You could do this either by piping the output of your XML parsing program to the input of your [...]]]></description>
			<content:encoded><![CDATA[<p>Oh, well. We&#8217;re back to kill-me-now territory.</p>
<p>This week&#8217;s assignment was</p>
<blockquote><p>Get some XML from a web service. Extract some interesting information from the XML and use it as input to one of your homework assignments from previous weeks.</p>
<p>You could do this either by piping the output of your XML parsing program to the input of your previously implemented program, or by using a class (e.g., instantiate and use the MarkovChain class).</p></blockquote>
<p>So I thought, cool, I&#8217;ll scramble the <cite>New York Times</cite> Best Seller titles using their <a href="http://developer.nytimes.com/docs/best_sellers_api/">shiny new API</a>. Okay, so, I got an API key and managed to pull in lists of titles using&#8212;</p>
<pre class="brush: java">import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.dom4j.Element;
import java.util.List;

public class BestSeller
{
  public static void main(String[] args) throws Exception
  {

/*  Input should be one of the NY Times Best Seller list categories.
    Available categories:
    hardcover-fiction
    hardcover-nonfiction
    hardcover-advice
    paperback-nonfiction
    paperback-advice
    trade-fiction-paperback
    picture-books
    chapter-books
    paperback-books
    series-books
    mass-market-paperback
*/
    String listName = args[0];

    SAXReader reader = new SAXReader();
    EasyHTTPGet getter = new EasyHTTPGet(
      &quot;http://api.nytimes.com/svc/books/v2/lists/&quot; + listName + &quot;.xml?api-key=f25de92cf1d2615621b68d2d31f81b63:4:1703697&quot;
    );

    Document document = reader.read(getter.responseAsInputStream());
    List bookTitle = document.selectNodes(&quot;//results/book/book_details/book_detail/title&quot;);

//  If I wanted to scramble the authors, . . .
//  List bookAuthor =
//  document.selectNodes(&quot;//results/book/book_details/book_detail/author&quot;);

    for (Object o: bookTitle)
    {
      Element elem = (Element)o;
      String text = elem.getText();
      System.out.println(text);
    } // end for
  } // end main
} // end class</pre>
<p>I had tried to make an array of category names and then loop through them, but I got lost after the first bit&#8212;</p>
<pre class="brush: java">import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.dom4j.Element;
import java.util.List;

public class BestSellerAll
{
  public static void main(String[] args) throws Exception
  {

/*  There are 11 categories of NY Times Best Seller lists. I want to download all of them, but the Times makes you download them individually.
*/

    String [] book_cats = new String [] {
    &quot;hardcover-fiction&quot;, &quot;hardcover-nonfiction&quot;, &quot;hardcover-advice&quot;, &quot;paperback-nonfiction&quot;, &quot;paperback-advice&quot;, &quot;trade-fiction-paperback&quot;, &quot;picture-books&quot;, &quot;chapter-books&quot;, &quot;paperback-books&quot;, &quot;series-books&quot;, &quot;mass-market-paperback&quot;};

//    String listName = args[0];

    SAXReader [] reader = new SAXReader() [];
    EasyHTTPGet [] getter = new EasyHTTPGet [];
    for (int i = 0; i &lt; 11; i++)
    {
        getter[i] = &quot;http://api.nytimes.com/svc/books/v2/lists/&quot; + book_cats[n] + &quot;.xml?api-key=f25de92cf1d2615621b68d2d31f81b63:4:1703697&quot;;
    } // end for i

// I got sadly confused somewhere in this block:
    Document [] document = new Document [];
    for (int j = 0; j &lt; 11; j++)
    {
        document[j] = reader.read(getter[j].responseAsInputStream());
        List bookTitle = document.selectNodes(&quot;//results/book/book_details/book_detail/title&quot;);
    } // end for j

//  If I wanted to scramble the authors, . . .
//  List bookAuthor =
//  document.selectNodes(&quot;//results/book/book_details/book_detail/author&quot;);

    for (Object o: bookTitle)
    {
      Element elem = (Element)o;
      String text = elem.getText();
      System.out.println(text);
    } // end for bookTitle
  } // end main
} // end class</pre>
<p>So, semimanually, then, I ran this on one category list at a time and used cat to agglomerate them. So then I had my list of all the current best sellers&#8217; titles:</p>
<blockquote><p>HANDLE WITH CARE<br />
CORSAIR<br />
THE ASSOCIATE<br />
THE HOST<br />
RUN FOR YOUR LIFE<br />
PROMISES IN DEATH<br />
DEAD SILENCE<br />
HEART AND SOUL<br />
ONE DAY AT A TIME<br />
NIGHT AND DAY<br />
THE GUERNSEY LITERARY AND POTATO PEEL PIE SOCIETY<br />
WHITE WITCH, BLACK CURSE<br />
PATHS OF GLORY<br />
TERMINAL FREEZE<br />
FOOL<br />
THE HELP<br />
DON&#8217;T LOOK TWICE<br />
FAULT LINE<br />
TRUE COLORS<br />
STORM FROM THE SHADOWS<br />
OUTLIERS<br />
HOUSE OF CARDS<br />
THE YANKEE YEARS<br />
OUT OF CAPTIVITY<br />
DEWEY<br />
THE LOST CITY OF Z<br />
A LION CALLED CHRISTIAN<br />
A BOLD FRESH PIECE OF HUMANITY<br />
MY BOOKY WOOK<br />
THE UNFORGIVING MINUTE<br />
INSIDE THE REVOLUTION<br />
MELTDOWN<br />
ARE YOU THERE, VODKA? IT’S ME, CHELSEA<br />
JESUS, INTERRUPTED<br />
JOKER ONE<br />
NO ANGEL<br />
LORDS OF FINANCE<br />
THE NEXT 100 YEARS<br />
MULTIPLE BLESSINGS<br />
PICKING COTTON<br />
ACT LIKE A LADY, THINK LIKE A MAN<br />
THE LAST LECTURE<br />
THE POWER OF SOUL<br />
THE SECRET<br />
THE ULTRAMIND SOLUTION<br />
FLAT BELLY DIET!<br />
THE GREAT DEPRESSION AHEAD<br />
PEAKS AND VALLEYS<br />
UNCOMMON<br />
THE SURVIVORS CLUB<br />
MAGNIFICENT MIND AT ANY AGE<br />
THE TOTAL MONEY MAKEOVER<br />
EMOTIONAL FREEDOM<br />
THE 4 DAY DIET<br />
FIGHT FOR YOUR MONEY<br />
THREE CUPS OF TEA<br />
THE MIDDLE PLACE<br />
I HOPE THEY SERVE BEER IN HELL<br />
DREAMS FROM MY FATHER<br />
THE TIPPING POINT<br />
EAT, PRAY, LOVE<br />
THE AUDACITY OF HOPE<br />
MY HORIZONTAL LIFE<br />
90 MINUTES IN HEAVEN<br />
TEAM OF RIVALS<br />
SAME KIND OF DIFFERENT AS ME<br />
BLINK<br />
MARLEY &#038; ME<br />
THE FORGOTTEN MAN<br />
THE OMNIVORE’S DILEMMA<br />
THE ZOOKEEPER’S WIFE<br />
BEAUTIFUL BOY<br />
A WHOLE NEW MIND<br />
ANIMAL, VEGETABLE, MIRACLE<br />
INFIDEL<br />
THE LOVE DARE<br />
WHAT TO EXPECT WHEN YOU’RE EXPECTING<br />
EMERGENCY<br />
SUZE ORMAN’S 2009 ACTION PLAN<br />
NATURALLY THIN<br />
TWILIGHT<br />
SKINNY BITCH<br />
THE FIVE LOVE LANGUAGES<br />
THE POWER OF NOW<br />
HAPPY FOR NO REASON<br />
THE PURPOSE-DRIVEN LIFE<br />
A NEW EARTH<br />
THE BIGGEST LOSER 30-DAY JUMP START<br />
HE’S JUST NOT THAT INTO YOU<br />
THE BIGGEST LOSER FAMILY COOKBOOK<br />
THE SHACK<br />
THE READER<br />
FIREFLY LANE<br />
AMERICAN WIFE<br />
SUNDAYS AT TIFFANY’S<br />
PEOPLE OF THE BOOK<br />
A THOUSAND SPLENDID SUNS<br />
TAKE ONE<br />
THE ALCHEMIST<br />
SARAH’S KEY<br />
THE MIRACLE AT SPEEDY MOTORS<br />
THE BRIEF WONDROUS LIFE OF OSCAR WAO<br />
REVOLUTIONARY ROAD<br />
WATER FOR ELEPHANTS<br />
THE WHITE TIGER<br />
STILL ALICE<br />
THE ELEGANCE OF THE HEDGEHOG<br />
LOVING FRANK<br />
THE KITE RUNNER<br />
LUSH LIFE<br />
THE HOUSE IN THE NIGHT<br />
THE COMPOSER IS DEAD<br />
BLUEBERRY GIRL<br />
LISTEN TO THE WIND: THE STORY OF DR. GREG AND &#8220;THREE CUPS OF TEA&#8221;<br />
LADYBUG GIRL AND BUMBLEBEE BOY<br />
GALLOP!<br />
CAT<br />
SWING!<br />
NAKED MOLE RAT GETS DRESSED<br />
ALL IN A DAY<br />
MILES TO GO<br />
THE GRAVEYARD BOOK<br />
THIRTEEN REASONS WHY<br />
SCAT<br />
THE HUNGER GAMES<br />
FADE<br />
THREE CUPS OF TEA<br />
3 WILLOWS<br />
SEEKERS: GREAT BEAR LAKE<br />
THE MYSTERIOUS BENEDICT SOCIETY AND THE PERILOUS JOURNEY<br />
EVERMORE<br />
THE BOY IN THE STRIPED PAJAMAS<br />
THE BOOK THIEF<br />
THREE CUPS OF TEA: YOUNG READERS EDITION<br />
TWEAK<br />
WICKED: WITCH AND CURSE<br />
CORALINE<br />
THE MYSTERIOUS BENEDICT SOCIETY<br />
THE TALE OF DESPEREAUX<br />
SLAM<br />
THE TWILIGHT SAGA<br />
HOUSE OF NIGHT<br />
DIARY OF A WIMPY KID<br />
THE 39 CLUES<br />
THE CLIQUE<br />
PERCY JACKSON &#038; THE OLYMPIANS<br />
HARRY POTTER<br />
NIGHT WORLD<br />
KISSED BY AN ANGEL<br />
INKHEART<br />
THE WHOLE TRUTH<br />
HOLD TIGHT<br />
BONES<br />
THE GRAND FINALE<br />
PLAGUE SHIP<br />
LOST SOULS<br />
MONTANA CREEDS: DYLAN<br />
DANGER IN A RED DRESS<br />
THE APPEAL<br />
THE MACKADE BROTHERS: RAFE AND JARED<br />
MAVERICK<br />
SMALL FAVOR<br />
ANGELS AND DEMONS<br />
THE READER<br />
SECRETS<br />
FIRST COMES MARRIAGE<br />
CHASING DARKNESS<br />
SHADOW COMMAND<br />
TEMPTATION RIDGE<br />
CONFESSIONS OF A SHOPAHOLIC</p></blockquote>
<p>And then, all I wanted to fucking do was run the Markov code from week 5 and make some crazy new titles. I had it working earlier in this process, when I was working with just the hardcover fiction list, and came up with these completely uninteresting results:</p>
<blockquote><p>TERMINAL FREEZE<br />
TERMINAL FREEZE<br />
TERMINAL FREEZE<br />
THE ASSOCIETY<br />
ONE DAY AT A TIME<br />
NIGHT AND SOUL<br />
ONE DAY AT A TIME<br />
FOOL<br />
STORM FROM THE HELP<br />
FOOL<br />
TERMINAL FREEZE<br />
CORSAIR<br />
ONE DAY AT A TIME<br />
TRUE COLORS<br />
FOOL<br />
ONE DAY AT A TIME</p></blockquote>
<p>Clearly, the set of words was too small to do anything really interesting with, which is when I decided to make one file of all the lists, to get more words. But then . . . I couldn&#8217;t get the Markov code to work anymore. Kept getting this stupid error:</p>
<blockquote><p><code>java.lang.StringIndexOutOfBoundsException: String index out of range: 4<br />
	at java.lang.String.substring(String.java:1765)<br />
	at Markov.feedLine(Markov.java:21)<br />
	at MarkovFilter.eachLine(MarkovFilter.java:12)<br />
	at com.decontextualize.a2z.TextFilter.internalRun(TextFilter.java:326)<br />
	at com.decontextualize.a2z.TextFilter.run(TextFilter.java:208)<br />
	at MarkovFilter.main(MarkovFilter.java:6)</code></p></blockquote>
<p>And it took me one million years to determine that this was because the code was choking on the colon in</p>
<blockquote><p>LISTEN TO THE WIND: THE STORY OF DR. GREG AND &#8220;THREE CUPS OF TEA&#8221;</p></blockquote>
<p>and then the quotation marks, and then something else, and then I still don&#8217;t know what. It will not work if I include any lines after &#8220;GALLOP.&#8221; So, with that frustrating exception noted, here, finally, are the new titles:</p>
<blockquote><p>I HOPE THE STORM FROM MY FATHERE, VODKA? IT’S ME, CHELSEA<br />
THE FIVE LANE<br />
MY HORIZONTAL LIFE OF DIFFERENT MIND THE LOVE DARE<br />
THE BRIEF WONDROUS LIFE OF THERE, VODKA? IT’S WIFE<br />
INSIDE THE REVOLUTION AHEAD<br />
THE 4 DAY JUMP START<br />
MAGNIFICENT AS ME, CHELSEA<br />
THE ELEGANCE OF SOUL<br />
THE ELEPHANTS<br />
THE UNFORGOTTEN TO THE YANKEE YEARS<br />
THE HEDGEHOG<br />
THE COLORS<br />
THE BOY<br />
PROMISES IN HEAVEN<br />
I HOPE THE TOTAL LIFE OF Z<br />
HE’S DILEMMA<br />
PROMISES IN THE TIPPING MIND SPLENDID SUNS<br />
THE ZOOKEEPER’S JUST NOT THAT TO EXPECT WHEN YOUR LIFE OF NOW<br />
TWILIGHT ANY AGE<br />
A THOUSE OF DIFFERENT MINUTES IN HEAVEN<br />
A BOLD FRESH PIECE OF OSCAR WAO<br />
THE KIND OF HUMANITY<br />
OUT OF GLORY<br />
SAME KITE TIGER<br />
FIGHT ANY AGE<br />
MAGNIFICENT MIND SOUL<br />
SAME KIND OF HUMANITY<br />
THE FIVE LANGUAGES<br />
THE MIDDLE WITH CARDS<br />
TERMINAL FRESH PIE SOCIATE<br />
90 MINUTES IN DEAD SILENCE<br />
HE’S 2009 ACTIONARY AND SOLUTIONAL FRESH PIECE OF DIFFERENT MIND SOUL<br />
NIGHT FOR ELEGANCE OF THERE, VODKA? IT’S WIFE<br />
STORM FROM THERE, VODKA? IT’S JUST NOT THAT INTO YOUR LIFE OF THE LOVE DAY JUMP START<br />
THE NIGHT ANY AGE</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://itp.nyu.edu/~ia303/thunk/2009/03/31/markov-bookshelf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comparalator</title>
		<link>http://itp.nyu.edu/~ia303/thunk/2009/03/24/comparalator/</link>
		<comments>http://itp.nyu.edu/~ia303/thunk/2009/03/24/comparalator/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 10:48:43 +0000</pubDate>
		<dc:creator>India</dc:creator>
				<category><![CDATA[A2Z]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mainstreaming Information]]></category>
		<category><![CDATA[final project]]></category>
		<category><![CDATA[homework]]></category>
		<category><![CDATA[midterm]]></category>

		<guid isPermaLink="false">http://itp.nyu.edu/~ia303/thunk/?p=560</guid>
		<description><![CDATA[
As you may recall, for my midterm project, I got stumped on several seemingly simple tasks. One of those&#8212;the most important, since upon it depends my semester-long assignment for Mainstreaming Information&#8212;was figuring out a way to compare one list of words to another and pull out the words that were unique to one of those [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/nypl/3109979241/"><img src="http://itp.nyu.edu/~ia303/thunk/wp-content/uploads/date_merchant.jpg" alt="date merchant" title="date merchant" width="383" height="348" class="alignnone size-full wp-image-562" /></a></p>
<p>As you may recall, for my midterm project, I got <a href="/2009/03/10/a2z-midterm-vocabu-lame/">stumped</a> on several seemingly simple tasks. One of those&#8212;the most important, since upon it depends my semester-long assignment for Mainstreaming Information&#8212;was figuring out a way to compare one list of words to another and pull out the words that were unique to one of those lists. In my head, I can see very easily how this would be done. Given my special way of haphazardly flailing through code, however, I just couldn&#8217;t get it to work.</p>
<p>Until today!</p>
<p>In fiddling with the <a href="http://www.decontextualize.com/teaching/a2z/bayesed-and-confused/">Bayesian comparison code</a> for this week&#8217;s homework, I finally pulled out a list of unique words. Of course, this is a completely perverse misuse of that code&#8212;like using a steamroller to kill a pillbug&#8212;but as long as it works, I don&#8217;t fucking care.</p>
<p>So, here&#8217;s what I did. In BayesClassifier.java, I replaced the last two <code>for</code> loops with the following:</p>
<pre class="brush: java">for (String word: uniqueWords)
    {
      for (BayesCategory bcat: categories)
      {
        double wordProb = bcat.relevance(word, categories);
        if (wordProb &lt; 1)
        {
        println(word);
        }
        else {}
      } // end for bcat
    } // end for word

    for (BayesCategory bcat: categories)
    {
      double score = bcat.score(uniqueWords, categoryWordTotal);
      println(&quot;---The following words were not found in &quot; + bcat.getName());
    } // end for bcat</pre>
<p>And in BayesCategory.java I replaced the percentage and relevance blocks with</p>
<pre class="brush: java"> public double percentage(String word)
  {
    if (count.containsKey(word))
    {
      return count.get(word);
    } // end if
    else
    {
      return 0.001;
    } // end else
  } // end percentage

  public double relevance(String word, ArrayList&lt;BayesCategory&gt; categories)
  {
    double percentageSum = 0;
    for (BayesCategory bcat: categories)
    {
      percentageSum += bcat.percentage(word);
    } // end for bcat
    return percentage(word);
  } // end relevance</pre>
<p>So now, if I run the command </p>
<blockquote><p><code>$ java BayesClassifier A2_unique.txt < B1_unique.txt | sort >results.txt</code></p></blockquote>
<p>I get a list of words that are in B1_unique.txt (<cite><a rel="nofollow" href="http://www.amazon.com/gp/product/0765313383?ie=UTF8&amp;tag=indink-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0765313383indink-20" >The Masada Scroll</a></cite> by Paul Block and Robert Vaughan, 2007) but not in A2_unique.txt (<cite><a href="http://books.google.com/books?id=ko0NAAAAYAAJ">Zuleika Dobson or, An Oxford Love Story</a></cite> by Max Beerbohm, 1911). For example,</p>
<blockquote><p>Akbar, Allah, Allahu, Apostolic, Ariminum, Arkadiane, Asmodeus, Astaroth, Barabbas, Beelzebub, Bellarmino, Blavatsky, Brandeis, Breviary, Byzantine, Caiaphas, Calpurnius, Catacombs, Charlemagne, Clambering, DNA, Diavolo, Franciscan, Freemasons, GPS, Gymnasium, Haddad, Hades, IDs, IRA, Jettisoning, Kathleen, Lefkovitz, MD, MRI, Masada, Masonic, Muhammad, Muhammadan, Nazarene, Nazareth, Olympics, Orthodoxy, Palatine, Palazzi, Palestine, Palestinian, Palestinians, Petrovna, Pleasant, Plenty, Plunge, Pocketing, Pontiff, Pontifical, Pontius, Praetorian, Prissy, Professors, Protestants, Rasulullaah, Ratsach, Revving, Rosicrucians, Satan, Scrolls, Seder, Shakespeare, Syracuse, Tacitus, Theosophical, Torah, Trastevere, Turkish, USB, Uzi, VAIO, VCR, Yeah, Yechida, Yeetgadal, Yiddish, adrenalin, agita, airliner, airport, ankh, awesome, bitch, bomb, bookstores, braked, breastplate, briefcase, broadsword, broiler, brotherhood, bulrushes, cellular, checkpoint, chuckling, chutzpah, combatant, computer, dashboard, database, departmental, desktop, divorce, dysentery, electricity, enabling, entrepreneurs, firearms, firestorm, fishtailed, flagon, forensics, goatskin, groggily, gunfire, gunman, gunshots, handbag, handball, handbrake, handgun, helicopter, helmets, highwaymen, hijinks, homeland, homeless, homespun, hometown, innkeeper, internship, journalist, kebob, kidnappers, kilometers, lab, laptop, lyre, mawkish, monitor, muezzin, nickname, nightfall, nonbeliever, northeaster, notebook, notepad, notepaper, numerology, paganism, password, pastries, phone, photo, photocopies, photocopy, photograph, photos, pig, pigeons, pistol, playback, police, quintessentially, recycles, redialed, roadblock, roadway, sandwich, screensaver, site, sites, submachine, superheating, synagogue, taped, taxi, terrorism, terrorist, terrorists, thousandfold, thrashing, toga, tortured, trigonometry, universe, unto, vegetables, vehicles, video, videotape, vinegar, violence, warehouses, waterfall, welfare, wholeheartedly, whoosh, whore, windshield, worker, workstation, worldwide, yardstick, yarmulkes, yeetkadash, zooming</p></blockquote>
<p>And if I run the comparison in the opposite direction, I come up with words such as</p>
<blockquote><p>Abernethy, Abiding, Abimelech, Abyssinian, Academically, Academy, Accidents, Achillem, Adam, Adieu, Admirably, Age, Agency, Agents, Alas, Albert, Alighting, America, Atlantic, Australia, Balliol, Baron, Baronet, Britannia, Broadway, Brobdingnagian, Colonials, Cossacks, Crimea, Devon, Dewlap, Duchess, Duke, Dukedom, Earl, Edwardian, Egyptians, Elizabethan, Englishmen, Englishwoman, Europe, Holbein, Ireland, Iscariot, Isis, Japanese, Kaiser, Liberals, London, Madrid, Meistersinger, Messrs, Monsieur, Napoleon, Novalis, Papist, Parnassus, President, Prince, Professor, Prussians, Romanoff, Segregate, Slavery, Socrates, Switzerland, Tzar, Victoria, Wagnerian, Waterloo, Whithersoever, Zeus, absinthes, acolyte, adventures, affrights, affront, afire, afoot, aforesaid, aggravated, album, analogy, anarchy, ankle, ape, aright, aristocracy, ataraxy, automatically, avalanche, avow, balustrade, bandboxes, bank, beastliest, beau, beauteous, billiards, biography, bodyguard, bosky, boyish, broadcast, bruited, bulldog, businesslike, bustle, calorific, casuistry, catkins, chaperons, chidden, cigarettes, clergyman, cloven, comet, compeers, coquetry, cricket, crinolines, custard, dandiacal, dapperest, decanter, devil, dialogue, diet, dipsomaniacal, disemboldened, disinfatuate, drunken, ebullitions, equipage, exigent, eyelashes, eyelids, farthingales, female, femininity, fishwife, fob, forefather, forerunners, freemasonry, furbelows, gallimaufry, goodlier, gooseberry, gorgeous, gypsy, haberdasher, halfpence, handicapped, handicraft, handiwork, handwriting, hearthrug, helpless, hip, hireling, honeymoon, housemaid, housework, hoyden, hussy, idiotic, impertinent, impudence, inasmuch, incognisant, insipid, insolence, insouciance, item, keyboard, landau, legerdemain, loathsome, luck, maid, maidens, manhood, manumission, matador, maunderers, model, mushroom, nasty, newspaper, noodle, nosegay, novel, oarsmen, omnisubjugant, ostler, otiose, parasol, pinafore, poetry, poltroonery, postprandially, prank, prestidigitators, propinquity, queer, romance, sackcloth, salad, sardonic, saucy, schoolmaster, seraglio, sex, skimpy, skirt, snuff, socialistic, streetsters, surcease, surcoat, swooned, teens, telegram, telegraphs, thistledown, thither, thou, threepenny, tomboyish, toys, tradesmen, treacle, ugly, uncouthly, unvexed, vassalage, waylay, welter, wigwam, witchery, withal, woe, woebegone, womanly, womenfolk, wonderfully, wonderingly, wretchedness, wrought, yacht, yesternight, zounds</p></blockquote>
<p>Exciting!</p>
]]></content:encoded>
			<wfw:commentRss>http://itp.nyu.edu/~ia303/thunk/2009/03/24/comparalator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cookalator</title>
		<link>http://itp.nyu.edu/~ia303/thunk/2009/03/24/cookalator/</link>
		<comments>http://itp.nyu.edu/~ia303/thunk/2009/03/24/cookalator/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 08:05:24 +0000</pubDate>
		<dc:creator>India</dc:creator>
				<category><![CDATA[A2Z]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[homework]]></category>

		<guid isPermaLink="false">http://itp.nyu.edu/~ia303/thunk/?p=555</guid>
		<description><![CDATA[
For our Context Free assignment, I chose to make a recipe generator. Mmm, don&#8217;t you want to cook this up right now?

Toss 1/3 cup thinly sliced baking soda and 1 quart egg yolks with a whisk until just blended.
Knead 5 cups cubed light corn syrup with a wooden spoon until golden brown.
In a cast iron [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/iamos/2355222338/" title="Five eggs by iamos, on Flickr"><img src="http://farm4.static.flickr.com/3061/2355222338_01e2aacf55.jpg" width="450" height="337" alt="Five eggs" /></a></p>
<p>For our <a href="http://www.decontextualize.com/teaching/a2z/context-free-as-in-speech/">Context Free</a> assignment, I chose to make a recipe generator. Mmm, don&#8217;t you want to cook this up right now?</p>
<ol>
<li>Toss 1/3 cup thinly sliced baking soda and 1 quart egg yolks with a whisk until just blended.</li>
<li>Knead 5 cups cubed light corn syrup with a wooden spoon until golden brown.</li>
<li>In a cast iron Dutch oven, pour 1/4 pinch egg yolks, 1/4 cup whole milk, and 2 pounds sifted egg.</li>
<li>Simmer 3 pounds light corn syrup with 1 cup thinly sliced brown sugar and 2 teaspoons sifted heavy cream.</li>
<li>In a small saucepan, boil 3 ounces thinly sliced egg, 4 cups peeled water, and 3/4 tablespoon water until incorporated.</li>
<li>Whisk together 1 pound ginger and 2 cups candied egg whites until golden brown.</li>
<li>Beat 2 quarts marzipan with a wooden spoon until the pieces are pea-sized.</li>
<li>Grate 1/2 teaspoon sifted unsweetened cocoa powder with 2 quarts baking powder and 3/4 ounce ginger.</li>
<li>Beat 5 pounds thinly sliced buttermilk, 5 quarts sifted whole milk, and 4 tablespoons thinly sliced egg with a wooden spoon until slightly warm.</li>
<li>In a large bowl, boil 5 cups candied kosher salt, 2 cups diced lemon zest, and 1/2 cup sifted buttermilk until incorporated.</li>
<li>In a shallow pan, simmer 5 tablespoons thinly sliced ginger until golden brown.</li>
<li>Beat 2/3 teaspoon brown sugar, 2 ounces diced egg yolks, and 3 teaspoons unsalted butter with 3 teaspoons light corn syrup, 1/2 tablespoon thoroughly washed lemon zest, and 3/4 quart peeled whole milk.</li>
<li>Brush 2 tablespoons grated kosher salt, 2/3 tablespoon sugar, and 4 pounds diced baking powder until it forms a thick syrup.</li>
</ol>
<p>Here&#8217;s the grammar I used:</p>
<pre class="brush: java"># procedures
S -&gt; In a V Action IP with a Utensil until When
S -&gt; In a V Action IP until When
S -&gt; In a V Action IP .
S -&gt; Action IP with IP .
S -&gt; Action IP with a Utensil until When
S -&gt; Action IP until When
IP -&gt; IN
IP -&gt; IN and IN
IP -&gt; IN , IN , and IN
IN -&gt; SQuantity SUnit Prep Ingredient
IN -&gt; SQuantity SUnit Ingredient
IN -&gt; PQuantity PUnit Prep Ingredient
IN -&gt; PQuantity PUnit Ingredient
V -&gt; Size Quality Vessel
V -&gt; Size Vessel
V -&gt; Quality Vessel
V -&gt; Vessel

# components
SQuantity -&gt; 1/4 | 1/2 | 1/3 | 3/4 | 2/3 | 1
PQuantity -&gt; 2 | 3 | 4 | 5
SUnit -&gt; pinch | teaspoon | tablespoon | ounce | cup | pound | quart
PUnit -&gt; pinches | teaspoons | tablespoons | ounces | cups | pounds | quarts
Ingredient -&gt; all-purpose flour | water | egg whites | egg yolks | heavy cream | whole milk | almond paste | marzipan | sugar | baking powder | baking soda | kosher salt | ginger | unsalted butter | egg | buttermilk | lemon zest | light corn syrup | bittersweet chocolate | unsweetened cocoa powder | brown sugar
Prep -&gt; grated | cubed | chilled | sifted | diced | candied | thoroughly washed | peeled | thinly sliced | melted
Vessel -&gt; bowl, | saucepan, | pot, | Dutch oven, | pan, | ramekin, | skillet,
Quality -&gt; separate | airtight | cast iron | heatproof | nonstick | heavy-bottomed | shallow | buttered
Size -&gt; large | small | medium
Action -&gt; combine | whisk together | knead | brush | sprinkle | pour | stir | beat | boil | simmer | saute | brown | grate | mash | toss | blend
Utensil -&gt; wooden spoon | whisk
When -&gt; combined. | the pieces are pea-sized. | incorporated. | just blended. | it forms a thick syrup. | translucent. | golden brown. | slightly warm. | completely cooled.</pre>
<p>Yummers!</p>
]]></content:encoded>
			<wfw:commentRss>http://itp.nyu.edu/~ia303/thunk/2009/03/24/cookalator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A2Z midterm: Vocabu-lame</title>
		<link>http://itp.nyu.edu/~ia303/thunk/2009/03/10/a2z-midterm-vocabu-lame/</link>
		<comments>http://itp.nyu.edu/~ia303/thunk/2009/03/10/a2z-midterm-vocabu-lame/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 11:30:44 +0000</pubDate>
		<dc:creator>India</dc:creator>
				<category><![CDATA[A2Z]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mainstreaming Information]]></category>
		<category><![CDATA[midterm]]></category>
		<category><![CDATA[sketch]]></category>

		<guid isPermaLink="false">http://itp.nyu.edu/~ia303/thunk/?p=551</guid>
		<description><![CDATA[
Apparently, I have learned absolutely nothing all semester, because what seemed like a very straightforward project proved to be completely beyond my abilities.
The overarching goal is to generate data for the visualization I&#8217;m making for Lisa Strausfeld and Christian Marc Schmidt&#8217;s Mainstreaming Information class. Click the image above to see some slides (PDF, 128 KB) [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://itpindia.files.wordpress.com/2009/03/slides.pdf'><img src="http://itpindia.wordpress.com/files/2009/03/vocabulap_7.png" alt="vocabulap, slide 7" title="vocabulap, slide 7" width="450" height="338" class="alignnone size-full wp-image-31" /></a></p>
<p>Apparently, I have learned absolutely nothing all semester, because what seemed like a very straightforward project proved to be completely beyond my abilities.</p>
<p>The overarching goal is to generate data for the visualization I&#8217;m making for Lisa Strausfeld and Christian Marc Schmidt&#8217;s <a href="http://www.christianmarcschmidt.com/NYU2009/index.html">Mainstreaming Information</a> class. Click the image above to see some slides (PDF, 128 KB) explaining the gist of the project, provisionally called Vocabulap (<em>vocabulary</em> + <em>overlap</em>; not a handsome coinage). My specific goals for the A2Z midterm were as follows (with subsequent comments in all caps):</p>
<blockquote><p>For A2Z midterm<br />
===============<br />
Prep<br />
&#8212;-<br />
* Remove all blank lines<br />
    DONE<br />
* Remove all extra spaces<br />
    DONE<br />
* Break all lines &#8211; DONE<br />
* Rename all to number consecutively: A01, A02, . . . A10 (for old books); B01, B02, . . . B10 (for new books)<br />
    DONE</p>
<p>Compare major sets<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
* Extract the text from between the body tags in each file. Dump it out as a new file with the extension body.txt in the folder ../body.<br />
    THIS IS HARDER THAN IT LOOKS (FOR ME, AT LEAST). EASIER TO JUST CUT THEM OFF BY HAND.<br />
* Concatenate all the files in each set.<br />
    DID THIS FROM THE COMMAND LINE, USING CAT<br />
* Make a list of unique words in each concatenated set, with the number of times the word appears.<br />
    CAN GET THE UNIQUE WORDS, BUT NOT THE COUNT.<br />
* Strip out all words beginning with numerals.<br />
    DONE BY HAND<br />
* Create the following lists:<br />
    &#8211; Words shared by both major sets, with frequency counts<br />
    &#8211; Words unique to set 1, with frequency counts<br />
    &#8211; words unique to set 2, with frequency counts<br />
    I APPARENTLY CANNOT DO ANY OF THIS.</p>
<p>Find unique words in each book<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
For each book:<br />
* Concatenate all the files in that major set *except* the file for that book.<br />
* Make a list of the unique words, with frequency counts, in<br />
    &#8211; the current book<br />
    &#8211; the set of all books except the current one<br />
* Make three lists:<br />
    &#8211; Words shared by all books in the major set, with frequency counts<br />
    &#8211; Words that appear only in the current book, with frequency counts<br />
    &#8211; Words that appear only outside the current book, with frequency counts</p>
<p>Return lines surrounding specific words<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
For each word in a given list:<br />
* Get the line numbers on which it appears.<br />
For each appearance,<br />
* Print the line above<br />
* Print the line with the word, replacing it with itself wrapped in span tags to apply color<br />
* Print the line below</p></blockquote>
<p>The most essential piece of code that I could not get working is the comparison doodad. It almost worked for, like, five seconds, but it was generating a huge file of every unique word times however many words were in the document, or something like that. When I tried to fix it, it completely stopped working. The offending code is as follows:</p>
<pre class="brush: java">/*  1. Takes in a file name from the command line.
    2. Makes a string array out of the hard-coded comparison file.
    3. Imports the contents of the file whose name was passed in.
    4. For each line of the input file (i.e., each word), changes it to
       lowercase and checks to see if it&#039;s contained in the comparison file.
    5. If it&#039;s not in the comparison file, checks to see if it&#039;s in a hashset of
       unique words.
    6. If the word&#039;s not in the hashset, add it.
    7. Print the contents of the hashset.
*/

import java.util.ArrayList;
import java.util.HashSet;
import com.decontextualize.a2z.TextFilter;

public class CompareUnique extends TextFilter
{
    public static void main(String[] args)
    {
        new CompareUnique().run();
    } // end main

    private String filename = &quot;body/unique/allB_uci.txt&quot;;
    private HashSet uniqueWords = new HashSet();
    private HashSet lowercaseWords = new HashSet();

    // make a String array out of the contents of the comparison file
    String[] checkAgainst = new TextFilter().collectLines(fromFile(filename));

  public void eachLine(String word)
  {
    String wordLower = word.toLowerCase();
    for (int i = 0; i &amp;lt; checkAgainst.length; i++)
    {
        if (checkAgainst[i] != null &amp;amp;&amp;amp; checkAgainst[i].contains(wordLower))
		{} // end if
		else if (checkAgainst != null)
		{
            if (lowercaseWords != null &amp;amp;&amp;amp; lowercaseWords.contains(wordLower))
            { } // end if
            else if (lowercaseWords != null)
            {
                uniqueWords.add(wordLower);
                lowercaseWords.add(wordLower);
            } // end else
 		} // end else
    } // end for
  } // end eachLine

  public void end()
  {
    for (String reallyunique: uniqueWords) {
      println(reallyunique);
    } // end for
  } // end end

} // end class</pre>
<p><em>I know, it seems very simple, but you have no idea how long it took me to get this far.</em></p>
<p>So, basically, for the midterm I&#8217;ve got bupkis—just a big pile of text files, and a list of unique words for each.</p>
]]></content:encoded>
			<wfw:commentRss>http://itp.nyu.edu/~ia303/thunk/2009/03/10/a2z-midterm-vocabu-lame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kill me now.</title>
		<link>http://itp.nyu.edu/~ia303/thunk/2009/02/24/kill-me-now/</link>
		<comments>http://itp.nyu.edu/~ia303/thunk/2009/02/24/kill-me-now/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 12:30:47 +0000</pubDate>
		<dc:creator>India</dc:creator>
				<category><![CDATA[A2Z]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[homework]]></category>

		<guid isPermaLink="false">http://itp.nyu.edu/~ia303/thunk/?p=534</guid>
		<description><![CDATA[
Oh, honestly.
For once I actually set out to be a slacker on the homework. The assignment began,
Modify, augment, or replace one of the in-class examples. A few ideas, in order of increasing complexity:

Make Unique.java insensitive to case (i.e., “Foo” and “foo” should not count as different words).
Modify WordCount.java to count something other than just words [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/blah_oh_well/1507400172/"><img src="http://itp.nyu.edu/~ia303/thunk/wp-content/uploads/stabby_mcknife.jpg" alt="Stabby McKnife" title="Stabby McKnife" width="460" height="251" class="alignnone size-full wp-image-535" /></a></p>
<p>Oh, honestly.</p>
<p>For once I actually set out to be a slacker on the homework. The assignment began,</p>
<blockquote><p>Modify, augment, or replace one of the in-class examples. A few ideas, in order of increasing complexity:</p>
<ul>
<li>Make Unique.java insensitive to case (i.e., “Foo” and “foo” should not count as different words).</li>
<li>Modify WordCount.java to count something other than just words (e.g., particular characters, bigrams, co-occurrences of words, etc.). . . .</li>
</ul>
</blockquote>
<p>So I thought, &#8220;Today I feel like doing the easy thing. I&#8217;ll just take that first option.&#8221;</p>
<p>Yeah, right. Many hours later, after trying several extremely complicated methods of doing this really fucking simple thing, I finally found the rat-simple method that I&#8217;d been looking for all along and had all but given up hope of. Goddamnit.</p>
<p>The original code was this:</p>
<pre class="brush: java">import java.util.HashSet;
import com.decontextualize.a2z.TextFilter;

public class Unique extends TextFilter {
  public static void main(String[] args) {
    new Unique().run();
  }

  private HashSet&lt;String&gt; uniqueWords = new HashSet&lt;String&gt;();

  public void eachLine(String line) {
    String[] tokens = line.split(&quot;\\W+&quot;);
    for (String t: tokens) {
      uniqueWords.add(t);
    }
  }

  public void end() {
    for (String word: uniqueWords) {
      println(word);
    }
  }
}</pre>
<p>and what I came up with after way too much beating my head against the desk is this:</p>
<pre class="brush: java">import java.util.HashSet;
import java.util.regex.*;
import com.decontextualize.a2z.TextFilter;

public class UniqueCI extends TextFilter
{
  public static void main(String[] args)
  {
    new UniqueCI().run();
  } // end main

  private HashSet&lt;String&gt; uniqueWords = new HashSet&lt;String&gt;();
  private HashSet&lt;String&gt; lowercaseWords = new HashSet&lt;String&gt;();

  public void eachLine(String line)
  {
    String[] tokens = line.split(&quot;\\W+&quot;);
    for (String t: tokens)
    {
    	// If hashset that&#039;s all lowercased contains t all lowercased, then don&#039;t add anything.

		String tLower = t.toLowerCase();

		if (lowercaseWords != null &amp;&amp; lowercaseWords.contains(tLower))
		{
		} // end if
		else if (lowercaseWords != null)
		{
			uniqueWords.add(t);
			lowercaseWords.add(tLower);
 		} // end else
    } // end for
  } // end eachLine

  public void end()
  {
    for (String word: uniqueWords) {
      println(word);
    } // end for
  } // end end
} // end class UniqueCI</pre>
<p>If you put this in,</p>
<blockquote><p>It is a truth universally acknowledged, that a single man in possession of a large fortune must be in want of a wife.<br />
It Is A Truth Universally Acknowledged, That A Single Man In Possession Of A Large Fortune Must Be In Want Of A Wife.</p></blockquote>
<p>you get this out:</p>
<blockquote><pre>of
possession
wife
truth
be
large
It
fortune
universally
single
that
acknowledged
man
a
must
want
is
in</pre>
</blockquote>
<p>Big whoop. I wish I could say I learned a lot from this, but I think all I learned is that I&#8217;m much more lost than I thought I was.</p>
<p><span style="color:gray; font-size:smaller">Photo: <a href="http://www.flickr.com/photos/blah_oh_well/1507400172/">The Downward Knife</a> by Jill Greenseth; <a href="http://creativecommons.org/licenses/by-nc/2.0/deed.en">some rights reserved</a>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://itp.nyu.edu/~ia303/thunk/2009/02/24/kill-me-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>“Have you seen my wig around?”</title>
		<link>http://itp.nyu.edu/~ia303/thunk/2009/02/13/jane-says/</link>
		<comments>http://itp.nyu.edu/~ia303/thunk/2009/02/13/jane-says/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 12:21:14 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[A2Z]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[homework]]></category>

		<guid isPermaLink="false">http://itp.nyu.edu/~ia303/thunk/?p=507</guid>
		<description><![CDATA[
This week&#8217;s A2Z assignment was as follows:
Make a program that creatively transforms or performs analysis on a text using regular expressions. The program should take its input from the keyboard and send its to the screen (or redirect to/from a file). Your program might (a) filter lines from the input, based on whether they match [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="nofollow" href="http://www.amazon.com/gp/product/B000002LEE?ie=UTF8&#038;tag=indink-20&#038;linkCode=as2&#038;camp=211189&#038;creative=374929&#038;creativeASIN=B000002LEEindink-20" ><img src="http://itp.nyu.edu/~ia303/thunk/wp-content/uploads/janesays.jpg" alt="Jane Says" title="Jane Says" width="460" height="163" class="alignnone size-full wp-image-512" /></a></p>
<p>This week&#8217;s A2Z assignment was as follows:</p>
<blockquote><p>Make a program that creatively transforms or performs analysis on a text using regular expressions. The program should take its input from the keyboard and send its to the screen (or redirect to/from a file). Your program might (a) filter lines from the input, based on whether they match a pattern; (b) match and display certain portions of each line; (c) replace certain portions of each line with new text; or (d) any combination of the above.</p>
<p>Sample ideas: Replace all words in a text of a certain length with a random word; find telephone numbers or e-mail addresses in a text; locate words within a word list that will have a certain score in Scrabble; etc.</p>
<p>Bonus challenge 1: Use one or more features of regular expression syntax that we didn’t discuss in class. Reference here.</p>
<p>Bonus challenge 2: Use one or more features of the Pattern or Matcher class that we didn’t discuss in class. Of particular interest: regex flags (CASE_INSENSITIVE, MULTILINE), “back references” in replaceAll. Matcher class reference here.
</p></blockquote>
<p>So, what I made is a program that tries to find the proper names in the input text (my preferred input being the first scene of <cite>Pride and Prejudice</cite>) and replace them with names of people in our class. For my purposes, a proper name is any capitalized word that (a) follows an honorific, such as Mr., Mrs., Sir, Lady, or Miss, <em>or</em> (b) does not immediately follow a carriage return or chunk of terminal punctuation (i.e., a period, exclamation point, or question mark, with or without a closing quotation mark thereafter), and (c) is neither a day of the week, a month of the year, nor the name of a holiday (though the only holiday it&#8217;s really looking for is Michaelmas, as that&#8217;s what appears in my P&#038;P extract).</p>
<p>I tried for hours to do this in a compact way, by looking for the <em>absence</em> of certain words or characters (terminal punctuation, honorifics, days of the week, holidays) combined with the <em>presence</em> of other patterns, but it just would not fly. So the result requires a lot of intermediate steps, to avoid changing words that have been identified as not likely to be names. In a vain attempt to make testing my regular expressions quicker, I worked them out in BBEdit first, using the grep option in the search and replace panel. Saved me from having to recompile the thing fifty thousand times. And the expressions <em>worked</em> in BBEdit, for the most part. They do <em>not</em> work so well translated into Java, unfortunately&#8212;the success rate at finding names is much lower, and after ten straight hours, I just didn&#8217;t have the patience to troubleshoot it any more. But these glitches just make the results more funny, which is, of course, the point.</p>
<p>So, here is the code:</p>
<pre class="brush: java">import java.util.regex.*;
import com.decontextualize.a2z.TextFilter;

public class RegexNames extends TextFilter
{
  public static void main(String[] args)
  {
    new RegexNames().run();
  } // end main(String[] args)

  private String search1  = &quot;(Mr\\.|Mrs\\.|Lord|Lady|Sir) ([A-Z]\\w+)&quot;;
  private String replace1 = &quot;##NAME##&quot;;

  private String search2  = &quot;(\\.” |\\?” |!” |\\. |\\? |! |\\r|\\r“)([A-Z]\\w+)&quot;;

  private String search3  = &quot;( |“|\\r)(Mr\\.|Mrs\\.|Lord|Lady|Sir|Miss|Monday|Tuesday|Wednesday|Friday|Saturday|Sunday|January|February|March|April|May|June|July|August|September|October|November|December|Michaelmas)&quot;;

  private String search4  = &quot;( |“)([A-Z][a-z]+)&quot;;

  private String [] class_names = new String [] {
    &quot;Adam&quot;, &quot;Alejandro&quot;, &quot;Andrew&quot;, &quot;Bryan&quot;, &quot;Caroline&quot;, &quot;Dimitris&quot;, &quot;Jonathan&quot;, &quot;Joseph&quot;, &quot;Martin&quot;, &quot;Michael&quot;, &quot;Ozge&quot;, &quot;Sanjay&quot;, &quot;Steven&quot;       };
  public void begin()
  {
    println(&quot;* * *&quot;);
  }

  public void eachLine(String line)
  {
    String line_new;

    Pattern p1 = Pattern.compile(search1);
    Matcher m1 = p1.matcher(line);
    if (m1.find())
    {
      line = line.replaceAll(m1.group(2), replace1);
    }

    line_new = line;

    Pattern p2 = Pattern.compile(search2);
    Matcher m2 = p2.matcher(line_new);
    if (m2.find())
    {
      line_new = line_new.replaceAll(m2.group(2), &quot;##&quot; + m2.group(2) + &quot;##&quot;);
    }

    Pattern p3 = Pattern.compile(search3);
    Matcher m3 = p3.matcher(line_new);
    if (m3.find())
    {
      line_new = line_new.replaceAll(m3.group(2), &quot;##&quot; + m3.group(2) + &quot;##&quot;);
    }

    Pattern p4 = Pattern.compile(search4);
    Matcher m4 = p4.matcher(line_new);
    if (m4.find())
    {
      line_new = line_new.replaceAll(m4.group(2), &quot;##NAME##&quot;);
    }

    line_new = line_new.replace( &quot;##NAME##&quot;, class_names[(int)(Math.random() * 13)] );

    line_new = line_new.replace( &quot;##&quot;, &quot;&quot; );

    println(&quot;\t&quot; + line_new);
  } // end eachLine(String line)

  public void end()
  {
    println(&quot;* * *&quot;);
  }

} // end RegexNames extends TextFilter</pre>
<p>And here is the output (you can find the original text at <a href="http://www.gutenberg.org/catalog/world/readfile?fk_files=907737">Project Gutenberg</a>):</p>
<blockquote><p>* * *<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It is a truth universally acknowledged, that a single man in possession of a large fortune must be in want of a wife.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;However little known the feelings or views of such a man may be on his first entering a neighbourhood, this truth is so well fixed in the minds of the surrounding families, that he is considered the rightful property of someone or other of their daughters.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Adam dear Mr. Adam,” said his lady to him one day, “have you heard that Netherfield Park is let at last?”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mr. Bryan replied that he had not.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Steven it is, returned she; ”for Mrs. Steven has just been here, and she told me all about it.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mr. Michael made no answer.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Dimitris you not want to know who has taken it?” cried his wife impatiently.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“YOU want to tell me, and I have no objection to hearing it.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This was invitation enough.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Steven, my dear, you must know, Mrs. Steven says that Netherfield is taken by a young man of large fortune from the north of England; that he came down on Monday in a chaise and four to see the place, and was so much delighted with it, that he agreed with Mr. Morris immediately; that he is to take possession before Michaelmas, and some of his servants are to be in the house by the end of next week.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Joseph is his name?”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Adam.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Dimitris he married or single?”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Bryan! Single, my dear, to be sure! A single man of large fortune; four or five thousand a year. What a fine thing for our girls!”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“How so? How can it affect them?”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Bryan dear Mr. Bryan,” replied his wife, “how can you be so tiresome! You must know that I am thinking of his marrying one of them.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Ozge that his design in settling here?”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Caroline! Nonsense, how can you talk so! But it is very likely that he MAY fall in love with one of them, and therefore you must visit him as soon as he comes.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“I see no occasion for that. You and the girls may go, or you may send them by themselves, which perhaps will be still better, for as you are as handsome as any of them, Mr. Michael may like you the best of the party.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Michael dear, you flatter me. I certainly HAVE had my share of beauty, but I do not pretend to be anything extraordinary now. When a woman has five grown-up daughters, she ought to give over thinking of her own beauty.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Jonathan such cases, a woman has not often much beauty to think of.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Michael, my dear, you must indeed go and see Mr. Michael when he comes into the neighbourhood.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Steven is more than I engage for, I assure you.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Jonathan consider your daughters. Only think what an establishment it would be for one of them. Sir Jonathan and Lady Lucas are determined to go, merely on that account, for in general, you know, they visit no newcomers. Indeed you must go, for it will be impossible for US to visit him if you do not.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Sanjay are over-scrupulous, surely. I dare say Mr. Sanjay will be very glad to see you; and I will send a few lines by you to assure him of my hearty consent to his marrying whichever he chooses of the girls; though I must throw in a good word for my little Lizzy.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“I desire you will do no such thing. Lizzy is not a bit better than the others; and I am sure she is not half so handsome as Michael, nor half so good-humoured as Lydia. But you are always giving HER the preference.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Andrew have none of them much to recommend them,” replied he; “they are all silly and ignorant like other girls; but Lizzy has something more of quickness than her sisters.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Mr. Bryan, how CAN you abuse your own children in such a way? You take delight in vexing me. You have no compassion for my poor nerves.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“Caroline mistake me, my dear. I have a high respect for your nerves. They are my old friends. I have heard you mention them with consideration these last twenty years at least.”<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mr. Dimitris was so odd a mixture of quick parts, sarcastic humour, reserve, and caprice, that the experience of three-and- twenty years had been insufficient to make his wife understand his character. HER mind was less difficult to develop. Dimitris was a woman of mean understanding, little information, and uncertain temper. When she was discontented, she fancied herself nervous. The business of her life was to get her daughters married; its solace was visiting and news.<br />
* * *</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://itp.nyu.edu/~ia303/thunk/2009/02/13/jane-says/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reinventing the wheel</title>
		<link>http://itp.nyu.edu/~ia303/thunk/2009/02/03/reinventing-the-wheel/</link>
		<comments>http://itp.nyu.edu/~ia303/thunk/2009/02/03/reinventing-the-wheel/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 12:38:18 +0000</pubDate>
		<dc:creator>India</dc:creator>
				<category><![CDATA[A2Z]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[homework]]></category>

		<guid isPermaLink="false">http://itp.nyu.edu/~ia303/thunk/?p=455</guid>
		<description><![CDATA[
This week&#8217;s A&#8211;Z assignment:
Create a program (using, e.g., the tools presented in class) that behaves like a UNIX text processing program (such as cat, grep, tr, etc.). Your program should take text as input (any text, or a particular text of your choosing) and output a version of the text that has been filtered and/or [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/powerhouse_museum/2821106432/"><img src="http://itp.nyu.edu/~ia303/thunk/wp-content/uploads/wheel.jpg" alt="wheel" title="wheel" width="460" height="311" class="alignnone size-full wp-image-463" /></a></p>
<p>This week&#8217;s A&#8211;Z assignment:</p>
<blockquote><p>Create a program (using, e.g., the tools presented in class) that behaves like a UNIX text processing program (such as cat, grep, tr, etc.). Your program should take text as input (any text, or a particular text of your choosing) and output a version of the text that has been filtered and/or munged. <span id="more-455"></span>Your program should use at least one method of Java’s String class that we didn’t discuss in class.</p>
<p>Be creative, insightful, or intentionally banal. Optional: Use the program that you created in tandem with another UNIX command line utility</p></blockquote>
<p>Sounds easy-peasy, except that despite our handy <a href="http://www.decontextualize.com/teaching/a2z/strung-out-on-java/">review session</a>, I&#8217;ve completely forgotten anything I ever knew about Java or Processing. Not good.</p>
<p>Finally, after hours of beating my head against the couch and various O&#8217;Reilly books, I came up with two Java versions of the vowel shift&#8211;inducing UNIX command <code>tr 'AEIOUaeiou' 'EIOUAeioua'</code>. The first loops through the input letter by letter, checking each to see if it belongs to an array of vowels:</p>
<pre class="brush: java">import com.decontextualize.a2z.TextFilter;

public class Tr extends TextFilter
{
    public static void main(String[] args)
    {
        Tr t = new Tr();
        t.run();
    } // end main(String[] args)
    public void eachLine(String line)
    {
        char [] vowels_in = new char [] { &#039;A&#039;, &#039;a&#039;, &#039;E&#039;, &#039;e&#039;, &#039;I&#039;, &#039;i&#039;, &#039;O&#039;, &#039;o&#039;, &#039;U&#039;, &#039;u&#039; };
        char [] vowels_out = new char [] { &#039;E&#039;, &#039;e&#039;, &#039;I&#039;, &#039;i&#039;, &#039;O&#039;, &#039;o&#039;, &#039;U&#039;, &#039;u&#039;, &#039;A&#039;, &#039;a&#039; };
        for (int i = 0; i &lt; line.length(); i++)
        {
            char currentletter;
            char currentvowel;
            char printletter;
            currentletter = line.charAt(i);
            printletter = currentletter;
            for (int v = 0; v &lt; 10; v++)
            {
                currentvowel = vowels_in[v];
                if (currentletter == currentvowel)
                {
                    printletter = vowels_out[v];
                } // end if
            } // end for v loop
            print(printletter);
        } // end for i loop
    } // end eachLine(String line)
} // end Tr extends TextFilter</pre>
<p>The second rather tediously searches for and replaces each vowel in turn:</p>
<pre class="brush: java">import com.decontextualize.a2z.TextFilter;

public class Tr2 extends TextFilter
{
    public static void main(String[] args)
    {
        Tr2 t = new Tr2();
        t.run();
    } // end main(String[] args)
    public void eachLine(String line)
    {
        String line_new;
        line_new = line.replace( &quot;a&quot;, &quot;[1]&quot; );
        line_new = line_new.replace( &quot;e&quot;, &quot;[2]&quot; );
        line_new = line_new.replace( &quot;i&quot;, &quot;[3]&quot; );
        line_new = line_new.replace( &quot;o&quot;, &quot;[4]&quot; );
        line_new = line_new.replace( &quot;u&quot;, &quot;[5]&quot; );
        line_new = line_new.replace( &quot;A&quot;, &quot;[6]&quot; );
        line_new = line_new.replace( &quot;E&quot;, &quot;[7]&quot; );
        line_new = line_new.replace( &quot;I&quot;, &quot;[8]&quot; );
        line_new = line_new.replace( &quot;O&quot;, &quot;[9]&quot; );
        line_new = line_new.replace( &quot;U&quot;, &quot;[10]&quot; );
        line_new = line_new.replace( &quot;[1]&quot;, &quot;e&quot; );
        line_new = line_new.replace( &quot;[2]&quot;, &quot;i&quot; );
        line_new = line_new.replace( &quot;[3]&quot;, &quot;o&quot; );
        line_new = line_new.replace( &quot;[4]&quot;, &quot;u&quot; );
        line_new = line_new.replace( &quot;[5]&quot;, &quot;a&quot; );
        line_new = line_new.replace( &quot;[6]&quot;, &quot;E&quot; );
        line_new = line_new.replace( &quot;[7]&quot;, &quot;I&quot; );
        line_new = line_new.replace( &quot;[8]&quot;, &quot;O&quot; );
        line_new = line_new.replace( &quot;[9]&quot;, &quot;U&quot; );
        line_new = line_new.replace( &quot;[10]&quot;, &quot;A&quot; );
        print(line_new + &quot;\n&quot;);
    } // end eachLine(String line)
} // end Tr2 extends TextFilter</pre>
<p>I tried to rewrite the latter using arrays and a loop, as well&#8212;</p>
<pre class="brush: java">import com.decontextualize.a2z.TextFilter;

public class TrB extends TextFilter
{
    public static void main(String[] args)
    {
        TrB t = new TrB();
        t.run();
    } // end main(String[] args)
    public void eachLine(String line)
    {
        String line_new;
        String find_string;
        String replace_string;

        char [] vowels_in = new char [] { &#039;A&#039;, &#039;a&#039;, &#039;E&#039;, &#039;e&#039;, &#039;I&#039;, &#039;i&#039;, &#039;O&#039;, &#039;o&#039;, &#039;U&#039;, &#039;u&#039; };
        char [] vowels_out = new char [] { &#039;E&#039;, &#039;e&#039;, &#039;I&#039;, &#039;i&#039;, &#039;O&#039;, &#039;o&#039;, &#039;U&#039;, &#039;u&#039;, &#039;A&#039;, &#039;a&#039; };

        line_new = line;

        for (int i = 0; i &lt; vowels_in.length; i++)
        {
            find_string = &quot;[&quot; + i + &quot;]&quot;;
            line_new = line_new.replace( vowels_in[i], find_string );
        }
        for (int j = 0; j &lt; vowels_in.length; j++)
        {
            replace_string = &quot;[&quot; + j + &quot;]&quot;;
            line_new = line_new.replace( replace_string, vowels_out[j] );
        }
        print(line_new + &quot;\n&quot;);
    } // end eachLine(String line)
} // end Tr2 extends TextFilter</pre>
<p>but I just couldn&#8217;t get past this error message:</p>
<pre>rB.java:28: cannot find symbol
symbol  : method replace(char,java.lang.String)
location: class java.lang.String
            line_new = line_new.replace( vowels_in[i], find_string );
                               ^
TrB.java:33: cannot find symbol
symbol  : method replace(java.lang.String,char)
location: class java.lang.String
            line_new = line_new.replace( replace_string, vowels_out[j] );
                               ^
2 errors</pre>
<p>What stupid, obvious thing am I doing wrong?</p>
<h3>Sample Input</h3>
<blockquote><p>Nelson was enjoying a little quiet at his house in the pretty village of Merton, in Surrey, when he learnt that the French and Spanish fleet, joined by the Ferrol squadron, had succeeded in entering Cadiz. His resolution was quickly taken. He went to the Admiralty and offered his services, which were joyfully accepted. Nelson was full of hope. “Depend on it,” he said to captain Blackwood, “I shall yet give M. Villeneuve a drubbing.” He formed his plans of attack during the short time of preparation, when the Victory had to be refitted, and other ships were to be got ready to accompany him. Lord Sidmouth told Mr. Eush, the American ambassador, that in the course of a visit he had received from Nelson, three weeks before the battle of Trafalgar, he described the plan of it, with bits of paper on a table, as it was afterwards fought. Yet he had a presentiment of his own fate. The coffin which was made out of the mast of l’Orient was deposited at an upholsterer’s. He desired its history to be engraved on its lid, saying that he should probably want it on his return. When he arrived at Portsmouth on the 14th of September, the enthusiasm of the people reached that height which sometimes gives a character of sublimity to the movements of multitudes acting with one heart. They wept; they blessed him; they even knelt as he passed along. The cheer which went up from thousands of voices as his barge pushed off to his flag-ship, -was the Godspeed of hia country. He waved his hat—a last farewell to England.<br />
—<a href="http://books.google.com/books?id=kWINAAAAIAAJ&#038;pg=PA445"><cite>The Popular History of England: An Illustrated History of Society and Government from the Earliest Period to Our Own Times</cite></a> by Charles Knight (Boston: Estes and Lauriat, 1874)</p></blockquote>
<h3>Sample Output</h3>
<blockquote><p>Nilsun wes injuyong e lottli qaoit et hos huasi on thi pritty vollegi uf Mirtun, on Sarriy, whin hi liernt thet thi Frinch end Spenosh fliit, juonid by thi Firrul sqaedrun, hed sacciidid on intirong Cedoz. Hos risulatoun wes qaockly tekin. Hi wint tu thi Edmorelty end uffirid hos sirvocis, whoch wiri juyfally ecciptid. Nilsun wes fall uf hupi. “Dipind un ot,” hi seod tu cepteon Bleckwuud, “O shell yit govi M. Volliniavi e drabbong.” Hi furmid hos plens uf etteck darong thi shurt tomi uf priperetoun, whin thi Voctury hed tu bi rifottid, end uthir shops wiri tu bi gut riedy tu eccumpeny hom. Lurd Sodmuath tuld Mr. Iash, thi Emirocen embessedur, thet on thi cuarsi uf e vosot hi hed riciovid frum Nilsun, thrii wiiks bifuri thi bettli uf Trefelger, hi discrobid thi plen uf ot, woth bots uf pepir un e tebli, es ot wes eftirwerds fuaght. Yit hi hed e prisintomint uf hos uwn feti. Thi cuffon whoch wes medi uat uf thi mest uf l’Uroint wes dipusotid et en aphulstirir’s. Hi disorid ots hostury tu bi ingrevid un ots lod, seyong thet hi shuald prubebly went ot un hos ritarn. Whin hi errovid et Purtsmuath un thi 14th uf Siptimbir, thi inthasoesm uf thi piupli riechid thet hioght whoch sumitomis govis e cherectir uf sablomoty tu thi muvimints uf maltotadis ectong woth uni hiert. Thiy wipt; thiy blissid hom; thiy ivin knilt es hi pessid elung. Thi chiir whoch wint ap frum thuasends uf vuocis es hos bergi pashid uff tu hos fleg-shop, -wes thi Gudspiid uf hoe cuantry. Hi wevid hos het—e lest feriwill tu Inglend.<br />
—<i>Thi Pupaler Hostury uf Inglend: En Ollastretid Hostury uf Sucoity end Guvirnmint frum thi Ierloist Piroud tu Uar Uwn Tomis</i> by Cherlis Knoght (Bustun: Istis end Learoet, 1874)
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://itp.nyu.edu/~ia303/thunk/2009/02/03/reinventing-the-wheel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
