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
@@ -19,27 +19,30 @@ require_relative '../../../lib/zenlish/inflect/inflection_table'
19
19
 
20
20
  module Zenlish
21
21
  module Inflect
22
+ # rubocop: disable Naming/VariableNumber
23
+
22
24
  describe InflectionTable do
23
25
  let(:table_name) { 'Common_form' }
24
- subject { InflectionTable.new(table_name) }
26
+
27
+ subject(:inflection) { described_class.new(table_name) }
25
28
 
26
29
  context 'Initialization:' do
27
- it 'should be initialized with a name' do
28
- expect { InflectionTable.new(table_name) }.not_to raise_error
30
+ it 'is initialized with a name' do
31
+ expect { described_class.new(table_name) }.not_to raise_error
29
32
  end
30
33
 
31
- it 'should now its name' do
32
- expect(subject.name).to eq(table_name)
34
+ it 'knows its name' do
35
+ expect(inflection.name).to eq(table_name)
33
36
  end
34
37
 
35
- it 'should not have headings at start' do
36
- expect(subject.headings).to be_empty
38
+ it "doesn't have headings at start" do
39
+ expect(inflection.headings).to be_empty
37
40
  end
38
41
 
39
- it 'should not have rules at start' do
40
- expect(subject.rules).to be_empty
42
+ it "doesn't not have rules at start" do
43
+ expect(inflection.rules).to be_empty
41
44
  end
42
- end # context
45
+ end # context
43
46
 
44
47
  context 'Provided services:' do
45
48
  # DecisionTable: Common_form
@@ -77,32 +80,31 @@ module Zenlish
77
80
  let(:a_wclass) { WClasses::CommonNoun.new }
78
81
  let(:a_lemma) { 'body' }
79
82
  let(:an_entry) { Lex::LexicalEntry.new(a_lemma) }
80
- let(:lexm_body) { Lex::Lexeme.new(a_wclass, an_entry) }
81
-
82
- MockFeatureBearer = Struct.new(:NUMBER, :base_form)
83
-
84
- it 'should accept the addition of heading(s)' do
85
- expect { subject.add_heading(heading0) }.not_to raise_error
86
- expect(subject.headings.size).to eq(1)
87
- subject.add_heading(heading1)
88
- expect(subject.headings.last).to eq(heading1)
83
+ let(:lexm_body) { Lex::Lexeme.new(a_wclass, an_entry) }
84
+ let(:mock_feature_bearer) { Struct.new(:NUMBER, :base_form) }
85
+
86
+ it 'accepts the addition of heading(s)' do
87
+ expect { inflection.add_heading(heading0) }.not_to raise_error
88
+ expect(inflection.headings.size).to eq(1)
89
+ inflection.add_heading(heading1)
90
+ expect(inflection.headings.last).to eq(heading1)
89
91
  end
90
92
 
91
- it 'should accept the addition of rule(s)' do
92
- expect { subject.add_rule(rule_a) }.not_to raise_error
93
- expect(subject.rules.size).to eq(1)
94
- subject.add_rule(rule_b)
95
- expect(subject.rules.last).to eq(rule_b)
96
- subject.add_rule(rule_c)
97
- expect(subject.rules.last).to eq(rule_c)
93
+ it 'accepts the addition of rule(s)' do
94
+ expect { inflection.add_rule(rule_a) }.not_to raise_error
95
+ expect(inflection.rules.size).to eq(1)
96
+ inflection.add_rule(rule_b)
97
+ expect(inflection.rules.last).to eq(rule_b)
98
+ inflection.add_rule(rule_c)
99
+ expect(inflection.rules.last).to eq(rule_c)
98
100
  end
99
-
101
+
100
102
  def init_table(aTable)
101
103
  aTable.add_heading(heading0)
102
104
  aTable.add_heading(heading1)
103
105
  aTable.add_rule(rule_a)
104
106
  aTable.add_rule(rule_b)
105
- aTable.add_rule(rule_c)
107
+ aTable.add_rule(rule_c)
106
108
  end
107
109
 
108
110
  # DecisionTable: Common_form
@@ -118,27 +120,28 @@ module Zenlish
118
120
  # rule(equals(:plural) , matches(/[^aeiouy]y$/), sub(col(1), /y$/, 'ies'))
