zenlish 0.1.15 → 0.1.16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bae8e629cfa98ad394a1d883934396b1c4241f53e831387d870d51b84c25d863
4
- data.tar.gz: c5b3fdb5fb152967aa9fcaf296734336531ff8e855fd94ffbf9fb49f369df239
3
+ metadata.gz: 0b03b18d2aa554c1fa12c98c4fff5dce6a88de55055ae7f43e43a4b4db6b379b
4
+ data.tar.gz: 8f6a59c3ad405d4959f03b3cf6f818c7158fd2474df8eb86638f2a0563925209
5
5
  SHA512:
6
- metadata.gz: 11dce85cc695db9a7a5a374b4a8caa4b022a6914b7133adfe3b1a632e99619712169aed83f4a162331f13a6338505e0bf15462feae1102a2f9db13a0feb0ed85
7
- data.tar.gz: 4fddca277e63fd1e022704999b7500c2dcbf8a2d1fb4c45bc721108d84914097e9b42055c3d930f2fa481503274798a5685931e135aa3832e76f72a4f82ccbbb
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 | 89 |
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 | 129 |
43
+ | Number of production rules in grammar | 131 |
43
44
  | Number of lessons covered | 15 |
44
- | Number of sentences in spec files | 184 |
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', 'AdverbThere')
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
- rule 'complex_sentence' => 'subordinated_clause Comma LinkingAdverb main_clause'
25
- rule 'subordination_marker' => 'SubordinatingConjunction'
26
- rule 'subordination_marker' => 'SubordinatingConjunction PrepositionOf'
27
- rule 'declarative_simple_sentence' => 'affirmative_sentence'
28
- rule 'declarative_simple_sentence' => 'negative_sentence'
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' => 'DemonstrativePronoun'
33
- rule 'affirmative_sentence' => 'noun_phrase verb_phrase'
34
- rule 'affirmative_sentence' => 'propositional_phrase Comma noun_phrase verb_phrase'
35
- rule 'affirmative_sentence' => 'AdverbThere IrregularVerbBe verb_be_complement'
36
- rule 'affirmative_sentence' => 'numeral_of IrregularVerbBe verb_be_complement'
37
- rule 'affirmative_sentence' => 'DemonstrativePronoun IrregularVerbBe verb_be_complement'
38
- rule 'affirmative_sentence' => 'DemonstrativePronoun IrregularVerb verb_complement'
39
- rule 'affirmative_sentence' => 'conjunctive_prefix IrregularVerbBe verb_be_complement'
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 'noun_phrase' => 'simple_noun_phrase'
50
- rule 'noun_phrase' => 'compound_noun_phrase'
51
- # TODO: improve treatment of 'one very short time'
52
- rule 'simple_noun_phrase' => 'nominal'
53
- rule 'simple_noun_phrase' => 'determiner nominal'
54
- rule 'simple_noun_phrase' => 'numeral nominal'
55
- rule 'simple_noun_phrase' => 'determiner numeral nominal'
56
- rule 'simple_noun_phrase' => 'ProperNoun'
57
- rule 'simple_noun_phrase' => 'PersonalPronoun'
58
- rule 'simple_noun_phrase' => 'IndefinitePronoun'
59
- rule 'simple_noun_phrase' => 'IndefinitePronoun Adjective'
60
- rule 'simple_noun_phrase' => 'DemonstrativeDeterminer IndefinitePronoun'
61
- rule 'simple_noun_phrase' => 'simple_noun_phrase simple_noun_phrase verb_phrase'
62
-
63
- # Case: (all|many|some) one of (this|these)
64
- rule 'simple_noun_phrase' => 'subset_of noun_phrase'
65
-
66
- # CGE p.359, 360: <numeral> of + definite noun phrase
67
- rule 'simple_noun_phrase' => 'numeral_of noun_phrase'
68
-
69
- rule 'compound_noun_phrase' => 'simple_noun_phrase propositional_phrase'
70
- rule 'compound_noun_phrase' => 'simple_noun_phrase comparative_clause'
71
-
72
- # <numeral> of this/these...
73
- rule 'numeral_of' => 'numeral PrepositionOf DemonstrativeDeterminer'
74
- rule 'numeral_of' => 'numeral PrepositionOf DefiniteArticle'
75
- rule 'subset_of' => 'IndefiniteQuantifier PrepositionOf DemonstrativeDeterminer'
76
- rule 'nominal' => 'CommonNoun'
77
- rule 'nominal' => 'Adjective CommonNoun'
78
- rule 'nominal' => 'DegreeAdverb Adjective CommonNoun'
79
- rule 'determiner' => 'determiner single_determiner'
80
- rule 'determiner' => 'single_determiner'
81
- rule 'single_determiner' => 'DemonstrativeDeterminer'
82
- rule 'single_determiner' => 'DefiniteArticle'
83
- rule 'single_determiner' => 'IndefiniteArticle'
84
- rule 'single_determiner' => 'IndefiniteQuantifier'
85
- rule 'verb_phrase' => 'verb_group'
86
- rule 'verb_phrase' => 'verb_group verb_complement'
87
- rule 'verb_phrase' => 'RegularVerb propositional_phrase'
88
- rule 'verb_phrase' => 'RegularVerbWant Preposition verb_group'
89
- rule 'verb_phrase' => 'RegularVerbWant Preposition IrregularVerbKnow identifying_clause'
90
- rule 'verb_phrase' => 'RegularVerbWant Preposition verb_group noun_phrase'
91
- rule 'verb_phrase' => 'RegularVerbWant simple_noun_phrase Preposition verb_group noun_phrase'
92
- rule 'verb_phrase' => 'IrregularVerbDo DemonstrativePronoun'
93
- rule 'verb_phrase' => 'IrregularVerbDo DemonstrativePronoun propositional_phrase'
94
- rule 'verb_phrase' => 'ModalVerbCan verb_group DemonstrativePronoun'
95
- rule 'verb_phrase' => 'IrregularVerbBe verb_be_complement'
96
- rule 'verb_phrase' => 'IrregularVerbKnow identifying_clause'
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 'verb_phrase' => 'mental_verb dependent_clause'
100
- rule 'verb_phrase' => 'mental_verb noun_phrase Adverb negative_verb_phrase'
101
- rule 'verb_phrase' => 'IrregularVerbSay DemonstrativePronoun Preposition noun_phrase'
102
- rule 'verb_phrase' => 'IrregularVerbSay DemonstrativePronoun subordinated_clause'
103
- rule 'verb_phrase' => 'IrregularVerbSay Colon affirmative_sentence'
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
- # CGE p. 354 The order of determiners: quantifier > article or demonstrative
165
- # or possessive > numeral > head
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
- return engine.to_ptree(result)
56
+ result
28
57
  end
29
58
  end # class
30
59
  end # module
@@ -1,3 +1,3 @@
1
1
  module Zenlish
2
- VERSION = '0.1.15'
2
+ VERSION = '0.1.16'
3
3
  end
@@ -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'
@@ -0,0 +1,9 @@
1
+ require_relative 'pronoun'
2
+
3
+ module Zenlish
4
+ module WClasses
5
+ # Represents the expletive there (there is...)
6
+ class ExistentialThere < Pronoun
7
+ end # class
8
+ end # module
9
+ end # module