sequitur 0.1.18 → 0.1.23
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 +5 -5
- data/.rubocop.yml +430 -56
- data/.travis.yml +19 -13
- data/CHANGELOG.md +33 -0
- data/Gemfile +4 -3
- data/LICENSE.txt +1 -1
- data/README.md +1 -2
- data/Rakefile +2 -0
- data/appveyor.yml +20 -12
- data/examples/integer_sample.rb +8 -7
- data/examples/porridge.rb +6 -6
- data/examples/simple_case.rb +7 -6
- data/examples/symbol_sample.rb +8 -9
- data/examples/word_sample.rb +4 -3
- data/lib/sequitur/constants.rb +5 -3
- data/lib/sequitur/digram.rb +45 -43
- data/lib/sequitur/dynamic_grammar.rb +93 -95
- data/lib/sequitur/formatter/base_formatter.rb +3 -1
- data/lib/sequitur/formatter/base_text.rb +3 -1
- data/lib/sequitur/formatter/debug.rb +5 -3
- data/lib/sequitur/grammar_visitor.rb +99 -98
- data/lib/sequitur/production.rb +14 -19
- data/lib/sequitur/production_ref.rb +107 -106
- data/lib/sequitur/sequitur_grammar.rb +9 -6
- data/lib/sequitur/symbol_sequence.rb +10 -11
- data/lib/sequitur.rb +2 -0
- data/spec/sequitur/digram_spec.rb +10 -8
- data/spec/sequitur/dynamic_grammar_spec.rb +2 -0
- data/spec/sequitur/formatter/base_text_spec.rb +4 -2
- data/spec/sequitur/formatter/debug_spec.rb +4 -2
- data/spec/sequitur/grammar_visitor_spec.rb +2 -0
- data/spec/sequitur/production_ref_spec.rb +2 -0
- data/spec/sequitur/production_spec.rb +10 -8
- data/spec/sequitur/sequitur_grammar_spec.rb +13 -13
- data/spec/sequitur/symbol_sequence_spec.rb +6 -4
- data/spec/spec_helper.rb +2 -12
- metadata +18 -46
- data/.ruby-version +0 -1
- data/.simplecov +0 -7
data/.travis.yml
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
language: ruby
|
2
|
+
dist: trusty
|
3
|
+
|
4
|
+
before_install:
|
5
|
+
- gem update --system
|
6
|
+
- gem install bundler
|
7
|
+
|
8
|
+
script:
|
9
|
+
- bundle exec rake
|
10
|
+
|
2
11
|
rvm:
|
12
|
+
- 2.6.3
|
13
|
+
- 2.5.5
|
14
|
+
- 2.4.6
|
15
|
+
- 2.3.8
|
3
16
|
- ruby-head
|
4
|
-
- jruby-
|
5
|
-
-
|
6
|
-
|
7
|
-
- 2.1.9
|
8
|
-
- 2.0.0
|
9
|
-
- jruby
|
10
|
-
|
17
|
+
- jruby-9.1.9.0
|
18
|
+
- jruby-head
|
19
|
+
|
11
20
|
matrix:
|
12
21
|
allow_failures:
|
13
|
-
- rvm: jruby
|
14
22
|
- rvm: ruby-head
|
15
23
|
- rvm: jruby-head
|
16
24
|
|
17
|
-
|
18
|
-
- Gemfile
|
19
|
-
|
25
|
+
|
20
26
|
# whitelist
|
21
|
-
branches:
|
27
|
+
branches:
|
22
28
|
only:
|
23
|
-
- master
|
29
|
+
- master
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
## [0.1.23] - 2021-09-04
|
2
|
+
- Remove dependencies towards `coverall`, `simplecov`
|
3
|
+
- Code restyling to please rubocop 1.19.1
|
4
|
+
|
5
|
+
* [CHANGE] File 'sequitur.gemspec' Remove dependencies towards `coverall`, `simplecov`
|
6
|
+
* [CHANGE] File 'sequitur.gemspec' Ruby version must be 2.5+
|
7
|
+
|
8
|
+
## [0.1.22] - 2019-08-18
|
9
|
+
- Code refactoring to use string frozen magic comments (as a consequence, sequitur runs only on Rubies 2.3 or newer).
|
10
|
+
- Code restyling to please rubocop 0.7.40.
|
11
|
+
|
12
|
+
* [CHANGE] Files `Gemfile`, `.travis.yml`, `appveyor.yml` updated.
|
13
|
+
|
14
|
+
## 0.1.21 - 2019-01-13
|
15
|
+
- Removed Ruby versions older than 2.3 in CI testing because of breaking changes by Bundler 2.0
|
16
|
+
* [CHANGE] Files `Gemfile`, `.travis.yml`, `appveyor.yml` updated.
|
17
|
+
|
18
|
+
### 0.1.20 / 2019-01-03
|
19
|
+
Maintenance release.
|
20
|
+
* [CHANGE] File `.travis.yml`: updated Ruby versions.
|
21
|
+
* [CHANGE] File `appveyor.yml` updated Ruby versions.
|
22
|
+
* [CHANGE] File 'Gemfile' Code re-styling to please Rubocop 0.62.0.
|
23
|
+
* [CHANGE] File `LICENSE.txt` Updated copyright years.
|
24
|
+
|
25
|
+
### 0.1.19 / 2018-05-16
|
26
|
+
Maintenance release.
|
27
|
+
* [CHANGE] File `.travis.yml`: updated Ruby versions.
|
28
|
+
* [CHANGE] File `appveyor.yml` updated Ruby versions, updated for syntax changes.
|
29
|
+
* [CHANGE] File 'sequitur.gemspec' Updated versions in dependencies.
|
30
|
+
* [CHANGE] File 'Gemfile' Updated versions in dependencies.
|
31
|
+
* [CHANGE] File 'Gemfile' Code re-styling to please Rubocop 0.55.0.
|
32
|
+
|
33
|
+
|
1
34
|
### 0.1.18 / 2016-12-21
|
2
35
|
* [NEW] Added AppVeyor CI to Github commits. AppVeyor allows to build and test commits on Windows servers.
|
3
36
|
This is complementary to Travis CI which does Linux builds.
|
data/Gemfile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
# Prevent Bundler to load the dependencies from our .gemspec file
|
3
5
|
|
4
|
-
|
5
6
|
group :development do
|
6
7
|
gem 'coveralls', '>= 0.7.0'
|
7
|
-
gem 'rake', '>= 10.0.0'
|
8
|
-
gem 'rspec', '>=
|
8
|
+
gem 'rake', '>= 10.0.0'
|
9
|
+
gem 'rspec', '>= 3.0.0'
|
9
10
|
gem 'simplecov', '>= 0.8.0'
|
10
11
|
end
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,6 @@ _Ruby gem implementing the Sequitur algorithm_
|
|
7
7
|
[](https://ci.appveyor.com/project/famished-tiger/sequitur)
|
8
8
|
[](https://coveralls.io/r/famished-tiger/Sequitur)
|
9
9
|
[](http://badge.fury.io/rb/sequitur)
|
10
|
-
[](https://gemnasium.com/famished-tiger/Sequitur)
|
11
10
|
[](http://inch-ci.org/github/famished-tiger/Sequitur)
|
12
11
|
[](https://codeclimate.com/github/famished-tiger/Sequitur)
|
13
12
|
[](https://github.com/famished-tiger/Sequitur/blob/master/LICENSE.txt)
|
@@ -248,4 +247,4 @@ More examples are available in the examples folder.
|
|
248
247
|
|
249
248
|
Copyright
|
250
249
|
---------
|
251
|
-
Copyright (c) 2014-
|
250
|
+
Copyright (c) 2014-2018, Dimitri Geshef. Sequitur is released under the MIT License see [LICENSE.txt](https://github.com/famished-tiger/Sequitur/blob/master/LICENSE.txt) for details.
|
data/Rakefile
CHANGED
data/appveyor.yml
CHANGED
@@ -1,20 +1,28 @@
|
|
1
1
|
version: '{build}'
|
2
|
-
max_jobs:
|
2
|
+
max_jobs: 5
|
3
3
|
environment:
|
4
4
|
matrix:
|
5
|
-
- Ruby_version:
|
6
|
-
- Ruby_version:
|
7
|
-
- Ruby_version:
|
8
|
-
- Ruby_version: 21-x64
|
9
|
-
- Ruby_version: 22
|
10
|
-
- Ruby_version: 22-x64
|
11
|
-
- Ruby_version: 23
|
5
|
+
- Ruby_version: 26-x64
|
6
|
+
- Ruby_version: 25-x64
|
7
|
+
- Ruby_version: 24-x64
|
12
8
|
- Ruby_version: 23-x64
|
9
|
+
- Ruby_version: 26
|
10
|
+
- Ruby_version: 25
|
11
|
+
- Ruby_version: 24
|
12
|
+
- Ruby_version: 23
|
13
|
+
|
13
14
|
install:
|
14
|
-
-
|
15
|
-
|
15
|
+
- set PATH=C:\Ruby%Ruby_version%\bin;%PATH%
|
16
|
+
- gem update --system
|
17
|
+
- gem install bundler
|
18
|
+
- bundle install --retry=3 --clean --force
|
16
19
|
|
17
|
-
bundle install --retry=3 --clean
|
18
20
|
build: off
|
21
|
+
|
22
|
+
before_test:
|
23
|
+
- ruby -v
|
24
|
+
- gem -v
|
25
|
+
- bundle -v
|
26
|
+
|
19
27
|
test_script:
|
20
|
-
-
|
28
|
+
- bundle exec rake
|
data/examples/integer_sample.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sequitur' # Load the Sequitur library
|
2
4
|
|
3
5
|
#
|
4
6
|
# Purpose: show how to apply Sequitur on a stream of integer values
|
5
7
|
#
|
6
|
-
input_sequence =
|
8
|
+
input_sequence = [1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5]
|
7
9
|
|
8
10
|
# Generate the grammar from the sequence
|
9
11
|
grammar = Sequitur.build_from(input_sequence)
|
10
12
|
|
11
13
|
|
12
14
|
# Use a formatter to display the grammar rules on the console output
|
13
|
-
formatter = Sequitur::Formatter::BaseText.new(
|
15
|
+
formatter = Sequitur::Formatter::BaseText.new($stdout)
|
14
16
|
|
15
17
|
# Now render the rules
|
16
18
|
formatter.render(grammar.visitor)
|
@@ -23,11 +25,10 @@ formatter.render(grammar.visitor)
|
|
23
25
|
|
24
26
|
# Playing a bit with the API
|
25
27
|
# Access last symbol from rhs of start production:
|
26
|
-
last_symbol_p0 = grammar.start.rhs.symbols[-1]
|
27
|
-
puts last_symbol_p0
|
28
|
+
last_symbol_p0 = grammar.start.rhs.symbols[-1]
|
29
|
+
puts last_symbol_p0 # => 5
|
28
30
|
|
29
31
|
# Access first symbol from rhs of P1 production:
|
30
32
|
first_symbol_p1 = grammar.productions[1].rhs.symbols[0]
|
31
33
|
|
32
|
-
puts first_symbol_p1
|
33
|
-
|
34
|
+
puts first_symbol_p1 # => 1
|
data/examples/porridge.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'sequitur' # Load the Sequitur library
|
3
4
|
|
4
5
|
# Purpose: demo to show that sequitur gem works on example from sequitur.info website
|
5
|
-
input_sequence =
|
6
|
-
input = <<-SNIPPET
|
6
|
+
input_sequence = <<-SNIPPET
|
7
7
|
pease porridge hot,
|
8
8
|
pease porridge cold,
|
9
9
|
pease porridge in the pot,
|
@@ -19,9 +19,9 @@ grammar = Sequitur.build_from(input_sequence)
|
|
19
19
|
|
20
20
|
# To display the grammar rules on the console output
|
21
21
|
# We use a formatter
|
22
|
-
formatter = Sequitur::Formatter::BaseText.new(
|
22
|
+
formatter = Sequitur::Formatter::BaseText.new($stdout)
|
23
23
|
|
24
|
-
# Now render the rules.
|
24
|
+
# Now render the rules.
|
25
25
|
formatter.render(grammar.visitor)
|
26
26
|
|
27
27
|
# Rendered output is:
|
@@ -38,4 +38,4 @@ formatter.render(grammar.visitor)
|
|
38
38
|
# P9 : s o m P1 l i k P1 i t .
|
39
39
|
# P10 : c P7.
|
40
40
|
# P11 : P5 P9.
|
41
|
-
# P12 : P6 t h P4 t P5 n P6 P1 d a y s
|
41
|
+
# P12 : P6 t h P4 t P5 n P6 P1 d a y s P7 .
|
data/examples/simple_case.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'sequitur' # Load the Sequitur library
|
3
4
|
|
4
5
|
# Purpose: show how to apply Sequitur on a stream of single characters
|
5
|
-
input_sequence =
|
6
|
+
input_sequence = 'ababcabcdabcde' # Let's analyze this string
|
6
7
|
|
7
8
|
# The SEQUITUR algorithm will detect the repeated 'ab' pattern
|
8
9
|
# and will generate a context-free grammar that represents the input string
|
@@ -10,13 +11,13 @@ grammar = Sequitur.build_from(input_sequence)
|
|
10
11
|
|
11
12
|
# To display the grammar rules on the console output
|
12
13
|
# We use a formatter
|
13
|
-
formatter = Sequitur::Formatter::BaseText.new(
|
14
|
+
formatter = Sequitur::Formatter::BaseText.new($stdout)
|
14
15
|
|
15
16
|
# Now render the rules. Each rule is displayed with the format:
|
16
17
|
# rule_id : a_sequence_grammar_symbols.
|
17
|
-
# Where:
|
18
|
+
# Where:
|
18
19
|
# - rule_id is either 'start' or a name like 'Pxxxx' (xxxx is a sequential number)
|
19
|
-
# - a grammar symbol is either a terminal symbol
|
20
|
+
# - a grammar symbol is either a terminal symbol
|
20
21
|
# (i.e. a character from the input) or a rule id
|
21
22
|
formatter.render(grammar.visitor)
|
22
23
|
|
@@ -24,4 +25,4 @@ formatter.render(grammar.visitor)
|
|
24
25
|
# start : P1 P2 P3 P3 e.
|
25
26
|
# P1 : a b.
|
26
27
|
# P2 : P1 c.
|
27
|
-
# P3 : P2 d.
|
28
|
+
# P3 : P2 d.
|
data/examples/symbol_sample.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sequitur' # Load the Sequitur library
|
2
4
|
|
3
5
|
#
|
4
6
|
# Purpose: show how to apply Sequitur on a stream of Symbol values
|
5
7
|
#
|
6
|
-
input_sequence =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
:dd, :ee
|
8
|
+
input_sequence = %i[
|
9
|
+
aa bb aa bb cc
|
10
|
+
aa bb cc dd aa
|
11
|
+
bb cc dd ee
|
11
12
|
]
|
12
13
|
|
13
14
|
# Generate the grammar from the sequence
|
14
15
|
grammar = Sequitur.build_from(input_sequence)
|
15
16
|
|
16
|
-
|
17
17
|
# Use a formatter to display the grammar rules on the console output
|
18
|
-
formatter = Sequitur::Formatter::BaseText.new(
|
18
|
+
formatter = Sequitur::Formatter::BaseText.new($stdout)
|
19
19
|
|
20
20
|
# Now render the rules
|
21
21
|
formatter.render(grammar.visitor)
|
@@ -25,4 +25,3 @@ formatter.render(grammar.visitor)
|
|
25
25
|
# P1 : aa bb.
|
26
26
|
# P2 : P1 cc.
|
27
27
|
# P3 : P2 dd.
|
28
|
-
|
data/examples/word_sample.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sequitur' # Load the Sequitur library
|
2
4
|
|
3
5
|
#
|
4
6
|
# Purpose: show how to apply Sequitur on a stream of text words
|
@@ -18,7 +20,7 @@ grammar = Sequitur.build_from(input_sequence)
|
|
18
20
|
|
19
21
|
|
20
22
|
# Use a formatter to display the grammar rules on the console output
|
21
|
-
formatter = Sequitur::Formatter::BaseText.new(
|
23
|
+
formatter = Sequitur::Formatter::BaseText.new($stdout)
|
22
24
|
|
23
25
|
# Now render the rules
|
24
26
|
formatter.render(grammar.visitor)
|
@@ -27,4 +29,3 @@ formatter.render(grammar.visitor)
|
|
27
29
|
# start : P2 6 Error illegal P1 20 P2 9.
|
28
30
|
# P1 : character at position.
|
29
31
|
# P2 : Error unknown P1.
|
30
|
-
|
data/lib/sequitur/constants.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: constants.rb
|
2
4
|
# Purpose: definition of Sequitur constants.
|
3
5
|
|
4
6
|
module Sequitur # Module used as a namespace
|
5
7
|
# The version number of the gem.
|
6
|
-
Version = '0.1.
|
8
|
+
Version = '0.1.23'
|
7
9
|
|
8
10
|
# Brief description of the gem.
|
9
|
-
Description = 'Ruby implementation of the Sequitur algorithm'
|
11
|
+
Description = 'Ruby implementation of the Sequitur algorithm'
|
10
12
|
|
11
13
|
# Constant Sequitur::RootDir contains the absolute path of Sequitur's
|
12
14
|
# start directory. Note: it also ends with a slash character.
|
@@ -18,7 +20,7 @@ module Sequitur # Module used as a namespace
|
|
18
20
|
RootDir = begin
|
19
21
|
require 'pathname' # Load Pathname class from standard library
|
20
22
|
startdir = Pathname(__FILE__).dirname.parent.parent.expand_path
|
21
|
-
startdir
|
23
|
+
"#{startdir}/" # Append trailing slash character to it
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end # module
|
data/lib/sequitur/digram.rb
CHANGED
@@ -1,49 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: digram.rb
|
2
4
|
|
3
5
|
module Sequitur # Module for classes implementing the Sequitur algorithm
|
4
|
-
# In linguistics, a digram is a sequence of two letters.
|
5
|
-
# In Sequitur, a digram is a sequence of two consecutive symbols that
|
6
|
-
# appear in a production rule. Each symbol in a digram
|
7
|
-
# can be a terminal or not.
|
8
|
-
class Digram
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end # class
|
6
|
+
# In linguistics, a digram is a sequence of two letters.
|
7
|
+
# In Sequitur, a digram is a sequence of two consecutive symbols that
|
8
|
+
# appear in a production rule. Each symbol in a digram
|
9
|
+
# can be a terminal or not.
|
10
|
+
class Digram
|
11
|
+
# The sequence of two consecutive grammar symbols.
|
12
|
+
# The two symbols should respond to the :hash message.
|
13
|
+
attr_reader(:symbols)
|
14
|
+
|
15
|
+
# An unique hash key of the digram
|
16
|
+
attr_reader(:key)
|
17
|
+
|
18
|
+
# The production in which the digram occurs
|
19
|
+
attr_reader(:production)
|
20
|
+
|
21
|
+
# Constructor.
|
22
|
+
# A digram represents a sequence of two symbols
|
23
|
+
# (that appears in a rhs of a production).
|
24
|
+
# Terminal symbols must respond to the :hash message.
|
25
|
+
# @param symbol1 [StringOrSymbol] First element of the digram
|
26
|
+
# @param symbol2 [StringOrSymbol] Second element of the digram
|
27
|
+
# @param aProduction [Production] Production in which the RHS
|
28
|
+
# the sequence symbol1 symbol2 appears.
|
29
|
+
def initialize(symbol1, symbol2, aProduction)
|
30
|
+
@symbols = [symbol1, symbol2]
|
31
|
+
@key = "#{symbol1.hash.to_s(16)}:#{symbol2.hash.to_s(16)}"
|
32
|
+
@production = aProduction
|
33
|
+
end
|
34
|
+
|
35
|
+
# Equality testing.
|
36
|
+
# true iff keys of both digrams are equal, false otherwise
|
37
|
+
# @param other [Digram] another to compare with
|
38
|
+
# @return [true/false]
|
39
|
+
def ==(other)
|
40
|
+
return key == other.key
|
41
|
+
end
|
42
|
+
|
43
|
+
# Does the digram consists of twice the same symbols?
|
44
|
+
# @return [true/false] true when symbols.first == symbols.last
|
45
|
+
def repeating?
|
46
|
+
return symbols[0] == symbols[1]
|
47
|
+
end
|
48
|
+
end # class
|
47
49
|
end # module
|
48
50
|
|
49
51
|
# End of file
|