rley 0.3.04 → 0.3.05
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/.rubocop.yml +7 -3
- data/CHANGELOG.md +3 -0
- data/Rakefile +30 -30
- data/examples/parsers/parsing_L0.rb +1 -1
- data/examples/parsers/parsing_L1.rb +1 -1
- data/examples/parsers/parsing_abc.rb +1 -1
- data/examples/parsers/parsing_ambig.rb +1 -1
- data/examples/parsers/parsing_another.rb +1 -1
- data/examples/parsers/parsing_b_expr.rb +1 -1
- data/examples/parsers/parsing_err_expr.rb +1 -1
- data/examples/parsers/parsing_groucho.rb +1 -1
- data/examples/parsers/parsing_right_recursive.rb +1 -1
- data/examples/parsers/parsing_tricky.rb +1 -1
- data/lib/rley/constants.rb +2 -2
- data/lib/rley/formatter/base_formatter.rb +0 -2
- data/lib/rley/formatter/debug.rb +0 -2
- data/lib/rley/formatter/json.rb +1 -3
- data/lib/rley/gfg/call_edge.rb +31 -30
- data/lib/rley/gfg/edge.rb +22 -23
- data/lib/rley/gfg/end_vertex.rb +22 -24
- data/lib/rley/gfg/epsilon_edge.rb +20 -21
- data/lib/rley/gfg/grm_flow_graph.rb +39 -39
- data/lib/rley/gfg/item_vertex.rb +16 -17
- data/lib/rley/gfg/non_terminal_vertex.rb +3 -4
- data/lib/rley/gfg/return_edge.rb +32 -31
- data/lib/rley/gfg/scan_edge.rb +25 -26
- data/lib/rley/gfg/shortcut_edge.rb +25 -26
- data/lib/rley/gfg/start_vertex.rb +0 -2
- data/lib/rley/gfg/vertex.rb +8 -8
- data/lib/rley/parse_forest_visitor.rb +113 -115
- data/lib/rley/parse_tree_visitor.rb +0 -2
- data/lib/rley/parser/base_parser.rb +27 -27
- data/lib/rley/parser/chart.rb +14 -14
- data/lib/rley/parser/dotted_item.rb +33 -33
- data/lib/rley/parser/earley_parser.rb +6 -6
- data/lib/rley/parser/gfg_chart.rb +8 -15
- data/lib/rley/parser/gfg_earley_parser.rb +15 -13
- data/lib/rley/parser/gfg_parsing.rb +26 -22
- data/lib/rley/parser/grm_items_builder.rb +3 -2
- data/lib/rley/parser/parse_entry.rb +3 -9
- data/lib/rley/parser/parse_entry_set.rb +14 -19
- data/lib/rley/parser/parse_entry_tracker.rb +56 -56
- data/lib/rley/parser/parse_forest_builder.rb +215 -214
- data/lib/rley/parser/parse_forest_factory.rb +57 -56
- data/lib/rley/parser/parse_state.rb +8 -11
- data/lib/rley/parser/parse_state_tracker.rb +56 -56
- data/lib/rley/parser/parse_tracer.rb +3 -3
- data/lib/rley/parser/parse_tree_builder.rb +10 -10
- data/lib/rley/parser/parse_walker_factory.rb +30 -33
- data/lib/rley/parser/parsing.rb +8 -8
- data/lib/rley/parser/state_set.rb +23 -26
- data/lib/rley/ptree/non_terminal_node.rb +1 -1
- data/lib/rley/ptree/token_range.rb +2 -2
- data/lib/rley/sppf/alternative_node.rb +32 -34
- data/lib/rley/sppf/composite_node.rb +27 -27
- data/lib/rley/sppf/epsilon_node.rb +26 -27
- data/lib/rley/sppf/leaf_node.rb +11 -12
- data/lib/rley/sppf/non_terminal_node.rb +37 -38
- data/lib/rley/sppf/sppf_node.rb +1 -1
- data/lib/rley/sppf/token_node.rb +29 -29
- data/lib/rley/syntax/grammar.rb +1 -3
- data/lib/rley/syntax/grammar_builder.rb +8 -8
- data/lib/rley/syntax/non_terminal.rb +2 -4
- data/lib/rley/syntax/production.rb +3 -3
- data/lib/rley/syntax/symbol_seq.rb +1 -1
- data/spec/rley/gfg/call_edge_spec.rb +50 -51
- data/spec/rley/gfg/edge_spec.rb +33 -33
- data/spec/rley/gfg/end_vertex_spec.rb +26 -27
- data/spec/rley/gfg/epsilon_edge_spec.rb +25 -25
- data/spec/rley/gfg/grm_flow_graph_spec.rb +1 -1
- data/spec/rley/gfg/item_vertex_spec.rb +3 -4
- data/spec/rley/gfg/return_edge_spec.rb +51 -51
- data/spec/rley/gfg/scan_edge_spec.rb +32 -30
- data/spec/rley/gfg/shortcut_edge_spec.rb +1 -1
- data/spec/rley/gfg/vertex_spec.rb +3 -3
- data/spec/rley/parse_forest_visitor_spec.rb +239 -238
- data/spec/rley/parser/dotted_item_spec.rb +1 -1
- data/spec/rley/parser/earley_parser_spec.rb +16 -16
- data/spec/rley/parser/gfg_earley_parser_spec.rb +30 -31
- data/spec/rley/parser/gfg_parsing_spec.rb +11 -10
- data/spec/rley/parser/grm_items_builder_spec.rb +2 -2
- data/spec/rley/parser/parse_entry_set_spec.rb +4 -4
- data/spec/rley/parser/parse_entry_spec.rb +0 -2
- data/spec/rley/parser/parse_forest_builder_spec.rb +82 -57
- data/spec/rley/parser/parse_forest_factory_spec.rb +84 -82
- data/spec/rley/parser/parse_walker_factory_spec.rb +10 -9
- data/spec/rley/parser/parsing_spec.rb +0 -1
- data/spec/rley/sppf/alternative_node_spec.rb +2 -2
- data/spec/rley/sppf/non_terminal_node_spec.rb +0 -1
- data/spec/rley/support/ambiguous_grammar_helper.rb +1 -1
- data/spec/rley/support/expectation_helper.rb +37 -36
- data/spec/rley/support/grammar_abc_helper.rb +17 -17
- data/spec/rley/support/grammar_b_expr_helper.rb +40 -39
- data/spec/rley/support/grammar_helper.rb +2 -1
- data/spec/rley/support/{grammar_L0_helper.rb → grammar_l0_helper.rb} +82 -81
- data/spec/rley/support/grammar_sppf_helper.rb +24 -25
- data/spec/rley/syntax/grammar_spec.rb +1 -1
- metadata +2 -2
@@ -1,81 +1,82 @@
|
|
1
|
-
# Load the builder class
|
2
|
-
require_relative '../../../lib/rley/syntax/grammar_builder'
|
3
|
-
require_relative '../../../lib/rley/parser/token'
|
4
|
-
|
5
|
-
|
6
|
-
module GrammarL0Helper
|
7
|
-
########################################
|
8
|
-
# Factory method. Define a grammar for a micro English-like language
|
9
|
-
# based on Jurafky & Martin L0 language (chapter 12 of the book).
|
10
|
-
# It defines the syntax of a sentence in a language with a
|
11
|
-
# very limited syntax and lexicon in the context of airline reservation.
|
12
|
-
def
|
13
|
-
builder = Rley::Syntax::GrammarBuilder.new
|
14
|
-
builder.add_terminals('Noun', 'Verb', 'Pronoun', 'Proper-Noun')
|
15
|
-
builder.add_terminals('Determiner', 'Preposition'
|
16
|
-
builder.add_production('S' => %w
|
17
|
-
builder.add_production('NP' => 'Pronoun')
|
18
|
-
builder.add_production('NP' => 'Proper-Noun')
|
19
|
-
builder.add_production('NP' => %w
|
20
|
-
builder.add_production('Nominal' => %w
|
21
|
-
builder.add_production('Nominal' => 'Noun')
|
22
|
-
builder.add_production('VP' => 'Verb')
|
23
|
-
builder.add_production('VP' => %w
|
24
|
-
builder.add_production('VP' => %w
|
25
|
-
builder.add_production('VP' => %w
|
26
|
-
builder.add_production('PP' => %w
|
27
|
-
builder
|
28
|
-
end
|
29
|
-
|
30
|
-
# Return the language lexicon.
|
31
|
-
# A lexicon is just a Hash with pairs of the form:
|
32
|
-
# word => terminal symbol name
|
33
|
-
def
|
34
|
-
|
35
|
-
'flight' => 'Noun',
|
36
|
-
'breeze' => 'Noun',
|
37
|
-
'trip' => 'Noun',
|
38
|
-
'morning' => 'Noun',
|
39
|
-
'is' => 'Verb',
|
40
|
-
'prefer' => 'Verb',
|
41
|
-
'like' => 'Verb',
|
42
|
-
'need' => 'Verb',
|
43
|
-
'want' => 'Verb',
|
44
|
-
'fly' => 'Verb',
|
45
|
-
'me' => 'Pronoun',
|
46
|
-
'I' => 'Pronoun',
|
47
|
-
'you' => 'Pronoun',
|
48
|
-
'it' => 'Pronoun',
|
49
|
-
'Alaska' => 'Proper-Noun',
|
50
|
-
'Baltimore' => 'Proper-Noun',
|
51
|
-
'Chicago' => 'Proper-Noun',
|
52
|
-
'United' => 'Proper-Noun',
|
53
|
-
'American' => 'Proper-Noun',
|
54
|
-
'the' => 'Determiner',
|
55
|
-
'a' => 'Determiner',
|
56
|
-
'an' => 'Determiner',
|
57
|
-
'this' => 'Determiner',
|
58
|
-
'these' => 'Determiner',
|
59
|
-
'that' => 'Determiner',
|
60
|
-
'from' => 'Preposition',
|
61
|
-
'to' => 'Preposition',
|
62
|
-
'on' => 'Preposition',
|
63
|
-
'near' => 'Preposition'
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
# Highly simplified tokenizer implementation.
|
69
|
-
def
|
70
|
-
tokens = aText.scan(/\S+/).map do |word|
|
71
|
-
term_name =
|
72
|
-
if term_name.nil?
|
73
|
-
|
74
|
-
end
|
75
|
-
terminal = aGrammar.name2symbol[term_name]
|
76
|
-
Rley::Parser::Token.new(word, terminal)
|
77
|
-
end
|
78
|
-
|
79
|
-
return tokens
|
80
|
-
end
|
81
|
-
end # module
|
1
|
+
# Load the builder class
|
2
|
+
require_relative '../../../lib/rley/syntax/grammar_builder'
|
3
|
+
require_relative '../../../lib/rley/parser/token'
|
4
|
+
|
5
|
+
|
6
|
+
module GrammarL0Helper
|
7
|
+
########################################
|
8
|
+
# Factory method. Define a grammar for a micro English-like language
|
9
|
+
# based on Jurafky & Martin L0 language (chapter 12 of the book).
|
10
|
+
# It defines the syntax of a sentence in a language with a
|
11
|
+
# very limited syntax and lexicon in the context of airline reservation.
|
12
|
+
def grammar_l0_builder()
|
13
|
+
builder = Rley::Syntax::GrammarBuilder.new
|
14
|
+
builder.add_terminals('Noun', 'Verb', 'Pronoun', 'Proper-Noun')
|
15
|
+
builder.add_terminals('Determiner', 'Preposition')
|
16
|
+
builder.add_production('S' => %w(NP VP))
|
17
|
+
builder.add_production('NP' => 'Pronoun')
|
18
|
+
builder.add_production('NP' => 'Proper-Noun')
|
19
|
+
builder.add_production('NP' => %w(Determiner Nominal))
|
20
|
+
builder.add_production('Nominal' => %w(Nominal Noun))
|
21
|
+
builder.add_production('Nominal' => 'Noun')
|
22
|
+
builder.add_production('VP' => 'Verb')
|
23
|
+
builder.add_production('VP' => %w(Verb NP))
|
24
|
+
builder.add_production('VP' => %w(Verb NP PP))
|
25
|
+
builder.add_production('VP' => %w(Verb PP))
|
26
|
+
builder.add_production('PP' => %w(Preposition PP))
|
27
|
+
builder
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return the language lexicon.
|
31
|
+
# A lexicon is just a Hash with pairs of the form:
|
32
|
+
# word => terminal symbol name
|
33
|
+
def lexicon_l0()
|
34
|
+
return {
|
35
|
+
'flight' => 'Noun',
|
36
|
+
'breeze' => 'Noun',
|
37
|
+
'trip' => 'Noun',
|
38
|
+
'morning' => 'Noun',
|
39
|
+
'is' => 'Verb',
|
40
|
+
'prefer' => 'Verb',
|
41
|
+
'like' => 'Verb',
|
42
|
+
'need' => 'Verb',
|
43
|
+
'want' => 'Verb',
|
44
|
+
'fly' => 'Verb',
|
45
|
+
'me' => 'Pronoun',
|
46
|
+
'I' => 'Pronoun',
|
47
|
+
'you' => 'Pronoun',
|
48
|
+
'it' => 'Pronoun',
|
49
|
+
'Alaska' => 'Proper-Noun',
|
50
|
+
'Baltimore' => 'Proper-Noun',
|
51
|
+
'Chicago' => 'Proper-Noun',
|
52
|
+
'United' => 'Proper-Noun',
|
53
|
+
'American' => 'Proper-Noun',
|
54
|
+
'the' => 'Determiner',
|
55
|
+
'a' => 'Determiner',
|
56
|
+
'an' => 'Determiner',
|
57
|
+
'this' => 'Determiner',
|
58
|
+
'these' => 'Determiner',
|
59
|
+
'that' => 'Determiner',
|
60
|
+
'from' => 'Preposition',
|
61
|
+
'to' => 'Preposition',
|
62
|
+
'on' => 'Preposition',
|
63
|
+
'near' => 'Preposition'
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# Highly simplified tokenizer implementation.
|
69
|
+
def tokenizer_l0(aText, aGrammar)
|
70
|
+
tokens = aText.scan(/\S+/).map do |word|
|
71
|
+
term_name = lexicon_l0[word]
|
72
|
+
if term_name.nil?
|
73
|
+
raise StandardError, "Word '#{word}' not found in lexicon"
|
74
|
+
end
|
75
|
+
terminal = aGrammar.name2symbol[term_name]
|
76
|
+
Rley::Parser::Token.new(word, terminal)
|
77
|
+
end
|
78
|
+
|
79
|
+
return tokens
|
80
|
+
end
|
81
|
+
end # module
|
82
|
+
# End of file
|
@@ -1,25 +1,24 @@
|
|
1
|
-
# Load the builder class
|
2
|
-
require_relative '../../../lib/rley/syntax/grammar_builder'
|
3
|
-
|
4
|
-
|
5
|
-
module GrammarSPPFHelper
|
6
|
-
# Factory method. Creates a grammar builder for a
|
7
|
-
# grammar described in paper from Elisabeth Scott
|
8
|
-
# "SPPF-Style Parsing From Earley Recognizers" in
|
9
|
-
# Notes in Theoretical Computer Science 203, (2008), pp. 53-67
|
10
|
-
# contains a hidden left recursion and a cycle
|
11
|
-
def grammar_sppf_builder()
|
12
|
-
builder = Rley::Syntax::GrammarBuilder.new
|
13
|
-
builder.add_terminals('a', 'b')
|
14
|
-
builder.add_production('Phi' =>
|
15
|
-
builder.add_production('S' => %w
|
16
|
-
builder.add_production('S' => %w
|
17
|
-
builder.add_production('A' => 'a')
|
18
|
-
builder.add_production('A' => %w
|
19
|
-
builder.add_production('B' => [])
|
20
|
-
builder.add_production('T' => %w(
|
21
|
-
|
22
|
-
return builder
|
23
|
-
end
|
24
|
-
|
25
|
-
end # module
|
1
|
+
# Load the builder class
|
2
|
+
require_relative '../../../lib/rley/syntax/grammar_builder'
|
3
|
+
|
4
|
+
|
5
|
+
module GrammarSPPFHelper
|
6
|
+
# Factory method. Creates a grammar builder for a
|
7
|
+
# grammar described in paper from Elisabeth Scott
|
8
|
+
# "SPPF-Style Parsing From Earley Recognizers" in
|
9
|
+
# Notes in Theoretical Computer Science 203, (2008), pp. 53-67
|
10
|
+
# contains a hidden left recursion and a cycle
|
11
|
+
def grammar_sppf_builder()
|
12
|
+
builder = Rley::Syntax::GrammarBuilder.new
|
13
|
+
builder.add_terminals('a', 'b')
|
14
|
+
builder.add_production('Phi' => 'S')
|
15
|
+
builder.add_production('S' => %w(A T))
|
16
|
+
builder.add_production('S' => %w(a T))
|
17
|
+
builder.add_production('A' => 'a')
|
18
|
+
builder.add_production('A' => %w(B A))
|
19
|
+
builder.add_production('B' => [])
|
20
|
+
builder.add_production('T' => %w(b b b))
|
21
|
+
|
22
|
+
return builder
|
23
|
+
end
|
24
|
+
end # module
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.05
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
@@ -252,10 +252,10 @@ files:
|
|
252
252
|
- spec/rley/sppf/non_terminal_node_spec.rb
|
253
253
|
- spec/rley/support/ambiguous_grammar_helper.rb
|
254
254
|
- spec/rley/support/expectation_helper.rb
|
255
|
-
- spec/rley/support/grammar_L0_helper.rb
|
256
255
|
- spec/rley/support/grammar_abc_helper.rb
|
257
256
|
- spec/rley/support/grammar_b_expr_helper.rb
|
258
257
|
- spec/rley/support/grammar_helper.rb
|
258
|
+
- spec/rley/support/grammar_l0_helper.rb
|
259
259
|
- spec/rley/support/grammar_sppf_helper.rb
|
260
260
|
- spec/rley/syntax/grammar_builder_spec.rb
|
261
261
|
- spec/rley/syntax/grammar_spec.rb
|