Comparing a text file with two different text files
in
Programming Questions
•
2 years ago
Hello all,
I'm new to Processing and programming as a whole, so please bear with me.
I am trying to vizualize a book (Beyond good and evil) by comparing it with two text files -- one a database of positive words, the other a database of negative words. This is what i have so far:
- String[] beyond;
- String[] posText;
- String[] negText;
- String delimiters = " ,.?!;:\n";
- int x = 0;
- int y = 0;
- Map<String, Integer> words = new HashMap<String, Integer>();
- void setup(){
- background (255);
- size (200, 200);
- String[] myText = loadStrings ("bge.txt");
- // Join the big array together as one long string
- String everything = join(myText," ");
- // Split the array into words using any delimiter
- beyond = splitTokens(everything,delimiters);
- String[] posText = loadStrings ("positive-words.txt");
- String posLexicon = join(posText, " ");
- posText = splitTokens(posLexicon,delimiters);
- String[] negText = loadStrings ("negative-words.txt");
- String negLexicon = join(negText, " ");
- negText = split(negLexicon,delimiters);
- // 0 is negative, 1 is positive
- words.put("posText", 1);
- words.put("negText", 0);
- // go through each word from myText
- for(int i=0; i < myText.length; i++) {
- // check if its in the text
- if(words.get(myText[i]) == null){
- noFill();
- }else{
- if(words.get(myText[i]) == 0){
- fill(175);
- }else if(words.get(myText[i]) == 1){
- fill(0);
- }
- }
- for(x = 0; x < width; x+=10) {
- for(y = 0; y < height; y +=10) {
- rect(x,y,10,10);
- }
- }
- }
- }
I'm pretty sure something is wrong with the HashMap -- I've never used nor fully unterstood the bastard --, specifically lines 30 and 31. Instead of getting a nice pattern of red pixels (negative words in the book) and white pixels (positive words), I just get empty pixels.
If ye nice people can help me, I'd be really grateful.
Peace!
1