zenlish 0.1.0 → 0.1.01

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 026405b993a2736b1e5c5341308aa1ffab8e77ba07dfc38d2e2344e183c466a7
4
- data.tar.gz: 795d56d6e9b9c5204678912833c5817d04fef64e56e2128ac6ad6962b349b676
3
+ metadata.gz: f528c0f3df40d32748dde807e2ce52554640228b52595f7509b7f00ca0799f7d
4
+ data.tar.gz: 5845c212c6850e767720bf2eef53e8ff4fc0cebf7eac93c77d6fe30ab70c852c
5
5
  SHA512:
6
- metadata.gz: 1bc6680bbd7f6da39d795903c4ec9b67061bfbbc409289669f37a3fa97d50f176bc634f0b6c10a6f2de54b81e5595d38fbddad0dffb9a97b555c2bd83eb68d86
7
- data.tar.gz: a3772e8100491357a0776a4a83cf039ca17d7ba01792284ad4e92d96c4666b2394815199e9681853f4b796cea6f533cab81da65b6b6756b79a5559183f22d2db
6
+ metadata.gz: ecb70f4531e577ecbb15772edc118a3fc0c4b9cd06cc7c62dbe404cc4be2cbe576465d92678fadde229414ee55ad40c068d8a5e76a34ae2726616d450211263c
7
+ data.tar.gz: 21854cf7b004a6def164ee239448a8ef0dc9a93ff4c490f9f1e505b52dc16a6080c3323a8aeeafff5ff8741d3a92eac281e891baf533b7f72531e7787b76445b
@@ -0,0 +1,25 @@
1
+ # CHANGELOG
2
+
3
+ ## [0.1.01] - 2019-10-10
4
+ __Zenlish__ can parse all the sentences in lessons 1-A, 1-B from [Learn These Words First](http://learnthesewordsfirst.com/).
5
+
6
+ ### Added
7
+ - Class `Cardinal` to represent the abstract word class for cardinal and ordinal numbers.
8
+ - Class `Cardinal` to represent the word class of cardinal numbers.
9
+ - Class `ComparativeArticle` to represent the word class of the `as` in `same as`.
10
+ - File `empty_lexion_factory.rb`: added the `Cardinal` and `ComparativeArticle` as word classes in lexicon.
11
+ - File `minimal_lexicon.rb`: new entries in lexicon `as` (from same ... as expression),
12
+ `one`, `two`, `person` , `people.`
13
+
14
+
15
+ ### Changed
16
+ - File `README.md` added Rubygems badge.
17
+ - File `zparser_spec.rb`: tests include all sentences from lesson 1-B.
18
+ - `ZenlishGrammar`: grammar refactoring and extension.
19
+
20
+
21
+ ### Fixed
22
+ - File `zenlish.gemspec`: fixed typo in a Github hyperlink.
23
+
24
+ ## [0.1.0] - 2019-10-06
25
+ Initial project commit in Github and first gem version released.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Zenlish
2
+ [![Gem Version](https://badge.fury.io/rb/zenlish.svg)](https://badge.fury.io/rb/zenlish)
2
3
 
3
4
  ### What is __Zenlish__ ?
4
5
 
@@ -15,13 +15,15 @@ module Zenlish
15
15
  private
16
16
 
17
17
  def add_word_classes(aLexicon)
18
- aLexicon.add_terminal(WClasses::CommonNoun.new)
19
- aLexicon.add_terminal(WClasses::ProperNoun.new)
20
- aLexicon.add_terminal(WClasses::IrregularVerb.new)
21
- aLexicon.add_terminal(WClasses::Adjective.new)
22
- aLexicon.add_terminal(WClasses::DefiniteArticle.new)
23
- aLexicon.add_terminal(WClasses::DemonstrativeDeterminer.new)
24
- aLexicon.add_terminal(WClasses::IndefinitePronoun.new)
18
+ aLexicon.add_terminal(WClasses::Adjective.new.freeze)
19
+ aLexicon.add_terminal(WClasses::Cardinal.new.freeze)
20
+ aLexicon.add_terminal(WClasses::CommonNoun.new.freeze)
21
+ aLexicon.add_terminal(WClasses::ComparativeParticle.new.freeze)
22
+ aLexicon.add_terminal(WClasses::DefiniteArticle.new.freeze)
23
+ aLexicon.add_terminal(WClasses::DemonstrativeDeterminer.new.freeze)
24
+ aLexicon.add_terminal(WClasses::IndefinitePronoun.new.freeze)
25
+ aLexicon.add_terminal(WClasses::IrregularVerb.new.freeze)
26
+ aLexicon.add_terminal(WClasses::ProperNoun.new.freeze)
25
27
  end
26
28
 
27
29
  def add_punctuation(aLexicon)
@@ -12,18 +12,29 @@ builder = Rley::Syntax::GrammarBuilder.new do
12
12
 
13
13
  rule 'language' => 'sentence'
14
14
  rule 'sentence' => 'simple_sentence'
15
- rule 'simple_sentence' => 'declarative_simple_sentence'
16
- rule 'declarative_simple_sentence' => 'noun_phrase verb_phrase Period'
17
- rule 'noun_phrase' => 'noun'
18
- rule 'noun' => 'ProperNoun'
19
- rule 'noun' => 'CommonNoun'
20
- rule 'verb_phrase' => 'lexical_verb complement'
15
+ rule 'simple_sentence' => 'declarative_simple_sentence Period'
16
+ rule 'declarative_simple_sentence' => 'noun_phrase verb_phrase'
17
+ rule 'noun_phrase' => 'noun_bar'
18
+ rule 'noun_phrase' => 'determiner noun_bar'
19
+ rule 'noun_phrase' => 'numeral noun_bar'
20
+ rule 'noun_phrase' => 'determiner numeral noun_bar'
21
+ rule 'noun_phrase' => 'ProperNoun'
22
+ rule 'noun_phrase' => 'IndefinitePronoun'
23
+ rule 'noun_bar' => 'CommonNoun'
24
+ rule 'noun_bar' => 'Adjective CommonNoun'
25
+ rule 'noun_bar' => 'Adjective CommonNoun comparative_clause'
26
+ rule 'determiner' => 'DemonstrativeDeterminer'
27
+ rule 'determiner' => 'DefiniteArticle'
28
+ rule 'verb_phrase' => 'lexical_verb'
29
+ rule 'verb_phrase' => 'lexical_verb noun_phrase'
21
30
  rule 'lexical_verb' => 'IrregularVerb'
22
- rule 'complement' => 'ProperNoun'
23
- rule 'complement' => 'IndefinitePronoun'
24
- rule 'complement' => 'DemonstrativeDeterminer noun'
25
- rule 'complement' => 'DefiniteArticle Adjective CommonNoun'
31
+ rule 'numeral' => 'Cardinal'
32
+ rule 'comparative_clause' => 'comparative_start noun_phrase verb_phrase'
33
+ rule 'comparative_start' => 'ComparativeParticle'
26
34
  end
27
35
 
36
+ # CGE p. 354 The order of determiners: quantifier > article or demonstrative
37
+ # or possessive > numeral > head
38
+
28
39
  # And now build the grammar...
29
40
  ZenlishGrammar = builder.grammar
@@ -1,3 +1,3 @@
1
1
  module Zenlish
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.01'
3
3
  end
@@ -2,6 +2,8 @@
2
2
  # Algorithm: load the leaf classes from hierarchy
3
3
 
4
4
  require_relative 'adjective'
5
+ require_relative 'cardinal'
6
+ require_relative 'comparative_particle'
5
7
  require_relative 'common_noun'
6
8
  require_relative 'pronoun'
7
9
  require_relative 'proper_noun'
@@ -0,0 +1,9 @@
1
+ require_relative 'numeral'
2
+
3
+ module Zenlish
4
+ module WClasses
5
+ # TODO: document
6
+ class Cardinal < Numeral
7
+ end # class
8
+ end # module
9
+ end # module
@@ -0,0 +1,10 @@
1
+ require_relative 'word_class'
2
+
3
+ module Zenlish
4
+ module WClasses
5
+ # TODO: document
6
+ # Example: 'as' in 'same ... as'
7
+ class ComparativeParticle < WordClass
8
+ end # class
9
+ end # module
10
+ end # module
@@ -0,0 +1,9 @@
1
+ require_relative 'determiner'
2
+
3
+ module Zenlish
4
+ module WClasses
5
+ # TODO: document
6
+ class Numeral < Determiner
7
+ end # class
8
+ end # module
9
+ end # module
@@ -16,69 +16,94 @@ module Zenlish
16
16
  end
17
17
  end # context
18
18
 
19
- context 'Provided services:' do
20
- def get_lexeme(aLemma)
21
- $ZenlishLexicon.get_lexeme(aLemma)
22
- end
19
+ def get_lexeme(aLemma)
20
+ $ZenlishLexicon.get_lexeme(aLemma)
21
+ end
23
22
 
24
- let(:tony) do
25
- Lex::Literal.new('Tony', $ZenlishLexicon.get_lexeme('Tony'), 0)
26
- end
27
- let(:lisa) do
28
- Lex::Literal.new('Lisa', $ZenlishLexicon.get_lexeme('Lisa'), 0)
29
- end
30
- let(:the) do
31
- Lex::Literal.new('the', $ZenlishLexicon.get_lexeme('the'), 0)
32
- end
33
- let(:other) do
34
- Lex::Literal.new('other', $ZenlishLexicon.get_lexeme('other'), 0)
35
- end
36
- let(:sees) do
37
- Lex::Literal.new('sees', $ZenlishLexicon.get_lexeme('see'), 0)
38
- end
39
- let(:dot) do
40
- Lex::Literal.new('.', $ZenlishLexicon.get_lexeme('.'), 0)
41
- end
42
- let(:something) do
43
- Lex::Literal.new('something', $ZenlishLexicon.get_lexeme('something'), 0)
44
- end
45
- let(:thing) do
46
- Lex::Literal.new('thing', $ZenlishLexicon.get_lexeme('thing'), 0)
23
+ def as ; Lex::Literal.new('as', get_lexeme('as'), 0) ; end
24
+ def lisa ; Lex::Literal.new('Lisa', get_lexeme('Lisa'), 0) ; end
25
+ def one ; Lex::Literal.new('one', get_lexeme('one'), 0) ; end
26
+ def two ; Lex::Literal.new('two', get_lexeme('two'), 0) ; end
27
+ def other ; Lex::Literal.new('other', get_lexeme('other'), 0) ; end
28
+ def people ; Lex::Literal.new('people', get_lexeme('people'), 0) ; end
29
+ def person ; Lex::Literal.new('person', get_lexeme('person'), 0) ; end
30
+ def same ; Lex::Literal.new('same', get_lexeme('same'), 0) ; end
31
+ def sees ; Lex::Literal.new('sees', get_lexeme('see'), 0) ; end
32
+ def something ; Lex::Literal.new('something', get_lexeme('something'), 0) ; end
33
+ def the ; Lex::Literal.new('the', get_lexeme('the'), 0) ; end
34
+ def thing ; Lex::Literal.new('thing', get_lexeme('thing'), 0) ; end
35
+ def things ; Lex::Literal.new('things', get_lexeme('thing'), 0) ; end
36
+ def this ; Lex::Literal.new('this', get_lexeme('this'), 0) ; end
37
+ def tony ; Lex::Literal.new('Tony', get_lexeme('Tony'), 0) ; end
38
+ def dot ; Lex::Literal.new('.', get_lexeme('.'), 0) ; end
39
+
40
+ class ZProxy
41
+ attr_reader :literal
42
+
43
+ def initialize(aTarget)
44
+ @literal = aTarget
47
45
  end
48
- let(:this) do
49
- Lex::Literal.new('this', $ZenlishLexicon.get_lexeme('this'), 0)
46
+
47
+ def method_missing(name, *args, &aBlock)
48
+ puts "#{literal.lexeme} about to receive #{name}"
49
+ $stdout.flush
50
+ literal.send(name, *args, &aBlock)
50
51
  end
52
+ end
51
53
 
52
- it 'should parse sample sentence 1-01' do
53
- # Sentence is: "Tony sees Lisa."
54
+ context 'Parsing lessons:' do
55
+ it 'should parse sample sentences from lesson 1-A' do
56
+ # Sentence 1-01: "Tony sees Lisa."
54
57
  # in absence of a tokenizer, we create a sequence of literals by hand...
58
+ # prox_tony = ZProxy.new(tony)
55
59
  literals = [tony, sees, lisa, dot]
56
60
  expect { subject.parse(literals) }.not_to raise_error
57
- end
58
61
 
59
- it 'should parse sample sentence 1-02a' do
60
- # Sentence is: "Tony sees something."
62
+ # Sentence 1-02a: "Tony sees something."
61
63
  sentence_literals = [tony, sees, something, dot]
62
64
  expect { subject.parse(sentence_literals) }.not_to raise_error
63
- end
64
65
 
65
- it 'should parse sample sentence 1-02b' do
66
- # Sentence is: "Lisa sees something"
66
+ # Sentence 1-02b: "Lisa sees something."
67
67
  sentence_literals = [lisa, sees, something, dot]
68
68
  expect { subject.parse(sentence_literals) }.not_to raise_error
69
- end
70
69
 
71
- it 'should parse sample sentence 1-03' do
72
- # Sentence is: "Tony sees this thing."
70
+ # Sentence 1-03: "Tony sees this thing."
73
71
  sentence_literals = [tony, sees, this, thing, dot]
74
72
  expect { subject.parse(sentence_literals) }.not_to raise_error
75
- end
76
73
 
77
- it 'should parse sample sentence 1-04' do
78
- # Sentence is: "Lisa sees the other thing."
74
+ # Sentence 1-04: "Lisa sees the other thing."
79
75
  sentence_literals = [lisa, sees, the, other, thing, dot]
80
76
  expect { subject.parse(sentence_literals) }.not_to raise_error
81
77
  end
78
+
79
+ it 'should parse sample sentences from lesson 1-B' do
80
+ # Sentence 1-05a: "Lisa sees the same thing."
81
+ literals = [lisa, sees, the, same, thing, dot]
82
+ expect { subject.parse(literals) }.not_to raise_error
83
+
84
+ # Sentence 1-05b: "Lisa sees the same thing as Tony sees."
85
+ literals = [lisa, sees, the, same, thing, as, tony, sees, dot]
86
+ # same is an adjective of equality comparison
87
+ # as is part of same ... as combination
88
+ # it introduces a comparative clause
89
+ expect { subject.parse(literals) }.not_to raise_error
90
+
91
+ # Sentence 1-06: "Tony sees one thing."
92
+ literals = [tony, sees, one, thing, dot]
93
+ expect { subject.parse(literals) }.not_to raise_error
94
+
95
+ # Sentence 1-07: "Lisa sees two things."
96
+ literals = [lisa, sees, two, things, dot]
97
+ expect { subject.parse(literals) }.not_to raise_error
98
+
99
+ # Sentence 1-08a: "Tony sees one person."
100
+ literals = [tony, sees, one, person, dot]
101
+ expect { subject.parse(literals) }.not_to raise_error
102
+
103
+ # Sentence 1-08b: "Lisa sees two people."
104
+ literals = [lisa, sees, two, people, dot]
105
+ expect { subject.parse(literals) }.not_to raise_error
106
+ end
82
107
  end # context
83
108
  end # describe
84
109
  end # module
@@ -3,11 +3,6 @@ require_relative '../../../lib/zenlish/lex/lexical_entry'
3
3
  require_relative '../../../lib/zenlish/lex/lexeme'
4
4
  require_relative '../../../lib/zenlish/lex/lexicon'
5
5
 
6
- def add_entry(aLemma, aWordClass)
7
- entry = Zenlish::Lex::LexicalEntry.new(aLemma)
8
- lexeme = Zenlish::Lex::Lexeme.new(aWordClass, entry)
9
- $ZenlishLexicon.add_entry(entry)
10
- end
11
6
 
12
7
  common_noun = $ZenlishLexicon.name2terminal['CommonNoun']
13
8
  adjective = $ZenlishLexicon.name2terminal['Adjective']
@@ -15,16 +10,32 @@ proper_noun = $ZenlishLexicon.name2terminal['ProperNoun']
15
10
  irregular_verb = $ZenlishLexicon.name2terminal['IrregularVerb']
16
11
  indefinite_pronoun = $ZenlishLexicon.name2terminal['IndefinitePronoun']
17
12
  demonstrative_determiner = $ZenlishLexicon.name2terminal['DemonstrativeDeterminer']
18
- definite_article = $ZenlishLexicon.name2terminal['DefiniteArticle']
13
+ definite_article = $ZenlishLexicon.name2terminal['DefiniteArticle']
14
+ cardinal = $ZenlishLexicon.name2terminal['Cardinal']
15
+ comparative_particle = $ZenlishLexicon.name2terminal['ComparativeParticle']
19
16
  dot = $ZenlishLexicon.name2terminal['Period']
20
17
 
18
+ def add_entry(aLemma, aWordClass)
19
+ entry = Zenlish::Lex::LexicalEntry.new(aLemma)
20
+ raise StandardError, 'Unregistered word class' unless aWordClass
21
+ lexeme = Zenlish::Lex::Lexeme.new(aWordClass, entry).freeze
22
+ $ZenlishLexicon.add_entry(entry.freeze)
23
+ end
24
+
25
+ # Our minimalistic lexicon
26
+ add_entry('as', comparative_particle)
21
27
  add_entry('Lisa', proper_noun)
28
+ add_entry('one', cardinal)
22
29
  add_entry('other', adjective)
30
+ add_entry('people', common_noun)
31
+ add_entry('person', common_noun)
32
+ add_entry('same', adjective)
23
33
  add_entry('see', irregular_verb)
24
34
  add_entry('something', indefinite_pronoun)
25
35
  add_entry('the', definite_article)
26
36
  add_entry('thing', common_noun)
27
37
  add_entry('this', demonstrative_determiner)
28
38
  add_entry('Tony', proper_noun)
39
+ add_entry('two', cardinal)
29
40
 
30
41
  add_entry('.', dot)
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
42
42
 
43
43
  spec.summary = %q{A toolkit for the Zenlish language (a simplified English language).}
44
44
  spec.description = %q{A toolkit for the Zenlish language (a simplified English language).}
45
- spec.homepage = "https://github.com/famished-tiger/zenlish."
45
+ spec.homepage = "https://github.com/famished-tiger/zenlish"
46
46
  spec.license = 'MIT'
47
47
 
48
48
  spec.bindir = 'exe'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zenlish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.01
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-06 00:00:00.000000000 Z
11
+ date: 2019-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley
@@ -76,6 +76,7 @@ extra_rdoc_files:
76
76
  files:
77
77
  - ".rspec"
78
78
  - ".yardopts"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md
@@ -93,7 +94,9 @@ files:
93
94
  - lib/zenlish/wclasses/adjective.rb
94
95
  - lib/zenlish/wclasses/all_word_classes.rb
95
96
  - lib/zenlish/wclasses/article.rb
97
+ - lib/zenlish/wclasses/cardinal.rb
96
98
  - lib/zenlish/wclasses/common_noun.rb
99
+ - lib/zenlish/wclasses/comparative_particle.rb
97
100
  - lib/zenlish/wclasses/definite_article.rb
98
101
  - lib/zenlish/wclasses/demonstrative_determiner.rb
99
102
  - lib/zenlish/wclasses/determiner.rb
@@ -101,6 +104,7 @@ files:
101
104
  - lib/zenlish/wclasses/irregular_verb.rb
102
105
  - lib/zenlish/wclasses/lexical_verb.rb
103
106
  - lib/zenlish/wclasses/noun.rb
107
+ - lib/zenlish/wclasses/numeral.rb
104
108
  - lib/zenlish/wclasses/pronoun.rb
105
109
  - lib/zenlish/wclasses/proper_noun.rb
106
110
  - lib/zenlish/wclasses/test_hierarchy.rb
@@ -120,7 +124,7 @@ files:
120
124
  - spec/zenlish/wclasses/proper_noun_spec.rb
121
125
  - spec/zenlish_spec.rb
122
126
  - zenlish.gemspec
123
- homepage: https://github.com/famished-tiger/zenlish.
127
+ homepage: https://github.com/famished-tiger/zenlish
124
128
  licenses:
125
129
  - MIT
126
130
  metadata: {}