calyx 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 719581f0b1a1255f386ed91d64b2d956b1e7820c
4
- data.tar.gz: 173aaada6063be3dad4c1eaa707390608a5b952e
3
+ metadata.gz: 833328ded64a82edb7997b924f740a458d179215
4
+ data.tar.gz: bfca7e43959b79427ecfed6116344bd82aa79e95
5
5
  SHA512:
6
- metadata.gz: c1510e5ba1db72a661965766c78cb5e6a79e04be682997c2e1f4ddf5c85623c9eb5785bc273a492feed090704e84cc78dc791a4ccdbadec9ac2e436b1849009a
7
- data.tar.gz: b835c0ddee655a64bdad32f8487aa1563812a355c916713e8e9476a0a021f0cf689639a0a986591e3777a8b81a40ca55173140f3bc3e800f04516cc7b4ad6c0b
6
+ metadata.gz: 79b97a8dbb5ded857a14f61f687ff2e93ba6c65f75b2f9acbab74c5b34803d2bfd6f5c2b26eeda52640037ba60d56926d849dd0de2d7a1db84ecde9ffbe37c0c
7
+ data.tar.gz: 7f846571bdefe5c2e922e00218d7f64b79c343344cce9e0395dfe1f7ced7d8cf79ddd71c9be1d061d95d07de09c35ae8ce73954fbcdda000433b358eac6bec15
data/README.md CHANGED
@@ -1,3 +1,97 @@
1
1
  # Calyx
2
2
 
3
3
  Calyx provides a simple API for generating text with declarative recursive grammars.
4
+
5
+ ## Install
6
+
7
+ ### Command Line
8
+
9
+ ```
10
+ gem install calyx
11
+ ```
12
+
13
+ ## Gemfile
14
+
15
+ ```
16
+ gem 'calyx'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Require the library and inherit from `Calyx::Grammar` to construct a set of rules to generate a text. All grammars require a `start` rule, which specifies the starting point for generating the text structure.
22
+
23
+ ```ruby
24
+ require 'calyx'
25
+
26
+ class HelloWorld < Calyx::Grammar
27
+ start 'Hello world.'
28
+ end
29
+ ```
30
+
31
+ To generate the text itself, initialize the object and call the `generate` method.
32
+
33
+ ```ruby
34
+ hello = HelloWorld.new
35
+ hello.generate
36
+ # > "Hello world."
37
+ ```
38
+
39
+ Obviously, this hardcoded sentence isn’t very interesting by itself. Possible variations can be added to the text using the `rule` constructor to provide a named set of text strings and the rule delimiter syntax (`{}`) within the text strings to substitute the generated content of the rule.
40
+
41
+ ```ruby
42
+ class HelloWorld < Calyx::Grammar
43
+ start '{greeting} world.'
44
+ rule :greeting, 'Hello', 'Hi', 'Hey', 'Yo'
45
+ end
46
+
47
+ hello = HelloWorld.new
48
+
49
+ hello.generate
50
+ # > "Hi world."
51
+
52
+ hello.generate
53
+ # > "Hello world."
54
+
55
+ hello.generate
56
+ # > "Yo world."
57
+ ```
58
+
59
+ Rules are recursive. They can be arbitrarily nested and connected to generate larger and more complex texts.
60
+
61
+ ```ruby
62
+ class HelloWorld < Calyx::Grammar
63
+ start '{greeting} {world_phrase}.'
64
+ rule :greeting, 'Hello', 'Hi', 'Hey', 'Yo'
65
+ rule :world_phrase, '{happy_adj} world', '{sad_adj} world', 'world'
66
+ rule :happy_adj, 'wonderful', 'amazing', 'bright', 'beautiful'
67
+ rule :sad_adj, 'cruel', 'miserable'
68
+ end
69
+ ```
70
+
71
+ Nesting and hierarchy can be manipulated to balance consistency with variation. The exact same word atoms can be combined in different ways to produce strikingly different resulting texts.
72
+
73
+ ```ruby
74
+ module HelloWorld
75
+ Sentiment < Calyx::Grammar
76
+ start '{happy_phrase}', '{sad_phrase}'
77
+ rule :happy_phrase, '{happy_greeting} {happy_adj} world.'
78
+ rule :happy_greeting, 'Hello', 'Hi', 'Hey', 'Yo'
79
+ rule :happy_adj, 'wonderful', 'amazing', 'bright', 'beautiful'
80
+ rule :sad_phrase, '{sad_greeting} {sad_adj} world.'
81
+ rule :sad_greeting, 'Goodbye', 'So long', 'Farewell'
82
+ rule :sad_adj, 'cruel', 'miserable'
83
+ end
84
+
85
+ Mixed < Calyx::Grammar
86
+ start '{greeting} {adj} world.'
87
+ rule :greeting, 'Hello', 'Hi', 'Hey', 'Yo', 'Goodbye', 'So long', 'Farewell'
88
+ rule :adj, 'wonderful', 'amazing', 'bright', 'beautiful', 'cruel', 'miserable'
89
+ end
90
+ end
91
+ ```
92
+
93
+ ## License
94
+
95
+ Calyx is open source and provided under the terms of the MIT license. Copyright (c) 2015 Mark Rickerby
96
+
97
+ See the `LICENSE` file [included with the project distribution](https://github.com/maetl/calyx/blob/master/LICENSE) for more information.
data/lib/calyx.rb CHANGED
@@ -104,7 +104,10 @@ module Calyx
104
104
  end
105
105
 
106
106
  def evaluate(registry)
107
- choice = @collection.max_by { |_, weight| rand ** (1.0 / weight) }.first
107
+ choice = @collection.max_by do |_, weight|
108
+ rand ** (1.0 / weight)
109
+ end.first
110
+
108
111
  choice.evaluate(registry)
109
112
  end
110
113
  end
data/lib/calyx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Calyx
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.4.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calyx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-14 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler