First lets assume some things. According to the comment "mystring is the string correctly recognized" you are not asking about voice recognition for the commands, only about the user names.
For the user name you may need to compute a distance between what was understood by the VR mechanism and your user database. The VR system "hears" Duck, looks up the distance for all users to Duck and take the smallest distance. "Chuck" would be a much more likely contender than "Buckingham".
I think you may have to tweak the mechanism to be able to work according to your business rules, but you can already create a proof of concept with the Levensthein distance between names.
I'm going to sweep the name recognition under the rug. You need to nail down your requirements, and your question is not precise enough to do just that yet.
Now regarding the parsing of the language, I think the simpler approach would be to create a Parsing Expression Grammar. It lets you define a grammar that is then turned into code by a generator. The code will then be able to parse the text obeying the grammar you are expecting. There is even a PEG library for C# that you can use to generate the parsing code, peg-sharp
PEGs are easy to build and quite readable. You can train online with PEG.js to build your first grammar. You need first to look at how a sentence would be translated into code. Let's say that
- Give me 2015 revenue for Duck
- Fetch Duck's revenue in 2015
should be equivalent commands, you would say that your system should translate this into an Operation
(get) with parameters customer
(Duck), dataFields
(revenue) and timeWindow
(year 2015). This could be translated into the following grammar:
start
= command
command
= "Give me " year:year " " dataFields:dataFields " for " customer:customer
{
return {
"operation" : "get"
, "customer": customer
, "year": year
, "dataFields": dataFields
};
}
/
"Fetch " customer:customer "'s " dataFields:dataFields " in " year:year
{
return {
"operation" : "get"
, "customer": customer
, "year": year
, "dataFields": dataFields
};
}
dataFields "dataFields"
= "revenue"
year "year"
= digits:[0-9]+ { return parseInt(digits.join(""), 10);}
customer "customer"
= letters:[a-zA-Z]+ {return letters.join("");}
Of course this sample grammar is very naïve; the sentence structure is not able to take into account variations, but this is a matter of finding the general rules of your sentences parsing:
- ignoring spaces and noise (such as the possessive
's
in this example, or expletives if the user is frustrated :) )
- creating rules where elements don't depend on order but can be picked up from anywhere in the sentence
- extending possible
dataFields
and commands
If you try it on PEG.js you can see that it is able to translate the sentence into a JSON object (with peg-sharp that would be a C# object which behavior you control through the code)
With this and some planning of the variations you can have in your sentences you should be able to create a first approach to what you need