calyx 0.17.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/docs/_data/breadcrumbs.yml +9 -0
  3. data/docs/_data/docs.yml +35 -0
  4. data/docs/_data/examples.yml +9 -0
  5. data/docs/_includes/breadcrumbs.html +36 -0
  6. data/docs/_includes/contents.html +12 -0
  7. data/docs/_includes/icon-github.html +4 -0
  8. data/docs/_includes/icon-rubygems.html +9 -0
  9. data/docs/_includes/navbar.html +24 -0
  10. data/docs/_includes/pagebar.html +12 -0
  11. data/docs/_layouts/default.html +3 -23
  12. data/docs/_layouts/docs.html +14 -0
  13. data/docs/_layouts/home.html +13 -0
  14. data/docs/_layouts/page.html +20 -0
  15. data/docs/_posts/2017-09-14-welcome-to-jekyll.markdown +1 -1
  16. data/docs/_posts/2017-09-21-0.17.0-released.md +10 -0
  17. data/docs/_styles/card.scss +7 -0
  18. data/docs/_styles/colors.scss +18 -0
  19. data/docs/_styles/content.scss +57 -0
  20. data/docs/_styles/cta.scss +25 -0
  21. data/docs/_styles/grid.scss +22 -0
  22. data/docs/_styles/media.scss +50 -0
  23. data/docs/_styles/menu.scss +54 -0
  24. data/docs/_styles/modifiers.scss +3 -0
  25. data/docs/_styles/navbar.scss +161 -0
  26. data/docs/_styles/pagebar.scss +32 -0
  27. data/docs/_styles/reset.scss +92 -0
  28. data/docs/_styles/scale.scss +23 -0
  29. data/docs/_styles/spread.scss +55 -0
  30. data/docs/_styles/styleguide.scss +52 -0
  31. data/docs/_styles/syntax.scss +84 -0
  32. data/docs/_styles/typography.scss +49 -0
  33. data/docs/_styles/yard.scss +36 -0
  34. data/docs/api.html +9662 -0
  35. data/docs/assets/calyx-docs.css +253 -162
  36. data/docs/assets/calyx-flower-outline.svg +202 -0
  37. data/docs/assets/calyx-flower-reverse.svg +202 -0
  38. data/docs/assets/calyx-flower.svg +202 -0
  39. data/docs/assets/logo-small.png +0 -0
  40. data/docs/assets/logos/calyx-flower-1.svg +22 -0
  41. data/docs/assets/logos/calyx-flower-2.svg +21 -0
  42. data/docs/content/documentation.html +20 -0
  43. data/docs/content/examples.html +12 -0
  44. data/docs/content/examples/any-gradient.md +32 -0
  45. data/docs/content/examples/faker.md +16 -0
  46. data/docs/content/examples/tiny-woodland-bot.md +24 -0
  47. data/docs/{guide → content/guides}/context.md +2 -2
  48. data/docs/{guide → content/guides}/expressions.md +2 -2
  49. data/docs/content/guides/features.md +50 -0
  50. data/docs/{guide → content/guides}/formats.md +1 -1
  51. data/docs/content/guides/installation.md +51 -0
  52. data/docs/{guide → content/guides}/random.md +1 -1
  53. data/docs/{guide → content/guides}/results.md +1 -1
  54. data/docs/content/index.html +44 -0
  55. data/docs/content/introduction.md +23 -0
  56. data/docs/content/introduction/concepts.md +82 -0
  57. data/docs/content/introduction/contributing.md +43 -0
  58. data/docs/content/introduction/tutorial.md +129 -0
  59. data/docs/content/styleguide.html +71 -0
  60. data/docs/docs.scss +94 -0
  61. data/docs/index.html +1 -23
  62. data/docs/package.json +1 -1
  63. data/lib/calyx/production/choices.rb +7 -0
  64. data/lib/calyx/production/unique.rb +0 -2
  65. data/lib/calyx/registry.rb +5 -0
  66. data/lib/calyx/rule.rb +4 -0
  67. data/lib/calyx/version.rb +1 -1
  68. metadata +59 -13
  69. data/docs/about.md +0 -18
  70. data/docs/calyx-docs.scss +0 -66
  71. data/docs/guide/examples.md +0 -59
  72. data/docs/guide/getting-started.md +0 -129
  73. data/docs/guide/installation.md +0 -19
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <svg width="400px"
3
+ height="400px"
4
+ version="1.1"
5
+ xmlns="http://www.w3.org/2000/svg"
6
+ xmlns:xlink="http://www.w3.org/1999/xlink">
7
+ <defs>
8
+ <symbol id="petals">
9
+ <ellipse cx="200" cy="120" rx="37" ry="80" /><ellipse cx="200" cy="280" rx="37" ry="80" /><ellipse cx="280" cy="200" rx="80" ry="37" /><ellipse cx="120" cy="200" rx="80" ry="37" />
10
+ </symbol>
11
+ <symbol id="corolla">
12
+ <use xlink:href="#petals" />
13
+ <use xlink:href="#petals" transform="rotate(22.5 200 200)" />
14
+ <use xlink:href="#petals" transform="rotate(45 200 200)" />
15
+ <use xlink:href="#petals" transform="rotate(-22.5 200 200)" />
16
+ </symbol>
17
+ </defs>
18
+ <use xlink:href="#corolla" fill="#1BDE81" stroke="#2F5E52" stroke-width="16"/>
19
+ <use xlink:href="#corolla" fill="#76FABB" stroke="#2F5E52" stroke-width="18" transform="scale(0.80 0.80) translate(50 50)" />
20
+ <use xlink:href="#corolla" fill="#218764" stroke="#2F5E52" stroke-width="5" transform="scale(0.40 0.40) translate(300 300)" />
21
+ </svg>
22
+
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <svg width="400px"
3
+ height="400px"
4
+ version="1.1"
5
+ xmlns="http://www.w3.org/2000/svg"
6
+ xmlns:xlink="http://www.w3.org/1999/xlink">
7
+ <defs>
8
+ <symbol id="petals">
9
+ <ellipse cx="200" cy="120" rx="25" ry="80" /><ellipse cx="200" cy="280" rx="25" ry="80" /><ellipse cx="280" cy="200" rx="80" ry="25" /><ellipse cx="120" cy="200" rx="80" ry="25" />
10
+ </symbol>
11
+ <symbol id="corolla">
12
+ <use xlink:href="#petals" />
13
+ <use xlink:href="#petals" transform="rotate(22.5 200 200)" />
14
+ <use xlink:href="#petals" transform="rotate(45 200 200)" />
15
+ <use xlink:href="#petals" transform="rotate(-22.5 200 200)" />
16
+ </symbol>
17
+ </defs>
18
+ <use xlink:href="#corolla" fill="#1BDE81" stroke="#218764" stroke-width="10"/>
19
+ <use xlink:href="#corolla" fill="#76FABB" stroke="#1BDE81" stroke-width="18" transform="scale(0.80 0.80) translate(50 50)" />
20
+ <use xlink:href="#corolla" fill="#218764" stroke="#76FABB" stroke-width="15" transform="scale(0.40 0.40) translate(300 300)" />
21
+ </svg>
@@ -0,0 +1,20 @@
1
+ ---
2
+ title: Documentation
3
+ layout: page
4
+ permalink: /docs/
5
+ ---
6
+
7
+ <div class="row">
8
+ {% for section in site.data.docs %}
9
+ <div class="col">
10
+ <div class="menu">
11
+ <h2 class="menu-label"><a href="{{ section.permalink }}">{{ section.title }}</a></h2>
12
+ <ul class="menu-list">
13
+ {% for doc_page in section.pages %}
14
+ <li><a href="{{ doc_page.permalink }}">{{ doc_page.title }}</a></li>
15
+ {% endfor %}
16
+ </ul>
17
+ </div>
18
+ </div>
19
+ {% endfor %}
20
+ </div>
@@ -0,0 +1,12 @@
1
+ ---
2
+ title: Examples
3
+ layout: page
4
+ permalink: /examples/
5
+ ---
6
+
7
+ {% for example in site.data.examples %}
8
+ <div class="card">
9
+ <h2><a href="{{ example.permalink }}">{{ example.title }}</a></h2>
10
+ <p>{{ example.description }}</p>
11
+ </div>
12
+ {% endfor %}
@@ -0,0 +1,32 @@
1
+ ---
2
+ layout: default
3
+ title: Examples
4
+ layout: page
5
+ permalink: /examples/any-gradient
6
+ ---
7
+
8
+ # Examples
9
+
10
+ The best way to get started quickly is to install the gem and run the examples locally.
11
+
12
+ ## Any Gradient
13
+
14
+ Requires Roda and Rack to be available.
15
+
16
+ ```
17
+ gem install roda
18
+ ```
19
+
20
+ Demonstrates how to use Calyx to construct SVG graphics. **Any Gradient** generates a rectangle with a linear gradient of random colours.
21
+
22
+ Run as a web server and preview the output in a browser (`http://localhost:9292`):
23
+
24
+ ```
25
+ ruby examples/any_gradient.rb
26
+ ```
27
+
28
+ Or generate SVG files via a command line pipe:
29
+
30
+ ```
31
+ ruby examples/any_gradient > gradient1.xml
32
+ ```
@@ -0,0 +1,16 @@
1
+ ---
2
+ layout: default
3
+ title: Examples
4
+ layout: page
5
+ permalink: /examples/faker
6
+ ---
7
+
8
+ ## Faker
9
+
10
+ [Faker](https://github.com/stympy/faker) is a popular library for generating fake names and associated sample data like internet addresses, company names and locations.
11
+
12
+ This example demonstrates how to use Calyx to reproduce the same functionality using custom lists defined in a YAML configuration file.
13
+
14
+ ```
15
+ ruby examples/faker.rb
16
+ ```
@@ -0,0 +1,24 @@
1
+ ---
2
+ layout: default
3
+ title: Examples
4
+ layout: page
5
+ permalink: /examples/tiny-woodland-bot
6
+ ---
7
+
8
+ ## Tiny Woodland Bot
9
+
10
+ Requires the Twitter client gem and API access configured for a specific Twitter handle.
11
+
12
+ ```
13
+ gem install twitter
14
+ ```
15
+
16
+ Demonstrates how to use Calyx to make a minimal Twitter bot that periodically posts unique tweets. See [@tiny_woodland on Twitter](https://twitter.com/tiny_woodland) and the [writeup here](http://maetl.net/notes/storyboard/tiny-woodlands).
17
+
18
+ ```
19
+ TWITTER_CONSUMER_KEY=XXX-XXX
20
+ TWITTER_CONSUMER_SECRET=XXX-XXX
21
+ TWITTER_ACCESS_TOKEN=XXX-XXX
22
+ TWITTER_CONSUMER_SECRET=XXX-XXX
23
+ ruby examples/tiny_woodland_bot.rb
24
+ ```
@@ -1,7 +1,7 @@
1
1
  ---
2
- layout: default
2
+ layout: page
3
3
  title: Context
4
- permalink: /context/
4
+ permalink: /guides/context
5
5
  ---
6
6
 
7
7
  j,jnnnnnnjjj
@@ -1,7 +1,7 @@
1
1
  ---
2
- layout: default
2
+ layout: page
3
3
  title: Template Expressions
4
- permalink: /expressions/
4
+ permalink: /guides/expressions
5
5
  ---
6
6
 
7
7
  # Template Expressions
@@ -0,0 +1,50 @@
1
+ ---
2
+ layout: docs
3
+ title: Features documented in README
4
+ ---
5
+
6
+ ## Template Expressions
7
+
8
+ Basic rule substitution uses single curly brackets as delimiters for template expressions:
9
+
10
+ ```ruby
11
+ fruit = Calyx::Grammar.new do
12
+ start '{colour} {fruit}'
13
+ colour 'red', 'green', 'yellow'
14
+ fruit 'apple', 'pear', 'tomato'
15
+ end
16
+
17
+ 6.times { fruit.generate }
18
+ # => "yellow pear"
19
+ # => "red apple"
20
+ # => "green tomato"
21
+ # => "red pear"
22
+ # => "yellow tomato"
23
+ # => "green apple"
24
+ ```
25
+
26
+ ## The start symbol
27
+
28
+ By convention, the `start` rule specifies the default starting point for generating the final text. You can start from any other named rule by passing it explicitly to the generate method.
29
+
30
+ ```ruby
31
+ class HelloWorld < Calyx::Grammar
32
+ hello 'Hello world!'
33
+ end
34
+
35
+ hello = HelloWorld.new
36
+ hello.generate(:hello)
37
+ ```
38
+
39
+ ## Block Constructors
40
+
41
+ As an alternative to subclassing, you can also construct rules unique to an instance by passing a block when initializing the class:
42
+
43
+ ```ruby
44
+ hello = Calyx::Grammar.new do
45
+ start '{greeting} world.'
46
+ greeting 'Hello', 'Hi', 'Hey', 'Yo'
47
+ end
48
+
49
+ hello.generate
50
+ ```
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  layout: default
3
3
  title: File Formats
4
- permalink: /formats/
4
+ permalink: /guides/formats
5
5
  ---
6
6
 
7
7
  # File Formats
@@ -0,0 +1,51 @@
1
+ ---
2
+ title: Installation
3
+ layout: docs
4
+ permalink: /guides/installation
5
+ ---
6
+
7
+ ## System requirements
8
+
9
+ The following prerequisites are needed to install Calyx:
10
+
11
+ - macOS, Windows, GNU/Linux or Unix
12
+ - Ruby 2.3 or above (MRI 2.3+, JRuby 9+, Rubinius 3+)
13
+ - RubyGems
14
+
15
+ Calyx has no external Gem dependencies.
16
+
17
+ ## For command line use
18
+
19
+ Install the Calyx gem using the [RubyGems](https://rubygems.org) package manager:
20
+
21
+ ```
22
+ gem install calyx
23
+ ```
24
+
25
+ ## For applications
26
+
27
+ Add the `calyx` dependency to your app’s `Gemfile`:
28
+
29
+ ```ruby
30
+ gem 'calyx'
31
+ ```
32
+
33
+ Run [Bundler](https://bundler.io/) to install it:
34
+
35
+ ```
36
+ bundle install
37
+ ```
38
+
39
+ ## For local development
40
+
41
+ To contribute code back to Calyx or fork it in a new direction, clone the repo from GitHub:
42
+
43
+ ```
44
+ git clone git@github.com:maetl/calyx
45
+ ```
46
+
47
+ You can also download the latest build of the project as a ZIP archive:
48
+
49
+ ```
50
+ wget https://github.com/maetl/calyx/archive/master.zip
51
+ ```
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  layout: default
3
3
  title: Random Sampling
4
- permalink: /random/
4
+ permalink: /guides/random/
5
5
  ---
6
6
 
7
7
  # Random Sampling
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  layout: default
3
3
  title: Results
4
- permalink: /results/
4
+ permalink: /guides/results/
5
5
  ---
6
6
 
7
7
  # Generating Results
@@ -0,0 +1,44 @@
1
+ ---
2
+ title: Calyx
3
+ layout: home
4
+ permanlink: /
5
+ ---
6
+
7
+ {% include navbar.html %}
8
+
9
+ <div class="spread spread-hero">
10
+ <figure class="identity">
11
+ <img src="/assets/logos/calyx-flower-2.svg" width="80%" height="80%">
12
+ </figure>
13
+ <div class="lede">
14
+ <h2>Create writing machines with generative grammars</h2>
15
+
16
+ <ul class="cta-list">
17
+ <li><a class="cta-button" href="#">Download</a></li>
18
+ <li><a class="cta-button" href="#">Learn more</a></li>
19
+ </ul>
20
+ </div>
21
+ </div>
22
+
23
+ <div class="spread spread-intro">
24
+ <p>Calyx is a simple and powerful tool for creating writing machines using the Ruby programming language.</p>
25
+ </div>
26
+
27
+ <div class="content">
28
+ <h1>Calyx</h1>
29
+ <p>Calyx provides a simple and powerful generative grammar format for creating writing machines using the Ruby programming language.</p>
30
+ <p>Although the primary use case is procedurally generating text, Calyx grammars can be used to make anything where the output format is a string.</p>
31
+ <p>Calyx provides a simple Ruby API for creating writing machines of all shapes and sizes using generative grammars.</p>
32
+ <ul>
33
+ <li><a href="https://github.com/maetl/calyx">Source code on GitHub</a></li>
34
+ <li><a href="https://rubygems.org/gems/calyx">Package on Rubygems</a></li>
35
+ </ul>
36
+ </div>
37
+
38
+ <div class="features">
39
+ <p>An intuitive syntax for constructing text generators in native Ruby or JSON.</p>
40
+
41
+ <p>Randomly select desired output from multiple choices.</p>
42
+
43
+ <p>Use weighted probabilities to shape the odds of choices occurring.</p>
44
+ </div>
@@ -0,0 +1,23 @@
1
+ ---
2
+ layout: docs
3
+ title: Introduction
4
+ permalink: /introduction/
5
+ ---
6
+
7
+ ## What is Calyx?
8
+
9
+ Calyx is a simple and powerful software library for creating writing machines using the Ruby programming language. It provides tools for producing randomized sequences of text using a syntax inspired by generative grammars.
10
+
11
+ Its primary affordances are for creating bots and weird combinatorial prose and poetry but you can use it to generate anything that has a textual or tree-based representation, including SVG graphics, narrative graphs and fake data schemas.
12
+
13
+ ## Why grammars?
14
+
15
+ There are many useful and interesting methods for generative writing. The grammar-based approach is popular, widely studied and practiced, and easy to get started with.
16
+
17
+ Grammars offer direct authorial control over the fragments that combine to produce an output text. This involves more effort and structure than other more random approaches, but leads to carefully crafted and expressive results which still have a capacity to surprise, delight, and confound—as any good text generation method should.
18
+
19
+ ## Getting Started
20
+
21
+ Get started with a [simple tutorial](/introduction/tutorial/) or learn more about the [underlying concepts](/introduction/concepts/). If you’re new to Ruby and generative art in general, the [documentation for beginners](/introduction/beginners/) is a good place to start.
22
+
23
+ Use the [guides](/docs/guides/) to learn how to use the various features and capabilities of the library. For more direct and structured information, the [reference](/docs/reference/) contains a full breakdown of everything that Calyx supports.
@@ -0,0 +1,82 @@
1
+ ---
2
+ title: Key Concepts
3
+ layout: docs
4
+ permalink: /introduction/concepts/
5
+ ---
6
+
7
+ ## What are grammars?
8
+
9
+ A grammar is a set of interconnected rules that describe the syntax of a language. The grammar rules describe how to form strings in that language based on an alphabet.
10
+
11
+ ## A dash of theory
12
+
13
+ Traditionally, generative grammars are often described as recognizers. Given a particular string as input, the grammar defines whether or not that string is recognized.
14
+
15
+ For example, let’s imagine what a pseudocode grammar representing whole numbers greater than zero might look like.
16
+
17
+ ```
18
+ start := leading_digit *digit
19
+ leading_digit := 1..9
20
+ digit := 0..9
21
+ ```
22
+
23
+ If we could turn this pseudocode grammar into a recognizer function and run it on a range of possible strings, we’d see the following results.
24
+
25
+ ```ruby
26
+ grammar.parse("1") # => true
27
+ grammar.parse("2") # => true
28
+ grammar.parse("99") # => true
29
+ grammar.parse("111") # => true
30
+ grammar.parse("134534") # => true
31
+ grammar.parse("0") # => false
32
+ grammar.parse("055") # => false
33
+ grammar.parse("abc") # => false
34
+ grammar.parse("1.5") # => false
35
+ ```
36
+
37
+ How does it work?
38
+
39
+ The grammar here is made up of ‘production rules’, which in turn are made up of named symbols called ‘nonterminals’ and literal patterns called ‘terminals’ which match a range of possible strings.
40
+
41
+ In this case, `start`, `leading_digit` and `digit` are nonterminals whereas `1..9` and `0..9` are terminals. By convention, `*` means ‘zero or more’, which specifies that the production can match repeating characters over and over until an unmatched character is found (formally, this is known as the [Kleene star](https://en.wikipedia.org/wiki/Kleene_star)).
42
+
43
+ To recognize a string with the grammar, we start with a left hand side nonterminal (by convention, this is known as the start symbol, often named `start`) and substitute it with its right hand side production. We then do the same for the next set of nonterminals we find in the production, until we bottom out at a set of terminals matching the literal string.
44
+
45
+ If we walk through
46
+
47
+ ```
48
+ grammar.parse("1")
49
+ ```
50
+
51
+ 1. Replace `start` with `leading_digit` then `*digit`
52
+ 2. `leading_digit` is a terminal `1..9`, so check that the first character matches
53
+ 3. `*digit`
54
+
55
+
56
+
57
+ If you’re familiar with regular expressions, you’ll notice that this grammar seems to do exactly the same thing as the following regular expression.
58
+
59
+ ```ruby
60
+ /^[1-9][0-9]*$/
61
+ ```
62
+
63
+ Remarkably, this isn’t a coincidence or example of TMTOWTDI. It turns out that there’s a deep symmetry between grammars and regular expressions. Every regular grammar can be transformed into an equivalent regular expression and vice versa.
64
+
65
+ ```
66
+ Number := Zero | Integer | Decimal | Real
67
+ Integer := LeadingDigit *Digit
68
+ LeadingDigit := [1-9]
69
+ Digit := [0-9]
70
+ Decimal := Integer "." *Digit
71
+ Real := Integer "/" Integer
72
+ Zero := "0"
73
+ ```
74
+
75
+ The following sequences are recognised as valid by the number grammar:
76
+
77
+ - `1`
78
+ - `23.424`
79
+ - `30000`
80
+ - `1/7`
81
+
82
+ Template expansion grammars