Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Problems using TEXTEXISTS in perl to construct a list

Hi all ... I'm using Version 7.

The problem:
Checking the text in an open question, and asking for more detail if certain words are or are not present.

The simple problem:
Just use the textexists command to skip (or not).

The complication:
You guessed it - common misspellings.

So I want to simplify the skip by basing it on a list.
Parent list called yn contains just yes.
Constructed list (will obviously have more lines than this) would have:

Begin Unverified Perl

if(TEXTEXISTS(VALUE "P42","service"))
{
  ADD("yn",1);
}

End Unverified


Doesn't work.  I have tried:
if(TEXTEXISTS(VALUE("P42","service")))
if(TEXTEXISTS("P42","service"))

Any further ideas?  Putting a page of stuff into a skip doesn't fill me with the joy of life.
asked Jun 14, 2012 by Marion Bronze (3,360 points)
retagged Sep 13, 2012 by Walter Williams

2 Answers

+1 vote
its the closing parenthesis. you were quite close in one of your tries.
if(TEXTEXISTS(VALUE("P42"),"service"))
answered Jun 14, 2012 by Bahadir Ozkurt Gold (16,830 points)
Oh groan!  Scuttled by a bracket!

Thanks so much, Bahadir!  Next stage (a job to work on in my "down" time) will be to work out how to do this based on a loop, so that I don't have to put 2 pages of misspellings in manually.  But this certainly fixes my immediate problem :-)
I've used the following dozens of times in a study without an obvious performance hit
Begin Unverified Perl
my $criterialist = "service,serviec,servic," ;
my $criteria = VALUE("P42") . ",";
if (index($criterialist,$criteria) == -1) {return "TRUE";}
End Unverified

this goes right into skip logic area, not a list
AHHH but therein lies the rub, you see ... the skip in plain english is something like:

If "service" typed in, but "customer" or "product" not typed in, ask this question.

And then there are a heap of misspellings and synonyms for each.  Other questions have other similar combinations.  AND, just to add that extra layer of heartburn, as the job is ongoing, they may want to add in more misspellings, etc as we go along.  Currently, there are 7 pages of the dang things.

So this is the reason for shoving everything into (relatively) easily updateable lists and skipping using those.

This is what I've done previously (for checking brands):

Begin Unverified Perl

 my $counter=1;
 my $Spell1=(LISTLENGTH("zzzBrand1")+1);

 for ($counter=1; $counter < $Spell1; $counter++)
  {
    if ((lc(VALUE("AD1P29oth"))) eq (lc(LISTLABEL("zzzBrand1",$counter))))
    {
       ADD("yn",1);
    }
  }
 
End Unverified


the bit "zzzBrand1" is a list holding the misspellings.  Using this, I can check against several brands, as long as I'm looking at the entire value of the question.  But I couldn't quickly get this working for TEXTEXISTS.  Will work on it when I get a chance - unless, clever person, you see an obvious solution.
the thing with "index" or textexists is partial matches. "product" would match "productivity" using either of these methods.
if that doesnt bother you, doesnt the following work?
Begin Unverified Perl
 
 my $counter=1;
 my $Spell1=(LISTLENGTH("zzzBrand1")+1);
 
 for ($counter=1; $counter < $Spell1; $counter++)
  {
    if (index(lc(VALUE("P42")),lc(LISTLABEL("zzzBrand1",$counter)))>-1)
    {
       ADD("yn",1);
    }
  }
  
End Unverified
+1 vote
If all else fails you can use the built in perl functions to do the same thing

if (index(lc(VALUE("P42")), "service") != -1)
{
   ADD("yn", 1);
}


or the regular expression way

my $strText = VALUE("P42");
if ($strText =~ m/service/i)
{
   ADD("yn", 1);
}
answered Jun 14, 2012 by Mike Lodder Gold (23,410 points)
Thanks, Mike!

This way might help get the checks into a loop (ie have a list of common misspellings and get the code to loop through.  If there is a match on any of them, set the code).  What do you think?
Sure just add the loop like so

my @Misspellings = qw(service, serv, ser, srvice);
foreach my $strMisspelling (@Misspellings)
{
   if (index(lc(VALUE("P42")), $strMisspelling) != -1)
   {
      ADD("yn", 1);
      last;
   }
}
...