119
121
  # rule(equals(:plural) , dont_care , concat(col(1), 's'))
120
122
  # end
121
- it 'should determine the word form given input entries' do
122
- init_table(subject)
123
- mck_1 = MockFeatureBearer.new(:singular, 'animal')
124
- expect(subject.inflect(mck_1, [nil, nil])).to eq('animal')
125
- mck_1['NUMBER'] = :plural
126
- expect(subject.inflect(mck_1, [nil, nil])).to eq('animals')
127
-
128
- mck_2 = MockFeatureBearer.new(:singular, 'boy')
129
- expect(subject.inflect(mck_2, [nil, nil])).to eq('boy')
130
- mck_2['NUMBER'] = :plural
131
- expect(subject.inflect(mck_2, [nil, nil])).to eq('boys')
132
-
133
- expect(subject.inflect(lexm_body, [:singular, nil])).to eq('body')
134
- expect(subject.inflect(lexm_body, [:plural, nil])).to eq('bodies')
123
+ it 'determines the word form given input entries' do
124
+ init_table(inflection)
125
+ mck1 = mock_feature_bearer.new(:singular, 'animal')
126
+ expect(inflection.inflect(mck1, [nil, nil])).to eq('animal')
127
+ mck1['NUMBER'] = :plural
128
+ expect(inflection.inflect(mck1, [nil, nil])).to eq('animals')
129
+
130
+ mck2 = mock_feature_bearer.new(:singular, 'boy')
131
+ expect(inflection.inflect(mck2, [nil, nil])).to eq('boy')
132
+ mck2['NUMBER'] = :plural
133
+ expect(inflection.inflect(mck2, [nil, nil])).to eq('boys')
134
+
135
+ expect(inflection.inflect(lexm_body, [:singular, nil])).to eq('body')
136
+ expect(inflection.inflect(lexm_body, [:plural, nil])).to eq('bodies')
135
137
  end
136
138
 
137
- it 'should know all the word forms of a given lexeme' do
138
- init_table(subject)
139
- expect(subject.all_inflections(lexm_body)).to eq(['body', 'bodies'])
139
+ it 'knows all the word forms of a given lexeme' do
140
+ init_table(inflection)
141
+ expect(inflection.all_inflections(lexm_body)).to eq(%w[body bodies])
140
142
  end
141
143
  end # context
142
144
  end # describe
145
+ # rubocop: enable Naming/VariableNumber
143
146
  end # module
144
- end # module
147
+ end # module
@@ -13,38 +13,35 @@ module Zenlish
13
13
  describe InputAsIs do
14
14
  let(:sample_argument) { FormalArgument.new(2) }
15
15
  let(:sample_values) { [nil, nil, 'Hello, world.', nil] }
16
- subject { InputAsIs.new(sample_argument) }
16
+
17
+ subject(:input) { described_class.new(sample_argument) }
17
18
 
18
19
  context 'Initialization:' do
19
- it 'should be initialized with a formal rgument' do
20
- expect { InputAsIs.new(sample_argument) }.not_to raise_error
20
+ it 'is initialized with a formal rgument' do
21
+ expect { described_class.new(sample_argument) }.not_to raise_error
21
22
  end
22
23
 
23
- it 'should know its text value' do
24
- expect(subject.formal).to eq(sample_argument)
24
+ it 'knows its text value' do
25
+ expect(input.formal).to eq(sample_argument)
25
26
  end
26
27
  end # context
27
28
 
28
29
  context 'Provided services:' do
29
- it 'should return the text of given argument during generation' do
30
+ it 'returns the text of given argument during generation' do
30
31
  lexeme = double('fake-lexeme')
31
32
  headings = double('fake-headings')
32
- expect(subject.generate(headings, lexeme, sample_values)).to eq('Hello, world.')
33
+ expect(input.generate(headings, lexeme, sample_values)).to eq('Hello, world.')
33
34
  end
34
-
35
- it 'should return the text of given lexeme during generation' do
35
+
36
+ it 'returns the text of given lexeme during generation' do
36
37
  c_noun = WClasses::CommonNoun.new
37
38
  an_entry = Lex::LexicalEntry.new('cherry')
38
39
  lexeme = Lex::Lexeme.new(c_noun, an_entry)
39
40
  heading = MethodHeading.new('base_form')
40
41
  headings = [nil, nil, heading, nil]
