sequitur 0.0.13 → 0.0.14
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 +8 -8
- data/CHANGELOG.md +8 -4
- data/lib/sequitur/constants.rb +1 -1
- data/lib/sequitur/sequitur_grammar.rb +0 -114
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTMxYzgwZmZkMzg1YTYzMjEzZTA4Yzg0NWY2YTdkZjk2ODI2ZDVhYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTgxM2M1MjY2MzNkYmE0NjhhNzBkOTIwNDdmOGM0OWYwMjNkOGMwZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmI0YzAyNTRhYmRmODc5MTgwZmYyYWNmMzExMmRhM2FjNWI0OGQyOTYxZmRk
|
10
|
+
N2FkOTc2ZDU1Mzg3NjllN2M1ZmQyMDM2YWJjNGIzY2IwN2JjYzhiZjg2MGQ1
|
11
|
+
ZjcxYmQxYzAwYmFlOTc2MTRmMmU4YzJmMDk5ZDU5OTZkZWFlYjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDU3NDUxZjA1NDg0Njg5MzYzMmM0MDRiMDIzOGY2ZTlmMDIwYWNlMjJjYTNm
|
14
|
+
ZjA0YTdhMjc0MTg3MTFkNjBmMWVlZTQzY2FlMDVmNjg5ODFmODMwNDMxY2U5
|
15
|
+
OGI3ZGI4ZDFjZDFhMzFjMTFjZTg5MWYzMzc3Y2QwZWIyNmFiZDU=
|
data/CHANGELOG.md
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
-
### 0.0.
|
1
|
+
### 0.0.14 / 2014-09-10
|
2
|
+
* [CHANGE] Removal of invariant checking methods in `SequiturGrammar` class. These caused polynomial slowdown.
|
3
|
+
|
4
|
+
|
5
|
+
### 0.0.13 / 2014-09-07
|
2
6
|
* [CHANGE] Test coverage for all classes but SequiturGrammar is 100%
|
3
7
|
|
4
|
-
### 0.0.12 / 2014-
|
8
|
+
### 0.0.12 / 2014-09-06
|
5
9
|
* [CHANGE] Significant internal refactoring.
|
6
10
|
* [CHANGE] Method `ObjectSpace::id2ref` is no more used => one obstacle to JRuby porting is removed.
|
7
11
|
* [NEW] Added new class `ProductionReference`
|
8
12
|
|
9
|
-
### 0.0.11 / 2014-08-
|
13
|
+
### 0.0.11 / 2014-08-26
|
10
14
|
* [FIX] `SequiturGrammar#check_unicity`: an exception was raised when it shouldn't. Added example in spec file.
|
11
15
|
* [CHANGE] `sequitur.rb` : Added the convenience Sequitur::build_from method.
|
12
16
|
|
13
|
-
### 0.0.10 / 2014-08-
|
17
|
+
### 0.0.10 / 2014-08-25
|
14
18
|
* [CHANGE] `README.md`: Added hyperlinks about Sequitur algorithm.
|
15
19
|
|
16
20
|
### 0.0.09 / 2014-08-24
|
data/lib/sequitur/constants.rb
CHANGED
@@ -28,28 +28,6 @@ class SequiturGrammar < DynamicGrammar
|
|
28
28
|
super
|
29
29
|
end
|
30
30
|
|
31
|
-
# Check the invariant:
|
32
|
-
# Every digram appearing in a rhs must occur at most once in the grammar.
|
33
|
-
def check_unicity()
|
34
|
-
all_digrams = {}
|
35
|
-
productions.each do |a_prod|
|
36
|
-
prod_digrams = a_prod.digrams
|
37
|
-
prod_digrams.each_with_index do |a_digram, index|
|
38
|
-
next if index && a_digram == a_prod.digrams[index - 1]
|
39
|
-
if all_digrams.include? a_digram.key
|
40
|
-
msg = "Digram #{a_digram.symbols} occurs twice!"
|
41
|
-
colliding = all_digrams[a_digram.key]
|
42
|
-
msg << "\nOnce in production #{colliding.production.object_id}"
|
43
|
-
msg << "\nSecond in production #{a_prod.object_id}"
|
44
|
-
msg << "\n#{to_string}"
|
45
|
-
fail StandardError, msg unless colliding == a_prod
|
46
|
-
else
|
47
|
-
all_digrams[a_digram.key] = a_digram
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
31
|
|
54
32
|
private
|
55
33
|
|
@@ -77,7 +55,6 @@ class SequiturGrammar < DynamicGrammar
|
|
77
55
|
end
|
78
56
|
|
79
57
|
def append_symbol_to(aProduction, aSymbol)
|
80
|
-
check_digrams # TODO: remove this
|
81
58
|
super
|
82
59
|
|
83
60
|
prod_digrams = aProduction.digrams
|
@@ -131,8 +108,6 @@ class SequiturGrammar < DynamicGrammar
|
|
131
108
|
aProduction.replace_digram(new_prod)
|
132
109
|
add_production(new_prod)
|
133
110
|
update_digrams_from(aProduction)
|
134
|
-
check_digrams # TODO: remove
|
135
|
-
check_unicity
|
136
111
|
else
|
137
112
|
# Duplicate digram used in distinct production
|
138
113
|
# Two cases: other production is a single digram one or a multi-digram
|
@@ -151,7 +126,6 @@ class SequiturGrammar < DynamicGrammar
|
|
151
126
|
preserve_unicity(aProduction)
|
152
127
|
end
|
153
128
|
|
154
|
-
check_references # TODO: remove this
|
155
129
|
else
|
156
130
|
# aProduction, other_prod use both the same digram
|
157
131
|
# Then create a new production with the digram as its rhs
|
@@ -168,11 +142,7 @@ class SequiturGrammar < DynamicGrammar
|
|
168
142
|
# TODO: Check when aProduction and other_prod have same preceding symbol
|
169
143
|
update_digrams_from(other_prod)
|
170
144
|
end
|
171
|
-
check_unicity
|
172
145
|
end
|
173
|
-
|
174
|
-
check_unicity
|
175
|
-
check_registered
|
176
146
|
end
|
177
147
|
|
178
148
|
# Rule utility: except for the root production, every production must occur
|
@@ -188,7 +158,6 @@ class SequiturGrammar < DynamicGrammar
|
|
188
158
|
# Update digrams
|
189
159
|
def enforce_rule_utility()
|
190
160
|
return if productions.size < 2
|
191
|
-
check_references
|
192
161
|
|
193
162
|
loop do
|
194
163
|
all_refcount_ok = true
|
@@ -203,7 +172,6 @@ class SequiturGrammar < DynamicGrammar
|
|
203
172
|
dependent.replace_production(productions[index])
|
204
173
|
delete_production(index)
|
205
174
|
update_digrams_from(dependent)
|
206
|
-
check_references
|
207
175
|
end
|
208
176
|
|
209
177
|
break if all_refcount_ok
|
@@ -232,88 +200,6 @@ class SequiturGrammar < DynamicGrammar
|
|
232
200
|
end
|
233
201
|
end
|
234
202
|
|
235
|
-
# Check the invariant:
|
236
|
-
# Every reference in a rhs that is bound must point
|
237
|
-
# to a production of the grammar.
|
238
|
-
def check_references()
|
239
|
-
productions.each do |a_prod|
|
240
|
-
rhs_prods = a_prod.references
|
241
|
-
rhs_prods.each do |a_reference|
|
242
|
-
next if a_reference.unbound?
|
243
|
-
referenced_prod = a_reference.production
|
244
|
-
next if productions.include? referenced_prod
|
245
|
-
|
246
|
-
msg = "Production #{a_prod.object_id} #{a_prod.to_string}"
|
247
|
-
msg << " references the unknown production #{referenced_prod.object_id}"
|
248
|
-
msg << "\nOrphan production: #{referenced_prod.to_string}"
|
249
|
-
msg << "\n#{to_string}"
|
250
|
-
fail StandardError, msg
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
# Check the invariant:
|
256
|
-
# Every registered digram must reference a production from the grammar
|
257
|
-
def check_registered()
|
258
|
-
digrams.each do |_key, digr|
|
259
|
-
found = productions.find { |a_prod| digr.production == a_prod }
|
260
|
-
next if found
|
261
|
-
|
262
|
-
msg = "Digram #{digr.symbols} references the unknown "
|
263
|
-
msg << "production (#{digr.production.object_id})."
|
264
|
-
msg << "\n#{to_string}"
|
265
|
-
fail StandardError, msg
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
# Compare the contents of digrams Hash with
|
270
|
-
# All digrams from all productions
|
271
|
-
def check_digrams()
|
272
|
-
# Control that every registered digram refers
|
273
|
-
# to a production that really has that digram
|
274
|
-
digrams.each do |key, digr|
|
275
|
-
its_prod = digr.production
|
276
|
-
prod_digrams = its_prod.digrams
|
277
|
-
prod_keys = prod_digrams.map(&:key)
|
278
|
-
next if prod_keys.include? key
|
279
|
-
|
280
|
-
msg = "Production #{digr.production_id} doesn't have "
|
281
|
-
msg << "the digram #{digr.symbols}"
|
282
|
-
msg << "\n#{prod_digrams.map(&:symbols)}"
|
283
|
-
msg << "\n#{to_string}"
|
284
|
-
fail StandardError, msg
|
285
|
-
end
|
286
|
-
|
287
|
-
all_digrams = {}
|
288
|
-
productions.each do |a_prod|
|
289
|
-
its_digrams = a_prod.digrams
|
290
|
-
its_digrams.each do |digr|
|
291
|
-
check_unicity if all_digrams[digr.key]
|
292
|
-
all_digrams[digr.key] = digr
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
all_digrams.each do |key, digr|
|
297
|
-
registered = digrams[key]
|
298
|
-
if registered
|
299
|
-
if registered != digr
|
300
|
-
msg = "Production #{digr.production.object_id} has "
|
301
|
-
msg << "the digram #{digr.symbols} that collides"
|
302
|
-
msg << "\n with same digram from #{registered.production.object_id}"
|
303
|
-
msg << "\n#{to_string}"
|
304
|
-
fail StandardError, msg
|
305
|
-
end
|
306
|
-
else
|
307
|
-
its_prod = digr.production
|
308
|
-
msg = "Production #{its_prod.object_id} (#{its_prod.rhs}) "
|
309
|
-
msg << "has the digram #{digr.symbols} that isn't registered."
|
310
|
-
msg << "\n#{to_string}"
|
311
|
-
fail StandardError, msg
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
|
317
203
|
end # class
|
318
204
|
|
319
205
|
end # module
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequitur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|