zenlish 0.2.05 → 0.2.07

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.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +228 -0
  3. data/CHANGELOG.md +19 -0
  4. data/Gemfile +5 -3
  5. data/LICENSE.txt +1 -1
  6. data/Rakefile +5 -3
  7. data/lib/zenlish/feature/boolean_domain.rb +6 -4
  8. data/lib/zenlish/feature/boolean_value.rb +3 -2
  9. data/lib/zenlish/feature/enumeration_domain.rb +5 -2
  10. data/lib/zenlish/feature/feature.rb +9 -7
  11. data/lib/zenlish/feature/feature_def.rb +9 -6
  12. data/lib/zenlish/feature/feature_domain.rb +4 -2
  13. data/lib/zenlish/feature/feature_struct.rb +3 -1
  14. data/lib/zenlish/feature/feature_struct_def.rb +5 -3
  15. data/lib/zenlish/feature/feature_struct_def_bearer.rb +6 -4
  16. data/lib/zenlish/feature/feature_value.rb +4 -2
  17. data/lib/zenlish/feature/identifier_domain.rb +5 -3
  18. data/lib/zenlish/feature/identifier_value.rb +3 -2
  19. data/lib/zenlish/feature/symbol_value.rb +3 -1
  20. data/lib/zenlish/inflect/atomic_o_expression.rb +2 -1
  21. data/lib/zenlish/inflect/composite_o_expression.rb +3 -1
  22. data/lib/zenlish/inflect/concatenation.rb +3 -2
  23. data/lib/zenlish/inflect/equals_literal.rb +3 -1
  24. data/lib/zenlish/inflect/feature_heading.rb +2 -5
  25. data/lib/zenlish/inflect/formal_argument.rb +3 -1
  26. data/lib/zenlish/inflect/function_call.rb +4 -1
  27. data/lib/zenlish/inflect/heading.rb +2 -0
  28. data/lib/zenlish/inflect/inflection_rule.rb +2 -0
  29. data/lib/zenlish/inflect/inflection_table.rb +6 -4
  30. data/lib/zenlish/inflect/inflection_table_builder.rb +21 -18
  31. data/lib/zenlish/inflect/input_asis.rb +3 -0
  32. data/lib/zenlish/inflect/input_expression.rb +4 -2
  33. data/lib/zenlish/inflect/literal_asis.rb +4 -1
  34. data/lib/zenlish/inflect/matches_pattern.rb +2 -0
  35. data/lib/zenlish/inflect/membership.rb +2 -0
  36. data/lib/zenlish/inflect/method_heading.rb +3 -6
  37. data/lib/zenlish/inflect/not_equals_literal.rb +2 -0
  38. data/lib/zenlish/inflect/nullary_input_expression.rb +3 -1
  39. data/lib/zenlish/inflect/output_expression.rb +6 -0
  40. data/lib/zenlish/inflect/substitution.rb +3 -1
  41. data/lib/zenlish/inflect/unary_input_expression.rb +4 -1
  42. data/lib/zenlish/inflect/unconditionally_true.rb +4 -2
  43. data/lib/zenlish/lang/dictionary.rb +19 -16
  44. data/lib/zenlish/lang/lemmatizer.rb +40 -0
  45. data/lib/zenlish/lang/zenlish_grammar.rb +6 -4
  46. data/lib/zenlish/lex/empty_lexicon_factory.rb +3 -2
  47. data/lib/zenlish/lex/lexeme.rb +6 -4
  48. data/lib/zenlish/lex/lexical_entry.rb +6 -4
  49. data/lib/zenlish/lex/lexicon.rb +4 -3
  50. data/lib/zenlish/lex/literal.rb +3 -1
  51. data/lib/zenlish/lexer/lexer.rb +144 -0
  52. data/lib/zenlish/trie/base_trie_node.rb +27 -0
  53. data/lib/zenlish/trie/trie.rb +132 -0
  54. data/lib/zenlish/trie/trie_node.rb +21 -0
  55. data/lib/zenlish/trie/trie_root.rb +10 -0
  56. data/lib/zenlish/version.rb +3 -1
  57. data/lib/zenlish/wclasses/adjective.rb +4 -2
  58. data/lib/zenlish/wclasses/adverb.rb +3 -1
  59. data/lib/zenlish/wclasses/adverb_maybe.rb +3 -1
  60. data/lib/zenlish/wclasses/adverb_not.rb +2 -0
  61. data/lib/zenlish/wclasses/all_word_classes.rb +3 -1
  62. data/lib/zenlish/wclasses/article.rb +2 -0
  63. data/lib/zenlish/wclasses/auxiliary.rb +2 -0
  64. data/lib/zenlish/wclasses/auxiliary_be.rb +7 -6
  65. data/lib/zenlish/wclasses/auxiliary_do.rb +6 -5
  66. data/lib/zenlish/wclasses/cardinal.rb +3 -1
  67. data/lib/zenlish/wclasses/common_noun.rb +2 -0
  68. data/lib/zenlish/wclasses/comparative_particle.rb +5 -3
  69. data/lib/zenlish/wclasses/conjunction.rb +2 -0
  70. data/lib/zenlish/wclasses/conjunctive_pronoun.rb +2 -0
  71. data/lib/zenlish/wclasses/coordinator.rb +4 -2
  72. data/lib/zenlish/wclasses/definite_article.rb +2 -0
  73. data/lib/zenlish/wclasses/degree_adverb.rb +2 -0
  74. data/lib/zenlish/wclasses/demonstrative_determiner.rb +6 -4
  75. data/lib/zenlish/wclasses/demonstrative_pronoun.rb +2 -0
  76. data/lib/zenlish/wclasses/determiner.rb +3 -1
  77. data/lib/zenlish/wclasses/distributive_determiner.rb +2 -0
  78. data/lib/zenlish/wclasses/existential_there.rb +2 -0
  79. data/lib/zenlish/wclasses/fronting_quantifier.rb +3 -1
  80. data/lib/zenlish/wclasses/indefinite_article.rb +2 -0
  81. data/lib/zenlish/wclasses/indefinite_pronoun.rb +3 -1
  82. data/lib/zenlish/wclasses/irregular_linking_verb.rb +3 -1
  83. data/lib/zenlish/wclasses/irregular_verb.rb +13 -15
  84. data/lib/zenlish/wclasses/irregular_verb_be.rb +8 -7
  85. data/lib/zenlish/wclasses/irregular_verb_can.rb +8 -7
  86. data/lib/zenlish/wclasses/irregular_verb_do.rb +7 -6
  87. data/lib/zenlish/wclasses/irregular_verb_extension.rb +8 -7
  88. data/lib/zenlish/wclasses/irregular_verb_have.rb +12 -11
  89. data/lib/zenlish/wclasses/irregular_verb_know.rb +3 -1
  90. data/lib/zenlish/wclasses/irregular_verb_say.rb +3 -1
  91. data/lib/zenlish/wclasses/irregular_verb_think.rb +3 -1
  92. data/lib/zenlish/wclasses/lexical_verb.rb +3 -4
  93. data/lib/zenlish/wclasses/linking_adverb.rb +2 -0
  94. data/lib/zenlish/wclasses/modal_verb_can.rb +7 -5
  95. data/lib/zenlish/wclasses/noun.rb +4 -2
  96. data/lib/zenlish/wclasses/numeral.rb +2 -0
  97. data/lib/zenlish/wclasses/personal_pronoun.rb +8 -6
  98. data/lib/zenlish/wclasses/possessive_determiner.rb +13 -12
  99. data/lib/zenlish/wclasses/preposition.rb +3 -1
  100. data/lib/zenlish/wclasses/preposition_of.rb +2 -0
  101. data/lib/zenlish/wclasses/preposition_than.rb +2 -0
  102. data/lib/zenlish/wclasses/pronoun.rb +3 -1
  103. data/lib/zenlish/wclasses/proper_noun.rb +10 -8
  104. data/lib/zenlish/wclasses/quantifier.rb +3 -1
  105. data/lib/zenlish/wclasses/regular_verb.rb +9 -9
  106. data/lib/zenlish/wclasses/regular_verb_want.rb +4 -2
  107. data/lib/zenlish/wclasses/relative_pronoun.rb +4 -2
  108. data/lib/zenlish/wclasses/subordinating_conjunction.rb +7 -5
  109. data/lib/zenlish/wclasses/verb.rb +5 -3
  110. data/lib/zenlish/wclasses/word_class.rb +7 -5
  111. data/lib/zenlish.rb +3 -3
  112. data/spec/spec_helper.rb +3 -1
  113. data/spec/zenlish/feature/boolean_domain_spec.rb +16 -16
  114. data/spec/zenlish/feature/boolean_value_spec.rb +7 -6
  115. data/spec/zenlish/feature/enumeration_domain_spec.rb +21 -21
  116. data/spec/zenlish/feature/feature_def_spec.rb +15 -14
  117. data/spec/zenlish/feature/feature_spec.rb +17 -17
  118. data/spec/zenlish/feature/feature_struct_def_bearer_spec.rb +23 -21
  119. data/spec/zenlish/feature/feature_struct_def_spec.rb +26 -25
  120. data/spec/zenlish/feature/identifier_domain_spec.rb +15 -15
  121. data/spec/zenlish/feature/identifier_value_spec.rb +10 -9
  122. data/spec/zenlish/feature/symbol_value_spec.rb +9 -8
  123. data/spec/zenlish/inflect/concatenation_spec.rb +14 -14
  124. data/spec/zenlish/inflect/equals_literal_spec.rb +17 -16
  125. data/spec/zenlish/inflect/feature_heading_spec.rb +22 -21
  126. data/spec/zenlish/inflect/formal_argument_spec.rb +7 -7
  127. data/spec/zenlish/inflect/function_call_spec.rb +11 -12
  128. data/spec/zenlish/inflect/inflection_rule_spec.rb +28 -24
  129. data/spec/zenlish/inflect/inflection_table_builder_spec.rb +62 -57
  130. data/spec/zenlish/inflect/inflection_table_spec.rb +49 -46
  131. data/spec/zenlish/inflect/input_asis_spec.rb +12 -15
  132. data/spec/zenlish/inflect/literal_asis_spec.rb +10 -10
  133. data/spec/zenlish/inflect/matches_pattern_spec.rb +16 -15
  134. data/spec/zenlish/inflect/membership_spec.rb +17 -16
  135. data/spec/zenlish/inflect/method_heading_spec.rb +15 -14
  136. data/spec/zenlish/inflect/not_equals_literal_spec.rb +17 -16
  137. data/spec/zenlish/inflect/substitution_spec.rb +10 -11
  138. data/spec/zenlish/inflect/unconditionally_true_spec.rb +8 -6
  139. data/spec/zenlish/lang/dictionary_spec.rb +28 -31
  140. data/spec/zenlish/lang/lemmatizer_spec.rb +43 -0
  141. data/spec/zenlish/lang/zenlish_grammar_spec.rb +5 -5
  142. data/spec/zenlish/lex/empty_lexicon_factory_spec.rb +8 -8
  143. data/spec/zenlish/lex/lexeme_spec.rb +27 -28
  144. data/spec/zenlish/lex/lexical_entry_spec.rb +15 -15
  145. data/spec/zenlish/lex/lexicon_spec.rb +52 -50
  146. data/spec/zenlish/lex/literal_spec.rb +8 -8
  147. data/spec/zenlish/lexer/lexer_spec.rb +52 -0
  148. data/spec/zenlish/parser/lesson1_spec.rb +81 -81
  149. data/spec/zenlish/parser/lesson2_spec.rb +133 -138
  150. data/spec/zenlish/parser/lesson3_spec.rb +186 -226
  151. data/spec/zenlish/parser/zparser_spec.rb +8 -7
  152. data/spec/zenlish/support/minimal_lexicon.rb +2 -0
  153. data/spec/zenlish/support/var2word.rb +16 -9
  154. data/spec/zenlish/trie/base_trie_node_spec.rb +33 -0
  155. data/spec/zenlish/trie/trie_spec.rb +108 -0
  156. data/spec/zenlish/wclasses/common_noun_spec.rb +15 -19
  157. data/spec/zenlish/wclasses/demonstrative_determiner_spec.rb +12 -12
  158. data/spec/zenlish/wclasses/irregular_verb_can_spec.rb +18 -18
  159. data/spec/zenlish/wclasses/irregular_verb_extension_spec.rb +10 -10
  160. data/spec/zenlish/wclasses/irregular_verb_spec.rb +28 -28
  161. data/spec/zenlish/wclasses/lexical_verb_spec.rb +9 -9
  162. data/spec/zenlish/wclasses/modal_verb_can_spec.rb +12 -12
  163. data/spec/zenlish/wclasses/noun_spec.rb +7 -7
  164. data/spec/zenlish/wclasses/personal_pronoun_spec.rb +20 -23
  165. data/spec/zenlish/wclasses/possessive_determiner_spec.rb +28 -31
  166. data/spec/zenlish/wclasses/preposition_spec.rb +5 -5
  167. data/spec/zenlish/wclasses/proper_noun_spec.rb +3 -3
  168. data/spec/zenlish/wclasses/regular_verb_spec.rb +30 -30
  169. data/spec/zenlish/wclasses/regular_verb_want_spec.rb +30 -0
  170. data/spec/zenlish/wclasses/verb_spec.rb +9 -9
  171. data/spec/zenlish_spec.rb +4 -2
  172. data/zenlish.gemspec +18 -14
  173. metadata +49 -16
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../spec_helper' # Use the RSpec framework
4
+ require_relative '../../../lib/zenlish/lang/dictionary'
5
+
6
+ # Load the class under test
7
+ require_relative '../../../lib/zenlish/lang/lemmatizer'
8
+
9
+ module Zenlish
10
+ module Lang
11
+ describe Lemmatizer do
12
+ subject { described_class.new(Dictionary) }
13
+
14
+ context 'Initialization:' do
15
+ # it 'is initialized with a lexicon argument' do
16
+ # expect { described_class.new(Dictionary) }.not_to raise_error
17
+ # end
18
+ end # context
19
+
20
+ context 'Provided services:' do
21
+ # it 'retrieves an unambiguous word form' do
22
+ # # Coordinator
23
+ # found = described_class.lemmatize('and')
24
+ # expect(found).to be_a(Lex::Lexeme)
25
+ # expect(found.lemma).to eq('and')
26
+ # expect(found.wclass).to be_a(WClasses::Coordinator)
27
+ #
28
+ # # Common noun
29
+ # found = described_class.lemmatize('surfaces')
30
+ # expect(found).to be_a(Lex::Lexeme)
31
+ # expect(found.lemma).to eq('surface')
32
+ # expect(found.wclass).to be_a(WClasses::CommonNoun)
33
+ #
34
+ # # Verb
35
+ # found = described_class.lemmatize('seeing')
36
+ # expect(found).to be_a(Lex::Lexeme)
37
+ # expect(found.lemma).to eq('see')
38
+ # expect(found.wclass).to be_a(WClasses::IrregularVerb)
39
+ # end
40
+ end # context
41
+ end # describe
42
+ end # module
43
+ end # module
@@ -4,13 +4,13 @@ require_relative '../../spec_helper' # Use the RSpec framework
4
4
  require_relative '../../../lib/zenlish/lang/zenlish_grammar' # Load the class under test
5
5
 
6
6
  module Zenlish
7
- module Parser
7
+ module Lang
8
8
  describe ZenlishGrammar do
9
- subject { ZenlishGrammar }
9
+ subject(:grammar) { described_class }
10
10
 
11
11
  context 'Initialization:' do
12
- it 'should know its terminal symbols' do
13
- expect { subject.name2symbol['CommonNoun'] }.not_to raise_error
12
+ it 'knows its terminal symbols' do
13
+ expect { grammar.name2symbol['CommonNoun'] }.not_to raise_error
14
14
  end
15
15
  end # context
16
16
 
@@ -18,4 +18,4 @@ module Zenlish
18
18
  end # context
19
19
  end # describe
20
20
  end # module
21
- end # module
21
+ end # module
@@ -8,24 +8,24 @@ require_relative '../../../lib/zenlish/lex/empty_lexicon_factory'
8
8
  module Zenlish
9
9
  module Lex
10
10
  describe EmptyLexiconFactory do
11
- subject do
11
+ subject(:factory) do
12
12
  obj = Object.new
13
- obj.extend(EmptyLexiconFactory)
13
+ obj.extend(described_class)
14
14
  end
15
15
 
16
16
  context 'Mix-in integration:' do
17
- it 'should acquire the methods of the mix-in module' do
18
- expect(subject.respond_to?(:create_empty_lexicon)).to be_truthy
17
+ it 'acquires the methods of the mix-in module' do
18
+ expect(factory).to respond_to(:create_empty_lexicon)
19
19
  end
20
20
  end # context
21
21
 
22
22
  context 'Created lexicon:' do
23
- it 'should allow the creation of empty lexicon' do
24
- expect(subject.create_empty_lexicon).to be_kind_of(Lexicon)
23
+ it 'allows the creation of empty lexicon' do
24
+ expect(factory.create_empty_lexicon).to be_a(Lexicon)
25
25
  end
26
26
 
27
- it 'should initialize lexicon with terminal symbols of the language' do
28
- lexicon = subject.create_empty_lexicon
27
+ it 'initializes lexicon with terminal symbols of the language' do
28
+ lexicon = factory.create_empty_lexicon
29
29
  found = lexicon.terminals.find { |symb| symb.kind_of?(WClasses::CommonNoun) }
30
30
  expect(found).to be_truthy
31
31
  end
@@ -10,55 +10,54 @@ module Zenlish
10
10
  module Lex
11
11
  describe Lexeme do
12
12
  include Feature::FeatureStructDefBearer
13
-
13
+
14
14
  let(:a_wclass) { WClasses::CommonNoun.new }
15
15
  let(:a_lemma) { 'people' }
16
16
  let(:an_entry) { LexicalEntry.new(a_lemma) }
17
- let(:a_feat_struct_def) {
17
+ let(:a_feat_struct_def) do
18
18
  { 'NUMBER' => enumeration(:plural),
19
19
  'PARADIGM' => [identifier, 'Plural_only'] }
20
- }
20
+ end
21
21
 