41
- expect(subject.generate(headings, lexeme, [])).to eq('cherry')
42
+ expect(input.generate(headings, lexeme, [])).to eq('cherry')
42
43
  end
43
-
44
- =begin
45
-
46
- =end
47
44
  end # context
48
45
  end # describe
49
46
  end # module
50
- end # module
47
+ end # module
@@ -6,26 +6,26 @@ require_relative '../../../lib/zenlish/inflect/literal_asis'
6
6
  module Zenlish
7
7
  module Inflect
8
8
  describe LiteralAsIs do
9
- subject { LiteralAsIs.new('s') }
9
+ subject(:literal) { described_class.new('s') }
10
10
 
11
11
  context 'Initialization:' do
12
- it 'should be initialized with a text literal' do
13
- expect { LiteralAsIs.new('s') }.not_to raise_error
12
+ it 'is initialized with a text literal' do
13
+ expect { described_class.new('s') }.not_to raise_error
14
14
  end
15
-
16
- it 'should know its text value' do
17
- expect(subject.text).to eq('s')
15
+
16
+ it 'knows its text value' do
17
+ expect(literal.text).to eq('s')
18
18
  end
19
19
  end # context
20
20
 
21
21
  context 'Provided services:' do
22
- it 'should return the affix during word form generation' do
23
- headings = double('fake-headings')
22
+ it 'returns the affix during word form generation' do
23
+ headings = double('fake-headings')
24
24
  lexeme = double('fake-lexeme')
25
25
  values = double('fake-values')
26
- expect(subject.generate(headings, lexeme, values)).to eq('s')
26
+ expect(literal.generate(headings, lexeme, values)).to eq('s')
27
27
  end
28
28
  end # context
29
29
  end # describe
30
30
  end # module
31
- end # module
31
+ end # module
@@ -13,44 +13,45 @@ module Zenlish
13
13
  describe MatchesPattern do
14
14
  let(:an_argument) { FormalArgument.new(1) }
15
15
  let(:patt) { /[^aeiouy]y$/ }
16
- subject { MatchesPattern.new(an_argument, patt) }
16
+
17
+ subject(:pattern) { described_class.new(an_argument, patt) }
17
18
 
18
19
  context 'Initialization:' do
19
- it 'should be initialized with an argument and pattern' do
20
- expect { MatchesPattern.new(an_argument, patt) }.not_to raise_error
20
+ it 'is initialized with an argument and pattern' do
21
+ expect { described_class.new(an_argument, patt) }.not_to raise_error
21
22
  end
22
23
 
23
- it 'should know its argument' do
24
- expect(subject.argument).to eq(an_argument)
24
+ it 'knows its argument' do
25
+ expect(pattern.argument).to eq(an_argument)
25
26
  end
26
27
 
27
- it 'should know the pattern' do
28
- expect(subject.pattern).to eq(patt)
28
+ it 'knows the pattern' do
29
+ expect(pattern.pattern).to eq(patt)
29
30
  end
30
31
  end # context
31
32
 
32
33
  context 'Provided services:' do
33
- it 'should check the actual argument' do
34
+ it 'checks the actual argument' do
34
35
  lexeme = double('dummy-lexeme')
35
36
  headings = double('fake-headings')
36
37
  actual_args = [nil, 'cherry', nil]
37
- expect(subject.success?(headings, lexeme, actual_args)).to be_truthy
38
+ expect(pattern).to be_success(headings, lexeme, actual_args)
38
39
  actual_args[1] = 'boy'
39
- expect(subject.success?(headings, lexeme, actual_args)).to be_falsy
40
+ expect(pattern).not_to be_success(headings, lexeme, actual_args)
40
41
  actual_args[1] = 'girl'
41
- expect(subject.success?(headings, lexeme, actual_args)).to be_falsy
42
+ expect(pattern).not_to be_success(headings, lexeme, actual_args)
42
43
  end
43
44
 
44
- it 'should test the lexeme' do
45
+ it 'tests the lexeme' do
45
46
  c_noun = WClasses::CommonNoun.new
46
47
  entry = Lex::LexicalEntry.new('cherry')
47
48
  lexeme = Lex::Lexeme.new(c_noun, entry)
48
49
  headings = [nil, MethodHeading.new('lemma'), nil]
