INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Build dynamic JSON-like data structure

Build dynamic JSON-like data structure

(OP)
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:

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;'

RE: Build dynamic JSON-like data structure

Looks like it would be something like this:

CODE

map<string, map<string, map<string, string> > >

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close