Hello, I am writting a chatbot which works out a percetage match based on human reading style of a search term and the input. For flexibility, parts of the search term can vary, for example if this was used:
<hello,hey> there! Having a nice <morning,afternoon>?
Then the function would test all of these strings, and return the best match:
hello there! Having a nice morning?
hello there! Having a nice afternoon?
hey there! Having a nice morning?
hey there! Having a nice afternoon?
The code creates a 16x16 2-D array to store all the terms in, with unused spaces just containing an empty string:
1 2 3 4 5 6 7 8 9 10
|
GROUPS (<...> = group)
0 1 2 3 4...
0 "hello" "morning" "" "" ""
TERMS
1 "hey" "afternoon""" "" ""
.
.
.
|
However, I cant figure out a way to test every single possibilty of combinations that one of these 'flexable terms' could yeild. The only thing I thought of would be making a 16-deep nested for loop, which seems monstrous. Although that may be the only soloution, I dont know. My question is, is there a better way of doing this? Or is the evil for loops the only option. Thankyou
P.S If its relevent, my code also creates a 32 element array containg the positions of the main string which needs to be replaced by the terms. e.g:
1 2 3
|
<hello,hey> there! Having a nice <morning,afternoon>?
^ ^ ^ ^
0 13 44 61
|
foo[0] = 0
foo[1] = 13
foo[2] = 44
foo[3] = 61
foo[4] = -1
foo[5] = -1
etc...