22
- subject { Lexeme.new(a_wclass, an_entry) }
22
+ subject(:a_lexeme) { described_class.new(a_wclass, an_entry) }
23
23
 
24
24
  context 'Initialization:' do
25
- it 'could be initialized with a word class and a lexical entry' do
26
- expect { Lexeme.new(a_wclass, an_entry) }.not_to raise_error
25
+ it 'can be initialized with a word class and a lexical entry' do
26
+ expect { described_class.new(a_wclass, an_entry) }.not_to raise_error
27
+ end
28
+
29
+ it 'can be initialized with a w. class, lexical ent., feature hash' do
30
+ expect { described_class.new(a_wclass, an_entry, a_feat_struct_def) }.not_to raise_error
27
31
  end
28
-
29
- it 'could be initialized with a w. class, lexical ent., feature hash' do
30
- expect { Lexeme.new(a_wclass, an_entry, a_feat_struct_def) }.not_to raise_error
31
- end
32
32
 
33
- it 'should know its word class' do
34
- expect(subject.wclass).to eq(a_wclass)
33
+ it 'knows its word class' do
34
+ expect(a_lexeme.wclass).to eq(a_wclass)
35
35
  end
36
36
 
37
- it 'should know its lexical entry' do
38
- expect(subject.entry).to eq(an_entry)
37
+ it 'knows its lexical entry' do
38
+ expect(a_lexeme.entry).to eq(an_entry)
39
39
  end
40
40
  end # context
41
41
 
42
42
  context 'Provided services:' do
43
- subject { Lexeme.new(a_wclass, an_entry, a_feat_struct_def) }
44
- it 'should know its lemma' do
45
- expect(subject.lemma).to eq(a_lemma)
43
+ subject(:a_lexeme) { described_class.new(a_wclass, an_entry, a_feat_struct_def) }
44
+ it 'knows its lemma' do
45
+ expect(a_lexeme.lemma).to eq(a_lemma)
46
46
  end
47
-
48
- it 'should know its own feature defs' do
49
- instance = Lexeme.new(a_wclass, an_entry, a_feat_struct_def)
47
+
48
+ it 'knows its own feature defs' do
49
+ instance = described_class.new(a_wclass, an_entry, a_feat_struct_def)
50
50
  expect(instance['NUMBER'].default.val).to eq(:plural)
51
51
  end
52
-
53
- it 'should know its inflection paradigm' do
54
- expect(subject.paradigm).to be_kind_of(Inflect::InflectionTable)
52
+
53
+ it 'knows its inflection paradigm' do
54
+ expect(a_lexeme.paradigm).to be_a(Inflect::InflectionTable)
55
+ end
56
+
57
+ it 'knows all its inflections' do
58
+ expect(a_lexeme.all_inflections).to eq(['people'])
55
59
  end
56
-
57
- it 'should know all its inflections' do
58
- expect(subject.all_inflections).to eq(['people'])
59
- end
60
60
  end # context
61
61
  end # describe
62
62
  end # module
63
63
  end # module
64
-
@@ -9,38 +9,38 @@ module Zenlish
9
9
  let(:sample_lemma) { 'other' }
10
10
  let(:sample_lexeme1) { double('other-as-adjective') }
11
11
  let(:sample_lexeme2) { double('other-as-pronoun') }
12
- subject { LexicalEntry.new(sample_lemma) }
12
+
13
+ subject(:lex_entry) { described_class.new(sample_lemma) }
13
14
 
14
15
  context 'Initialization:' do
15
16
  it 'can be initialized with a lemma only' do
16
- expect { LexicalEntry.new(sample_lemma) }.not_to raise_error
17
+ expect { described_class.new(sample_lemma) }.not_to raise_error
17
18
  end
18
19
 
19
20
  it 'can be initialized with a lemma and a word class' do
20
- expect { LexicalEntry.new(sample_lemma, sample_lexeme1) }.not_to raise_error
21
+ expect { described_class.new(sample_lemma, sample_lexeme1) }.not_to raise_error
21
22
  end
22
23
 
23
- it 'should know its lemma' do
24
- expect(subject.lemma).to eq(sample_lemma)
24
+ it 'knows its lemma' do
25
+ expect(lex_entry.lemma).to eq(sample_lemma)
25
26
  end
26
27
 
27
- it 'should know its lexeme (if any)' do
28
- expect(subject.lexemes).to be_empty
29
- instance = LexicalEntry.new(sample_lemma, sample_lexeme1)
28
+ it 'knows its lexeme (if any)' do
29
+ expect(lex_entry.lexemes).to be_empty
30
+ instance = described_class.new(sample_lemma, sample_lexeme1)
30
31
  expect(instance.lexemes).to eq([sample_lexeme1])
31
32
  end
32
33
  end # context
33
34
 
34
35
  context 'Provided services:' do
36
+ it 'accepts links with lexeme(s)' do
37
+ lex_entry.add_lexeme(sample_lexeme1)
38
+ expect(lex_entry.lexemes).to eq([sample_lexeme1])
35
39
 
36
- it 'should accept links with lexeme(s)' do
37
- subject.add_lexeme(sample_lexeme1)
38
- expect(subject.lexemes).to eq([sample_lexeme1])
39
-
40
- subject.add_lexeme(sample_lexeme2)
41
- expect(subject.lexemes).to eq([sample_lexeme1, sample_lexeme2])
40
+ lex_entry.add_lexeme(sample_lexeme2)
41
+ expect(lex_entry.lexemes).to eq([sample_lexeme1, sample_lexeme2])
42
42
  end
43
43
  end # context
44
44
  end # describe
45
45
  end # module
46
- end # module
46
+ end # module
@@ -12,7 +12,8 @@ module Zenlish
12
12
  describe Lexicon do
13
13
  def create_entry(aLemma, aWordClass)
14
14
  entry = Zenlish::Lex::LexicalEntry.new(aLemma)
15
- lexeme = Zenlish::Lex::Lexeme.new(aWordClass, entry)
15
+ # lexeme =
16
+ Zenlish::Lex::Lexeme.new(aWordClass, entry)
16
17
  entry
17
18
  end
18
19
 
@@ -23,78 +24,79 @@ module Zenlish
23
24
  let(:sample_entry) { create_entry('other', adjective) }
24
25
  let(:similar_entry) { create_entry('other', pronoun) }
25
26
  let(:distinct_entry) { create_entry('hope', irregular_verb) }
26
- subject { Lexicon.new }
27
+
28
+ subject(:lexicon) { described_class.new }
27
29
 
28
30
  context 'Initialization:' do
29
- it 'should be initialized without parameter' do
30
- expect { Lexicon.new }.not_to raise_error
31
+ it 'is initialized without parameter' do
32
+ expect { described_class.new }.not_to raise_error
31
33
  end
32
34
 
33
- it 'should have no registered terminals at initialization' do
34
- expect(subject.terminals).to be_empty
35
+ it 'has no registered terminals at initialization' do
36
+ expect(lexicon.terminals).to be_empty
35
37
  end
36
38
 
37
- it 'should have no entry at initialization' do
38
- expect(subject.entries).to be_empty
39
- expect(subject.lemma2entry).to be_empty
39
+ it 'has no entry at initialization' do
40
+ expect(lexicon.entries).to be_empty
41
+ expect(lexicon.lemma2entry).to be_empty
40
42
  end
41
43
  end # context
42
44
 
43
45
  context 'Provided services:' do
44
- it 'should accept the addition of terminals' do
46
+ it 'accepts the addition of terminals' do
45
47
  terminal1 = pronoun
46
48
  terminal2 = irregular_verb
47
49
  terminal3 = adjective
48
50
 
49
- subject.add_terminal(terminal1)
50
- expect(subject.terminals).to eq([terminal1])
51
- subject.add_terminal(terminal2)
52
- expect(subject.terminals).to eq([terminal1, terminal2])
53
- subject.add_terminal(terminal3)
54
- expect(subject.terminals).to eq([terminal1, terminal2, terminal3])
55
- expect(subject.name2terminal['Pronoun']).to eq(terminal1)
56
- expect(subject.name2terminal['IrregularVerb']).to eq(terminal2)
57
- expect(subject.name2terminal['Adjective']).to eq(terminal3)
51
+ lexicon.add_terminal(terminal1)
52
+ expect(lexicon.terminals).to eq([terminal1])
53
+ lexicon.add_terminal(terminal2)
54
+ expect(lexicon.terminals).to eq([terminal1, terminal2])
55
+ lexicon.add_terminal(terminal3)
56
+ expect(lexicon.terminals).to eq([terminal1, terminal2, terminal3])
57
+ expect(lexicon.name2terminal['Pronoun']).to eq(terminal1)
58
+ expect(lexicon.name2terminal['IrregularVerb']).to eq(terminal2)
59
+ expect(lexicon.name2terminal['Adjective']).to eq(terminal3)
58
60
  end
59
61
 
60
- it 'should accept the addition of entries' do
61
- subject.add_entry(sample_entry)
62
- expect(subject.entries).to eq([sample_entry])
63
- expect(subject.lemma2entry['other']).to eq(sample_entry)
62
+ it 'accepts the addition of entries' do
63
+ lexicon.add_entry(sample_entry)
64
+ expect(lexicon.entries).to eq([sample_entry])
65
+ expect(lexicon.lemma2entry['other']).to eq(sample_entry)
64
66
 
65
67
  # Add dissimilar entry
66
- subject.add_entry(distinct_entry)
67
- expect(subject.entries).to eq([sample_entry, distinct_entry])
68
- expect(subject.lemma2entry['hope']).to eq(distinct_entry)
68
+ lexicon.add_entry(distinct_entry)
69
+ expect(lexicon.entries).to eq([sample_entry, distinct_entry])
70
+ expect(lexicon.lemma2entry['hope']).to eq(distinct_entry)
69
71
 
70
72
  # Add "homonym" entry
71
- subject.add_entry(similar_entry)
72
- expect(subject.entries).to eq([sample_entry, distinct_entry, similar_entry])
73
- expect(subject.lemma2entry['other']).to eq([sample_entry, similar_entry])
73
+ lexicon.add_entry(similar_entry)
74
+ expect(lexicon.entries).to eq([sample_entry, distinct_entry, similar_entry])
75
+ expect(lexicon.lemma2entry['other']).to eq([sample_entry, similar_entry])
74
76
  end
75
-
76
- it 'should retrieve the lexeme of an entry with unique lemma' do
77
- subject.add_entry(sample_entry)
78
- subject.add_entry(distinct_entry)
79
- subject.add_entry(similar_entry)
80
-
81
- lexeme = subject.get_lexeme('hope')
82
- expect(lexeme.wclass).to be_kind_of(Zenlish::WClasses::IrregularVerb)
77
+
78
+ it 'retrieves the lexeme of an entry with unique lemma' do
79
+ lexicon.add_entry(sample_entry)
80
+ lexicon.add_entry(distinct_entry)
81
+ lexicon.add_entry(similar_entry)
82
+
83
+ lexeme = lexicon.get_lexeme('hope')
84
+ expect(lexeme.wclass).to be_a(Zenlish::WClasses::IrregularVerb)
83
85
  end
84
-
85
- it 'should retrieve the lexeme of an entry with duplicate lemma' do
86
- subject.add_entry(sample_entry)
87
- subject.add_entry(distinct_entry)
88
- subject.add_entry(similar_entry)
89
-
90
- lexeme = subject.get_lexeme('other', Zenlish::WClasses::Pronoun)
91
- expect(lexeme).to be_kind_of(Zenlish::Lex::Lexeme)
92
- end
93
-
94
- it 'should complain when retrieving an non-existing entry' do
95
- subject.add_entry(sample_entry)
86
+
87
+ it 'retrieves the lexeme of an entry with duplicate lemma' do
88
+ lexicon.add_entry(sample_entry)
89
+ lexicon.add_entry(distinct_entry)
90
+ lexicon.add_entry(similar_entry)
91
+
92
+ lexeme = lexicon.get_lexeme('other', Zenlish::WClasses::Pronoun)
93
+ expect(lexeme).to be_a(Zenlish::Lex::Lexeme)
94
+ end
95
+
96
+ it 'complains when retrieving an non-existing entry' do
97
+ lexicon.add_entry(sample_entry)
96
98
  err_msg = 'key not found: "hapax"'
