detect if a combination of string objects from an array matches against any commands


Please be patient and read my current scenario. My question is below.

My application takes in speech input and is successfully able to group words that match together to form either one word or a group of words - called phrases; be it a name, an action, a pet, or a time frame.

I have a master list of the phrases that are allowed and are stored in their respective arrays. So I have the following arrays validNamesArray, validActionsArray, validPetsArray, and a validTimeFramesArray.

A new array of phrases is returned each and every time the user stops speaking.

NSArray *phrasesBeingFedIn = @[@"CHARLIE", @"EAT", @"AT TEN O CLOCK", @"CAT", @"DOG", "URINATE", @"CHILDREN", @"ITS TIME TO", @"PLAY"];

Knowing that its ok to have the following combination to create a command:

COMMAND 1: NAME + ACTION + TIME FRAME COMMAND 2: PET + ACTION COMMAND n: n + n, .. + n //In the example above, only the groups of phrases 'Charlie eat at ten o clock' and 'dog urinate' //would be valid commands, the phrase 'cat' would not qualify any of the commands //and will therefor be ignored


What is the best way for me to parse through the phrases being fed in and determine which combination phrases will satisfy my list of commands?

<strong>POSSIBLE solution I've come up with</strong> One way is to step through the array and have if and else statements that check the phrases ahead and see if they satisfy any valid command patterns from the list, however my solution is not dynamic, I would have to add a new set of if and else statements for every single new command permutation I create.

My solution is not efficient. Any ideas on how I could go about creating something like this that will work and is dynamic no matter if I add a new command sequence of phrase combination?


I think what I would do is make an array for each category of speech (pet, command, etc). Those arrays would obviously have strings as elements. You could then test each word against each simple array using

[simpleWordListOfPets containsObject:word]

Which would return a BOOL result. You could do that in a case statement. The logic after that is up to you, but I would keep scanning the sentence using NSScanner until you have finished evaluating each section.

I've used some similar concepts to analyze a paragraph... it starts off like this:

while ([scanner scanUpToString:@"," intoString:&word]) { processedWordCount++; NSLog(@"%i total words processed", processedWordCount); // Does word exist in the simple list? if ([simpleWordList containsObject:word]) { //NSLog(@"Word already exists: %@", word);

You would continue it with whatever logic you wanted (and you would search for a space rather than a ",".


  • Copy current CLOB column to new BLOB column in Oracle
  • How to load an NSDictionary from a file created with writeToFile?
  • Upload file onto Server from the IPhone using ASIHTTPRequest
  • how to get all installed applications with Objective C in OSX
  • Keep playing a sound over and over again in Matlab?
  • Fibonacci Computation Time
  • VHDL - iSIM output uninitialised, doesn't change states
  • Check if a UITableViewCell is completely visible
  • JFrame attached on the side of another JFrame
  • F# NativePtr.stackalloc Unexpected Stack Overflow
  • How to query property value when property name is a parameter?
  • Why is JSON.NET adding all these backslashes
  • Catching exceptions caused in different threads [duplicate]
  • How do display a UIAlertView from a block on iOS?
  • AWS Cognito- get user information with ID
  • Keep Sql Connection open for iterating many requests? Or close each step?
  • PHP Handling Namespace with SimpleXML
  • Getting a generic method to infer the type parameter from the runtime type
  • Finding parents in a tree hierarchy for a given child LINQ (lambda expression)
  • Angular2 emit event up to the DOM tree
  • Firebase, only get new children
  • How to generate an asynchronous reset verilog always blocks with chisel
  • Yii2: Using Kartik Depdrop Widget?
  • How to determine the CCSID used in CPYFRMIMPF command?
  • NSMutableArray instance used in a block
  • php is_file always return false
  • What is the difference between a “service account” and an “installed application”?
  • Clear fused location provider's location for testing
  • How to disable all widgets inside Panel or inside Composite?
  • Firefox Extension - Monitor refresh and change of tab
  • Saving Changes After In-App Purchase Has Been Purchased
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • Limiting recursion to certain level - Duplicate rows
  • Row Count Is Returning the incorrect number using RaptureXML
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Knitr HTML Loop - Some HTML output, some R output
  • Adding custom controls to a full screen movie
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]