Extract categories automatically from an open-ended question
If you want to classify topics entered in an open-ended question, you can use a basic comparison between character strings extracted from the open-ended question texts and create a closed question with categories.
Closed question with categories
Create a closed question with categories, e.g. ^Q1^- Q1 Reasons to choose this hotel:
- Room
- Cleanliness|Clean
- Restaurant
- Leisure
- Holidays|Vacation|Days off
- Room service
- Business
- Location
Note, if you need to concatenate several words in one category, use the "|" as the delimiter.
Routing
Insert a "Set value" routing after the open-ended question (^Comments^ - Why did you chose this hotel ?) assuming we have at least one character.
Condition:
^Comments^.hasnodata = false
In order to simplify the comparison between contents, we set temporarily variables with no accent and no regular expressions:
Dim arrResult = {}
Dim i
Dim j
Dim arrSpellings 'Q1 Responses caption
'----------------------------------------------------------------------------------
'Accent and quote cleaning
'--------------------------------------------------------------------------------
Dim varcom = ^Comments^.value.toLowerCase().ReplaceRegexp("[^\w\s]", " ", "gi")
Dim map = @{
"a" : "á|à|ã|â|ä|À|Á|Ã|Â|Ä",
"e" : "é|è|ê|ë|É|È|Ê|Ë",
"i" : "í|ì|î|ï|Í|Ì|Î|Ï",
"o" : "ó|ò|ô|õ|ö|Ó|Ò|Ô|Õ|Ö",
"u" : "ú|ù|û|ü|Ú|Ù|Û|Ü",
"c" : "ç|Ç",
"n" : "ñ|Ñ"
}
Dim k = 0
For k = 1 to map.count
varcom = varcom.ReplaceRegexp(map.Values[k].ToString(), map.Keys[k], "gi")
Next k
'--------------------------------------------------------------------------------
'Comparison with the question Q1 with categories
'--------------------------------------------------------------------------------
For i = 1 to Q1.Responses.Count
dim varcat = Q1.responses[i].caption.toString().Replace("'", " ")
For k = 1 to map.count
varcat = varcat.ReplaceRegexp(map.Values[k].ToString(), map.Keys[k], "gi")
Next k
arrSpellings = varcat.split("|")
For j = 1 to arrSpellings.Count
If instr(arrSpellings[j], varcom) > 0 Then
arrResult = arrResult + i
Endif
Next j
Next i
return arrResult
In the 📥 attached QEX , you will find a multi-lingual example.