« Visualization Examples | Main | Week 01- Project 1: Physical Computing Improv »

Week 01

For my first assignment I worked with several newspapers headlines taking advantage of its "flexible" grammar. The code splits each line and each word of every line, keeping the first word of each headline in an array, and then reconstructing the text, assigning randomly the initial word.


The original text:

* Iraqi Head Seeks Arms
* Something Went Wrong in Jet Crash, Expert Says
* Police Begin Campaign to Run Down Jaywalkers
* Enraged Cow Injures Farmer with Ax
* Farmer Bill Dies in House
* British Left Waffles on Falkland Islands
* Teacher Strikes Idle Kids
* Miners Refuse to Work after Death
* Juvenile Court to Try Shooting Defendant
* War Dims Hope for Peace
* If Strike Isn't Settled Quickly, It May Last Awhile
* Cold Wave Linked to Temperatures
* Enfield (London) Couple Slain; Police Suspect Homicide
* Red Tape Holds Up New Bridges
* Man Struck By Lightning Faces Battery Charge
* New Study of Obesity Looks for Larger Test Group
* Astronaut Takes Blame for Gas in Spacecraft
* Kids Make Nutritious Snacks
* Chef Throws His Heart into Helping Feed Needy
* Local High School Dropouts Cut in Half
* Hospitals are Sued by 7 Foot Doctors
* Typhoon Rips Through Cemetery; Hundreds Dead


The result:

Something Head Seeks Arms
Juvenile Went Wrong in Jet Crash, Expert Says
Juvenile Begin Campaign to Run Down Jaywalkers
Hospitals Cow Injures Farmer with Ax
New Bill Dies in House
Enfield Left Waffles on Falkland Islands
British Strikes Idle Kids
Red Refuse to Work after Death
Farmer Court to Try Shooting Defendant
Red Dims Hope for Peace
New Strike Isn't Settled Quickly, It May Last Awhile
Red Wave Linked to Temperatures
War (London) Couple Slain; Police Suspect Homicide
Teacher Tape Holds Up New Bridges
War Struck By Lightning Faces Battery Charge
Cold Study of Obesity Looks for Larger Test Group
Kids Takes Blame for Gas in Spacecraft
null Make Nutritious Snacks
Farmer Throws His Heart into Helping Feed Needy
Local High School Dropouts Cut in Half
Local are Sued by 7 Foot Doctors
Iraqi Rips Through Cemetery; Hundreds Dead


Main part of the code:


String[] lines = content.split("\\*");
System.out.println("Read " + lines.length + " lines from " + args[0]);

String[] fwords= new String[lines.length];
StringBuffer result = new StringBuffer();

for( int i=1; i
String[] words = lines[i].split("\\b");
System.out.println("Read " + words.length + " words from line" + i);
fwords[i]=words[1];

}

for( int i=1; i
String[] allwords = lines[i].split("\\b");
Random r = new Random();
int first = r.nextInt(fwords.length);
allwords[1]=fwords[first];
for(int j=0;j
result.append(allwords[j]);
}

}


String output = result.toString();

TrackBack

TrackBack URL for this entry:
http://itp.nyu.edu/~mfm317/cgi-bin/mt/mt-tb.cgi/16

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)