Have an idea?

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

Text box - word recognition

Dear All,

Is it possible somehow to recognize if a specific word is entered to a text box?
I want to recognize brand name or manufacturer name and then based on that use a skip logic to ask a question or skip a question. I don't want to suggest anything to respondents so list of brands for selection is not an option. Respondents can enter many words but I want to recognize just specific two words.
Below code obviously doesn't work but it shows what I mean:

Begin Unverified Perl 
 
 my $BrandManuf="";
 
 if((VALUE("TextQuestion")=='BrandName' || VALUE("TextQuestion"))=='Manuf name')
  {  
   $BrandManuf=1; 
  }
 else
  {  
   $BrandManuf=0; 
  }
 
End Unverified


Is it possible?

Regards,
robson
asked Jan 31 by robson Bronze (750 points)

1 Answer

+2 votes
You can use the TextExists function within your Perl Script.

The format and information is as follows for Perl ...

TEXTEXISTS (GETVALUE("QuestionName"),"TextToLookFor")

Searches for "TextToLookFor" in the answer of QuestionName.  If found, a 1 is returned; if not found, a 0 is returned.

Example using your question names and variables:

TEXTEXISTS (GETVALUE("TextQuestion"),"BrandName")

Also, in your example above, you would not use "==" in your conditional script as the operator when using text, you would do something like this ...
if(GETVALUE("QName") eq "Sally")
{
 ADD("ColorList", 4);
}

One final comment. Some respondents tend to type in script with typos, so you may want to consider that when writing your Perl Script.
answered Jan 31 by Paul Moon Platinum (80,455 points)
In addition to above mentioned by Paul, we may also need to covert the response provided by respondent to either upper or lower case and then compare it with "SALLY" or "sally" respectively. Because there is chance respondent might enter all the letter upper or in a irregular fashion i.e. few upper and few lower case
I just ran a little test to confirm my suspicions, and that is, the TextExists function will pick up on both lower and upper case matches. The case sensitive issue won't come into it.

Here's an example of the test I ran ...

I have assume Q1 to be the text question you are searching on.
[%Begin Unverified Perl 
  
 my $BrandResult="";
  
 if(TEXTEXISTS(GETVALUE("Q1"),"abc")==1)
  {  
   $BrandResult="Match found"; 
  }
 else
  {  
   $BrandResult="No match found"; 
  }
 
 return $BrandResult; 
  
End Unverified%]

BrandResult will be true for "abc" and "ABC" at Q1.

As mentioned earlier, the bigger issue are the typos made by the respondent. You can include the more common / obvious typos in the Perl Script, but the lesser expected typos will be an issue still.
Just one further comment. If the function was case sensitive, we could include both conditions of lower case and upper case. But a neater method would be to use the the "ToLower" or the "ToUpper" script functions. Using Perl, these would be represented as "lc" and "uc". So you have a number of options available to you.
Thank you very much Paul and Karthik.
It really works! I didn't implement ToLower / ToUpper script but above code recognizes properly searched words regardless of font.
I'm very grateful!
Correct, the case issue is not an issue with TextExists. This function automatically caters for it. But if it didn't, we had a very neat Plan B. Karthik was spot on with that approach if required.
Regular expressions could potentially lessen the typo concern, but they are limited by what typos the survey author thinks of beforehand and codes into the regex.  For example, "gr[ae]y" would capture both common spellings of that color, but it would still fail to catch a misclick like "gery."
...