galaxykate / tracery

Tracery: a story-grammar generation library for javascript
Apache License 2.0
2.11k stars 246 forks source link

Feature request(?): change probabilities #23

Closed shirish93 closed 8 years ago

shirish93 commented 8 years ago

Hello,

I checked the documentation and was unable to find it, so this is probably a feature request. Does it make sense to add a feature to mess around with the likelihood of certain tokens? For example, if one wanted to make a faux astrology bot (not to give you any ideas, @dariusk ), and wanted to use some tokens ("Mars", "Venus") more than others?

THANKS!

Shirish

dariusk commented 8 years ago

@shirish93 What I would do is fake it by putting the same token multiple times.

[a, a, b, b, c, d, e] is not Tracery but illustrates what I'm talking about -- a and b are 2x as likely as c or d or e.

Johnicholas commented 8 years ago

I like using a function that takes a map and returns the repeated array that Darius mentions.

function weighted(dict) { var out = [] for (var key in dict) { for (var i = 0; i < dict[key]; i++) { out.push(key) } } return out }

weighted({a: 2, b: 2, c: 1, d: 1, e: 1})

returns

[a, a, b, b, c, d, e]

On Tue, May 10, 2016 at 8:59 PM Darius Kazemi notifications@github.com wrote:

@shirish93 https://github.com/shirish93 What I would do is fake it by putting the same token multiple times.

[a, a, b, b, c, d, e] is not Tracery but illustrates what I'm talking about -- a and b are 2x as likely as c or d or e.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/galaxykate/tracery/issues/23#issuecomment-218335055

shirish93 commented 8 years ago

Fair. Closing the issue. Thanks everyone!