rley 0.0.09 → 0.0.10
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 +3 -1
- data/examples/grammars/grammar_L0.rb +35 -0
- data/examples/grammars/grammar_abc.rb +27 -0
- data/lib/rley.rb +9 -0
- data/lib/rley/constants.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmIxMmNjMmEwZDYwMTUxMzFjY2ZhMjgzNzg4OWEwNTIzMDAxNWMxOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTU0MDBmMzliOWE4ZTgyZjMzMGJlNzQxNzE4MDY4MWM5NTc2MGI2ZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTkyOWUzZDIzYWU3OWM5YmYzN2MwNzkzZGMwNThjYTM4YWIzMzdkMjI0ZDc0
|
10
|
+
ZjBhZDc5ZWFjYTAyYzNhOTIxZTU2YTM0Nzg2MjE0M2E1NWNjMzA0MjM4ZGJh
|
11
|
+
NjIyNGE3MjVhMDY3MWEyZjhiZjZhOWEyYzA3MTBiMmRkM2E2ZmI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzRkY2QzZjRiMDI1ODgwYmE1N2VmYWJjNzc0ZmM1MDM0NjgzZGRmYmFlNjYy
|
14
|
+
ZTM5MDU3ZTIyMTE4NGY3OTUzNDEyMzg4NzQ1NzBkMDc4Yjc3YmM4M2EwMzQ4
|
15
|
+
YzJlZGUyZDJjZjNjYjZmNDU3MTE4NmNjNWNhOTAzZjBhZjM1ZjY=
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
### 0.0.10 / 2014-11-15
|
2
|
+
* [NEW] New folder `examples` added with two examples of grammar creation
|
3
|
+
|
1
4
|
### 0.0.09 / 2014-11-15
|
2
5
|
* [NEW] New class `GrammarBuilder` added and tested, its purpose is
|
3
6
|
to simplify the construction of grammars.
|
4
7
|
|
5
|
-
|
6
8
|
### 0.0.08 / 2014-11-14
|
7
9
|
* [CHANGE] `EarleyParser#parse` method: Initial API documentation.
|
8
10
|
* [INFO] This version was committed to force Travis CI to execute a complete build
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Purpose: to demonstrate how to build a very simple grammar
|
2
|
+
require 'rley' # Load the gem
|
3
|
+
|
4
|
+
# Sample grammar for a very limited English language
|
5
|
+
# based on the language L0 from Jurafsky & Martin
|
6
|
+
|
7
|
+
# Let's create the grammar step-by-step with the grammar builder:
|
8
|
+
builder = Rley::Syntax::GrammarBuilder.new
|
9
|
+
|
10
|
+
# Enumerate the POS Part-Of-Speech...
|
11
|
+
builder.add_terminals('Noun', 'Verb', 'Adjective')
|
12
|
+
builder.add_terminals('Pronoun', 'Proper-Noun', 'Determiner')
|
13
|
+
builder.add_terminals('Preposition', 'Conjunction')
|
14
|
+
|
15
|
+
# Enumerate the non-terminal symbols...
|
16
|
+
builder.add_non_terminals('S', 'NP', 'Nominal', 'VP', 'PP')
|
17
|
+
|
18
|
+
# Now the production rules...
|
19
|
+
builder.add_production('S'=> ['NP', 'VP']) # e.g. I + want a morning flight
|
20
|
+
builder.add_production('NP' => 'Pronoun') # e.g. I
|
21
|
+
builder.add_production('NP' => 'Proper-Noun') # e.g. Los Angeles
|
22
|
+
builder.add_production('NP' => ['Det', 'Nominal']) # e.g. a + flight
|
23
|
+
builder.add_production('Nominal' => %w(Nominal Noun)) # morning + flight
|
24
|
+
builder.add_production('Nominal' => 'Noun') # e.g. flights
|
25
|
+
builder.add_production('VP' => 'Verb') # e.g. do
|
26
|
+
builder.add_production('VP' => ['Verb', 'NP']) # e.g. want + a flight
|
27
|
+
builder.add_production('VP' => ['Verb', 'NP', 'PP'])
|
28
|
+
builder.add_production('VP' => ['Verb', 'PP']) # leaving + on Thursday
|
29
|
+
builder.add_production('PP' => ['Preposition', 'NP']) # from + Los Angeles
|
30
|
+
|
31
|
+
# And now we 're ready to build the grammar...
|
32
|
+
grammar_L0 = builder.grammar
|
33
|
+
|
34
|
+
# Prove that it is a grammar
|
35
|
+
puts grammar_L0.class.name
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Purpose: to demonstrate how to build a very simple grammar
|
2
|
+
require 'rley' # Load the gem
|
3
|
+
|
4
|
+
# A very simple language
|
5
|
+
# It recognizes/generates strings like 'b', 'abc', 'aabcc', 'aaabccc',...
|
6
|
+
# (based on example in N. Wirth's book "Compiler Construction", p. 6)
|
7
|
+
# S ::= A.
|
8
|
+
# A ::= "a" A "c".
|
9
|
+
# A ::= "b".
|
10
|
+
|
11
|
+
|
12
|
+
# Let's create the grammar step-by-step with the grammar builder:
|
13
|
+
builder = Rley::Syntax::GrammarBuilder.new
|
14
|
+
builder.add_terminals('a', 'b', 'c')
|
15
|
+
builder.add_non_terminals('S', 'A')
|
16
|
+
builder.add_production('S' => 'A')
|
17
|
+
builder.add_production('A' => %w(a A c))
|
18
|
+
builder.add_production('A' => 'b')
|
19
|
+
|
20
|
+
# And now build the grammar...
|
21
|
+
grammar_abc = builder.grammar
|
22
|
+
|
23
|
+
# Prove that it is a grammar
|
24
|
+
puts grammar_abc.class.name
|
25
|
+
|
26
|
+
# End of file
|
27
|
+
|
data/lib/rley.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# File: rley.rb
|
2
|
+
# This file acts as a jumping-off point for loading dependencies expected
|
3
|
+
# for a Rley client.
|
4
|
+
|
5
|
+
require_relative './rley/constants'
|
6
|
+
require_relative './rley/syntax/grammar_builder'
|
7
|
+
require_relative './rley/parser/earley_parser'
|
8
|
+
|
9
|
+
# End of file
|
data/lib/rley/constants.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
@@ -85,6 +85,9 @@ files:
|
|
85
85
|
- CHANGELOG.md
|
86
86
|
- LICENSE.txt
|
87
87
|
- README.md
|
88
|
+
- examples/grammars/grammar_abc.rb
|
89
|
+
- examples/grammars/grammar_L0.rb
|
90
|
+
- lib/rley.rb
|
88
91
|
- lib/rley/constants.rb
|
89
92
|
- lib/rley/parser/chart.rb
|
90
93
|
- lib/rley/parser/dotted_item.rb
|