We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › if/string reading problem
Page Index Toggle Pages: 1
if/string reading problem (Read 554 times)
if/string reading problem
Apr 6th, 2010, 2:26am
 
Hi all,

I'm using Rita to analyze text; specifically, right now, I'm going through it to try to get rid of prepositions, definite articles, etc. So I've got my whole text loaded, each word, into a String[] and the part-of-speech tagging is working just fine. It should read the tag (which in this case would be a text string like "dt" or "cc") and add the corresponding word in the thisText array to the "ignore" array, but for some reason isn't. (The code isn't optimized, I'm just trying to get it to recognize the tag Strings.)

Code:
import rita.*;

RiConcorder analyst;
RiPosTagger tagger;

String[] thisText;

void setup() {
 analyst = new RiConcorder(this);
 tagger = new RiPosTagger(this);
 
 String[] lines = loadStrings("scum.txt");
 String allText = join(lines, " ");
 thisText = splitTokens(allText, " ,.?!:;[]()`-");
 
 String[] tags = tagger.tag(thisText);
 
 String[] ignore = new String[500];
 
 int iCount = 0;
 
 for (int i = 0; i < thisText.length; i++) {
   println(i + " " + tags[i] + " " + thisText[i]);
   if (tags[i] == "dt") {
ignore[iCount] = thisText[i];
iCount++;
   }
   
   if (tags[i] == "cc") {
ignore[iCount] = thisText[i];
iCount++;
   }
 }


The println above returns this (excerpt):

3153 cc and
3154 nnp Prevention
3155 in of
3156 nnp Community
3157 prp$ Our
3158 nn society
3159 vbz is
3160 rb not
3161 dt a
3162 nn community
3163 cc but
3164 rb merely
3165 dt a
3166 nn collection

So I would think that a few of those, with tags like "cc" and "dt," should be added to the ignore array. Am I missing something?
Re: if/string reading problem
Reply #1 - Apr 6th, 2010, 4:52am
 
You should read again String reference and the FAQ... Smiley
You will see there, in big red bold flashing letters (well, only a small exaggeration...) that you must not compare strings with ==.
Re: if/string reading problem
Reply #2 - Apr 6th, 2010, 10:05am
 
I knew it was something stupid. Thanks.
Page Index Toggle Pages: 1