kotodama 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/wordgen +2 -1
- data/lib/kotodama.rb +1 -1
- data/lib/kotodama_grammar.rb +4 -0
- metadata +4 -6
- data/lib/kotodama_grammar.rb~ +0 -181
- data/lib/language.rb~ +0 -41
data/bin/wordgen
CHANGED
@@ -67,7 +67,8 @@ if File.exist? ARGV[0]
|
|
67
67
|
output_file.puts output
|
68
68
|
output_file.close if output_file != STDOUT
|
69
69
|
else
|
70
|
-
STDERR.puts result.error
|
70
|
+
STDERR.puts result.backtrace :error
|
71
|
+
STDERR.puts result.backtrace
|
71
72
|
end
|
72
73
|
else
|
73
74
|
STDERR.puts "File `#{ARGV[0]}' does not exist"
|
data/lib/kotodama.rb
CHANGED
data/lib/kotodama_grammar.rb
CHANGED
@@ -18,6 +18,7 @@ module Kotodama
|
|
18
18
|
action do
|
19
19
|
@language.options[@key] = @value
|
20
20
|
end
|
21
|
+
tag_error :error
|
21
22
|
end
|
22
23
|
|
23
24
|
rule :content_block do
|
@@ -42,6 +43,7 @@ module Kotodama
|
|
42
43
|
action do
|
43
44
|
@symbols.each {|n| @type.add n, @weight }
|
44
45
|
end
|
46
|
+
tag_error :error
|
45
47
|
end
|
46
48
|
|
47
49
|
rule :rule_block do
|
@@ -59,12 +61,14 @@ module Kotodama
|
|
59
61
|
rule :exclude_expression do
|
60
62
|
parses 'exclude'.skip & :ID.one_or_more & ';'.skip
|
61
63
|
action { @rule.excludes << @result.join }
|
64
|
+
tag_error :error
|
62
65
|
end
|
63
66
|
|
64
67
|
rule :rule_expression do
|
65
68
|
parses :ATOM.one_or_more & :WEIGHT.optional & ';'.skip
|
66
69
|
node [:expression, :weight]
|
67
70
|
action { @rule.add @expression, @weight }
|
71
|
+
tag_error :error
|
68
72
|
end
|
69
73
|
|
70
74
|
rule :change_block do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: kotodama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.2.
|
5
|
+
version: 1.2.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- William Hamilton-Levi
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-03-01 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -19,9 +19,9 @@ dependencies:
|
|
19
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
|
-
- -
|
22
|
+
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 1.
|
24
|
+
version: 1.3.0
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
description: A programable word generator
|
@@ -38,9 +38,7 @@ files:
|
|
38
38
|
- lib/change.rb
|
39
39
|
- lib/rule.rb
|
40
40
|
- lib/mod_array.rb
|
41
|
-
- lib/kotodama_grammar.rb~
|
42
41
|
- lib/language.rb
|
43
|
-
- lib/language.rb~
|
44
42
|
- lib/kotodama.rb
|
45
43
|
- lib/kotodama_grammar.rb
|
46
44
|
- README
|
data/lib/kotodama_grammar.rb~
DELETED
@@ -1,181 +0,0 @@
|
|
1
|
-
module Kotodama
|
2
|
-
GRAMMAR = Kaiseki::Grammar.new do
|
3
|
-
starting :document
|
4
|
-
skipping :WS | :COMMENT
|
5
|
-
|
6
|
-
rule :document do
|
7
|
-
parses proc { @language = Language.new } & :options_block.optional & :content_block.zero_or_more & :EOF.skip
|
8
|
-
filter { @language }
|
9
|
-
end
|
10
|
-
|
11
|
-
rule :options_block do
|
12
|
-
parses 'options'.skip & '{'.skip & :option.zero_or_more & '}'.skip
|
13
|
-
end
|
14
|
-
|
15
|
-
rule :option do
|
16
|
-
parses :LITERAL & '=>'.skip & (:ATOM | :INT) & ';'.skip
|
17
|
-
node [:key, :value]
|
18
|
-
action do
|
19
|
-
@language.options[@key] = @value
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
rule :content_block do
|
24
|
-
parses :type_block | :rule_block | :change_block | :spelling_rule | :zipf_block
|
25
|
-
end
|
26
|
-
|
27
|
-
rule :type_block do
|
28
|
-
parses 'type'.skip & :ATOM.set(:id) & :get_type & '{'.skip & :symbol_declaration.zero_or_more & '}'.skip
|
29
|
-
end
|
30
|
-
|
31
|
-
action :get_type do
|
32
|
-
if @language.types.key? @id
|
33
|
-
@type = @language.types[@id]
|
34
|
-
else
|
35
|
-
@type = @language.types[@id] = Type.new(@language)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
rule :symbol_declaration do
|
40
|
-
parses :LIST & :WEIGHT.optional & ';'.skip
|
41
|
-
node [:symbols, :weight]
|
42
|
-
action do
|
43
|
-
@symbols.each {|n| @type.add n, @weight }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
rule :rule_block do
|
48
|
-
parses 'rule'.skip & :ATOM.set(:id) & :get_rule & '{'.skip & (:exclude_expression | :rule_expression).zero_or_more & '}'.skip
|
49
|
-
end
|
50
|
-
|
51
|
-
action :get_rule do
|
52
|
-
if @language.rules.key? @id
|
53
|
-
@rule = @language.rules[@id]
|
54
|
-
else
|
55
|
-
@rule = @language.rules[@id] = Rule.new(@language)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
rule :exclude_expression do
|
60
|
-
parses 'exclude'.skip & :ID.one_or_more & ';'.skip
|
61
|
-
action { @rule.excludes << @result.join }
|
62
|
-
end
|
63
|
-
|
64
|
-
rule :rule_expression do
|
65
|
-
parses :ATOM.one_or_more & :WEIGHT.optional & ';'.skip
|
66
|
-
node [:expression, :weight]
|
67
|
-
action { @rule.add @expression, @weight }
|
68
|
-
end
|
69
|
-
|
70
|
-
rule :change_block do
|
71
|
-
parses 'change'.skip & :ATOM.set(:id) & :get_change & '{'.skip & (:ATOM.set(:id).action { @change.add [:load, @id, nil] } | :sound_change).zero_or_more & '}'.skip
|
72
|
-
end
|
73
|
-
|
74
|
-
action :get_change do
|
75
|
-
if @language.changes.key? @id
|
76
|
-
@change = @language.changes[@id]
|
77
|
-
else
|
78
|
-
@change = @language.changes[@id] = Change.new(@language)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
rule :sound_change do
|
83
|
-
parses (:insert_change | :delete_change | :convert_change) & :change_env.optional & ';'.skip
|
84
|
-
node [:type, :env]
|
85
|
-
action do
|
86
|
-
@type[2] = @env
|
87
|
-
@change.add @type
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
rule :insert_change do
|
92
|
-
parses 'insert'.skip & :ATOM.one_or_more
|
93
|
-
filter { [:insert, (@result.is_a?(Array) ? @result : [@result]), nil] }
|
94
|
-
end
|
95
|
-
|
96
|
-
rule :delete_change do
|
97
|
-
parses 'delete'.skip & :ATOM.one_or_more
|
98
|
-
filter { [:delete, (@result.is_a?(Array) ? @result : [@result]), nil] }
|
99
|
-
end
|
100
|
-
|
101
|
-
rule :convert_change do
|
102
|
-
parses :ATOM.one_or_more & '>'.skip & :ATOM.one_or_more
|
103
|
-
node [:from, :to]
|
104
|
-
filter { [:convert, [@from, @to], nil] }
|
105
|
-
end
|
106
|
-
|
107
|
-
rule :change_env do
|
108
|
-
parses '/'.skip & '#'.optional & :ATOM.zero_or_more & '_'.skip & :ATOM.zero_or_more & '#'.optional
|
109
|
-
end
|
110
|
-
|
111
|
-
rule :spelling_rule do
|
112
|
-
parses 'spell'.skip & :ID & 'as'.skip & :LITERAL & ';'.skip
|
113
|
-
node [:symbol, :spelling]
|
114
|
-
action do
|
115
|
-
@language.spellings[@symbol] = @spelling[1..-1]
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
rule :zipf_block do
|
120
|
-
parses 'zipf'.skip & :FLOAT.set(:float) & '{'.skip & (:LIST & ';'.skip).one_or_more.set(:lists) & '}'.skip
|
121
|
-
action do
|
122
|
-
zipf_list = []
|
123
|
-
@lists.each {|list1| list1.each {|n| zipf_list << n } }
|
124
|
-
zipf_list.length.times do |i|
|
125
|
-
value = 1.0 / (i + 1) ** @float
|
126
|
-
value = (value * 100).to_i
|
127
|
-
@language.zipf[zipf_list[i]] = value
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
rule :ID do
|
133
|
-
parses /[a-zA-Z][0-9]?/
|
134
|
-
filter do
|
135
|
-
if @result.length == 1
|
136
|
-
@result + '0'
|
137
|
-
else
|
138
|
-
@result
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
rule :LIST do
|
144
|
-
parses (:ID & (','.skip & :ID).zero_or_more).merge
|
145
|
-
end
|
146
|
-
|
147
|
-
rule :LITERAL do
|
148
|
-
parses /\"([^"]*)\"/ | /\'([^']*)\'/
|
149
|
-
simplify false
|
150
|
-
filter do
|
151
|
-
'$' + @result.captures[0]
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
rule :ATOM do
|
156
|
-
parses :ID | :LITERAL
|
157
|
-
end
|
158
|
-
|
159
|
-
rule :WEIGHT do
|
160
|
-
parses '('.skip & :INT & ')'.skip
|
161
|
-
end
|
162
|
-
|
163
|
-
rule :INT do
|
164
|
-
parses /\d+/
|
165
|
-
cast Integer
|
166
|
-
end
|
167
|
-
|
168
|
-
rule :FLOAT do
|
169
|
-
parses /\d+\.\d+/
|
170
|
-
cast Float
|
171
|
-
end
|
172
|
-
|
173
|
-
rule :WS do
|
174
|
-
parses /\s+/
|
175
|
-
end
|
176
|
-
|
177
|
-
rule :COMMENT do
|
178
|
-
parses /%[^\n]*\n/
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
data/lib/language.rb~
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Kotodama
|
2
|
-
class Language
|
3
|
-
attr_reader :types, :rules, :changes, :spellings, :options, :zipf
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@types = {}
|
7
|
-
@rules = {}
|
8
|
-
@changes = {}
|
9
|
-
@spellings = {}
|
10
|
-
@options = {}
|
11
|
-
@zipf = {}
|
12
|
-
end
|
13
|
-
|
14
|
-
def generate options = {}
|
15
|
-
rule = options[:rule] || @options['$rule']
|
16
|
-
raise "rule `#{rule}' isn't defined" unless @rules.key? rule
|
17
|
-
output = @rules[rule].generate
|
18
|
-
puts output
|
19
|
-
return output.join if options[:generate_only]
|
20
|
-
change = options[:change] || @options['$change']
|
21
|
-
if change
|
22
|
-
raise "change `#{change}' isn't defined" unless @changes.key? change
|
23
|
-
output = @changes[change].apply self, output
|
24
|
-
end
|
25
|
-
return output.join if options[:change_only]
|
26
|
-
string = ''
|
27
|
-
output.each do |n|
|
28
|
-
if @spellings.key? n
|
29
|
-
string << @spellings[n]
|
30
|
-
else
|
31
|
-
if n[0] == '$'
|
32
|
-
string << n[1..-1]
|
33
|
-
else
|
34
|
-
string << n[0]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
string
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|