49
- expect(subject.success?(headings, lexeme, [])).to be_truthy
50
+ expect(pattern).to be_success(headings, lexeme, [])
50
51
 
51
52
  entry2 = Lex::LexicalEntry.new('boy')
52
53
  lexeme2 = Lex::Lexeme.new(c_noun, entry2)
53
- expect(subject.success?(headings, lexeme2, [])).to be_falsey
54
+ expect(pattern).not_to be_success(headings, lexeme2, [])
54
55
 
55
56
  # instance = EqualsLiteral.new(an_argument, :irregular)
56
57
  # expect(instance.success?(headings, lexeme, [])).to be_falsey
@@ -58,4 +59,4 @@ module Zenlish
58
59
  end # context
59
60
  end # describe
60
61
  end # module
61
- end # module
62
+ end # module
@@ -12,46 +12,47 @@ module Zenlish
12
12
  module Inflect
13
13
  describe Membership do
14
14
  let(:an_argument) { FormalArgument.new(1) }
15
- let(:feat_val) { [:singular, :plural] }
16
- subject { Membership.new(an_argument, feat_val) }
15
+ let(:feat_val) { %i[singular plural] }
16
+
17
+ subject(:membership) { described_class.new(an_argument, feat_val) }
17
18
 
18
19
  context 'Initialization:' do
19
- it 'should be initialized with a formal argument and an array' do
20
- expect { Membership.new(an_argument, feat_val) }.not_to raise_error
20
+ it 'is initialized with a formal argument and an array' do
21
+ expect { described_class.new(an_argument, feat_val) }.not_to raise_error
21
22
  end
22
23
 
23
- it 'should know its argument' do
24
- expect(subject.argument).to eq(an_argument)
24
+ it 'knows its argument' do
25
+ expect(membership.argument).to eq(an_argument)
25
26
  end
26
27
 
27
- it 'should know the array of literals' do
28
- expect(subject.members).to eq(feat_val)
28
+ it 'knows the array of literals' do
29
+ expect(membership.members).to eq(feat_val)
29
30
  end
30
31
  end # context
31
32
 
32
33
  context 'Provided services:' do
33
- it 'should test the actual values' do
34
+ it 'tests the actual values' do
34
35
  lexeme = double('dummy-lexeme')
35
36
  headings = double('fake-headings')
36
37
  actual_args = [nil, :plural, nil]
37
- expect(subject.success?(headings, lexeme, actual_args)).to be_truthy
38
+ expect(membership).to be_success(headings, lexeme, actual_args)
38
39
  actual_args[1] = :singular
39
- expect(subject.success?(headings, lexeme, actual_args)).to be_truthy
40
+ expect(membership).to be_success(headings, lexeme, actual_args)
40
41
  actual_args[1] = :dual
41
- expect(subject.success?(headings, lexeme, actual_args)).to be_falsy
42
+ expect(membership).not_to be_success(headings, lexeme, actual_args)
42
43
  end
43
44
 
44
- # it 'should test the lexeme' do
45
+ # it 'tests the lexeme' do
45
46
  # c_noun = WClasses::CommonNoun.new
46
47
  # entry = Lex::LexicalEntry.new('animal')
47
48
  # lexeme = Lex::Lexeme.new(c_noun, entry)
48
49
  # headings = [nil, FeatureHeading.new('NUMBER'), nil]
49
- # expect(subject.success?(headings, lexeme, [])).to be_truthy
50
+ # expect(membership.success?(headings, lexeme, [])).to be_truthy
50
51
 
51
- # instance = Membership.new(an_argument, :singular)
52
+ # instance = described_class.new(an_argument, :singular)
52
53
  # expect(instance.success?(headings, lexeme, [])).to be_truthy
53
54
 
54
- # instance = Membership.new(an_argument, :irregular)
55
+ # instance = described_class.new(an_argument, :irregular)
55
56
  # expect(instance.success?(headings, lexeme, [])).to be_falsey
56
57
  # end
57
58
  end # context
@@ -7,31 +7,32 @@ module Zenlish
7
7
  module Inflect
8
8
  describe MethodHeading do
9
9
  let(:method_name) { 'base_form' }
10
- subject { MethodHeading.new(method_name) }
10
+
11
+ subject(:heading) { described_class.new(method_name) }
11
12
 
