6.11.08

it found no cheese!!

After this it will now find cheese.
because i've typed in cheese.

The following code looks through my blog for the word cheese, and then prints the result.


//Trying to get it recognizing words.
//Would be nice.

HashMap words; //hashmap object

String[] tokens; //array
int counter;

PFont f;

void setup() {
size(500, 500);
words = new HashMap();

//load file and split up words
String[] lines = loadStrings("http://fionnualamurphy.blogspot.com/feeds/posts/default");
String allText = join(lines, " ");
tokens = splitTokens(allText, " ,.?!:;[]-");
f = createFont("Calibri-Bold", 36, true);
}

//so it's now pulling in that scentence and splitting it up. It's also going to show it in Calibri-Bold, size 36.

void draw() {
background(255);
fill(0);

String s = tokens[counter];
counter = (counter +1) % tokens.length;
//look at the words one at a time please

//is the word there?
if (words.containsKey("cheese")) {
System.out.println("CHEESY!");
} else {
System.out.println("no cheese.");
}
}


// IT FOUND NO CHEESE!! SUCCESS!


There was no cheese.



EDIT: doesn't work, i'm sad now.

EDIT: Got it working with a .txt file, just not an RSS feed.

No comments: