/wordz

A minimalist generative grammar library

Primary LanguageRubyMIT LicenseMIT

Gem Version Build Maintainability

Wordz

A minimalist generative grammar library. For use in bots and other mischief.

Usage

grammar = {
  "<root>" => [
    ["#dog#name#", "says", "<bark>", "."],
  ],
  "<bark>" => [
    ["ruff"],
    ["woof"],
  ]
}

class Dog
  def name
    "Daisy"
  end
end

Wordz.generate(
  grammar: grammar,
  subjects: { dog: Dog.new },
)

# Will return one of the following, at random.
# => "Daisy says ruff."
# => "Daisy says arf."