12
13
  context 'Initialization:' do
13
- it 'should be initialized with a method name' do
14
- expect { MethodHeading.new(method_name) }.not_to raise_error
14
+ it 'is initialized with a method name' do
15
+ expect { described_class.new(method_name) }.not_to raise_error
15
16
  end
16
17
 
17
- it 'should know its label' do
18
- expect(subject.label).to eq(method_name)
18
+ it 'knows its label' do
19
+ expect(heading.label).to eq(method_name)
19
20
  end
20
21
  end # context
21
22
 
22
23
  context 'Provided services:' do
23
- it 'should obtain the method result from a word' do
24
+ it 'obtains the method result from a word' do
24
25
  mocked = double('dummy-lexeme')
25
- expect(mocked).to receive(:base_form).and_return('cherry')
26
- expect(subject.evaluate_for(mocked)).to eq('cherry')
26
+ allow(mocked).to receive(:base_form).and_return('cherry')
27
+ expect(heading.evaluate_for(mocked)).to eq('cherry')
27
28
  end
28
-
29
- it 'should obtain the method result as an array' do
29
+
30
+ it 'obtains the method result as an array' do
30
31
  mocked = double('dummy-lexeme')
31
- expect(mocked).to receive(:base_form).and_return('cherry')
32
- expect(subject.all_matches(mocked)).to eq(['cherry'])
33
- end
32
+ allow(mocked).to receive(:base_form).and_return('cherry')
33
+ expect(heading.all_matches(mocked)).to eq(['cherry'])
34
+ end
34
35
  end # context
35
36
  end # describe
36
37
  end # module
37
- end # module
38
+ end # module
@@ -13,44 +13,45 @@ module Zenlish
13
13
  describe NotEqualsLiteral do
14
14
  let(:an_argument) { FormalArgument.new(1) }
15
15
  let(:feat_val) { :plural }
16
- subject { NotEqualsLiteral.new(an_argument, feat_val) }
16
+
17
+ subject(:literal) { described_class.new(an_argument, feat_val) }
17
18
 
18
19
  context 'Initialization:' do
19
- it 'should be initialized with formal argument and a literal' do
20
- expect { NotEqualsLiteral.new(an_argument, feat_val) }.not_to raise_error
20
+ it 'is initialized with formal argument and a literal' do
21
+ expect { described_class.new(an_argument, feat_val) }.not_to raise_error
21
22
  end
22
23
 
23
- it 'should know its argument' do
24
- expect(subject.argument).to eq(an_argument)
24
+ it 'knows its argument' do
25
+ expect(literal.argument).to eq(an_argument)
25
26
  end
26
27
 
27
- it 'should know the literal' do
28
- expect(subject.literal).to eq(feat_val)
28
+ it 'knows the literal' do
29
+ expect(literal.literal).to eq(feat_val)
29
30
  end
30
31
  end # context
31
32
 
32
33
  context 'Provided services:' do
33
- it 'should test the actual argument' do
34
+ it 'tests the actual argument' do
34
35
  lexeme = double('dummy-lexeme')
35
36
  headings = double('fake-headings')
36
37
  actual_args = [nil, :plural, nil]
37
- expect(subject.success?(headings, lexeme, actual_args)).to be_falsy
38
+ expect(literal).not_to be_success(headings, lexeme, actual_args)
38
39
  actual_args[1] = :singular
39
- expect(subject.success?(headings, lexeme, actual_args)).to be_truthy
40
+ expect(literal).to be_success(headings, lexeme, actual_args)
40
41
  end
41
42
 
42
- it 'should test the lexeme' do
43
+ it 'tests the lexeme' do
43
44
  c_noun = WClasses::CommonNoun.new
44
45
  entry = Lex::LexicalEntry.new('animal')
45
46
  lexeme = Lex::Lexeme.new(c_noun, entry)
46
47
  headings = [nil, FeatureHeading.new('NUMBER'), nil]
47
- expect(subject.success?(headings, lexeme, [])).to be_falsy
48
+ expect(literal).not_to be_success(headings, lexeme, [])
48
49
 
49
- instance = NotEqualsLiteral.new(an_argument, :singular)
50
- expect(instance.success?(headings, lexeme, [])).to be_falsy
50
+ instance = described_class.new(an_argument, :singular)
51
+ expect(instance).not_to be_success(headings, lexeme, [])
51
52
 
