Main

Programming A2Z Archives

February 1, 2008

Week 1 - Strings in Java

After getting several days frustrated with the Eclipse and also with Java Language, I finally gave my first steps in working with Strings in Java.

For this assignment, I did something very simple. Using one of the txt.files that were on the CVS ( bible.txt -- but it's working with any txt.file), I started to extract from the txt file the word I and the following word. In the middle of this 2 words I put the word don't just for fun.

String[] words = content.split("\\b");
// create a new string buffer ( that will store the words I + don't + nextword )
StringBuffer findI = new StringBuffer();
for ( int i=0; i< words.length;i++){
String find = "I";
if(words[i].equals(find)){
findI.append(words[i]+ " don't " + words[i+2] + " " + "\n");
}
}
String output1 = findI.toString();

The result was the String output1 that contains this (excerpt) :

I don't have
I don't have
I don't will
I don't heard
I don't was
I don't was
I don't hid
I don't commanded
I don't did
I don't did
I don't will
I don't will
I don't commanded
I don't have
I don't know
I don't my

I saw that some phrases were repeating, so the next step was to avoid that the same phrase appeared several times or more that once. I started by splitting that String (output1) into an Array phrase and then, using two for loops, comparing each elements of that Array with the rest of the elements. If the element of the Array ( that was been compare to the rest) was different , it was appended to the String Buffer finali

The trick that I use for this, was to create an empty String finali2 that allowed me to see if that element was already in the String Buffer finali. If it was, it wasn't appended, since it was already there.


String [] phrases = output1.split("\n");
// Create new String Buffer ( to each the unique phrases will be appended)
StringBuffer finali = new StringBuffer();
// temp String to compare content ( use contains -- cannot use any method for String Buffer?)
String finali2= "";
for ( int b=0; b String Temp = phrases[b];
for(int c = b+1; c if ( !phrases[c].equals(Temp) && !finali2.contains(Temp) ){
finali.append(Temp + "\n");
finali2 = finali.toString();
}
}
}

String output = finali2;

See the result txt file here and to see all the code, click here

Week 1 - Strings in Java II

Having the experience with the last exercise, I decided to go back to my initial idea and work with a txt file that contains all the posts from my blog.

In this exercise, I count how many times I used the word "I" in my student blog to see how this blog is self/centered in my activities and also to see to what I which action I was referring to. Using the same logic of the first exercise I got to this result:

I wrote 245 times the word I in my blog
Take a look of the some of the phrases where I use the word I

I wish I
I had only
I still have
I Code Therefore
I Am STATUS
I WANT 255
I m interested
I STATUS Publish
I start with
I was missing
I was trying
I came out
I can develop
I went back
I thought in
I think it
I though on
I have to
I spend yesterday
I can build
I was thinking
I decided to
I went to
I had to
I bought plastic
I shaped them
I thought in
I decided to
I hope I
...../////


see code
// see final txt.file

February 5, 2008

Week2 - Regular Expressions

Still working with the txt.file that I exported from my itp blog, I started by replacing all characters and non characters on the file with one single character, in this case /.
I wanted to visualize the patterns that a txt file can created.

The important and simple code I had to write:

String regex = ".";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(content);
String output = m.replaceAll("/");

see the code // see the final txt file

February 26, 2008

A2Z Midterm - Blog Generated Exquisite Corpse

Idea:
Create a program that generate a random Exquisite Corpse, crawling personal (maybe other theme) blogs in the web.

The program will allow users to selected the first word of the Exquisite Corpse and based on that word the program will crawl blogs that contain that word and extract the following 12 words.

The last word that was extracted will be save as the following word to crawl in the next blog in the queue of blogs to visited ( need to define how this list will be created - for now it will be just a list of selected blogs).

This way the program will try to re-create the logic behind the Exquisite Corpse, where several persons create collectively a text where the next person playing have to start to write a phrase with the last word written by the previous person.

Work Plan:

1. Find and create a list of blogs ( not using the crawl for now)
It's was funny and stupid at the same time trying to find "personal blogs" or more personal content in the web. When I noticed I was goggling " My life is a mess" and
"she broke up with me". I also try to goggle " I can't believe she blogged that" that someone wrote in the Draw Installation at Eyebeam on Saturday and that I loved but the results weren't valid. This is the list I'll be using:
1. http://shomernegiah.blogspot.com/feeds/posts/default
2. http://mylife27.wordpress.com/feed/
3. http://tiffanireilly.blogspot.com/feeds/posts/default
4. http://beingelim.blogspot.com/
5. http://www.swerdloff.com/personal/index.xml
6. http://dreamsofazaro.com/?feed=rss

2. Create a " fake process" to see how the program could result. Shiffman asked me to do this process in order to help me understand better how can the program could be "design" and the steps I'll need to implement.
I made this scheme -- take a look or download the pdf ( better resolution)

3. Analise the results of the previous step

4. Write the program !!

March 4, 2008

A2Z Midterm - Generative text

For this midterm assignment I wanted to work and play with generative text, grabbing text form personal blogs in the web. Using the logic of the Exquisite Corpse, the program, based on a word chosen by the user, starts to find it into the first text file and extracts the word and the 11 words that follows. Then, the last word extract became the keyword that the program will look in the following text and the process starts to repeat itself till it doesn't find more phrases.

To make the process easier, I started by copying text from 5 blogs and pasting into separate txt files, simulating different url's and what the crawler could get.
The next stop will be creating the crawler to look on the web for personal blogs.

The result needs to be tuned a little more but once I get the crawler working, I can see better the results and improve the program.

here are some examples of the output:

generate2.png

generate3.png

generate4.png

see source code

One idea of where this could go is to create a fake blog, writing a program that everyday crawl personal blogs, search for posts with the same date and using this set rules, creates a "fake" post or a mash/up post.

It was an interesting exercise to get my hands in regular expressions and feel more comfortable with programming in java

May 16, 2008

A2Z Final Project - Visualization of the Web

This project aim was to visualize the flow of text when we are browsing the web, or more specific when we make an http request. I ended with just a starting point of the project:

- Using Carnivore Library to sniff the packets received/send when an http request happens
- Creating a node class to store all the nodes on the network based on the IP address of the sender and based on the port
- Parsing the data inside of the packets to extract the hostname, the title of the page and all the text that was available inside the html - extracting the html tags
- Animating the text on the screen

The result:

one-small.jpg

two_small.jpg


Each node is define by the hostname and the title of the website. The circle is define by the amount of text that the node contains ( text parsed from the html)

see code here:


I also did other visualization just showing the text ( the first 10 words) of the node. Visually and technical I couldn't developed better. Here is what results from that experience:

three-small.jpg


I am not happy with the result of this project. I wanted to make the text fly from one node to the other ( my computer) and I also think that adapting random positions for the nodes based on their IP addresses is not the right choice but I was happy somehow in putting in practice the knowledge learned in class : parsing data using regular expressions and using hashmaps.
I also would like to continuing this idea but using another method to sniff the packets, instead of using Carnivore to do that.

About Programming A2Z

This page contains an archive of all entries posted to I´m born into a house with no computer in the Programming A2Z category. They are listed from oldest to newest.

Network Objects is the previous category.

Urban Computing is the next category.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.35