I'm trying to create a simple speech based command interface, using pre-defined commands. The specific part that I am having an issue with is when the program is trying to understand parameters passed with the command. I have some working code but it isn't ideal for what I'd like.
For example, I might have a command that checks the weather as follows:
In london united kingdom what is the weather
and the pattern to be recognised would be this:
In _ what is the weather
I'm already getting the commands with some relevance based mysql queries, that's not my problem, my problem is separating out the context of "London united kingdom" from the command.
I have got some working code at the moment but it isn't ideal:
//SPLIT CONTEXT FROM COMMAND
$query = "in london what is the weather";
$trigger = "in _ what is the weather";
$triggers = explode("_", $trigger);
foreach($triggers as $word){
$query = str_replace($word, "'", $query);
}
$query = explode("'", $query);
array_shift($query);
This will mean that $query['0'] = "london". But it can only support one word at a time, is there a way to support more than one word, by somehow treating it as a variable or something along those lines?
tl;dr
- Code to separate parameters
- multiple words
- Separate it out as a string
Cheers