52
- instance = NotEqualsLiteral.new(an_argument, :irregular)
53
- expect(instance.success?(headings, lexeme, [])).to be_truthy
53
+ instance = described_class.new(an_argument, :irregular)
54
+ expect(instance).to be_success(headings, lexeme, [])
54
55
  end
55
56
  end # context
56
57
  end # describe
@@ -13,18 +13,17 @@ module Zenlish
13
13
  let(:base) { InputAsIs.new(sample_argument) }
14
14
  let(:pattern) { /y$/ }
15
15
 
16
-
17
- subject { Substitution.new(base, pattern, suffix) }
16
+ subject(:substitution) { described_class.new(base, pattern, suffix) }
18
17
 
19
18
  context 'Initialization:' do
20
- it 'should be initialized with two arguments' do
21
- expect { Substitution.new(base, pattern, suffix) }.not_to raise_error
19
+ it 'is initialized with two arguments' do
20
+ expect { described_class.new(base, pattern, suffix) }.not_to raise_error
22
21
  end
23
22
 
24
- it 'should know its arguments' do
25
- expect(subject.children.first).to eq(base)
26
- expect(subject.children[1]).to eq(pattern)
27
- expect(subject.children.last).to eq(suffix)
23
+ it 'knows its arguments' do
24
+ expect(substitution.children.first).to eq(base)
25
+ expect(substitution.children[1]).to eq(pattern)
26
+ expect(substitution.children.last).to eq(suffix)
28
27
  end
29
28
  end # context
30
29
 
@@ -32,12 +31,12 @@ module Zenlish
32
31
  let(:sample_heading) { double('fake-headings') }
33
32
  let(:sample_values) { [nil, 'cherry', nil] }
34
33
 
35
- it 'should do the concatenation of children results' do
34
+ it 'concatenates children results' do
36
35
  lexeme = double('fake-lexeme')
37
36
 
38
- expect(subject.generate(sample_heading, lexeme, sample_values)).to eq('cherries')
37
+ expect(substitution.generate(sample_heading, lexeme, sample_values)).to eq('cherries')
39
38
  end
40
39
  end # context
41
40
  end # describe
42
41
  end # module
43
- end # module
42
+ end # module
@@ -7,22 +7,24 @@ module Zenlish
7
7
  module Inflect
8
8
  describe UnconditionallyTrue do
9
9
  let(:method_name) { 'base_form' }
10
- subject { UnconditionallyTrue.new }
10
+
11
+ subject(:u_true) { described_class.new }
11
12
 
12
13
  context 'Initialization:' do
13
- it 'should be initialized without argument' do
14
- expect { UnconditionallyTrue.new}.not_to raise_error
14
+ it 'is initialized without argument' do
15
+ expect { described_class.new }.not_to raise_error
15
16
  end
16
17
  end # context
17
18
 
18
19
  context 'Provided services:' do
19
- it 'should always return true' do
20
+ it 'always return true' do
20
21
  headings = double('dummy-headings')
21
22
  lexeme = double('dummy-lexeme')
22
23
  values = double('dummy-heading-values')
23
- expect(subject.success?(headings, lexeme, values)).to be_truthy
24
+ # expect(u_true.success?(headings, lexeme, values)).to be_truthy
25
+ expect(u_true).to be_success(headings, lexeme, values)
24
26
  end
25
27
  end # context
26
28
  end # describe
27
29
  end # module
28
- end # module
30
+ end # module
@@ -7,26 +7,14 @@ require_relative '../../../lib/zenlish/lang/dictionary' # Load the class under t
7
7
  module Zenlish
8
8
  module Lang
9
9
  describe Dictionary do
10
- subject { Dictionary }
10
+ subject(:dictionary) { described_class }
11
11
 
12
12
  context 'Provided services:' do
13
13
  let(:common_nouns) do
14
14
  # Some Zenlish common nouns
15
- %w( animal body container here kind machine moment now part people
16
- person place side surface thing time word)
15
+ %w(animal body container here kind machine moment now part people
16
+ person place side surface thing time word)
17
17
  end
