zenlish 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +5 -4
- data/lib/zenlish/lang/dictionary.rb +4 -1
- data/lib/zenlish/lang/zenlish_grammar.rb +190 -127
- data/lib/zenlish/lex/empty_lexicon_factory.rb +1 -1
- data/lib/zenlish/parser/zparser.rb +31 -2
- data/lib/zenlish/version.rb +1 -1
- data/lib/zenlish/wclasses/all_word_classes.rb +2 -2
- data/lib/zenlish/wclasses/existential_there.rb +9 -0
- data/spec/zenlish/parser/zparser_spec.rb +238 -165
- data/zenlish.gemspec +1 -1
- metadata +5 -6
- data/lib/zenlish/wclasses/adverb_there.rb +0 -9
- data/lib/zenlish/wclasses/test_hierarchy.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b03b18d2aa554c1fa12c98c4fff5dce6a88de55055ae7f43e43a4b4db6b379b
|
4
|
+
data.tar.gz: 8f6a59c3ad405d4959f03b3cf6f818c7158fd2474df8eb86638f2a0563925209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1df388e9589d5dd7ccec7c72b46a72deb325cd9dada87e82a951b1df7386125cd40cc1e737589d70008ab9e375be2f47aaf60c23b8ab5988f90cded5dad82fee
|
7
|
+
data.tar.gz: 30d7ac36e86b95e11217fadda5c9ebb09060273643740bd8446cfc59df24e256ce8326a6b1c0e90057f6eda27e82a8334cf8152ca6b144d038aa20dec68c819e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## [0.1.16] - 2019-11-23
|
4
|
+
__Zenlish__ can parse all sentences in lesson 1 and 2-A..2-G from
|
5
|
+
[Learn These Words First](http://learnthesewordsfirst.com/).
|
6
|
+
- `ZenlishGrammar`: Vast grammar reworking.
|
7
|
+
- File `dictionary.rb`: `there` in lexicon has `ExistentialThere` as word class.
|
8
|
+
- File `dictionary.rb`: new entries for `body`, `one` (as indefinite pronoun), `two` (as indefinite pronoun)
|
9
|
+
- Class `ZParser`: Added method `to_pforest` to generate a parse forest, `to_ptree` is an alias of `parse`
|
10
|
+
|
3
11
|
## [0.1.15] - 2019-11-02
|
4
12
|
__Zenlish__ can parse all sentences in lesson 1 and 2-A..2-G from
|
5
13
|
[Learn These Words First](http://learnthesewordsfirst.com/).
|
data/README.md
CHANGED
@@ -20,7 +20,8 @@ users with a language that is close enough to English.
|
|
20
20
|
### Project status
|
21
21
|
|
22
22
|
The project is still in inception. Currently, zenlish is able to parse all
|
23
|
-
sentences from lessons 1-A up to 2-G.
|
23
|
+
sentences from lessons 1-A up to 2-G. The parser is able to cope with syntactical
|
24
|
+
ambiguities generating parse forests instead of parse trees.
|
24
25
|
|
25
26
|
The intent is to deliver gem versions in small increments.
|
26
27
|
|
@@ -37,11 +38,11 @@ Over time, the zenlish gem will contain:
|
|
37
38
|
#### Some project metrics (v. 0.1.15)
|
38
39
|
|Metric|Value|
|
39
40
|
|:-:|:-:|
|
40
|
-
| Number of lemmas in dictionary |
|
41
|
+
| Number of lemmas in dictionary | 92 |
|
41
42
|
| [Coverage 100 commonest English words](https://en.wikipedia.org/wiki/Most_common_words_in_English) | 45 |
|
42
|
-
| Number of production rules in grammar |
|
43
|
+
| Number of production rules in grammar | 131 |
|
43
44
|
| Number of lessons covered | 15 |
|
44
|
-
| Number of sentences in spec files |
|
45
|
+
| Number of sentences in spec files | 189 |
|
45
46
|
|
46
47
|
|
47
48
|
## Installation...
|
@@ -35,6 +35,7 @@ unless defined?(Zenlish::Lang::Dictionary)
|
|
35
35
|
add_entry('before', 'Adverb')
|
36
36
|
add_entry('before', 'SubordinatingConjunction')
|
37
37
|
add_entry('big', 'Adjective')
|
38
|
+
add_entry('body', 'CommonNoun')
|
38
39
|
add_entry('can', 'ModalVerbCan')
|
39
40
|
add_entry('do', 'AuxiliaryDo')
|
40
41
|
add_entry('do', 'IrregularVerbDo')
|
@@ -71,6 +72,7 @@ unless defined?(Zenlish::Lang::Dictionary)
|
|
71
72
|
add_entry('of', 'PrepositionOf')
|
72
73
|
add_entry('on', 'Preposition')
|
73
74
|
add_entry('one', 'Cardinal')
|
75
|
+
add_entry('one', 'IndefinitePronoun')
|
74
76
|
add_entry('other', 'Adjective')
|
75
77
|
add_entry('part', 'CommonNoun')
|
76
78
|
add_entry('people', 'CommonNoun')
|
@@ -88,7 +90,7 @@ unless defined?(Zenlish::Lang::Dictionary)
|
|
88
90
|
add_entry('than', 'PrepositionThan')
|
89
91
|
add_entry('the', 'DefiniteArticle')
|
90
92
|
add_entry('then', 'LinkingAdverb')
|
91
|
-
add_entry('there', '
|
93
|
+
add_entry('there', 'ExistentialThere')
|
92
94
|
add_entry('thing', 'CommonNoun')
|
93
95
|
add_entry('think', 'IrregularVerbThink')
|
94
96
|
add_entry('this', 'DemonstrativeDeterminer')
|
@@ -99,6 +101,7 @@ unless defined?(Zenlish::Lang::Dictionary)
|
|
99
101
|
add_entry('touch', 'RegularVerb')
|
100
102
|
add_entry('true', 'Adjective')
|
101
103
|
add_entry('two', 'Cardinal')
|
104
|
+
add_entry('two', 'IndefinitePronoun')
|
102
105
|
add_entry('very', 'DegreeAdverb')
|
103
106
|
add_entry('want', 'RegularVerbWant')
|
104
107
|
add_entry('what','ConjunctivePronoun')
|
@@ -15,122 +15,138 @@ builder = Rley::Syntax::GrammarBuilder.new do
|
|
15
15
|
|
16
16
|
rule 'sentence' => 'simple_sentence Period'
|
17
17
|
rule 'sentence' => 'complex_sentence Period'
|
18
|
+
|
19
|
+
#################
|
20
|
+
# Simple sentence
|
21
|
+
#################
|
18
22
|
rule 'simple_sentence' => 'declarative_simple_sentence'
|
23
|
+
rule 'declarative_simple_sentence' => 'affirmative_sentence'
|
24
|
+
rule 'declarative_simple_sentence' => 'existential_sentence'
|
25
|
+
rule 'declarative_simple_sentence' => 'predicative_sentence'
|
26
|
+
rule 'declarative_simple_sentence' => 'negative_sentence'
|
27
|
+
rule 'declarative_simple_sentence' => 'inexistential_sentence'
|
28
|
+
rule 'affirmative_sentence' => 'noun_phrase verb_phrase'
|
29
|
+
rule 'affirmative_sentence' => 'prepositional_phrase Comma simple_sentence'
|
30
|
+
# Case of time adjunct adverbial put in front position
|
31
|
+
rule 'affirmative_sentence' => 'noun_phrase Adverb Comma simple_sentence'
|
32
|
+
|
33
|
+
# there + (auxiliary/raising verb) + be + notional subject.
|
34
|
+
rule 'existential_sentence' => 'ExistentialThere IrregularVerbBe existential_subject'
|
35
|
+
rule 'negative_sentence' => 'noun_phrase negative_verb_phrase'
|
36
|
+
rule 'negative_sentence' => 'negated_predicate_sentence'
|
37
|
+
rule 'inexistential_sentence' => 'ExistentialThere IrregularVerbBe AdverbNot existential_subject'
|
38
|
+
rule 'existential_subject' => 'noun_phrase adverb_phrase_opt'
|
39
|
+
rule 'existential_subject' => 'prepositional_phrase'
|
40
|
+
|
41
|
+
rule 'predicative_sentence' => 'noun_phrase IrregularVerbBe predicative_complement'
|
42
|
+
rule 'predicative_sentence' => 'conjunctive_prefix IrregularVerbBe predicative_complement'
|
43
|
+
rule 'negated_predicate_sentence' => 'noun_phrase adverb_phrase_opt IrregularVerbBe AdverbNot predicative_complement'
|
44
|
+
rule 'negated_predicate_sentence' => 'conjunctive_prefix IrregularVerbBe AdverbNot predicative_complement'
|
45
|
+
rule 'predicative_complement' => 'noun_phrase'
|
46
|
+
rule 'predicative_complement' => 'adjective_phrase comparative_clause_opt'
|
47
|
+
# X is far from the start.
|
48
|
+
rule 'predicative_complement' => 'adverb_phrase_opt prepositional_phrase'
|
19
49
|
|
50
|
+
#################
|
51
|
+
# Complex sentence
|
52
|
+
#################
|
20
53
|
# Case of dropped ´that´ conjunction
|
21
|
-
rule 'complex_sentence' => 'main_clause subordinated_clause'
|
22
|
-
rule 'complex_sentence' => 'main_clause Comma subordinated_clause'
|
54
|
+
rule 'complex_sentence' => 'main_clause comma_opt subordinated_clause'
|
23
55
|
rule 'complex_sentence' => 'subordinated_clause Comma main_clause'
|
24
|
-
|
25
|
-
rule '
|
26
|
-
rule '
|
27
|
-
rule '
|
28
|
-
|
56
|
+
# CGE 287d: verb + direct object + infinitive clause (without to)
|
57
|
+
rule 'complex_sentence' => 'main_clause infinitive_clause'
|
58
|
+
rule 'comma_opt' => 'Comma'
|
59
|
+
rule 'comma_opt' => []
|
60
|
+
|
61
|
+
######################
|
62
|
+
# CLAUSES
|
63
|
+
######################
|
29
64
|
rule 'main_clause' => 'simple_sentence'
|
30
65
|
rule 'subordinated_clause' => 'subordination_marker dependent_clause'
|
66
|
+
rule 'subordination_marker' => 'SubordinatingConjunction'
|
67
|
+
rule 'subordination_marker' => 'SubordinatingConjunction PrepositionOf'
|
31
68
|
rule 'dependent_clause' => 'simple_sentence'
|
32
|
-
rule 'dependent_clause' => '
|
33
|
-
rule '
|
34
|
-
rule '
|
35
|
-
rule '
|
36
|
-
rule '
|
37
|
-
rule '
|
38
|
-
rule '
|
39
|
-
rule '
|
40
|
-
|
41
|
-
# Case of time adjunct adverbial put in fromt position
|
42
|
-
rule 'affirmative_sentence' => 'simple_noun_phrase Adverb Comma noun_phrase verb_phrase'
|
43
|
-
rule 'negative_sentence' => 'noun_phrase negative_verb_phrase'
|
44
|
-
rule 'negative_sentence' => 'AdverbThere negative_verb_phrase'
|
45
|
-
rule 'negative_sentence' => 'numeral_of negative_verb_phrase'
|
46
|
-
rule 'negative_sentence' => 'DemonstrativePronoun negative_verb_phrase'
|
47
|
-
rule 'negative_sentence' => 'conjunctive_prefix negative_verb_phrase'
|
69
|
+
rule 'dependent_clause' => 'noun_phrase'
|
70
|
+
rule 'infinitive_clause' => 'verb_phrase' # Too generic
|
71
|
+
rule 'comparative_clause_opt' => 'comparative_clause'
|
72
|
+
rule 'comparative_clause_opt' => []
|
73
|
+
rule 'comparative_clause' => 'comparative_start noun_phrase'
|
74
|
+
rule 'comparative_clause' => 'comparative_start declarative_simple_sentence'
|
75
|
+
# rule 'comparative_clause' => 'comparative_start DefiniteArticle Adjective Cardinal'
|
76
|
+
rule 'comparative_start' => 'PrepositionThan'
|
77
|
+
rule 'comparative_start' => 'ComparativeParticle'
|
48
78
|
rule 'conjunctive_prefix' => 'ConjunctivePronoun noun_phrase verb_phrase'
|
49
|
-
rule '
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
rule '
|
56
|
-
rule '
|
57
|
-
rule '
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
rule '
|
62
|
-
|
63
|
-
|
64
|
-
rule '
|
65
|
-
|
66
|
-
|
67
|
-
rule '
|
68
|
-
|
69
|
-
rule '
|
70
|
-
rule '
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
rule '
|
80
|
-
|
81
|
-
|
82
|
-
rule '
|
83
|
-
rule '
|
84
|
-
rule '
|
85
|
-
|
86
|
-
rule '
|
87
|
-
rule '
|
88
|
-
|
89
|
-
|
90
|
-
rule '
|
91
|
-
rule '
|
92
|
-
|
93
|
-
rule '
|
94
|
-
rule '
|
95
|
-
rule '
|
96
|
-
rule '
|
79
|
+
rule 'identifying_clause' => 'RelativePronoun verb_phrase'
|
80
|
+
|
81
|
+
|
82
|
+
#############
|
83
|
+
# NOUN PHRASE
|
84
|
+
#############
|
85
|
+
rule 'noun_phrase_opt' => 'noun_phrase'
|
86
|
+
rule 'noun_phrase_opt' => []
|
87
|
+
rule 'noun_phrase' => 'pre_head_noun head_noun post_head_noun'
|
88
|
+
# someone, somebody, something, somewhere; no one, nobody, nothing,
|
89
|
+
# nowhere; anyone, anybody, anything, anywhere; everyone, everybody,
|
90
|
+
# everything, everywhere, the attributive adjective phrase occurs as a postmodifier
|
91
|
+
rule 'pre_head_noun' => 'determiners adjective_phrase_opt'
|
92
|
+
rule 'head_noun' => 'CommonNoun'
|
93
|
+
rule 'head_noun' => 'ProperNoun'
|
94
|
+
rule 'head_noun' => 'PersonalPronoun'
|
95
|
+
rule 'head_noun' => 'DemonstrativePronoun'
|
96
|
+
rule 'head_noun' => 'IndefinitePronoun'
|
97
|
+
# rule 'head_noun' => 'Cardinal' # ... as indefinite pronoun in complement "There were three pies. I ate one."
|
98
|
+
rule 'post_head_noun' => 'adjective_phrase_opt prepositional_phrases clause_noun_opt'
|
99
|
+
rule 'clause_noun_opt' => 'clause_noun'
|
100
|
+
rule 'clause_noun_opt' => []
|
101
|
+
rule 'clause_noun' => 'comparative_clause'
|
102
|
+
rule 'clause_noun' => 'dependent_clause'
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
#############
|
107
|
+
# DETERMINERS
|
108
|
+
#############
|
109
|
+
rule 'determiners' => 'predeterminers central_determiners postdeterminers'
|
110
|
+
|
111
|
+
# Pre-determiners
|
112
|
+
rule 'predeterminers' => 'IndefiniteQuantifier' # all, ... both, half
|
113
|
+
rule 'predeterminers' => 'partitive_predeterminer'
|
114
|
+
rule 'predeterminers' => []
|
115
|
+
|
116
|
+
rule 'partitive_predeterminer' => 'numeral PrepositionOf' # one of ...
|
117
|
+
rule 'partitive_predeterminer' => 'IndefiniteQuantifier PrepositionOf' # some of...
|
118
|
+
|
119
|
+
# Central determiners: article, demonstrative or possessive
|
120
|
+
rule 'central_determiners' => 'article'
|
121
|
+
rule 'central_determiners' => 'demonstrative'
|
122
|
+
# central_determiners => possessive
|
123
|
+
rule 'central_determiners' => []
|
124
|
+
rule 'article' => 'DefiniteArticle' # 'the'
|
125
|
+
rule 'article' => 'IndefiniteArticle' # 'a/an', .., any, some, that, those,
|
126
|
+
rule 'demonstrative' => 'DemonstrativeDeterminer' # 'this', .., that, these, those
|
127
|
+
# possessive => possessive_determiner # ...my, your, his, her, its, our, their
|
128
|
+
|
129
|
+
# Postdeterminers
|
130
|
+
rule 'postdeterminers' => 'numeral'
|
131
|
+
rule 'postdeterminers' => []
|
132
|
+
|
133
|
+
#############
|
134
|
+
# VERB PHRASE
|
135
|
+
#############
|
136
|
+
rule 'verb_phrase' => 'pre_head_verb head_verb post_head_verb'
|
137
|
+
rule 'pre_head_verb' => 'adverb_phrase_opt'
|
138
|
+
rule 'head_verb' => 'lexical_verb'
|
139
|
+
rule 'head_verb' => 'AuxiliaryBe lexical_verb'
|
140
|
+
rule 'head_verb' => 'ModalVerbCan lexical_verb'
|
141
|
+
rule 'head_verb' => 'IrregularVerbSay direct_speech'
|
142
|
+
rule 'head_verb' => 'RegularVerbWant Preposition head_verb post_head_verb'
|
97
143
|
|
98
144
|
# Cover case where ´that´ conjunction is dropped.
|
99
|
-
rule '
|
100
|
-
|
101
|
-
rule '
|
102
|
-
|
103
|
-
rule '
|
104
|
-
rule 'verb_phrase' => 'IrregularVerbSay Colon Quote affirmative_sentence Period Quote'
|
105
|
-
rule 'verb_phrase' => 'IrregularVerbSay Preposition noun_phrase Colon Quote affirmative_sentence Period Quote'
|
106
|
-
rule 'mental_verb' => 'IrregularVerbKnow'
|
107
|
-
rule 'mental_verb' => 'IrregularVerbThink'
|
108
|
-
rule 'verb_complement' => 'noun_phrase'
|
109
|
-
rule 'verb_complement' => 'noun_phrase adverb_phrase'
|
110
|
-
rule 'verb_complement' => 'adverb_phrase'
|
111
|
-
rule 'verb_complement' => 'adverb_phrase nominal'
|
112
|
-
|
113
|
-
# perception verb (hear, see, watch, notice, ...): verb + object + infinitive
|
114
|
-
rule 'verb_complement' => 'simple_noun_phrase lexical_verb'
|
115
|
-
rule 'verb_complement' => 'Adjective propositional_phrase'
|
116
|
-
rule 'verb_complement' => 'Preposition simple_noun_phrase lexical_verb'
|
117
|
-
rule 'verb_complement' => 'Preposition IndefinitePronoun'
|
118
|
-
rule 'verb_be_complement' => 'noun_phrase'
|
119
|
-
rule 'verb_be_complement' => 'adjective_as_complement' # Specific to be as lexical verb
|
120
|
-
rule 'verb_be_complement' => 'propositional_phrase'
|
121
|
-
rule 'verb_be_complement' => 'noun_phrase adverb_phrase'
|
122
|
-
rule 'identifying_clause' => 'RelativePronoun verb_phrase'
|
123
|
-
|
124
|
-
rule 'adjective_as_complement' => 'DegreeAdverb Adjective'
|
125
|
-
rule 'adjective_as_complement' => 'Adjective'
|
126
|
-
rule 'adjective_as_complement' => 'Adjective comparative_clause'
|
127
|
-
rule 'negative_verb_phrase' => 'IrregularVerbBe AdverbNot verb_be_complement'
|
128
|
-
rule 'negative_verb_phrase' => 'AuxiliaryDo AdverbNot verb_phrase'
|
129
|
-
# rule 'negative_verb_phrase' => 'ModalVerbCan AdverbNot verb_phrase'
|
130
|
-
rule 'negative_verb_phrase' => 'ModalVerbCan AdverbNot verb_group DemonstrativePronoun'
|
131
|
-
rule 'verb_group' => 'lexical_verb'
|
132
|
-
rule 'verb_group' => 'AuxiliaryBe lexical_verb'
|
133
|
-
rule 'verb_group' => 'ModalVerbCan lexical_verb'
|
145
|
+
rule 'head_verb' => 'mental_verb dependent_clause'
|
146
|
+
# ex. 2-23c
|
147
|
+
rule 'head_verb' => 'mental_verb identifying_clause'
|
148
|
+
|
149
|
+
rule 'post_head_verb' => 'noun_phrase_opt adverb_phrase_opt prepositional_phrases adverb_phrase_opt'
|
134
150
|
rule 'lexical_verb' => 'RegularVerb'
|
135
151
|
rule 'lexical_verb' => 'RegularVerbWant'
|
136
152
|
rule 'lexical_verb' => 'IrregularVerb'
|
@@ -138,31 +154,78 @@ builder = Rley::Syntax::GrammarBuilder.new do
|
|
138
154
|
rule 'lexical_verb' => 'IrregularVerbDo'
|
139
155
|
rule 'lexical_verb' => 'IrregularVerbHave'
|
140
156
|
rule 'lexical_verb' => 'IrregularVerbKnow'
|
141
|
-
rule 'lexical_verb' => 'IrregularVerbThink'
|
142
157
|
rule 'lexical_verb' => 'IrregularVerbSay'
|
158
|
+
rule 'lexical_verb' => 'IrregularVerbThink'
|
159
|
+
|
160
|
+
rule 'mental_verb' => 'IrregularVerbKnow'
|
161
|
+
rule 'mental_verb' => 'IrregularVerbThink'
|
162
|
+
rule 'direct_speech' => 'Colon Quote declarative_simple_sentence Period Quote'
|
163
|
+
rule 'direct_speech' => 'Preposition noun_phrase Colon Quote declarative_simple_sentence Period Quote'
|
164
|
+
rule 'direct_speech' => 'Colon declarative_simple_sentence'
|
165
|
+
|
166
|
+
|
167
|
+
#############
|
168
|
+
# NEGATIVE VERB PHRASE
|
169
|
+
#############
|
170
|
+
rule 'negative_verb_phrase' => 'AuxiliaryDo AdverbNot head_verb post_head_verb'
|
171
|
+
rule 'negative_verb_phrase' => 'ModalVerbCan AdverbNot head_verb post_head_verb'
|
172
|
+
|
173
|
+
##################
|
174
|
+
# ADJECTIVE PHRASE
|
175
|
+
##################
|
176
|
+
rule 'adjective_phrase_opt' => 'adjective_phrase'
|
177
|
+
rule 'adjective_phrase_opt' => []
|
178
|
+
rule 'adjective_phrase' => 'premodifiers_adj head_adjective postmodifiers_adj'
|
179
|
+
rule 'premodifiers_adj' => 'adverb_phrase_opt'
|
180
|
+
rule 'head_adjective' => 'head_adjective Adjective' # sequence of adjectives (rem: could be comma separated or anded)
|
181
|
+
rule 'head_adjective' => 'Adjective'
|
182
|
+
rule 'postmodifiers_adj' => 'prepositional_phrase' # TODO: multiple prepositional phrases, gerund and to + infinitive
|
183
|
+
rule 'postmodifiers_adj' => []
|
184
|
+
|
185
|
+
################
|
186
|
+
# ADJVERB PHRASE
|
187
|
+
################
|
188
|
+
rule 'adverb_phrase_opt' => 'adverb_phrase'
|
189
|
+
rule 'adverb_phrase_opt' => []
|
190
|
+
rule 'adverb_phrase' => 'premodifiers_adv head_adverb'
|
191
|
+
rule 'premodifiers_adv' => 'adverb_occurrence'
|
192
|
+
rule 'premodifiers_adv' => []
|
193
|
+
rule 'head_adverb' => 'adverb_occurrence'
|
194
|
+
rule 'adverb_occurrence' => 'Adverb'
|
195
|
+
rule 'adverb_occurrence' => 'DegreeAdverb'
|
196
|
+
rule 'adverb_occurrence' => 'LinkingAdverb'
|
197
|
+
|
198
|
+
|
199
|
+
######################
|
200
|
+
# PREPOSITIONAL PHRASE
|
201
|
+
######################
|
202
|
+
rule 'prepositional_phrases' => 'prepositional_phrases prepositional_phrase'
|
203
|
+
rule 'prepositional_phrases' => []
|
204
|
+
rule 'prepositional_phrase' => 'premodifier_prep preposition_head preposition_object'
|
205
|
+
# premodifier_prep => # "A degree word" example 1: _straight_ across the street example 2: _right_ from the start
|
206
|
+
rule 'premodifier_prep' => []
|
207
|
+
rule 'preposition_head' => 'Preposition'
|
208
|
+
rule 'preposition_head' => 'PrepositionOf'
|
209
|
+
rule 'preposition_object' => 'noun_phrase' # (noun and pronoun)
|
210
|
+
|
211
|
+
# complementation by a verb: gerund -ing form...
|
212
|
+
rule 'preposition_object' => 'noun_phrase_opt lexical_verb post_head_verb'
|
213
|
+
# preposition_object => "a gerund (a verb form ending in "-ing") that acts as a noun # Example: He beat Lee without overly trying.
|
214
|
+
rule 'preposition_object' => 'conjunctive_prefix' # It's obvious from _what he said_.
|
215
|
+
rule 'preposition_object' => []
|
216
|
+
|
217
|
+
######################
|
218
|
+
# REMAINING RULES
|
219
|
+
######################
|
143
220
|
rule 'numeral' => 'Cardinal'
|
144
|
-
rule 'comparative_clause' => 'comparative_start noun_phrase'
|
145
|
-
rule 'comparative_clause' => 'comparative_start affirmative_sentence'
|
146
|
-
rule 'comparative_clause' => 'comparative_start DefiniteArticle Adjective Cardinal'
|
147
|
-
rule 'comparative_start' => 'PrepositionThan'
|
148
|
-
rule 'comparative_start' => 'ComparativeParticle'
|
149
|
-
rule 'adverb_phrase' => 'adverbial_marker'
|
150
|
-
rule 'adverb_phrase' => 'adverbial_marker propositional_phrase'
|
151
|
-
rule 'adverbial_marker' => 'Adverb'
|
152
|
-
rule 'adverbial_marker' => 'Adverb Adverb' # 'here now', 'much more'
|
153
|
-
rule 'propositional_phrase' => 'preposition propositional_complement'
|
154
|
-
rule 'propositional_phrase' => 'preposition'
|
155
|
-
rule 'propositional_complement' => 'noun_phrase'
|
156
|
-
# rule 'propositional_complement' => 'simple_noun_phrase lexical_verb propositional_phrase'
|
157
|
-
rule 'propositional_complement' => 'conjunctive_prefix'
|
158
|
-
rule 'propositional_complement' => 'DemonstrativePronoun'
|
159
|
-
rule 'preposition' => 'Preposition'
|
160
|
-
rule 'preposition' => 'PrepositionOf'
|
161
|
-
end
|
162
221
|
|
163
222
|
|
164
|
-
|
165
|
-
|
223
|
+
|
224
|
+
######################
|
225
|
+
# DUMMY RULE
|
226
|
+
######################
|
227
|
+
rule 'dummy' => "ConjunctivePronoun RelativePronoun"
|
228
|
+
end
|
166
229
|
|
167
230
|
# And now build the grammar...
|
168
231
|
ZenlishGrammar = builder.grammar
|
@@ -18,13 +18,13 @@ module Zenlish
|
|
18
18
|
aLexicon.add_terminal(WClasses::Adjective.new.freeze)
|
19
19
|
aLexicon.add_terminal(WClasses::Adverb.new.freeze)
|
20
20
|
aLexicon.add_terminal(WClasses::AdverbNot.new.freeze)
|
21
|
-
aLexicon.add_terminal(WClasses::AdverbThere.new.freeze)
|
22
21
|
aLexicon.add_terminal(WClasses::AuxiliaryBe.new.freeze)
|
23
22
|
aLexicon.add_terminal(WClasses::AuxiliaryDo.new.freeze)
|
24
23
|
aLexicon.add_terminal(WClasses::Cardinal.new.freeze)
|
25
24
|
aLexicon.add_terminal(WClasses::CommonNoun.new.freeze)
|
26
25
|
aLexicon.add_terminal(WClasses::ComparativeParticle.new.freeze)
|
27
26
|
aLexicon.add_terminal(WClasses::DefiniteArticle.new.freeze)
|
27
|
+
aLexicon.add_terminal(WClasses::ExistentialThere.new.freeze)
|
28
28
|
aLexicon.add_terminal(WClasses::IndefiniteArticle.new.freeze)
|
29
29
|
aLexicon.add_terminal(WClasses::DegreeAdverb.new.freeze)
|
30
30
|
aLexicon.add_terminal(WClasses::DemonstrativeDeterminer.new.freeze)
|
@@ -4,17 +4,46 @@ require_relative '../lang/zenlish_grammar'
|
|
4
4
|
|
5
5
|
module Zenlish
|
6
6
|
class ZParser
|
7
|
+
# @!attribute [r] engine
|
8
|
+
# @return [Rley::Engine] Facade object of Rley library
|
7
9
|
attr_reader(:engine)
|
8
10
|
|
9
11
|
def initialize
|
10
12
|
# Create a Rley facade object
|
11
|
-
@engine = Rley::Engine.new
|
13
|
+
@engine = Rley::Engine.new do |config|
|
14
|
+
config.diagnose = true
|
15
|
+
end
|
12
16
|
|
13
17
|
# Step 1. Load Zenlish grammar
|
14
18
|
@engine.use_grammar(ZenlishGrammar)
|
15
19
|
end
|
16
20
|
|
21
|
+
# Parse the sequence of words into a parse tree.
|
22
|
+
# @raise [StandardError] Fails when the parse is ambiguous.
|
23
|
+
# @return [Rley::PTree;;ParseTree] the resulting parse tree.
|
17
24
|
def parse(tokenSeq)
|
25
|
+
result = earley_parse(tokenSeq)
|
26
|
+
|
27
|
+
# Convert into a parse tree
|
28
|
+
engine.to_ptree(result)
|
29
|
+
end
|
30
|
+
|
31
|
+
alias to_ptree parse
|
32
|
+
|
33
|
+
# Parse the sequence of words into a parse forest.
|
34
|
+
# Parse forests are needed when dealing with ambiguous input.
|
35
|
+
# @return [Rley::SPPF::ParseForest] the resulting parse forest.
|
36
|
+
def to_pforest(tokenSeq)
|
37
|
+
result = earley_parse(tokenSeq)
|
38
|
+
# puts result
|
39
|
+
|
40
|
+
# Convert into a parse forest
|
41
|
+
engine.to_pforest(result)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def earley_parse(tokenSeq)
|
18
47
|
result = engine.parse(tokenSeq)
|
19
48
|
|
20
49
|
unless result.success?
|
@@ -24,7 +53,7 @@ module Zenlish
|
|
24
53
|
raise StandardError, line1 + line2
|
25
54
|
end
|
26
55
|
|
27
|
-
|
56
|
+
result
|
28
57
|
end
|
29
58
|
end # class
|
30
59
|
end # module
|
data/lib/zenlish/version.rb
CHANGED
@@ -4,13 +4,14 @@
|
|
4
4
|
require_relative 'adjective'
|
5
5
|
require_relative 'adverb'
|
6
6
|
require_relative 'adverb_not'
|
7
|
-
require_relative 'adverb_there'
|
8
7
|
require_relative 'auxiliary_be'
|
9
8
|
require_relative 'auxiliary_do'
|
10
9
|
require_relative 'cardinal'
|
11
10
|
require_relative 'comparative_particle'
|
12
11
|
require_relative 'common_noun'
|
13
12
|
require_relative 'degree_adverb'
|
13
|
+
require_relative 'definite_article'
|
14
|
+
require_relative 'existential_there'
|
14
15
|
require_relative 'pronoun'
|
15
16
|
require_relative 'proper_noun'
|
16
17
|
require_relative 'irregular_verb'
|
@@ -20,7 +21,6 @@ require_relative 'irregular_verb_have'
|
|
20
21
|
require_relative 'irregular_verb_know'
|
21
22
|
require_relative 'irregular_verb_say'
|
22
23
|
require_relative 'irregular_verb_think'
|
23
|
-
require_relative 'definite_article'
|
24
24
|
require_relative 'demonstrative_determiner'
|
25
25
|
require_relative 'conjunctive_pronoun'
|
26
26
|
require_relative 'demonstrative_pronoun'
|