lib/zenlish/lang/zenlish_grammar.rb in zenlish-0.1.14 vs lib/zenlish/lang/zenlish_grammar.rb in zenlish-0.1.15
- old
+ new
@@ -8,30 +8,28 @@
# Define a grammar for a highly English-like language
builder = Rley::Syntax::GrammarBuilder.new do
add_terminals(*Zenlish::Lang::Dictionary.terminals)
rule 'zenlish' => 'prose'
-
- # Temporary limitation: from 1 to 3 sentences
rule 'prose' => 'sentence'
- rule 'prose' => 'sentence sentence'
- rule 'prose' => 'sentence sentence sentence'
+ rule 'prose' => 'prose sentence'
rule 'sentence' => 'simple_sentence Period'
rule 'sentence' => 'complex_sentence Period'
rule 'simple_sentence' => 'declarative_simple_sentence'
# Case of dropped ´that´ conjunction
- rule 'complex_sentence' => 'main_clause subordination_marker dependent_clause'
- rule 'complex_sentence' => 'main_clause Comma subordination_marker dependent_clause'
- rule 'complex_sentence' => 'subordination_marker dependent_clause Comma main_clause'
- rule 'complex_sentence' => 'subordination_marker dependent_clause Comma LinkingAdverb main_clause'
+ rule 'complex_sentence' => 'main_clause subordinated_clause'
+ rule 'complex_sentence' => 'main_clause Comma subordinated_clause'
+ rule 'complex_sentence' => 'subordinated_clause Comma main_clause'
+ rule 'complex_sentence' => 'subordinated_clause Comma LinkingAdverb main_clause'
rule 'subordination_marker' => 'SubordinatingConjunction'
rule 'subordination_marker' => 'SubordinatingConjunction PrepositionOf'
rule 'declarative_simple_sentence' => 'affirmative_sentence'
rule 'declarative_simple_sentence' => 'negative_sentence'
rule 'main_clause' => 'simple_sentence'
+ rule 'subordinated_clause' => 'subordination_marker dependent_clause'
rule 'dependent_clause' => 'simple_sentence'
rule 'dependent_clause' => 'DemonstrativePronoun'
rule 'affirmative_sentence' => 'noun_phrase verb_phrase'
rule 'affirmative_sentence' => 'propositional_phrase Comma noun_phrase verb_phrase'
rule 'affirmative_sentence' => 'AdverbThere IrregularVerbBe verb_be_complement'
@@ -48,18 +46,20 @@
rule 'negative_sentence' => 'DemonstrativePronoun negative_verb_phrase'
rule 'negative_sentence' => 'conjunctive_prefix negative_verb_phrase'
rule 'conjunctive_prefix' => 'ConjunctivePronoun noun_phrase verb_phrase'
rule 'noun_phrase' => 'simple_noun_phrase'
rule 'noun_phrase' => 'compound_noun_phrase'
+ # TODO: improve treatment of 'one very short time'
rule 'simple_noun_phrase' => 'nominal'
rule 'simple_noun_phrase' => 'determiner nominal'
rule 'simple_noun_phrase' => 'numeral nominal'
rule 'simple_noun_phrase' => 'determiner numeral nominal'
rule 'simple_noun_phrase' => 'ProperNoun'
rule 'simple_noun_phrase' => 'PersonalPronoun'
rule 'simple_noun_phrase' => 'IndefinitePronoun'
rule 'simple_noun_phrase' => 'IndefinitePronoun Adjective'
+ rule 'simple_noun_phrase' => 'DemonstrativeDeterminer IndefinitePronoun'
rule 'simple_noun_phrase' => 'simple_noun_phrase simple_noun_phrase verb_phrase'
# Case: (all|many|some) one of (this|these)
rule 'simple_noun_phrase' => 'subset_of noun_phrase'
@@ -73,46 +73,56 @@
rule 'numeral_of' => 'numeral PrepositionOf DemonstrativeDeterminer'
rule 'numeral_of' => 'numeral PrepositionOf DefiniteArticle'
rule 'subset_of' => 'IndefiniteQuantifier PrepositionOf DemonstrativeDeterminer'
rule 'nominal' => 'CommonNoun'
rule 'nominal' => 'Adjective CommonNoun'
+ rule 'nominal' => 'DegreeAdverb Adjective CommonNoun'
rule 'determiner' => 'determiner single_determiner'
rule 'determiner' => 'single_determiner'
rule 'single_determiner' => 'DemonstrativeDeterminer'
rule 'single_determiner' => 'DefiniteArticle'
rule 'single_determiner' => 'IndefiniteArticle'
rule 'single_determiner' => 'IndefiniteQuantifier'
rule 'verb_phrase' => 'verb_group'
rule 'verb_phrase' => 'verb_group verb_complement'
rule 'verb_phrase' => 'RegularVerb propositional_phrase'
rule 'verb_phrase' => 'RegularVerbWant Preposition verb_group'
+ rule 'verb_phrase' => 'RegularVerbWant Preposition IrregularVerbKnow identifying_clause'
rule 'verb_phrase' => 'RegularVerbWant Preposition verb_group noun_phrase'
rule 'verb_phrase' => 'RegularVerbWant simple_noun_phrase Preposition verb_group noun_phrase'
rule 'verb_phrase' => 'IrregularVerbDo DemonstrativePronoun'
rule 'verb_phrase' => 'IrregularVerbDo DemonstrativePronoun propositional_phrase'
rule 'verb_phrase' => 'ModalVerbCan verb_group DemonstrativePronoun'
rule 'verb_phrase' => 'IrregularVerbBe verb_be_complement'
+ rule 'verb_phrase' => 'IrregularVerbKnow identifying_clause'
# Cover case where ´that´ conjunction is dropped.
rule 'verb_phrase' => 'mental_verb dependent_clause'
+ rule 'verb_phrase' => 'mental_verb noun_phrase Adverb negative_verb_phrase'
rule 'verb_phrase' => 'IrregularVerbSay DemonstrativePronoun Preposition noun_phrase'
+ rule 'verb_phrase' => 'IrregularVerbSay DemonstrativePronoun subordinated_clause'
rule 'verb_phrase' => 'IrregularVerbSay Colon affirmative_sentence'
rule 'verb_phrase' => 'IrregularVerbSay Colon Quote affirmative_sentence Period Quote'
rule 'verb_phrase' => 'IrregularVerbSay Preposition noun_phrase Colon Quote affirmative_sentence Period Quote'
rule 'mental_verb' => 'IrregularVerbKnow'
rule 'mental_verb' => 'IrregularVerbThink'
rule 'verb_complement' => 'noun_phrase'
- rule 'verb_complement' => 'adverb_phrase'
rule 'verb_complement' => 'noun_phrase adverb_phrase'
+ rule 'verb_complement' => 'adverb_phrase'
+ rule 'verb_complement' => 'adverb_phrase nominal'
# perception verb (hear, see, watch, notice, ...): verb + object + infinitive
rule 'verb_complement' => 'simple_noun_phrase lexical_verb'
rule 'verb_complement' => 'Adjective propositional_phrase'
+ rule 'verb_complement' => 'Preposition simple_noun_phrase lexical_verb'
+ rule 'verb_complement' => 'Preposition IndefinitePronoun'
rule 'verb_be_complement' => 'noun_phrase'
rule 'verb_be_complement' => 'adjective_as_complement' # Specific to be as lexical verb
rule 'verb_be_complement' => 'propositional_phrase'
rule 'verb_be_complement' => 'noun_phrase adverb_phrase'
+ rule 'identifying_clause' => 'RelativePronoun verb_phrase'
+
rule 'adjective_as_complement' => 'DegreeAdverb Adjective'
rule 'adjective_as_complement' => 'Adjective'
rule 'adjective_as_complement' => 'Adjective comparative_clause'
rule 'negative_verb_phrase' => 'IrregularVerbBe AdverbNot verb_be_complement'
rule 'negative_verb_phrase' => 'AuxiliaryDo AdverbNot verb_phrase'
@@ -134,15 +144,19 @@
rule 'comparative_clause' => 'comparative_start noun_phrase'
rule 'comparative_clause' => 'comparative_start affirmative_sentence'
rule 'comparative_clause' => 'comparative_start DefiniteArticle Adjective Cardinal'
rule 'comparative_start' => 'PrepositionThan'
rule 'comparative_start' => 'ComparativeParticle'
- rule 'adverb_phrase' => 'Adverb'
- rule 'adverb_phrase' => 'Adverb Adverb' # 'here now'
- rule 'adverb_phrase' => 'Adverb propositional_phrase'
+ rule 'adverb_phrase' => 'adverbial_marker'
+ rule 'adverb_phrase' => 'adverbial_marker propositional_phrase'
+ rule 'adverbial_marker' => 'Adverb'
+ rule 'adverbial_marker' => 'Adverb Adverb' # 'here now', 'much more'
rule 'propositional_phrase' => 'preposition propositional_complement'
rule 'propositional_phrase' => 'preposition'
rule 'propositional_complement' => 'noun_phrase'
+ # rule 'propositional_complement' => 'simple_noun_phrase lexical_verb propositional_phrase'
+ rule 'propositional_complement' => 'conjunctive_prefix'
+ rule 'propositional_complement' => 'DemonstrativePronoun'
rule 'preposition' => 'Preposition'
rule 'preposition' => 'PrepositionOf'
end