I am working on a parser for natural language. Words from natural language are parsed to the concepts that they represent. The purpose is to allow a robot to interpret commands given in natural language. One way to execute these commands would be by creating an enormous amount of if statements, which would turn into at east one for each concept. I was wondering if there was a way to retrieve a function pointer to a function whose name is stored as string. Each concept could then contain a string that represented the function that would need to executed if the concept is present in the parse. This way the concept would already know what to do.
Asked
Active
Viewed 475 times
1
-
1See [this question](http://stackoverflow.com/questions/630920/store-pointers-to-member-function-in-the-map). – jonsca Apr 26 '11 at 03:49
-
@jonsca: Or see [this answer](http://stackoverflow.com/questions/746604/bind-pointer-to-member-operators-in-c/746653#746653) for slightly more readable example. (Disclaimer: I wrote that post.) – C. K. Young Apr 26 '11 at 03:57
-
@Chris Certainly. That one happened to be one of the first to come up. Plus, who wants readable? ;) – jonsca Apr 26 '11 at 04:03
-
@jonsca, @Chris: Thanks for the suggestions. Those should work pretty well. – jeffminton Apr 26 '11 at 04:08
1 Answers
0
This is not so complicated. I would try to (theoretically, of course) implement one of these "possible" solutions:
This is very C++: Read Instantiate class from name? and create a class for each of the "natural" language, make sure that these classes derive from a common interface, and each of the classes would have the overridden method would handle the specific word.
This is more C: In case you are not afraid to use shared libraries, create a shared library, with all the functions for the commands you want, make sure the functions name match the "words" and then just load the specific function (word) you want to use. This is even easier than the one above, since you don't need to know all the words, and there is less maintenance.
Cheers

Community
- 1
- 1

Ferenc Deak
- 34,348
- 17
- 99
- 167