Skip

Decision Tree Generator
October 25, 2012 4:21 PM   Subscribe

Decision Tree Generator
The Decision Tree Generator parses a YAML file and, if it's in the correct syntax, creates a series of questions and responses that can be displayed on a webpage. It doesn't require a login, and the tree you create is around until someone else overwrites it.

Inspired by the post here:

http://ask.metafilter.com/227215/

An example tree:
http://jeremiahsturgill.com/decision_tree/?tree_name=example

The YAML file should be formatted like so:
prompt: This is the question or prompt that the viewer is reacting to.
key_0_0:
  response_html: This is the option text the user sees that they can use to pick key_0_0.
  prompt: This is the next prompt that will be displayed if key_0_0 is chosen.
  key_1_0:
    response_html: This option can be selected to pick key_1_0
    result: This is the result that is displayed if they pick the above option # terminal value; a leaf
  key_1_1:
    response_html: This can be selected to pick key_1_1.
    result: If key_1_1 is selected, this is the result # another terminal value; a leaf
key_0_1:
  response_html: This is the option text the user sees that they can use to pick key_0_1.
  # etc...
Below key_0_0 there can be any number of additional keys (that is, responses to the first prompt).

The same holds true for key_1_0. While here the tree ends after two prompts, the tree can actually extend to an arbitrary depth.

HTML is escaped to avoid badness. A template is available on the site that you can modify to create a decision tree.

The keys can be named anything you like. They are only used to create a unique hash for each node in the tree. The names are processed, however, to strip out everything but alphanumeric characters and underscores. The only other restriction is that the keys for a given prompt should be unique, or else the last node with that key will overwrite the previous one(s).

This is a proof of concept and playground I created because I thought it would be fun to build. It was! It is not an expert system or anything difficult, and there are no extra features. It can only do one thing: move the user through the specified tree.

JavaScript is used to load the next node in the tree, and is required for the site to work properly.

If you like your tree and wish to preserve it, be sure to save the file somewhere as it could be overwritten at any moment on the site.
Role: programmer
posted by jsturgill (2 comments total) 1 user marked this as a favorite

Added a mobile style sheet.
posted by jsturgill at 1:54 PM on October 26, 2012


The trees can now be exported and embedded on another page.
posted by jsturgill at 5:17 PM on October 26, 2012


« Older Reach Around America...   |   My Kindle word game just made ... Newer »


You are not currently logged in. Log in or create a new account to post comments.

Post