hutches
YaBB Newbies
Offline
Posts: 2
StopWords
Dec 14th , 2009, 7:05pm
OK, so I'm doing this project for a class and I'm using a HashMap class but i want to modify it. I want to use a function stop common words ('the', 'a', 'there', 'is', etc.) from being counted in the HashMap. I have written some code for it, but obviously I'm not very good with processing so I don't know how to do this. thus far I'm getting an 'unexpected token: stopwords' error. does anyone know how to fix my code?! import ddf.minim.*; Minim minim; AudioPlayer player; HashMap words; String[] tokens; int counter; String[] stopwords = {"a", "the", "is"}; PFont f; PImage crow; void setup() { size(550, 500); minim = new Minim(this); player = minim.loadFile("ravenReading.wav", 2048); player.loop(); crow = loadImage("crow2.png"); words = new HashMap(); String[] lines = loadStrings("theRaven.txt"); String allText = join(lines, " "); tokens = splitTokens(allText, " ,.?!:;[]-_"); f = createFont("Herculanum", 36, true); } void draw() { background(255); pushMatrix(); String s = tokens[counter]; counter = (counter + 1) % tokens.length; if (words.containsKey(s)) { Word w = (Word) words.get(s); w.count(); } else { Word w = new Word(s); if ( isStopWord(s) == false ) words.put(s, w); } Iterator i = words.values().iterator(); float x = 10; float y = height-65; while (i.hasNext()) { Word w = (Word) i.next(); if (w.count > 3) { int fsize = constrain(w.count, 10, 100); textFont(f, fsize); text(w.word, x, y); x += textWidth(w.word + " "); } if (x > width) { x = 0; y -= 10; if (y < 0) { break; } } } popMatrix(); image(crow, 0, 0); fill(0); } void stopwords { for (int i=0; i < stopwords.length; i++) { String stopword = stopwords[i]; if ( stopwords.equals(word) ) return true; } else{ return false; } } class Word { int count; String word; Word(String s) { word = s; count = 1; } void count() { count++; } }