rley 0.5.10 → 0.5.11
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 +4 -4
- data/CHANGELOG.md +15 -0
- data/LICENSE.txt +1 -1
- data/README.md +2 -1
- data/appveyor.yml +6 -5
- data/examples/NLP/engtagger.rb +176 -0
- data/examples/general/SRL/lib/ast_builder.rb +217 -21
- data/examples/general/SRL/lib/grammar.rb +33 -5
- data/examples/general/SRL/lib/regex/alternation.rb +30 -0
- data/examples/general/SRL/lib/regex/char_class.rb +28 -22
- data/examples/general/SRL/lib/regex/char_shorthand.rb +50 -0
- data/examples/general/SRL/lib/regex/character.rb +5 -3
- data/examples/general/SRL/lib/regex/concatenation.rb +32 -0
- data/examples/general/SRL/lib/regex/non_capturing_group.rb +29 -0
- data/examples/general/SRL/lib/regex/wildcard.rb +26 -0
- data/examples/general/SRL/lib/regex_repr.rb +5 -0
- data/examples/general/SRL/lib/tokenizer.rb +28 -3
- data/examples/general/SRL/spec/integration_spec.rb +151 -8
- data/examples/general/SRL/spec/tokenizer_spec.rb +12 -0
- data/examples/general/left.rb +36 -0
- data/examples/general/right.rb +36 -0
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/gfg/edge.rb +12 -1
- data/lib/rley/gfg/grm_flow_graph.rb +21 -1
- data/lib/rley/gfg/item_vertex.rb +1 -1
- data/lib/rley/gfg/non_terminal_vertex.rb +1 -1
- data/lib/rley/gfg/start_vertex.rb +1 -0
- data/lib/rley/gfg/vertex.rb +27 -0
- data/lib/rley/lexical/token.rb +1 -0
- data/lib/rley/parser/error_reason.rb +2 -1
- data/lib/rley/parser/gfg_chart.rb +14 -0
- data/lib/rley/parser/gfg_earley_parser.rb +0 -1
- data/lib/rley/parser/gfg_parsing.rb +4 -3
- data/lib/rley/parser/parse_entry.rb +33 -3
- data/lib/rley/parser/parse_entry_set.rb +14 -2
- data/lib/rley/parser/parse_tree_builder.rb +1 -1
- data/lib/rley/parser/parse_walker_factory.rb +0 -1
- data/lib/rley/syntax/grm_symbol.rb +2 -0
- data/lib/rley/syntax/production.rb +15 -3
- data/lib/rley/syntax/symbol_seq.rb +16 -1
- data/spec/rley/gfg/end_vertex_spec.rb +9 -1
- data/spec/rley/gfg/grm_flow_graph_spec.rb +9 -0
- data/spec/rley/gfg/item_vertex_spec.rb +9 -0
- data/spec/rley/gfg/start_vertex_spec.rb +9 -1
- data/spec/rley/parser/gfg_parsing_spec.rb +0 -1
- data/spec/rley/parser/parse_entry_set_spec.rb +15 -0
- data/spec/rley/parser/parse_entry_spec.rb +24 -13
- data/spec/rley/parser/parse_tracer_spec.rb +1 -1
- data/spec/rley/syntax/production_spec.rb +10 -0
- data/spec/rley/syntax/symbol_seq_spec.rb +5 -0
- metadata +10 -2
@@ -113,7 +113,6 @@ module Rley # This module is used as a namespace
|
|
113
113
|
# [event, entry, index, vertex]
|
114
114
|
def visit_entry(anEntry, aContext)
|
115
115
|
index = aContext.entry_set_index
|
116
|
-
|
117
116
|
aContext.nterm2start[[anEntry, index]] if anEntry.start_entry?
|
118
117
|
|
119
118
|
if aContext.visitees.include?(anEntry) # Already visited?...
|
@@ -13,7 +13,9 @@ module Rley # This module is used as a namespace
|
|
13
13
|
# Constructor.
|
14
14
|
# aName [String] The name of the grammar symbol.
|
15
15
|
def initialize(aName)
|
16
|
+
raise 'Internal error: nil name encountered' if aName.nil?
|
16
17
|
@name = aName.dup
|
18
|
+
@name.freeze
|
17
19
|
end
|
18
20
|
|
19
21
|
# The String representation of the grammar symbol
|
@@ -19,7 +19,7 @@ module Rley # This module is used as a namespace
|
|
19
19
|
# @return [String] The unique name of the production rule.
|
20
20
|
attr_accessor(:name)
|
21
21
|
|
22
|
-
# @return [Boolean
|
22
|
+
# @return [Boolean] A production is generative when all of its
|
23
23
|
# rhs members are generative (that is, they can each generate/derive
|
24
24
|
# a non-empty string of terminals).
|
25
25
|
attr_writer(:generative)
|
@@ -38,7 +38,7 @@ module Rley # This module is used as a namespace
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# Is the rhs empty?
|
41
|
-
# @
|
41
|
+
# @return [Boolean] true if the rhs has no members.
|
42
42
|
def empty?()
|
43
43
|
return rhs.empty?
|
44
44
|
end
|
@@ -49,7 +49,19 @@ module Rley # This module is used as a namespace
|
|
49
49
|
end
|
50
50
|
|
51
51
|
return @generative
|
52
|
-
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns a string containing a human-readable representation of the
|
55
|
+
# production.
|
56
|
+
# @return [String]
|
57
|
+
def inspect()
|
58
|
+
result = "#<#{self.class.name}:#{self.object_id}"
|
59
|
+
result << " @name=\"#{self.name}\""
|
60
|
+
result << " @lhs=#{lhs.name}"
|
61
|
+
result << " @rhs=#{rhs.inspect}"
|
62
|
+
result << " @generative=#{@generative}>"
|
63
|
+
return result
|
64
|
+
end
|
53
65
|
|
54
66
|
private
|
55
67
|
|
@@ -7,14 +7,19 @@ module Rley # This module is used as a namespace
|
|
7
7
|
extend Forwardable
|
8
8
|
def_delegators :@members, :empty?, :size, :[], :each, :find, :map
|
9
9
|
|
10
|
-
# The sequence of symbols
|
10
|
+
# @return [Array<GrmSymbol>] The sequence of symbols
|
11
11
|
attr_reader(:members)
|
12
12
|
|
13
|
+
# Create a sequence of grammar symbols (as in right-hand side of
|
14
|
+
# a production rule).
|
15
|
+
# @param theSymbols [Array<GrmSymbol>] An array of symbols.
|
13
16
|
def initialize(theSymbols)
|
14
17
|
@members = theSymbols.dup
|
15
18
|
end
|
16
19
|
|
17
20
|
# Equality operator.
|
21
|
+
# @param other [SymbolSeq|Array]
|
22
|
+
# @return [Boolean]
|
18
23
|
def ==(other)
|
19
24
|
return true if other.object_id == object_id
|
20
25
|
|
@@ -29,6 +34,16 @@ module Rley # This module is used as a namespace
|
|
29
34
|
return result
|
30
35
|
end
|
31
36
|
|
37
|
+
# Returns a string containing a human-readable representation of the
|
38
|
+
# sequence of symbols.
|
39
|
+
# @return [String]
|
40
|
+
def inspect()
|
41
|
+
result = "#<#{self.class.name}:#{self.object_id}"
|
42
|
+
symbol_names = self.members.map(&:name)
|
43
|
+
result << " @members=#{symbol_names}>"
|
44
|
+
return result
|
45
|
+
end
|
46
|
+
|
32
47
|
|
33
48
|
end # class
|
34
49
|
end # module
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/rley/syntax/non_terminal'
|
2
3
|
|
3
4
|
# Load the class under test
|
4
5
|
require_relative '../../../lib/rley/gfg/end_vertex'
|
@@ -6,7 +7,7 @@ require_relative '../../../lib/rley/gfg/end_vertex'
|
|
6
7
|
module Rley # Open this namespace to avoid module qualifier prefixes
|
7
8
|
module GFG # Open this namespace to avoid module qualifier prefixes
|
8
9
|
describe EndVertex do
|
9
|
-
let(:sample_nt) {
|
10
|
+
let(:sample_nt) { Syntax::NonTerminal.new('NT') }
|
10
11
|
subject { EndVertex.new(sample_nt) }
|
11
12
|
|
12
13
|
context 'Initialization:' do
|
@@ -19,6 +20,13 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
19
20
|
expect(subject.label).to eq('NT.')
|
20
21
|
end
|
21
22
|
end # context
|
23
|
+
|
24
|
+
context 'Provided services:' do
|
25
|
+
it 'should provide human-readable representation of itself' do
|
26
|
+
pattern = /^#<Rley::GFG::EndVertex:\d+ label="NT\."/
|
27
|
+
expect(subject.inspect).to match(pattern)
|
28
|
+
end
|
29
|
+
end # context
|
22
30
|
end # describe
|
23
31
|
end # module
|
24
32
|
end # module
|
@@ -197,6 +197,15 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
197
197
|
expect(result).to eq(expected)
|
198
198
|
end
|
199
199
|
|
200
|
+
it 'should provide human-readable representation of itself' do
|
201
|
+
prefix = /^#<Rley::GFG::GrmFlowGraph:\d+ @vertices=\[/
|
202
|
+
expect(subject.inspect).to match(prefix)
|
203
|
+
pattern = /@vertices=\[#<Rley::GFG::StartVertex:\d+ label="\.S"/
|
204
|
+
expect(subject.inspect).to match(pattern)
|
205
|
+
suffix = /]>$/
|
206
|
+
expect(subject.inspect).to match(suffix)
|
207
|
+
end
|
208
|
+
|
200
209
|
it 'should perform a diagnosis of a correct grammar' do
|
201
210
|
expect { subject.diagnose }.not_to raise_error
|
202
211
|
grammar_abc.non_terminals.each do |nterm|
|
@@ -117,6 +117,15 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
117
117
|
expect { subject.shortcut = 'invalid' }.to raise_error(err, err_msg)
|
118
118
|
end
|
119
119
|
end # context
|
120
|
+
|
121
|
+
context 'Provided services:' do
|
122
|
+
it 'should provide human-readable representation of itself' do
|
123
|
+
prefix = /^#<Rley::GFG::ItemVertex:\d+/
|
124
|
+
expect(subject.inspect).to match(prefix)
|
125
|
+
suffix = /label="sentence => a \. b_sequence c">$/
|
126
|
+
expect(subject.inspect).to match(suffix)
|
127
|
+
end
|
128
|
+
end # context
|
120
129
|
end # describe
|
121
130
|
end # module
|
122
131
|
end # module
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/rley/syntax/non_terminal'
|
2
3
|
|
3
4
|
# Load the class under test
|
4
5
|
require_relative '../../../lib/rley/gfg/start_vertex'
|
@@ -6,7 +7,7 @@ require_relative '../../../lib/rley/gfg/start_vertex'
|
|
6
7
|
module Rley # Open this namespace to avoid module qualifier prefixes
|
7
8
|
module GFG # Open this namespace to avoid module qualifier prefixes
|
8
9
|
describe StartVertex do
|
9
|
-
let(:sample_nt) {
|
10
|
+
let(:sample_nt) { Syntax::NonTerminal.new('NT') }
|
10
11
|
subject { StartVertex.new(sample_nt) }
|
11
12
|
|
12
13
|
context 'Initialization:' do
|
@@ -19,6 +20,13 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
19
20
|
expect(subject.label).to eq('.NT')
|
20
21
|
end
|
21
22
|
end # context
|
23
|
+
|
24
|
+
context 'Provided services:' do
|
25
|
+
it 'should provide human-readable representation of itself' do
|
26
|
+
pattern = /^#<Rley::GFG::StartVertex:\d+ label="\.NT"/
|
27
|
+
expect(subject.inspect).to match(pattern)
|
28
|
+
end
|
29
|
+
end # context
|
22
30
|
end # describe
|
23
31
|
end # module
|
24
32
|
end # module
|
@@ -90,6 +90,21 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
90
90
|
subject.push_entry(entry3)
|
91
91
|
expect(subject.entries4n_term(nt_rep_c)).to eq([entry3])
|
92
92
|
end
|
93
|
+
|
94
|
+
it 'should provide human-readable representation of itself' do
|
95
|
+
# Case 1: empty set
|
96
|
+
pattern_empty = /^#<Rley::Parser::ParseEntrySet:\d+ @entries=\[\]>$/
|
97
|
+
expect(subject.inspect).to match(pattern_empty)
|
98
|
+
|
99
|
+
# Case 2: non-empty set
|
100
|
+
subject.push_entry(entry1)
|
101
|
+
prefix = /^#<Rley::Parser::ParseEntrySet:\d+ @entries=\[#<Rley/
|
102
|
+
expect(subject.inspect).to match(prefix)
|
103
|
+
pattern_entry = /ParseEntry:\d+ @vertex=<Rley::GFG::ItemVertex:\d+/
|
104
|
+
expect(subject.inspect).to match(pattern_entry)
|
105
|
+
suffix = /=> a \. b b Repetition> @origin=2 @antecedents=\[\]>\]>$/
|
106
|
+
expect(subject.inspect).to match(suffix)
|
107
|
+
end
|
93
108
|
|
94
109
|
=begin
|
95
110
|
it 'should list of ambiguous states' do
|
@@ -26,14 +26,14 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
26
26
|
|
27
27
|
let(:dotted_rule) { Base::DottedItem.new(sample_prod, 2) }
|
28
28
|
let(:origin_val) { 3 }
|
29
|
-
let(:
|
29
|
+
let(:sample_vertex) { GFG::StartVertex.new(nt_sentence) }
|
30
30
|
let(:vertex2) { double('vertex-mock') }
|
31
31
|
# Default instantiation rule
|
32
|
-
subject { ParseEntry.new(
|
32
|
+
subject { ParseEntry.new(sample_vertex, origin_val) }
|
33
33
|
|
34
34
|
context 'Initialization:' do
|
35
35
|
it 'should be created with a vertex and an origin position' do
|
36
|
-
args = [
|
36
|
+
args = [sample_vertex, origin_val]
|
37
37
|
expect { ParseEntry.new(*args) }.not_to raise_error
|
38
38
|
end
|
39
39
|
|
@@ -44,7 +44,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should know the vertex' do
|
47
|
-
expect(subject.vertex).to eq(
|
47
|
+
expect(subject.vertex).to eq(sample_vertex)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should know the origin value' do
|
@@ -64,23 +64,23 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should compare with another' do
|
67
|
-
equal = ParseEntry.new(
|
67
|
+
equal = ParseEntry.new(sample_vertex, origin_val)
|
68
68
|
expect(subject == equal).to eq(true)
|
69
69
|
|
70
70
|
# Same vertex, different origin
|
71
|
-
diff_origin = ParseEntry.new(
|
71
|
+
diff_origin = ParseEntry.new(sample_vertex, 2)
|
72
72
|
expect(subject == diff_origin).to eq(false)
|
73
73
|
|
74
74
|
# Different vertices, same origin
|
75
|
-
diff_vertex = ParseEntry.new(double('
|
75
|
+
diff_vertex = ParseEntry.new(double('other_sample_vertex'), 3)
|
76
76
|
expect(subject == diff_vertex).to eq(false)
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'should know if the vertex is a start vertex' do
|
80
|
-
expect(subject).
|
80
|
+
expect(subject).to be_start_entry
|
81
81
|
|
82
|
-
instance = ParseEntry.new(GFG::
|
83
|
-
expect(instance).
|
82
|
+
instance = ParseEntry.new(GFG::EndVertex.new('.NT'), 3)
|
83
|
+
expect(instance).not_to be_start_entry
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should know if the vertex is an end vertex' do
|
@@ -191,13 +191,24 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
191
191
|
expect(subject.antecedents).to eql([antecedent])
|
192
192
|
expect(subject).not_to be_orphan
|
193
193
|
end
|
194
|
-
=begin
|
195
194
|
|
196
195
|
it 'should know its text representation' do
|
197
|
-
expected = 'sentence
|
196
|
+
expected = '.sentence | 3'
|
198
197
|
expect(subject.to_s).to eq(expected)
|
199
198
|
end
|
200
|
-
|
199
|
+
|
200
|
+
it 'should be inspectable' do
|
201
|
+
subject.add_antecedent(subject) # Cheat for the good cause...
|
202
|
+
expected = '.sentence | 3'
|
203
|
+
prefix = /^#<Rley::Parser::ParseEntry:\d+ @vertex/
|
204
|
+
expect(subject.inspect).to match(prefix)
|
205
|
+
pattern = /@vertex=<Rley::GFG::StartVertex:\d+ label=\.sentence/
|
206
|
+
expect(subject.inspect).to match(pattern)
|
207
|
+
pattern2 = /@origin=3 @antecedents=\[/
|
208
|
+
expect(subject.inspect).to match(pattern2)
|
209
|
+
suffix = /<Rley::GFG::StartVertex:\d+ label=\.sentence> @origin=3\]>$/
|
210
|
+
expect(subject.inspect).to match(suffix)
|
211
|
+
end
|
201
212
|
end # context
|
202
213
|
end # describe
|
203
214
|
end # module
|
@@ -18,7 +18,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
18
18
|
|
19
19
|
let(:token_seq) do
|
20
20
|
literals = %w[I saw John with a dog]
|
21
|
-
literals.map { |lexeme| Lexical::Token.new(lexeme,
|
21
|
+
literals.map { |lexeme| Lexical::Token.new(lexeme, double('fake-terminal')) }
|
22
22
|
end
|
23
23
|
|
24
24
|
subject { ParseTracer.new(1, output, token_seq) }
|
@@ -59,6 +59,16 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
59
59
|
subject.name = a_name
|
60
60
|
expect(subject.name).to eq(a_name)
|
61
61
|
end
|
62
|
+
|
63
|
+
it 'should provide human-readable representation of itself' do
|
64
|
+
subject.name = 'some name'
|
65
|
+
prefix = /^#<Rley::Syntax::Production:\d+ @name="some name"/
|
66
|
+
expect(subject.inspect).to match(prefix)
|
67
|
+
pattern = /@lhs=Sentence @rhs=#<Rley::Syntax::SymbolSeq/
|
68
|
+
expect(subject.inspect).to match(pattern)
|
69
|
+
suffix = /> @generative=>$/
|
70
|
+
expect(subject.inspect).to match(suffix)
|
71
|
+
end
|
62
72
|
end # context
|
63
73
|
end # describe
|
64
74
|
end # module
|
@@ -61,6 +61,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
61
61
|
msg = 'Cannot compare a SymbolSeq with a String'
|
62
62
|
expect { subject == 'dummy-text' }.to raise_error(err, msg)
|
63
63
|
end
|
64
|
+
|
65
|
+
it 'should provide human-readable representation of itself' do
|
66
|
+
suffix = /::SymbolSeq:\d+ @members=\["Verb", "NP", "PP"\]>$/
|
67
|
+
expect(subject.inspect).to match(suffix)
|
68
|
+
end
|
64
69
|
end # context
|
65
70
|
end # describe
|
66
71
|
end # module
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- Rakefile
|
132
132
|
- appveyor.yml
|
133
133
|
- examples/NLP/benchmark_pico_en.rb
|
134
|
+
- examples/NLP/engtagger.rb
|
134
135
|
- examples/NLP/nano_eng/nano_en_demo.rb
|
135
136
|
- examples/NLP/nano_eng/nano_grammar.rb
|
136
137
|
- examples/NLP/pico_en_demo.rb
|
@@ -147,17 +148,22 @@ files:
|
|
147
148
|
- examples/general/SRL/lib/grammar.rb
|
148
149
|
- examples/general/SRL/lib/parser.rb
|
149
150
|
- examples/general/SRL/lib/regex/abstract_method.rb
|
151
|
+
- examples/general/SRL/lib/regex/alternation.rb
|
150
152
|
- examples/general/SRL/lib/regex/atomic_expression.rb
|
151
153
|
- examples/general/SRL/lib/regex/char_class.rb
|
152
154
|
- examples/general/SRL/lib/regex/char_range.rb
|
155
|
+
- examples/general/SRL/lib/regex/char_shorthand.rb
|
153
156
|
- examples/general/SRL/lib/regex/character.rb
|
154
157
|
- examples/general/SRL/lib/regex/compound_expression.rb
|
158
|
+
- examples/general/SRL/lib/regex/concatenation.rb
|
155
159
|
- examples/general/SRL/lib/regex/expression.rb
|
156
160
|
- examples/general/SRL/lib/regex/monadic_expression.rb
|
157
161
|
- examples/general/SRL/lib/regex/multiplicity.rb
|
162
|
+
- examples/general/SRL/lib/regex/non_capturing_group.rb
|
158
163
|
- examples/general/SRL/lib/regex/polyadic_expression.rb
|
159
164
|
- examples/general/SRL/lib/regex/quantifiable.rb
|
160
165
|
- examples/general/SRL/lib/regex/repetition.rb
|
166
|
+
- examples/general/SRL/lib/regex/wildcard.rb
|
161
167
|
- examples/general/SRL/lib/regex_repr.rb
|
162
168
|
- examples/general/SRL/lib/tokenizer.rb
|
163
169
|
- examples/general/SRL/spec/integration_spec.rb
|
@@ -181,6 +187,8 @@ files:
|
|
181
187
|
- examples/general/calc_iter2/calc_lexer.rb
|
182
188
|
- examples/general/calc_iter2/calc_parser.rb
|
183
189
|
- examples/general/calc_iter2/spec/calculator_spec.rb
|
190
|
+
- examples/general/left.rb
|
191
|
+
- examples/general/right.rb
|
184
192
|
- lib/rley.rb
|
185
193
|
- lib/rley/base/base_parser.rb
|
186
194
|
- lib/rley/base/dotted_item.rb
|