18
-
19
- it 'should give the list of common nouns' do
20
- lexemes = []
21
- subject.entries.each do |ent|
22
- lexm = ent.lexemes.select { |lx| lx.wclass.kind_of?(Zenlish::WClasses::CommonNoun) }
23
- lexemes.concat(lexm) if lexm
24
- end
25
- lemmas = lexemes.map { |lx| lx.entry.lemma }
26
-
27
- expect(common_nouns.all? { |c_n| lemmas.include?(c_n) }).to be_truthy
28
- end
29
-
30
18
  let(:present_1sg) { [:first, :singular, :present, nil] }
31
19
  let(:present_2sg) { [:second, :singular, :present, nil] }
32
20
  let(:present_3sg) { [:third, :singular, :present, nil] }
@@ -45,9 +33,19 @@ module Zenlish
45
33
  end
46
34
  end
47
35
 
48
- it 'should know how to inflect an (irregular) verb' do
49
- lexm = subject.get_lexeme('become')
50
- expectations_1 = [
36
+ it 'gives the list of common nouns' do
37
+ lexemes = []
38
+ dictionary.entries.each do |ent|
39
+ lexm = ent.lexemes.select { |lx| lx.wclass.kind_of?(Zenlish::WClasses::CommonNoun) }
40
+ lexemes.concat(lexm) if lexm
41
+ end
42
+ lemmas = lexemes.map { |lx| lx.entry.lemma }
43
+ expect(common_nouns.all? { |c_n| lemmas.include?(c_n) }).to be_truthy
44
+ end
45
+
46
+ it 'knows how to inflect an (irregular) verb' do
47
+ lexm = dictionary.get_lexeme('become')
48
+ expectations1 = [
51
49
  [present_1sg, 'become'],
52
50
  [present_3sg, 'becomes'],
53
51
  [present_1pl, 'become'],
@@ -55,10 +53,10 @@ module Zenlish
55
53
  [past_simple, 'became'],
56
54
  [past_participle, 'become']
57
55
  ]
58
- test_inflection_of(lexm, expectations_1)
56
+ test_inflection_of(lexm, expectations1)
59
57
 
60
- lexm = subject.get_lexeme('do', WClasses::IrregularVerbDo)
61
- expectations_2 = [
58
+ lexm = dictionary.get_lexeme('do', WClasses::IrregularVerbDo)
59
+ expectations2 = [
62
60
  [present_1sg, 'do'],
63
61
  [present_3sg, 'does'],
64
62
  [present_1pl, 'do'],
@@ -66,10 +64,10 @@ module Zenlish
66
64
  [past_simple, 'did'],
67
65
  [past_participle, 'done']
68
66
  ]
69
- test_inflection_of(lexm, expectations_2, true)
67
+ test_inflection_of(lexm, expectations2, true)
70
68
 
71
- lexm = subject.get_lexeme('have', WClasses::IrregularVerbHave)
72
- expectations_3 = [
69
+ lexm = dictionary.get_lexeme('have', WClasses::IrregularVerbHave)
70
+ expectations3 = [
73
71
  [present_1sg, 'have'],
74
72
  [present_3sg, 'has'],
75
73
  [present_1pl, 'have'],
@@ -77,13 +75,13 @@ module Zenlish
77
75
  [past_simple, 'had'],
78
76
  [past_participle, 'had']
79
77
  ]
80
- test_inflection_of(lexm, expectations_3, true)
78
+ test_inflection_of(lexm, expectations3, true)
81
79
  end
82
80
 
83
- it 'should know how to inflect the verb be' do
81
+ it 'knows how to inflect the verb be' do
84
82
  [WClasses::IrregularVerbBe, WClasses::AuxiliaryBe].each do |wclass|
85
- lexm = subject.get_lexeme('be', wclass)
86
- expectations_1 = [
83
+ lexm = dictionary.get_lexeme('be', wclass)
84
+ expectations1 = [
87
85
  [present_1sg, 'am'],
88
86
  [present_2sg, 'are'],
89
87
  [present_3sg, 'is'],
@@ -95,11 +93,10 @@ module Zenlish
95
93
  [past_simple_1pl, 'were'],
96
94
  [past_participle, 'been']
97
95
  ]
98
- test_inflection_of(lexm, expectations_1, true)
96
+ test_inflection_of(lexm, expectations1, true)
99
97
  end
100
98
  end
101
-
102
99
  end # context
103
100
  end # describe
104
101
  end # module
105
- end # module
102
+ end # module