97
- expect { subject.get_lexeme('hapax') }.to raise_error(KeyError, err_msg)
99
+ expect { lexicon.get_lexeme('hapax') }.to raise_error(KeyError, err_msg)
98
100
  end
99
101
  end # context
100
102
  end # describe
@@ -8,24 +8,24 @@ require_relative '../../../lib/zenlish/lex/literal' # Load the class under test
8
8
 
9
9
  module Zenlish
10
10
  module Lex
11
- describe Lexeme do
11
+ describe Literal do
12
12
  let(:sample_wclass) { WClasses::CommonNoun.new }
13
13
  let(:sample_lemma) { 'thing' }
14
14
  let(:sample_entry) { LexicalEntry.new(sample_lemma) }
15
- let(:sample_position) { double('position') }
16
- let(:sample_lexeme) { Lexeme.new(sample_wclass, sample_entry) }
15
+ let(:sample_position) { instance_double(Rley::Lexical::Position) }
16
+ let(:sample_lexeme) { Lexeme.new(sample_wclass, sample_entry) }
17
17
 
18
- subject { Literal.new('things', sample_lexeme, sample_position) }
18
+ subject(:literal) { described_class.new('things', sample_lexeme, sample_position) }
19
19
 
20
20
  context 'Initialization:' do
21
- it 'should be initialized with a string, a lexeme and a position' do
22
- expect { Literal.new('things', sample_lexeme, sample_position) }.not_to raise_error
21
+ it 'is initialized with a string, a lexeme and a position' do
22
+ expect { described_class.new('things', sample_lexeme, sample_position) }.not_to raise_error
23
23
  end
24
24
  end # context
25
25
 
26
26
  context 'Provided services:' do
27
- it 'should know its lexeme' do
28
- expect(subject.zlexeme).to eq(sample_lexeme)
27
+ it 'knows its lexeme' do
28
+ expect(literal.zlexeme).to eq(sample_lexeme)
29
29
  end
30
30
  end # context
31
31
  end # describe
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../spec_helper' # Use the RSpec framework
4
+ require_relative '../../../lib/zenlish/wclasses/all_word_classes'
5
+ require_relative '../../../lib/zenlish/lex/lexical_entry'
6
+ require_relative '../../../lib/zenlish/lex/lexeme'
7
+
8
+ # Load the class under test
9
+ require_relative '../../../lib/zenlish/lexer/lexer'
10
+
11
+ module Zenlish
12
+ module Lexer
13
+ describe Lexer do
14
+ # let(:sample_wclass) { WClasses::CommonNoun.new }
15
+ # let(:sample_lemma) { 'thing' }
16
+ # let(:sample_entry) { LexicalEntry.new(sample_lemma) }
17
+ # let(:sample_position) { double('position') }
18
+ # let(:sample_lexeme) { Lexeme.new(sample_wclass, sample_entry) }
19
+ let(:sample_sentence) { 'Tony sees Lisa.' }
20
+
21
+ subject(:lexer) { described_class.new(sample_sentence) }
22
+
23
+ context 'Initialization:' do
24
+ it 'is initialized with Zenlish text' do
25
+ expect { described_class.new(sample_sentence) }.not_to raise_error
26
+ end
27
+
28
+ it 'knows its scanner object' do
29
+ expect(lexer.scanner).not_to be_nil
30
+ end
31
+
32
+ it 'has an initial position' do
33
+ expect(lexer.lineno).to eq(1)
34
+ expect(lexer.line_start).to eq(0)
35
+ end
36
+ end # context
37
+
38
+ context 'Provided services:' do
39
+ it 'returns a sequence of literals' do
40
+ tokens = lexer.tokens
41
+ expect(tokens.size).to eq(4)
42
+ expect(tokens[0].lexeme).to eq('Tony')
43
+ expect(tokens[0].terminal).to eq('WORD')
44
+ expect(tokens[1].lexeme).to eq('sees')
45
+ expect(tokens[2].lexeme).to eq('Lisa')
46
+ expect(tokens[3].lexeme).to eq('.')
47
+ expect(tokens[3].terminal).to eq('Period')
48
+ end
49
+ end # context
50
+ end # describe
51
+ end # module
52
+ end # module