zenlish 0.2.02 → 0.2.06
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +455 -0
- data/CHANGELOG.md +58 -1
- data/Gemfile +5 -3
- data/README.md +27 -0
- data/Rakefile +5 -3
- data/lib/zenlish/feature/boolean_domain.rb +9 -3
- data/lib/zenlish/feature/boolean_value.rb +3 -2
- data/lib/zenlish/feature/enumeration_domain.rb +8 -1
- data/lib/zenlish/feature/feature.rb +9 -7
- data/lib/zenlish/feature/feature_def.rb +10 -6
- data/lib/zenlish/feature/feature_domain.rb +9 -3
- data/lib/zenlish/feature/feature_struct.rb +3 -1
- data/lib/zenlish/feature/feature_struct_def.rb +5 -1
- data/lib/zenlish/feature/feature_struct_def_bearer.rb +6 -4
- data/lib/zenlish/feature/feature_value.rb +4 -2
- data/lib/zenlish/feature/identifier_domain.rb +5 -3
- data/lib/zenlish/feature/identifier_value.rb +3 -2
- data/lib/zenlish/feature/symbol_value.rb +3 -1
- data/lib/zenlish/inflect/atomic_o_expression.rb +2 -1
- data/lib/zenlish/inflect/composite_o_expression.rb +3 -1
- data/lib/zenlish/inflect/concatenation.rb +3 -2
- data/lib/zenlish/inflect/equals_literal.rb +7 -1
- data/lib/zenlish/inflect/feature_heading.rb +11 -5
- data/lib/zenlish/inflect/formal_argument.rb +3 -1
- data/lib/zenlish/inflect/function_call.rb +4 -1
- data/lib/zenlish/inflect/heading.rb +5 -0
- data/lib/zenlish/inflect/inflection_rule.rb +2 -0
- data/lib/zenlish/inflect/inflection_table.rb +29 -4
- data/lib/zenlish/inflect/inflection_table_builder.rb +27 -20
- data/lib/zenlish/inflect/input_asis.rb +3 -0
- data/lib/zenlish/inflect/input_expression.rb +4 -2
- data/lib/zenlish/inflect/literal_asis.rb +4 -1
- data/lib/zenlish/inflect/matches_pattern.rb +2 -0
- data/lib/zenlish/inflect/membership.rb +2 -0
- data/lib/zenlish/inflect/method_heading.rb +7 -6
- data/lib/zenlish/inflect/not_equals_literal.rb +2 -0
- data/lib/zenlish/inflect/nullary_input_expression.rb +3 -1
- data/lib/zenlish/inflect/output_expression.rb +2 -0
- data/lib/zenlish/inflect/substitution.rb +3 -1
- data/lib/zenlish/inflect/unary_input_expression.rb +4 -1
- data/lib/zenlish/inflect/unconditionally_true.rb +4 -2
- data/lib/zenlish/lang/dictionary.rb +35 -29
- data/lib/zenlish/lang/lemmatizer.rb +40 -0
- data/lib/zenlish/lang/zenlish_grammar.rb +9 -6
- data/lib/zenlish/lex/empty_lexicon_factory.rb +4 -3
- data/lib/zenlish/lex/lexeme.rb +9 -2
- data/lib/zenlish/lex/lexical_entry.rb +6 -4
- data/lib/zenlish/lex/lexicon.rb +10 -8
- data/lib/zenlish/lex/literal.rb +3 -1
- data/lib/zenlish/lexer/lexer.rb +144 -0
- data/lib/zenlish/trie/base_trie_node.rb +27 -0
- data/lib/zenlish/trie/trie.rb +132 -0
- data/lib/zenlish/trie/trie_node.rb +21 -0
- data/lib/zenlish/trie/trie_root.rb +10 -0
- data/lib/zenlish/version.rb +3 -1
- data/lib/zenlish/wclasses/adjective.rb +5 -2
- data/lib/zenlish/wclasses/adverb.rb +3 -1
- data/lib/zenlish/wclasses/adverb_maybe.rb +3 -1
- data/lib/zenlish/wclasses/adverb_not.rb +2 -0
- data/lib/zenlish/wclasses/all_word_classes.rb +4 -2
- data/lib/zenlish/wclasses/article.rb +2 -0
- data/lib/zenlish/wclasses/auxiliary.rb +5 -2
- data/lib/zenlish/wclasses/auxiliary_be.rb +34 -1
- data/lib/zenlish/wclasses/auxiliary_do.rb +31 -0
- data/lib/zenlish/wclasses/cardinal.rb +3 -1
- data/lib/zenlish/wclasses/common_noun.rb +2 -0
- data/lib/zenlish/wclasses/comparative_particle.rb +5 -3
- data/lib/zenlish/wclasses/conjunction.rb +2 -0
- data/lib/zenlish/wclasses/conjunctive_pronoun.rb +2 -0
- data/lib/zenlish/wclasses/coordinator.rb +4 -2
- data/lib/zenlish/wclasses/definite_article.rb +2 -0
- data/lib/zenlish/wclasses/degree_adverb.rb +2 -0
- data/lib/zenlish/wclasses/demonstrative_determiner.rb +40 -1
- data/lib/zenlish/wclasses/demonstrative_pronoun.rb +2 -0
- data/lib/zenlish/wclasses/determiner.rb +3 -1
- data/lib/zenlish/wclasses/distributive_determiner.rb +2 -0
- data/lib/zenlish/wclasses/existential_there.rb +2 -0
- data/lib/zenlish/wclasses/fronting_quantifier.rb +3 -1
- data/lib/zenlish/wclasses/indefinite_article.rb +2 -0
- data/lib/zenlish/wclasses/indefinite_pronoun.rb +3 -1
- data/lib/zenlish/wclasses/irregular_linking_verb.rb +3 -1
- data/lib/zenlish/wclasses/irregular_verb.rb +14 -22
- data/lib/zenlish/wclasses/irregular_verb_be.rb +41 -1
- data/lib/zenlish/wclasses/irregular_verb_can.rb +35 -0
- data/lib/zenlish/wclasses/irregular_verb_do.rb +38 -1
- data/lib/zenlish/wclasses/irregular_verb_extension.rb +8 -6
- data/lib/zenlish/wclasses/irregular_verb_have.rb +38 -1
- data/lib/zenlish/wclasses/irregular_verb_know.rb +3 -1
- data/lib/zenlish/wclasses/irregular_verb_say.rb +3 -1
- data/lib/zenlish/wclasses/irregular_verb_think.rb +3 -1
- data/lib/zenlish/wclasses/lexical_verb.rb +3 -4
- data/lib/zenlish/wclasses/linking_adverb.rb +2 -0
- data/lib/zenlish/wclasses/modal_verb_can.rb +27 -0
- data/lib/zenlish/wclasses/noun.rb +4 -2
- data/lib/zenlish/wclasses/numeral.rb +2 -0
- data/lib/zenlish/wclasses/personal_pronoun.rb +70 -1
- data/lib/zenlish/wclasses/possessive_determiner.rb +60 -0
- data/lib/zenlish/wclasses/preposition.rb +3 -1
- data/lib/zenlish/wclasses/preposition_of.rb +2 -0
- data/lib/zenlish/wclasses/preposition_than.rb +2 -0
- data/lib/zenlish/wclasses/pronoun.rb +3 -1
- data/lib/zenlish/wclasses/proper_noun.rb +10 -8
- data/lib/zenlish/wclasses/quantifier.rb +3 -1
- data/lib/zenlish/wclasses/regular_verb.rb +13 -18
- data/lib/zenlish/wclasses/regular_verb_want.rb +4 -2
- data/lib/zenlish/wclasses/relative_pronoun.rb +4 -2
- data/lib/zenlish/wclasses/subordinating_conjunction.rb +7 -5
- data/lib/zenlish/wclasses/verb.rb +16 -8
- data/lib/zenlish/wclasses/word_class.rb +11 -3
- data/spec/spec_helper.rb +3 -1
- data/spec/zenlish/feature/boolean_domain_spec.rb +6 -1
- data/spec/zenlish/feature/boolean_value_spec.rb +1 -1
- data/spec/zenlish/feature/enumeration_domain_spec.rb +9 -5
- data/spec/zenlish/feature/feature_spec.rb +3 -3
- data/spec/zenlish/feature/feature_struct_def_bearer_spec.rb +10 -8
- data/spec/zenlish/feature/feature_struct_def_spec.rb +3 -2
- data/spec/zenlish/feature/identifier_domain_spec.rb +3 -3
- data/spec/zenlish/feature/identifier_value_spec.rb +4 -4
- data/spec/zenlish/feature/symbol_value_spec.rb +3 -3
- data/spec/zenlish/inflect/concatenation_spec.rb +7 -7
- data/spec/zenlish/inflect/feature_heading_spec.rb +23 -3
- data/spec/zenlish/inflect/formal_argument_spec.rb +2 -2
- data/spec/zenlish/inflect/function_call_spec.rb +4 -4
- data/spec/zenlish/inflect/inflection_rule_spec.rb +9 -5
- data/spec/zenlish/inflect/inflection_table_builder_spec.rb +26 -21
- data/spec/zenlish/inflect/inflection_table_spec.rb +39 -22
- data/spec/zenlish/inflect/input_asis_spec.rb +2 -6
- data/spec/zenlish/inflect/literal_asis_spec.rb +3 -3
- data/spec/zenlish/inflect/matches_pattern_spec.rb +1 -1
- data/spec/zenlish/inflect/membership_spec.rb +2 -2
- data/spec/zenlish/inflect/method_heading_spec.rb +7 -1
- data/spec/zenlish/inflect/substitution_spec.rb +1 -1
- data/spec/zenlish/inflect/unconditionally_true_spec.rb +2 -2
- data/spec/zenlish/lang/dictionary_spec.rb +51 -16
- data/spec/zenlish/lang/lemmatizer_spec.rb +43 -0
- data/spec/zenlish/lang/zenlish_grammar_spec.rb +2 -2
- data/spec/zenlish/lex/lexeme_spec.rb +16 -11
- data/spec/zenlish/lex/lexical_entry_spec.rb +1 -2
- data/spec/zenlish/lex/lexicon_spec.rb +9 -8
- data/spec/zenlish/lex/literal_spec.rb +2 -2
- data/spec/zenlish/lexer/lexer_spec.rb +52 -0
- data/spec/zenlish/parser/lesson1_spec.rb +2 -2
- data/spec/zenlish/parser/lesson2_spec.rb +31 -36
- data/spec/zenlish/parser/lesson3_spec.rb +98 -138
- data/spec/zenlish/parser/zparser_spec.rb +2 -1
- data/spec/zenlish/support/minimal_lexicon.rb +2 -0
- data/spec/zenlish/support/var2word.rb +27 -18
- data/spec/zenlish/trie/base_trie_node_spec.rb +33 -0
- data/spec/zenlish/trie/trie_spec.rb +108 -0
- data/spec/zenlish/wclasses/common_noun_spec.rb +19 -7
- data/spec/zenlish/wclasses/demonstrative_determiner_spec.rb +47 -0
- data/spec/zenlish/wclasses/irregular_verb_can_spec.rb +60 -0
- data/spec/zenlish/wclasses/irregular_verb_spec.rb +14 -4
- data/spec/zenlish/wclasses/lexical_verb_spec.rb +9 -2
- data/spec/zenlish/wclasses/modal_verb_can_spec.rb +50 -0
- data/spec/zenlish/wclasses/personal_pronoun_spec.rb +66 -0
- data/spec/zenlish/wclasses/possessive_determiner_spec.rb +69 -0
- data/spec/zenlish/wclasses/regular_verb_spec.rb +35 -15
- data/spec/zenlish/wclasses/regular_verb_want_spec.rb +30 -0
- data/spec/zenlish/wclasses/verb_spec.rb +9 -2
- data/spec/zenlish_spec.rb +3 -1
- data/zenlish.gemspec +17 -14
- metadata +37 -10
- data/lib/zenlish/wclasses/modal_verb_could.rb +0 -9
@@ -13,7 +13,7 @@ module Zenlish
|
|
13
13
|
it 'should be initialized with a text literal' do
|
14
14
|
expect { FunctionCall.new('greet') }.not_to raise_error
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it 'should know its method name' do
|
18
18
|
expect(subject.mth_name).to eq('greet')
|
19
19
|
end
|
@@ -21,12 +21,12 @@ module Zenlish
|
|
21
21
|
|
22
22
|
context 'Provided services:' do
|
23
23
|
it 'should return the affix during word form generation' do
|
24
|
-
headings = double('fake-headings')
|
25
|
-
lexeme = OpenStruct.new(:
|
24
|
+
headings = double('fake-headings')
|
25
|
+
lexeme = OpenStruct.new(greet: 'Hello, world')
|
26
26
|
values = double('fake-values')
|
27
27
|
expect(subject.generate(headings, lexeme, values)).to eq('Hello, world')
|
28
28
|
end
|
29
29
|
end # context
|
30
30
|
end # describe
|
31
31
|
end # module
|
32
|
-
end # module
|
32
|
+
end # module
|
@@ -17,6 +17,8 @@ require_relative '../../../lib/zenlish/inflect/inflection_rule'
|
|
17
17
|
|
18
18
|
module Zenlish
|
19
19
|
module Inflect
|
20
|
+
# rubocop: disable Naming/VariableNumber
|
21
|
+
|
20
22
|
describe InflectionRule do
|
21
23
|
# One rule in row representation:
|
22
24
|
# | plural | ~ /[^aeiouy]y$/ | sub(base_form, /y$/, "ies")|
|
@@ -26,7 +28,7 @@ module Zenlish
|
|
26
28
|
let(:method_name) { 'base_form' }
|
27
29
|
let(:heading1) { MethodHeading.new(method_name) }
|
28
30
|
let(:headings) { [heading0, heading1] }
|
29
|
-
|
31
|
+
|
30
32
|
# Condition part
|
31
33
|
let(:feature_value) { :plural }
|
32
34
|
let(:arg_0) { FormalArgument.new(0) }
|
@@ -46,8 +48,9 @@ module Zenlish
|
|
46
48
|
|
47
49
|
context 'Initialization:' do
|
48
50
|
it 'should be initialized with condition and consequent parts' do
|
49
|
-
expect
|
50
|
-
|
51
|
+
expect do
|
52
|
+
InflectionRule.new(conditions, consequent)
|
53
|
+
end.not_to raise_error
|
51
54
|
end
|
52
55
|
|
53
56
|
it 'should know its condition part' do
|
@@ -82,7 +85,7 @@ module Zenlish
|
|
82
85
|
actuals = [:plural, 'cherry']
|
83
86
|
expect(subject.apply(headings, fake_lexeme, actuals)).to eq('cherries')
|
84
87
|
end
|
85
|
-
|
88
|
+
|
86
89
|
it 'should succeed when all conditions succeed for given lexeme' do
|
87
90
|
expect(subject.success?(headings, lexeme, [])).to be_truthy
|
88
91
|
end
|
@@ -95,8 +98,9 @@ module Zenlish
|
|
95
98
|
|
96
99
|
it 'should generate inflected form when rule works for given lexeme' do
|
97
100
|
expect(subject.apply(headings, lexeme, [])).to eq('cherries')
|
98
|
-
end
|
101
|
+
end
|
99
102
|
end # context
|
100
103
|
end # describe
|
104
|
+
# rubocop: enable Naming/VariableNumber
|
101
105
|
end # module
|
102
106
|
end # module
|
@@ -5,6 +5,9 @@ require_relative '../../../lib/zenlish/inflect/inflection_table_builder'
|
|
5
5
|
|
6
6
|
module Zenlish
|
7
7
|
module Inflect
|
8
|
+
# rubocop: disable Layout/SpaceInsideParens
|
9
|
+
# rubocop: disable Naming/VariableNumber
|
10
|
+
|
8
11
|
describe InflectionTableBuilder do
|
9
12
|
subject { InflectionTableBuilder.new }
|
10
13
|
|
@@ -95,7 +98,7 @@ module Zenlish
|
|
95
98
|
expect(conds_2[1]).to be_kind_of(UnconditionallyTrue)
|
96
99
|
end
|
97
100
|
|
98
|
-
|
101
|
+
let(:mock_feature_bearer) { Struct.new(:NUMBER, :base_form) }
|
99
102
|
|
100
103
|
it 'should build default paradigm for common nouns' do
|
101
104
|
table = subject.build('Common_form') do
|
@@ -106,22 +109,22 @@ module Zenlish
|
|
106
109
|
rule([equals(:plural), dont_care], concat(col('base_form'), 's'))
|
107
110
|
end
|
108
111
|
|
109
|
-
mck_1 =
|
112
|
+
mck_1 = mock_feature_bearer.new(:singular, 'animal')
|
110
113
|
expect(table.inflect(mck_1, [nil, nil])).to eq('animal')
|
111
114
|
mck_1['NUMBER'] = :plural
|
112
115
|
expect(table.inflect(mck_1, [nil, nil])).to eq('animals')
|
113
116
|
|
114
|
-
mck_2 =
|
117
|
+
mck_2 = mock_feature_bearer.new(:singular, 'boy')
|
115
118
|
expect(table.inflect(mck_2, [nil, nil])).to eq('boy')
|
116
119
|
mck_2['NUMBER'] = :plural
|
117
120
|
expect(table.inflect(mck_2, [nil, nil])).to eq('boys')
|
118
121
|
|
119
|
-
mck_3 =
|
122
|
+
mck_3 = mock_feature_bearer.new(:singular, 'body')
|
120
123
|
expect(table.inflect(mck_3, [nil, nil])).to eq('body')
|
121
124
|
mck_3['NUMBER'] = :plural
|
122
125
|
expect(table.inflect(mck_3, [nil, nil])).to eq('bodies')
|
123
126
|
end
|
124
|
-
|
127
|
+
|
125
128
|
MockRegularVerb = Struct.new(:base_form, :PERSON, :NUMBER, :TIME)
|
126
129
|
it 'should build default paradigm for regular verbs' do
|
127
130
|
table = subject.build('Regular_form') do
|
@@ -132,15 +135,15 @@ module Zenlish
|
|
132
135
|
# PERSON NUMBER TIME base_form
|
133
136
|
rule([not_equal(:third), dont_care, equals(:present), dont_care], col('base_form'))
|
134
137
|
rule([equals(:third), equals(:singular), equals(:present), matches(/[^aeiouy]y$/)], sub(col('base_form'), /y$/, 'ies'))
|
135
|
-
rule([equals(:third), equals(:singular), equals(:present), matches(/(?:[osxz]|ch|sh)$/)], concat(col('base_form'), 'es'))
|
136
|
-
rule([equals(:third), equals(:singular), equals(:present), dont_care], concat(col('base_form'), 's'))
|
137
|
-
rule([dont_care, dont_care, equals(:progressive), matches(/e$/)], sub(col('base_form'), /e$/, 'ing'))
|
138
|
+
rule([equals(:third), equals(:singular), equals(:present), matches(/(?:[osxz]|ch|sh)$/)], concat(col('base_form'), 'es'))
|
139
|
+
rule([equals(:third), equals(:singular), equals(:present), dont_care], concat(col('base_form'), 's'))
|
140
|
+
rule([dont_care, dont_care, equals(:progressive), matches(/e$/)], sub(col('base_form'), /e$/, 'ing'))
|
138
141
|
rule([dont_care, dont_care, equals(:progressive), dont_care], concat(col('base_form'), 'ing'))
|
139
|
-
rule([dont_care, dont_care, in?(:past_simple, :past_participle), matches(/e$/)], concat(col('base_form'), 'd'))
|
140
|
-
rule([dont_care, dont_care, in?(:past_simple, :past_participle), matches(/[^aeiouy]y$/)], sub(col('base_form'), /y$/, 'ied'))
|
142
|
+
rule([dont_care, dont_care, in?(:past_simple, :past_participle), matches(/e$/)], concat(col('base_form'), 'd'))
|
143
|
+
rule([dont_care, dont_care, in?(:past_simple, :past_participle), matches(/[^aeiouy]y$/)], sub(col('base_form'), /y$/, 'ied'))
|
141
144
|
rule([dont_care, dont_care, in?(:past_simple, :past_participle), dont_care], concat(col('base_form'), 'ed'))
|
142
145
|
end
|
143
|
-
|
146
|
+
|
144
147
|
verb_1 = MockRegularVerb.new('belong', :first, :singular, :present)
|
145
148
|
expect(table.inflect(verb_1, [nil, nil, nil, nil] )).to eq('belong')
|
146
149
|
expect(table.inflect(verb_1, [:third, nil, nil, nil] )).to eq('belongs')
|
@@ -148,7 +151,7 @@ module Zenlish
|
|
148
151
|
expect(table.inflect(verb_1, [nil, nil, :progressive, nil] )).to eq('belonging')
|
149
152
|
expect(table.inflect(verb_1, [nil, nil, :past_simple, nil] )).to eq('belonged')
|
150
153
|
expect(table.inflect(verb_1, [nil, nil, :past_participle, nil])).to eq('belonged')
|
151
|
-
|
154
|
+
|
152
155
|
verb_2 = MockRegularVerb.new('try', :first, :singular, :present)
|
153
156
|
expect(table.inflect(verb_2, [nil, nil, nil, nil] )).to eq('try')
|
154
157
|
expect(table.inflect(verb_2, [:third, nil, nil, nil] )).to eq('tries')
|
@@ -158,7 +161,7 @@ module Zenlish
|
|
158
161
|
expect(table.inflect(verb_2, [nil, nil, :past_participle, nil])).to eq('tried')
|
159
162
|
|
160
163
|
verb_3 = MockRegularVerb.new('touch', :first, :singular, :present)
|
161
|
-
expect(table.inflect(verb_3, [:second,nil,
|
164
|
+
expect(table.inflect(verb_3, [:second, nil, nil, nil] )).to eq('touch')
|
162
165
|
expect(table.inflect(verb_3, [:third, nil, nil, nil] )).to eq('touches')
|
163
166
|
expect(table.inflect(verb_3, [nil, :plural, nil, nil] )).to eq('touch')
|
164
167
|
expect(table.inflect(verb_3, [nil, nil, :progressive, nil] )).to eq('touching')
|
@@ -171,9 +174,9 @@ module Zenlish
|
|
171
174
|
expect(table.inflect(verb_4, [nil, :plural, nil, nil] )).to eq('cause')
|
172
175
|
expect(table.inflect(verb_4, [nil, nil, :progressive, nil] )).to eq('causing')
|
173
176
|
expect(table.inflect(verb_4, [nil, nil, :past_simple, nil] )).to eq('caused')
|
174
|
-
expect(table.inflect(verb_4, [nil, nil, :past_participle, nil])).to eq('caused')
|
177
|
+
expect(table.inflect(verb_4, [nil, nil, :past_participle, nil])).to eq('caused')
|
175
178
|
end
|
176
|
-
|
179
|
+
|
177
180
|
MockIrregularVerb = Struct.new(:base_form, :PERSON, :NUMBER, :TIME, :past_simple, :past_participle)
|
178
181
|
it 'should build default paradigm for irregular verbs' do
|
179
182
|
table = subject.build('Irregular_inflection') do
|
@@ -184,12 +187,12 @@ module Zenlish
|
|
184
187
|
# PERSON NUMBER TIME base_form
|
185
188
|
rule([not_equal(:third), dont_care, equals(:present), dont_care], col('base_form'))
|
186
189
|
rule([equals(:third), equals(:singular), equals(:present), matches(/[^aeiouy]y$/)], sub(col('base_form'), /y$/, 'ies'))
|
187
|
-
rule([equals(:third), equals(:singular), equals(:present), matches(/(?:[osxz]|ch|sh)$/)], concat(col('base_form'), 'es'))
|
188
|
-
rule([equals(:third), equals(:singular), equals(:present), dont_care], concat(col('base_form'), 's'))
|
189
|
-
rule([dont_care, dont_care, equals(:progressive), matches(/e$/)], sub(col('base_form'), /e$/, 'ing'))
|
190
|
+
rule([equals(:third), equals(:singular), equals(:present), matches(/(?:[osxz]|ch|sh)$/)], concat(col('base_form'), 'es'))
|
191
|
+
rule([equals(:third), equals(:singular), equals(:present), dont_care], concat(col('base_form'), 's'))
|
192
|
+
rule([dont_care, dont_care, equals(:progressive), matches(/e$/)], sub(col('base_form'), /e$/, 'ing'))
|
190
193
|
rule([dont_care, dont_care, equals(:progressive), dont_care], concat(col('base_form'), 'ing'))
|
191
|
-
rule([dont_care, dont_care, equals(:past_simple), dont_care], func('past_simple'))
|
192
|
-
rule([dont_care, dont_care, equals(:past_participle), dont_care], func('past_participle'))
|
194
|
+
rule([dont_care, dont_care, equals(:past_simple), dont_care], func('past_simple'))
|
195
|
+
rule([dont_care, dont_care, equals(:past_participle), dont_care], func('past_participle'))
|
193
196
|
end
|
194
197
|
|
195
198
|
verb_1 = MockIrregularVerb.new('choose', :first, :singular, :present, 'chose', 'chosen')
|
@@ -202,5 +205,7 @@ module Zenlish
|
|
202
205
|
end
|
203
206
|
end # context
|
204
207
|
end # describe
|
208
|
+
# rubocop: enable Naming/VariableNumber
|
209
|
+
# rubocop: enable Layout/SpaceInsideParens
|
205
210
|
end # module
|
206
|
-
end # module
|
211
|
+
end # module
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../../../lib/zenlish/lex/lexical_entry'
|
4
|
+
require_relative '../../../lib/zenlish/lex/lexeme'
|
5
|
+
require_relative '../../../lib/zenlish/wclasses/common_noun'
|
3
6
|
require_relative '../../../lib/zenlish/inflect/feature_heading'
|
4
7
|
require_relative '../../../lib/zenlish/inflect/method_heading'
|
5
8
|
require_relative '../../../lib/zenlish/inflect/unconditionally_true'
|
@@ -16,6 +19,8 @@ require_relative '../../../lib/zenlish/inflect/inflection_table'
|
|
16
19
|
|
17
20
|
module Zenlish
|
18
21
|
module Inflect
|
22
|
+
# rubocop: disable Naming/VariableNumber
|
23
|
+
|
19
24
|
describe InflectionTable do
|
20
25
|
let(:table_name) { 'Common_form' }
|
21
26
|
subject { InflectionTable.new(table_name) }
|
@@ -50,9 +55,9 @@ module Zenlish
|
|
50
55
|
let(:heading1) { MethodHeading.new(method_name) }
|
51
56
|
let(:arg_0) { FormalArgument.new(0) }
|
52
57
|
let(:arg_1) { FormalArgument.new(1) }
|
53
|
-
let(:feat_val_a) {
|
54
|
-
let(:feat_val_b) {
|
55
|
-
let(:feat_val_c) {
|
58
|
+
let(:feat_val_a) { :singular }
|
59
|
+
let(:feat_val_b) { :plural }
|
60
|
+
let(:feat_val_c) { :plural }
|
56
61
|
let(:cond_a_0) { EqualsLiteral.new(arg_0, feat_val_a) }
|
57
62
|
let(:cond_b_0) { EqualsLiteral.new(arg_0, feat_val_b) }
|
58
63
|
let(:cond_c_0) { EqualsLiteral.new(arg_0, feat_val_c) }
|
@@ -71,7 +76,11 @@ module Zenlish
|
|
71
76
|
let(:rule_a) { InflectionRule.new([cond_a_0, cond_a_1], cons_a) }
|
72
77
|
let(:rule_b) { InflectionRule.new([cond_b_0, cond_b_1], cons_b) }
|
73
78
|
let(:rule_c) { InflectionRule.new([cond_c_0, cond_c_1], cons_c) }
|
74
|
-
|
79
|
+
let(:a_wclass) { WClasses::CommonNoun.new }
|
80
|
+
let(:a_lemma) { 'body' }
|
81
|
+
let(:an_entry) { Lex::LexicalEntry.new(a_lemma) }
|
82
|
+
let(:lexm_body) { Lex::Lexeme.new(a_wclass, an_entry) }
|
83
|
+
let(:mock_feature_bearer) { Struct.new(:NUMBER, :base_form) }
|
75
84
|
|
76
85
|
it 'should accept the addition of heading(s)' do
|
77
86
|
expect { subject.add_heading(heading0) }.not_to raise_error
|
@@ -89,6 +98,14 @@ module Zenlish
|
|
89
98
|
expect(subject.rules.last).to eq(rule_c)
|
90
99
|
end
|
91
100
|
|
101
|
+
def init_table(aTable)
|
102
|
+
aTable.add_heading(heading0)
|
103
|
+
aTable.add_heading(heading1)
|
104
|
+
aTable.add_rule(rule_a)
|
105
|
+
aTable.add_rule(rule_b)
|
106
|
+
aTable.add_rule(rule_c)
|
107
|
+
end
|
108
|
+
|
92
109
|
# DecisionTable: Common_form
|
93
110
|
# | NUMBER | .base_form | Common_form |
|
94
111
|
# | singular | X | base_form |
|
@@ -103,27 +120,27 @@ module Zenlish
|
|
103
120
|
# rule(equals(:plural) , dont_care , concat(col(1), 's'))
|
104
121
|
# end
|
105
122
|
it 'should determine the word form given input entries' do
|
106
|
-
subject
|
107
|
-
|
108
|
-
subject.
|
109
|
-
|
110
|
-
subject.
|
111
|
-
mck_1 = MockFeatureBearer.new('singular', 'animal')
|
112
|
-
expect(subject.inflect(mck_1, [nil, nil])).to eq('animal')
|
113
|
-
mck_1['NUMBER'] = 'plural'
|
114
|
-
expect(subject.inflect(mck_1, [nil, nil])).to eq('animals')
|
123
|
+
init_table(subject)
|
124
|
+
mck1 = mock_feature_bearer.new(:singular, 'animal')
|
125
|
+
expect(subject.inflect(mck1, [nil, nil])).to eq('animal')
|
126
|
+
mck1['NUMBER'] = :plural
|
127
|
+
expect(subject.inflect(mck1, [nil, nil])).to eq('animals')
|
115
128
|
|
116
|
-
|
117
|
-
expect(subject.inflect(
|
118
|
-
|
119
|
-
expect(subject.inflect(
|
129
|
+
mck2 = mock_feature_bearer.new(:singular, 'boy')
|
130
|
+
expect(subject.inflect(mck2, [nil, nil])).to eq('boy')
|
131
|
+
mck2['NUMBER'] = :plural
|
132
|
+
expect(subject.inflect(mck2, [nil, nil])).to eq('boys')
|
133
|
+
|
134
|
+
expect(subject.inflect(lexm_body, [:singular, nil])).to eq('body')
|
135
|
+
expect(subject.inflect(lexm_body, [:plural, nil])).to eq('bodies')
|
136
|
+
end
|
120
137
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
expect(subject.inflect(mck_3, [nil, nil])).to eq('bodies')
|
138
|
+
it 'should know all the word forms of a given lexeme' do
|
139
|
+
init_table(subject)
|
140
|
+
expect(subject.all_inflections(lexm_body)).to eq(%w[body bodies])
|
125
141
|
end
|
126
142
|
end # context
|
127
143
|
end # describe
|
144
|
+
# rubocop: enable Naming/VariableNumber
|
128
145
|
end # module
|
129
|
-
end # module
|
146
|
+
end # module
|
@@ -31,7 +31,7 @@ module Zenlish
|
|
31
31
|
headings = double('fake-headings')
|
32
32
|
expect(subject.generate(headings, lexeme, sample_values)).to eq('Hello, world.')
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it 'should return the text of given lexeme during generation' do
|
36
36
|
c_noun = WClasses::CommonNoun.new
|
37
37
|
an_entry = Lex::LexicalEntry.new('cherry')
|
@@ -40,11 +40,7 @@ module Zenlish
|
|
40
40
|
headings = [nil, nil, heading, nil]
|
41
41
|
expect(subject.generate(headings, lexeme, [])).to eq('cherry')
|
42
42
|
end
|
43
|
-
|
44
|
-
=begin
|
45
|
-
|
46
|
-
=end
|
47
43
|
end # context
|
48
44
|
end # describe
|
49
45
|
end # module
|
50
|
-
end # module
|
46
|
+
end # module
|
@@ -12,7 +12,7 @@ module Zenlish
|
|
12
12
|
it 'should be initialized with a text literal' do
|
13
13
|
expect { LiteralAsIs.new('s') }.not_to raise_error
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it 'should know its text value' do
|
17
17
|
expect(subject.text).to eq('s')
|
18
18
|
end
|
@@ -20,7 +20,7 @@ module Zenlish
|
|
20
20
|
|
21
21
|
context 'Provided services:' do
|
22
22
|
it 'should return the affix during word form generation' do
|
23
|
-
headings = double('fake-headings')
|
23
|
+
headings = double('fake-headings')
|
24
24
|
lexeme = double('fake-lexeme')
|
25
25
|
values = double('fake-values')
|
26
26
|
expect(subject.generate(headings, lexeme, values)).to eq('s')
|
@@ -28,4 +28,4 @@ module Zenlish
|
|
28
28
|
end # context
|
29
29
|
end # describe
|
30
30
|
end # module
|
31
|
-
end # module
|
31
|
+
end # module
|
@@ -12,7 +12,7 @@ module Zenlish
|
|
12
12
|
module Inflect
|
13
13
|
describe Membership do
|
14
14
|
let(:an_argument) { FormalArgument.new(1) }
|
15
|
-
let(:feat_val) { [
|
15
|
+
let(:feat_val) { %i[singular plural] }
|
16
16
|
subject { Membership.new(an_argument, feat_val) }
|
17
17
|
|
18
18
|
context 'Initialization:' do
|
@@ -38,7 +38,7 @@ module Zenlish
|
|
38
38
|
actual_args[1] = :singular
|
39
39
|
expect(subject.success?(headings, lexeme, actual_args)).to be_truthy
|
40
40
|
actual_args[1] = :dual
|
41
|
-
expect(subject.success?(headings, lexeme, actual_args)).to be_falsy
|
41
|
+
expect(subject.success?(headings, lexeme, actual_args)).to be_falsy
|
42
42
|
end
|
43
43
|
|
44
44
|
# it 'should test the lexeme' do
|
@@ -25,7 +25,13 @@ module Zenlish
|
|
25
25
|
expect(mocked).to receive(:base_form).and_return('cherry')
|
26
26
|
expect(subject.evaluate_for(mocked)).to eq('cherry')
|
27
27
|
end
|
28
|
+
|
29
|
+
it 'should obtain the method result as an array' do
|
30
|
+
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
|
28
34
|
end # context
|
29
35
|
end # describe
|
30
36
|
end # module
|
31
|
-
end # module
|
37
|
+
end # module
|
@@ -11,7 +11,7 @@ module Zenlish
|
|
11
11
|
|
12
12
|
context 'Initialization:' do
|
13
13
|
it 'should be initialized without argument' do
|
14
|
-
expect { UnconditionallyTrue.new}.not_to raise_error
|
14
|
+
expect { UnconditionallyTrue.new }.not_to raise_error
|
15
15
|
end
|
16
16
|
end # context
|
17
17
|
|
@@ -25,4 +25,4 @@ module Zenlish
|
|
25
25
|
end # context
|
26
26
|
end # describe
|
27
27
|
end # module
|
28
|
-
end # module
|
28
|
+
end # module
|
@@ -12,8 +12,8 @@ module Zenlish
|
|
12
12
|
context 'Provided services:' do
|
13
13
|
let(:common_nouns) do
|
14
14
|
# Some Zenlish common nouns
|
15
|
-
%w(
|
16
|
-
|
15
|
+
%w(animal body container here kind machine moment now part people
|
16
|
+
person place side surface thing time word)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should give the list of common nouns' do
|
@@ -27,22 +27,27 @@ module Zenlish
|
|
27
27
|
expect(common_nouns.all? { |c_n| lemmas.include?(c_n) }).to be_truthy
|
28
28
|
end
|
29
29
|
|
30
|
-
let(:present_1sg)
|
31
|
-
let(:
|
32
|
-
let(:
|
33
|
-
let(:
|
34
|
-
let(:
|
35
|
-
let(:
|
30
|
+
let(:present_1sg) { [:first, :singular, :present, nil] }
|
31
|
+
let(:present_2sg) { [:second, :singular, :present, nil] }
|
32
|
+
let(:present_3sg) { [:third, :singular, :present, nil] }
|
33
|
+
let(:present_1pl) { [:first, :plural, :present, nil] }
|
34
|
+
let(:progressive) { [nil, nil, :progressive, nil] }
|
35
|
+
let(:past_simple) { [:first, :singular, :past_simple, nil] }
|
36
|
+
let(:past_simple_2sg) { [:second, :singular, :past_simple, nil] }
|
37
|
+
let(:past_simple_3sg) { [:third, :singular, :past_simple, nil] }
|
38
|
+
let(:past_simple_1pl) { [:first, :plural, :past_simple, nil] }
|
39
|
+
let(:past_participle) { [nil, nil, :past_participle, nil] }
|
36
40
|
|
37
|
-
def test_inflection_of(verb_lexeme, pairs)
|
41
|
+
def test_inflection_of(verb_lexeme, pairs, drop_last_column = false)
|
38
42
|
pairs.each do |(constraints, expected_form)|
|
39
|
-
|
43
|
+
restriction = drop_last_column ? constraints.slice(0..-2) : constraints
|
44
|
+
expect(verb_lexeme.inflect(restriction)).to eq(expected_form)
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
43
48
|
it 'should know how to inflect an (irregular) verb' do
|
44
49
|
lexm = subject.get_lexeme('become')
|
45
|
-
|
50
|
+
expectations1 = [
|
46
51
|
[present_1sg, 'become'],
|
47
52
|
[present_3sg, 'becomes'],
|
48
53
|
[present_1pl, 'become'],
|
@@ -50,10 +55,10 @@ module Zenlish
|
|
50
55
|
[past_simple, 'became'],
|
51
56
|
[past_participle, 'become']
|
52
57
|
]
|
53
|
-
test_inflection_of(lexm,
|
54
|
-
|
58
|
+
test_inflection_of(lexm, expectations1)
|
59
|
+
|
55
60
|
lexm = subject.get_lexeme('do', WClasses::IrregularVerbDo)
|
56
|
-
|
61
|
+
expectations2 = [
|
57
62
|
[present_1sg, 'do'],
|
58
63
|
[present_3sg, 'does'],
|
59
64
|
[present_1pl, 'do'],
|
@@ -61,9 +66,39 @@ module Zenlish
|
|
61
66
|
[past_simple, 'did'],
|
62
67
|
[past_participle, 'done']
|
63
68
|
]
|
64
|
-
test_inflection_of(lexm,
|
69
|
+
test_inflection_of(lexm, expectations2, true)
|
70
|
+
|
71
|
+
lexm = subject.get_lexeme('have', WClasses::IrregularVerbHave)
|
72
|
+
expectations3 = [
|
73
|
+
[present_1sg, 'have'],
|
74
|
+
[present_3sg, 'has'],
|
75
|
+
[present_1pl, 'have'],
|
76
|
+
[progressive, 'having'],
|
77
|
+
[past_simple, 'had'],
|
78
|
+
[past_participle, 'had']
|
79
|
+
]
|
80
|
+
test_inflection_of(lexm, expectations3, true)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should know how to inflect the verb be' do
|
84
|
+
[WClasses::IrregularVerbBe, WClasses::AuxiliaryBe].each do |wclass|
|
85
|
+
lexm = subject.get_lexeme('be', wclass)
|
86
|
+
expectations1 = [
|
87
|
+
[present_1sg, 'am'],
|
88
|
+
[present_2sg, 'are'],
|
89
|
+
[present_3sg, 'is'],
|
90
|
+
[present_1pl, 'are'],
|
91
|
+
[progressive, 'being'],
|
92
|
+
[past_simple, 'was'],
|
93
|
+
[past_simple_2sg, 'were'],
|
94
|
+
[past_simple_3sg, 'was'],
|
95
|
+
[past_simple_1pl, 'were'],
|
96
|
+
[past_participle, 'been']
|
97
|
+
]
|
98
|
+
test_inflection_of(lexm, expectations1, true)
|
99
|
+
end
|
65
100
|
end
|
66
101
|
end # context
|
67
102
|
end # describe
|
68
103
|
end # module
|
69
|
-
end # module
|
104
|
+
end # module
|