Hi,
I'm porting a Perl module for a chatterbot reply scripting language over to C++. The chatterbot scripting language consists of text files containing commands and data that is parsed by the module and turned into usable data in-memory so that the chatterbot app can receive messages from a user and return an appropriate response.
Here is a snippit of what the script source files look like:
The data structure that the Perl module comes up with after parsing this is:
The structure is basically,
topics["topic name"]["trigger text"]["replies"]->[0]
topics["topic name"]["trigger text"]["redirect"]
etc.
How do you implement a data structure like this in C++? I discovered map and multimap so far but these don't seem very flexible for having a multi-tiered data structure.
Kirsle.net | My personal homepage
I'm porting a Perl module for a chatterbot reply scripting language over to C++. The chatterbot scripting language consists of text files containing commands and data that is parsed by the module and turned into usable data in-memory so that the chatterbot app can receive messages from a user and return an appropriate response.
Here is a snippit of what the script source files look like:
Code:
// this is a comment
// the default "topic" is random
+ hello bot // this is what the human says
- Hello, human! // this is how the bot replies
- Hello mortal. // there can be multiple replies, they're chosen at random
+ hello robot
@ hello bot // this redirects so when the user says "hello robot" it's as if they just said "hello bot"
> topic my_topic
// this is a "topic" and its replies are isolated from
// the default "random" topic
+ test input
- test reply
< topic
The data structure that the Perl module comes up with after parsing this is:
Code:
$topics = {
"random" => {
"hello bot" => {
"replies" => [ // this is always an array
"Hello, human!",
"Hello mortal."
]
},
"hello robot" => {
"redirect" => "hello bot" // this is always a string
}
},
"my_topic" => {
"test input" => {
"replies" => [
"test reply"
]
}
}
};
The structure is basically,
topics["topic name"]["trigger text"]["replies"]->[0]
topics["topic name"]["trigger text"]["redirect"]
etc.
How do you implement a data structure like this in C++? I discovered map and multimap so far but these don't seem very flexible for having a multi-tiered data structure.
Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'