zenlish 0.1.25 → 0.2.00
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/lib/zenlish/feature/boolean_domain.rb +29 -0
- data/lib/zenlish/feature/boolean_value.rb +9 -0
- data/lib/zenlish/feature/enumeration_domain.rb +32 -0
- data/lib/zenlish/feature/feature.rb +30 -0
- data/lib/zenlish/feature/feature_def.rb +48 -0
- data/lib/zenlish/feature/feature_domain.rb +9 -0
- data/lib/zenlish/feature/feature_struct.rb +24 -0
- data/lib/zenlish/feature/feature_struct_def.rb +44 -0
- data/lib/zenlish/feature/feature_struct_def_bearer.rb +65 -0
- data/lib/zenlish/feature/feature_value.rb +17 -0
- data/lib/zenlish/feature/identifier_domain.rb +29 -0
- data/lib/zenlish/feature/identifier_value.rb +9 -0
- data/lib/zenlish/feature/symbol_value.rb +8 -0
- data/lib/zenlish/inflect/atomic_o_expression.rb +9 -0
- data/lib/zenlish/inflect/composite_o_expression.rb +14 -0
- data/lib/zenlish/inflect/concatenation.rb +36 -0
- data/lib/zenlish/inflect/equals_literal.rb +25 -0
- data/lib/zenlish/inflect/feature_heading.rb +16 -0
- data/lib/zenlish/inflect/formal_argument.rb +11 -0
- data/lib/zenlish/inflect/heading.rb +11 -0
- data/lib/zenlish/inflect/inflection_rule.rb +28 -0
- data/lib/zenlish/inflect/inflection_table.rb +46 -0
- data/lib/zenlish/inflect/inflection_table_builder.rb +120 -0
- data/lib/zenlish/inflect/input_asis.rb +22 -0
- data/lib/zenlish/inflect/input_expression.rb +9 -0
- data/lib/zenlish/inflect/literal_asis.rb +17 -0
- data/lib/zenlish/inflect/matches_pattern.rb +26 -0
- data/lib/zenlish/inflect/method_heading.rb +16 -0
- data/lib/zenlish/inflect/nullary_input_expression.rb +8 -0
- data/lib/zenlish/inflect/output_expression.rb +6 -0
- data/lib/zenlish/inflect/substitution.rb +65 -0
- data/lib/zenlish/inflect/unary_input_expression.rb +13 -0
- data/lib/zenlish/inflect/unconditionally_true.rb +11 -0
- data/lib/zenlish/lang/dictionary.rb +19 -6
- data/lib/zenlish/lang/zenlish_grammar.rb +1 -0
- data/lib/zenlish/lex/empty_lexicon_factory.rb +3 -0
- data/lib/zenlish/lex/lexeme.rb +27 -4
- data/lib/zenlish/lex/lexicon.rb +3 -0
- data/lib/zenlish/lex/literal.rb +5 -1
- data/lib/zenlish/version.rb +1 -1
- data/lib/zenlish/wclasses/common_noun.rb +45 -0
- data/lib/zenlish/wclasses/noun.rb +21 -0
- data/lib/zenlish/wclasses/preposition.rb +5 -0
- data/lib/zenlish/wclasses/proper_noun.rb +11 -0
- data/lib/zenlish/wclasses/verb.rb +9 -1
- data/lib/zenlish/wclasses/word_class.rb +21 -6
- data/spec/spec_helper.rb +2 -3
- data/spec/zenlish/feature/boolean_domain_spec.rb +35 -0
- data/spec/zenlish/feature/boolean_value_spec.rb +26 -0
- data/spec/zenlish/feature/enumeration_domain_spec.rb +42 -0
- data/spec/zenlish/feature/feature_def_spec.rb +50 -0
- data/spec/zenlish/feature/feature_spec.rb +51 -0
- data/spec/zenlish/feature/feature_struct_def_bearer_spec.rb +54 -0
- data/spec/zenlish/feature/feature_struct_def_spec.rb +69 -0
- data/spec/zenlish/feature/identifier_domain_spec.rb +36 -0
- data/spec/zenlish/feature/identifier_value_spec.rb +26 -0
- data/spec/zenlish/feature/symbol_value_spec.rb +27 -0
- data/spec/zenlish/inflect/concatenation_spec.rb +40 -0
- data/spec/zenlish/inflect/equals_literal_spec.rb +58 -0
- data/spec/zenlish/inflect/feature_heading_spec.rb +30 -0
- data/spec/zenlish/inflect/formal_argument_spec.rb +25 -0
- data/spec/zenlish/inflect/inflection_rule_spec.rb +102 -0
- data/spec/zenlish/inflect/inflection_table_builder_spec.rb +127 -0
- data/spec/zenlish/inflect/inflection_table_spec.rb +129 -0
- data/spec/zenlish/inflect/input_asis_spec.rb +50 -0
- data/spec/zenlish/inflect/literal_asis_spec.rb +31 -0
- data/spec/zenlish/inflect/matches_pattern_spec.rb +61 -0
- data/spec/zenlish/inflect/method_heading_spec.rb +31 -0
- data/spec/zenlish/inflect/substitution_spec.rb +43 -0
- data/spec/zenlish/inflect/unconditionally_true_spec.rb +28 -0
- data/spec/zenlish/lang/dictionary_spec.rb +33 -0
- data/spec/zenlish/lex/lexeme_spec.rb +24 -9
- data/spec/zenlish/lex/literal_spec.rb +3 -11
- data/spec/zenlish/parser/lesson3_spec.rb +44 -0
- data/spec/zenlish/support/minimal_lexicon.rb +0 -2
- data/spec/zenlish/support/var2word.rb +5 -1
- data/spec/zenlish/wclasses/common_noun_spec.rb +25 -4
- data/spec/zenlish/wclasses/noun_spec.rb +31 -0
- data/spec/zenlish/wclasses/preposition_spec.rb +24 -0
- data/spec/zenlish/wclasses/verb_spec.rb +24 -0
- metadata +89 -2
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../lib/zenlish/wclasses/common_noun'
|
4
|
+
require_relative '../../../lib/zenlish/lex/lexeme'
|
5
|
+
require_relative '../../../lib/zenlish/lex/lexical_entry'
|
6
|
+
require_relative '../../../lib/zenlish/inflect/feature_heading'
|
7
|
+
require_relative '../../../lib/zenlish/inflect/method_heading'
|
8
|
+
require_relative '../../../lib/zenlish/inflect/literal_asis'
|
9
|
+
require_relative '../../../lib/zenlish/inflect/input_asis'
|
10
|
+
require_relative '../../../lib/zenlish/inflect/equals_literal'
|
11
|
+
require_relative '../../../lib/zenlish/inflect/formal_argument'
|
12
|
+
require_relative '../../../lib/zenlish/inflect/matches_pattern'
|
13
|
+
require_relative '../../../lib/zenlish/inflect/substitution'
|
14
|
+
|
15
|
+
# Load the class under test
|
16
|
+
require_relative '../../../lib/zenlish/inflect/inflection_rule'
|
17
|
+
|
18
|
+
module Zenlish
|
19
|
+
module Inflect
|
20
|
+
describe InflectionRule do
|
21
|
+
# One rule in row representation:
|
22
|
+
# | plural | ~ /[^aeiouy]y$/ | sub(base_form, /y$/, "ies")|
|
23
|
+
# Heading part
|
24
|
+
let(:feature_name) { 'NUMBER' }
|
25
|
+
let(:heading0) { FeatureHeading.new(feature_name) }
|
26
|
+
let(:method_name) { 'base_form' }
|
27
|
+
let(:heading1) { MethodHeading.new(method_name) }
|
28
|
+
let(:headings) { [heading0, heading1] }
|
29
|
+
|
30
|
+
# Condition part
|
31
|
+
let(:feature_value) { :plural }
|
32
|
+
let(:arg_0) { FormalArgument.new(0) }
|
33
|
+
let(:cond_0) { EqualsLiteral.new(arg_0, feature_value) }
|
34
|
+
let(:arg_1) { FormalArgument.new(1) }
|
35
|
+
let(:patt) { /[^aeiouy]y$/ }
|
36
|
+
let(:cond_1) { MatchesPattern.new(arg_1, patt) }
|
37
|
+
let(:conditions) { [cond_0, cond_1] }
|
38
|
+
|
39
|
+
# Consequent part
|
40
|
+
let(:suffix) { LiteralAsIs.new('ies') }
|
41
|
+
let(:base) { InputAsIs.new(arg_1) }
|
42
|
+
let(:pattern) { /y$/ }
|
43
|
+
let(:consequent) { Substitution.new(base, pattern, suffix) }
|
44
|
+
|
45
|
+
subject { InflectionRule.new(conditions, consequent) }
|
46
|
+
|
47
|
+
context 'Initialization:' do
|
48
|
+
it 'should be initialized with condition and consequent parts' do
|
49
|
+
expect { InflectionRule.new(conditions, consequent)
|
50
|
+
}.not_to raise_error
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should know its condition part' do
|
54
|
+
expect(subject.conditions).to eq(conditions)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should know its consequent part' do
|
58
|
+
expect(subject.consequent).to eq(consequent)
|
59
|
+
end
|
60
|
+
end # context
|
61
|
+
|
62
|
+
context 'Provided services:' do
|
63
|
+
let(:fake_lexeme) { double('dummy-fake_lexeme') }
|
64
|
+
let(:c_noun) { WClasses::CommonNoun.new }
|
65
|
+
let(:an_entry) { Lex::LexicalEntry.new('cherry') }
|
66
|
+
let(:lexeme) { Lex::Lexeme.new(c_noun, an_entry) }
|
67
|
+
|
68
|
+
it 'should succeed when all conditions succeed with actuals' do
|
69
|
+
actuals = [:plural, 'cherry']
|
70
|
+
expect(subject.success?(headings, fake_lexeme, actuals)).to be_truthy
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should fail when one condition fails with actuals' do
|
74
|
+
actuals = [:singular, 'cherry']
|
75
|
+
expect(subject.success?(headings, fake_lexeme, actuals)).to be_falsy
|
76
|
+
|
77
|
+
actuals = [:plural, 'girl']
|
78
|
+
expect(subject.success?(headings, fake_lexeme, actuals)).to be_falsy
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should generate inflected form when rule iworks for actuals' do
|
82
|
+
actuals = [:plural, 'cherry']
|
83
|
+
expect(subject.apply(headings, fake_lexeme, actuals)).to eq('cherries')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should succeed when all conditions succeed for given lexeme' do
|
87
|
+
expect(subject.success?(headings, lexeme, [])).to be_truthy
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should fail when one condition fails with given lexeme' do
|
91
|
+
entry_2 = Lex::LexicalEntry.new('animal')
|
92
|
+
lex_m2 = Lex::Lexeme.new(c_noun, entry_2)
|
93
|
+
expect(subject.success?(headings, lex_m2, [])).to be_falsy
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should generate inflected form when rule works for given lexeme' do
|
97
|
+
expect(subject.apply(headings, lexeme, [])).to eq('cherries')
|
98
|
+
end
|
99
|
+
end # context
|
100
|
+
end # describe
|
101
|
+
end # module
|
102
|
+
end # module
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../../lib/zenlish/inflect/inflection_table_builder'
|
5
|
+
|
6
|
+
module Zenlish
|
7
|
+
module Inflect
|
8
|
+
describe InflectionTableBuilder do
|
9
|
+
subject { InflectionTableBuilder.new }
|
10
|
+
|
11
|
+
context 'Initialization:' do
|
12
|
+
it 'should be initialized without argument' do
|
13
|
+
expect { InflectionTableBuilder.new }.not_to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should not have headings after initialization' do
|
17
|
+
expect(subject.headings).to be_empty
|
18
|
+
end
|
19
|
+
end # context
|
20
|
+
|
21
|
+
context 'Basic services:' do
|
22
|
+
it 'should retain the table name' do
|
23
|
+
subject.build('Common_form')
|
24
|
+
expect(subject.table.name).to eq('Common_form')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should accept heading creation' do
|
28
|
+
# First way
|
29
|
+
subject.feature_heading 'NUMBER'
|
30
|
+
expect(subject.headings.size).to eq(1)
|
31
|
+
expect(subject.headings.last.label).to eq('NUMBER')
|
32
|
+
subject.method_heading 'base_form'
|
33
|
+
expect(subject.headings.last).to be_kind_of(MethodHeading)
|
34
|
+
expect(subject.headings.last.label).to eq('base_form')
|
35
|
+
|
36
|
+
# Second way
|
37
|
+
table = subject.build('Common_form') do
|
38
|
+
feature_heading 'NUMBER'
|
39
|
+
method_heading 'base_form'
|
40
|
+
end
|
41
|
+
expect(table.name).to eq('Common_form')
|
42
|
+
expect(table.headings.last.label).to eq('base_form')
|
43
|
+
end
|
44
|
+
end # context
|
45
|
+
|
46
|
+
context 'Table building:' do
|
47
|
+
it 'should be able to build consequents' do
|
48
|
+
table = subject.build('Common_form') do
|
49
|
+
feature_heading 'NUMBER'
|
50
|
+
method_heading 'base_form'
|
51
|
+
rule([], col('base_form'))
|
52
|
+
rule([], sub(col('base_form'), /y$/, 'ies'))
|
53
|
+
rule([], concat(col('base_form'), 's'))
|
54
|
+
end
|
55
|
+
expect(table.rules).not_to be_empty
|
56
|
+
consequent_0 = table.rules[0].consequent
|
57
|
+
expect(consequent_0).to be_kind_of(InputAsIs)
|
58
|
+
expect(consequent_0.formal.index).to eq(1)
|
59
|
+
|
60
|
+
consequent_1 = table.rules[1].consequent
|
61
|
+
expect(consequent_1).to be_kind_of(Substitution)
|
62
|
+
expect(consequent_1.children[0].formal.index).to eq(1)
|
63
|
+
expect(consequent_1.pattern).to eq(/y$/)
|
64
|
+
expect(consequent_1.children[-1].text).to eq('ies')
|
65
|
+
|
66
|
+
consequent_2 = table.rules[2].consequent
|
67
|
+
expect(consequent_2.children[0].formal.index).to eq(1)
|
68
|
+
expect(consequent_2).to be_kind_of(Concatenation)
|
69
|
+
expect(consequent_2.children[-1].text).to eq('s')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should be able to build conditions' do
|
73
|
+
table = subject.build('Common_form') do
|
74
|
+
feature_heading 'NUMBER'
|
75
|
+
method_heading 'base_form'
|
76
|
+
rule([equals(:singular), dont_care], col('base_form'))
|
77
|
+
rule([equals(:plural), matches(/[^aeiouy]y$/)], sub(col('base_form'), /y$/, 'ies'))
|
78
|
+
rule([equals(:plural), dont_care], concat(col('base_form'), 's'))
|
79
|
+
end
|
80
|
+
|
81
|
+
conds_0 = table.rules[0].conditions
|
82
|
+
expect(conds_0[0]).to be_kind_of(EqualsLiteral)
|
83
|
+
expect(conds_0[0].literal).to eq(:singular)
|
84
|
+
expect(conds_0[1]).to be_kind_of(UnconditionallyTrue)
|
85
|
+
|
86
|
+
conds_1 = table.rules[1].conditions
|
87
|
+
expect(conds_1[0]).to be_kind_of(EqualsLiteral)
|
88
|
+
expect(conds_1[0].literal).to eq(:plural)
|
89
|
+
expect(conds_1[1]).to be_kind_of(MatchesPattern)
|
90
|
+
expect(conds_1[1].pattern).to eq(/[^aeiouy]y$/)
|
91
|
+
|
92
|
+
conds_2 = table.rules[2].conditions
|
93
|
+
expect(conds_2[0]).to be_kind_of(EqualsLiteral)
|
94
|
+
expect(conds_2[0].literal).to eq(:plural)
|
95
|
+
expect(conds_2[1]).to be_kind_of(UnconditionallyTrue)
|
96
|
+
end
|
97
|
+
|
98
|
+
MockFeatureBearer = Struct.new(:NUMBER, :base_form)
|
99
|
+
|
100
|
+
it 'should build tables conform to specs' do
|
101
|
+
table = subject.build('Common_form') do
|
102
|
+
feature_heading 'NUMBER'
|
103
|
+
method_heading 'base_form'
|
104
|
+
rule([equals(:singular), dont_care], col('base_form'))
|
105
|
+
rule([equals(:plural), matches(/[^aeiouy]y$/)], sub(col('base_form'), /y$/, 'ies'))
|
106
|
+
rule([equals(:plural), dont_care], concat(col('base_form'), 's'))
|
107
|
+
end
|
108
|
+
|
109
|
+
mck_1 = MockFeatureBearer.new(:singular, 'animal')
|
110
|
+
expect(table.inflect(mck_1, [nil, nil])).to eq('animal')
|
111
|
+
mck_1['NUMBER'] = :plural
|
112
|
+
expect(table.inflect(mck_1, [nil, nil])).to eq('animals')
|
113
|
+
|
114
|
+
mck_2 = MockFeatureBearer.new(:singular, 'boy')
|
115
|
+
expect(table.inflect(mck_2, [nil, nil])).to eq('boy')
|
116
|
+
mck_2['NUMBER'] = :plural
|
117
|
+
expect(table.inflect(mck_2, [nil, nil])).to eq('boys')
|
118
|
+
|
119
|
+
mck_3 = MockFeatureBearer.new(:singular, 'body')
|
120
|
+
expect(table.inflect(mck_3, [nil, nil])).to eq('body')
|
121
|
+
mck_3['NUMBER'] = :plural
|
122
|
+
expect(table.inflect(mck_3, [nil, nil])).to eq('bodies')
|
123
|
+
end
|
124
|
+
end # context
|
125
|
+
end # describe
|
126
|
+
end # module
|
127
|
+
end # module
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../lib/zenlish/inflect/feature_heading'
|
4
|
+
require_relative '../../../lib/zenlish/inflect/method_heading'
|
5
|
+
require_relative '../../../lib/zenlish/inflect/unconditionally_true'
|
6
|
+
require_relative '../../../lib/zenlish/inflect/literal_asis'
|
7
|
+
require_relative '../../../lib/zenlish/inflect/input_asis'
|
8
|
+
require_relative '../../../lib/zenlish/inflect/equals_literal'
|
9
|
+
require_relative '../../../lib/zenlish/inflect/formal_argument'
|
10
|
+
require_relative '../../../lib/zenlish/inflect/matches_pattern'
|
11
|
+
require_relative '../../../lib/zenlish/inflect/concatenation'
|
12
|
+
require_relative '../../../lib/zenlish/inflect/substitution'
|
13
|
+
require_relative '../../../lib/zenlish/inflect/inflection_rule'
|
14
|
+
# Load the class under test
|
15
|
+
require_relative '../../../lib/zenlish/inflect/inflection_table'
|
16
|
+
|
17
|
+
module Zenlish
|
18
|
+
module Inflect
|
19
|
+
describe InflectionTable do
|
20
|
+
let(:table_name) { 'Common_form' }
|
21
|
+
subject { InflectionTable.new(table_name) }
|
22
|
+
|
23
|
+
context 'Initialization:' do
|
24
|
+
it 'should be initialized with a name' do
|
25
|
+
expect { InflectionTable.new(table_name) }.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should now its name' do
|
29
|
+
expect(subject.name).to eq(table_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not have headings at start' do
|
33
|
+
expect(subject.headings).to be_empty
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should not have rules at start' do
|
37
|
+
expect(subject.rules).to be_empty
|
38
|
+
end
|
39
|
+
end # context
|
40
|
+
|
41
|
+
context 'Provided services:' do
|
42
|
+
# DecisionTable: Common_form
|
43
|
+
# | NUMBER | .base_form | Common_form |
|
44
|
+
# | singular | X | base_form |
|
45
|
+
# | plural | ~ /[^aeiouy]y$/ | sub(base_form, /y$/, "ies")|
|
46
|
+
# | plural | X | base_form + "s" |
|
47
|
+
let(:feature_name) { 'NUMBER' }
|
48
|
+
let(:heading0) { FeatureHeading.new(feature_name) }
|
49
|
+
let(:method_name) { 'base_form' }
|
50
|
+
let(:heading1) { MethodHeading.new(method_name) }
|
51
|
+
let(:arg_0) { FormalArgument.new(0) }
|
52
|
+
let(:arg_1) { FormalArgument.new(1) }
|
53
|
+
let(:feat_val_a) { 'singular' }
|
54
|
+
let(:feat_val_b) { 'plural' }
|
55
|
+
let(:feat_val_c) { 'plural' }
|
56
|
+
let(:cond_a_0) { EqualsLiteral.new(arg_0, feat_val_a) }
|
57
|
+
let(:cond_b_0) { EqualsLiteral.new(arg_0, feat_val_b) }
|
58
|
+
let(:cond_c_0) { EqualsLiteral.new(arg_0, feat_val_c) }
|
59
|
+
let(:cond_a_1) { UnconditionallyTrue.new }
|
60
|
+
let(:patt_b_1) { /[^aeiouy]y$/ }
|
61
|
+
let(:cond_b_1) { MatchesPattern.new(arg_1, patt_b_1) }
|
62
|
+
let(:cond_c_1) { UnconditionallyTrue.new }
|
63
|
+
let(:cons_a) { InputAsIs.new(arg_1) }
|
64
|
+
let(:cons_b_arg) { InputAsIs.new(arg_1) }
|
65
|
+
let(:patt_b_2) { /y$/ }
|
66
|
+
let(:suffix_b) { LiteralAsIs.new('ies') }
|
67
|
+
let(:cons_b) { Substitution.new(cons_b_arg, patt_b_2, suffix_b) }
|
68
|
+
let(:cons_c_arg) { InputAsIs.new(arg_1) }
|
69
|
+
let(:suffix_c) { LiteralAsIs.new('s') }
|
70
|
+
let(:cons_c) { Concatenation.new(cons_c_arg, suffix_c) }
|
71
|
+
let(:rule_a) { InflectionRule.new([cond_a_0, cond_a_1], cons_a) }
|
72
|
+
let(:rule_b) { InflectionRule.new([cond_b_0, cond_b_1], cons_b) }
|
73
|
+
let(:rule_c) { InflectionRule.new([cond_c_0, cond_c_1], cons_c) }
|
74
|
+
MockFeatureBearer = Struct.new(:NUMBER, :base_form)
|
75
|
+
|
76
|
+
it 'should accept the addition of heading(s)' do
|
77
|
+
expect { subject.add_heading(heading0) }.not_to raise_error
|
78
|
+
expect(subject.headings.size).to eq(1)
|
79
|
+
subject.add_heading(heading1)
|
80
|
+
expect(subject.headings.last).to eq(heading1)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should accept the addition of rule(s)' do
|
84
|
+
expect { subject.add_rule(rule_a) }.not_to raise_error
|
85
|
+
expect(subject.rules.size).to eq(1)
|
86
|
+
subject.add_rule(rule_b)
|
87
|
+
expect(subject.rules.last).to eq(rule_b)
|
88
|
+
subject.add_rule(rule_c)
|
89
|
+
expect(subject.rules.last).to eq(rule_c)
|
90
|
+
end
|
91
|
+
|
92
|
+
# DecisionTable: Common_form
|
93
|
+
# | NUMBER | .base_form | Common_form |
|
94
|
+
# | singular | X | base_form |
|
95
|
+
# | plural | ~ /[^aeiouy]y$/ | sub(base_form, /y$/, "ies")|
|
96
|
+
# | plural | X | base_form + "s" |
|
97
|
+
# inflection_table('Common_form') do
|
98
|
+
# feature_heading 'NUMBER'
|
99
|
+
# method_heading 'base_form'
|
100
|
+
# | NUMBER | base_form | Common_form |
|
101
|
+
# rule(equals(:singular), dont_care , col(1))
|
102
|
+
# rule(equals(:plural) , matches(/[^aeiouy]y$/), sub(col(1), /y$/, 'ies'))
|
103
|
+
# rule(equals(:plural) , dont_care , concat(col(1), 's'))
|
104
|
+
# end
|
105
|
+
it 'should determine the word form given input entries' do
|
106
|
+
subject.add_heading(heading0)
|
107
|
+
subject.add_heading(heading1)
|
108
|
+
subject.add_rule(rule_a)
|
109
|
+
subject.add_rule(rule_b)
|
110
|
+
subject.add_rule(rule_c)
|
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')
|
115
|
+
|
116
|
+
mck_2 = MockFeatureBearer.new('singular', 'boy')
|
117
|
+
expect(subject.inflect(mck_2, [nil, nil])).to eq('boy')
|
118
|
+
mck_2['NUMBER'] = 'plural'
|
119
|
+
expect(subject.inflect(mck_2, [nil, nil])).to eq('boys')
|
120
|
+
|
121
|
+
mck_3 = MockFeatureBearer.new('singular', 'body')
|
122
|
+
expect(subject.inflect(mck_3, [nil, nil])).to eq('body')
|
123
|
+
mck_3['NUMBER'] = 'plural'
|
124
|
+
expect(subject.inflect(mck_3, [nil, nil])).to eq('bodies')
|
125
|
+
end
|
126
|
+
end # context
|
127
|
+
end # describe
|
128
|
+
end # module
|
129
|
+
end # module
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../lib/zenlish/wclasses/common_noun'
|
4
|
+
require_relative '../../../lib/zenlish/lex/lexeme'
|
5
|
+
require_relative '../../../lib/zenlish/lex/lexical_entry'
|
6
|
+
require_relative '../../../lib/zenlish/inflect/method_heading'
|
7
|
+
require_relative '../../../lib/zenlish/inflect/formal_argument'
|
8
|
+
# Load the class under test
|
9
|
+
require_relative '../../../lib/zenlish/inflect/input_asis'
|
10
|
+
|
11
|
+
module Zenlish
|
12
|
+
module Inflect
|
13
|
+
describe InputAsIs do
|
14
|
+
let(:sample_argument) { FormalArgument.new(2) }
|
15
|
+
let(:sample_values) { [nil, nil, 'Hello, world.', nil] }
|
16
|
+
subject { InputAsIs.new(sample_argument) }
|
17
|
+
|
18
|
+
context 'Initialization:' do
|
19
|
+
it 'should be initialized with a formal rgument' do
|
20
|
+
expect { InputAsIs.new(sample_argument) }.not_to raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should know its text value' do
|
24
|
+
expect(subject.formal).to eq(sample_argument)
|
25
|
+
end
|
26
|
+
end # context
|
27
|
+
|
28
|
+
context 'Provided services:' do
|
29
|
+
it 'should return the text of given argument during generation' do
|
30
|
+
lexeme = double('fake-lexeme')
|
31
|
+
headings = double('fake-headings')
|
32
|
+
expect(subject.generate(headings, lexeme, sample_values)).to eq('Hello, world.')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return the text of given lexeme during generation' do
|
36
|
+
c_noun = WClasses::CommonNoun.new
|
37
|
+
an_entry = Lex::LexicalEntry.new('cherry')
|
38
|
+
lexeme = Lex::Lexeme.new(c_noun, an_entry)
|
39
|
+
heading = MethodHeading.new('base_form')
|
40
|
+
headings = [nil, nil, heading, nil]
|
41
|
+
expect(subject.generate(headings, lexeme, [])).to eq('cherry')
|
42
|
+
end
|
43
|
+
|
44
|
+
=begin
|
45
|
+
|
46
|
+
=end
|
47
|
+
end # context
|
48
|
+
end # describe
|
49
|
+
end # module
|
50
|
+
end # module
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../../lib/zenlish/inflect/literal_asis'
|
5
|
+
|
6
|
+
module Zenlish
|
7
|
+
module Inflect
|
8
|
+
describe LiteralAsIs do
|
9
|
+
subject { LiteralAsIs.new('s') }
|
10
|
+
|
11
|
+
context 'Initialization:' do
|
12
|
+
it 'should be initialized with a text literal' do
|
13
|
+
expect { LiteralAsIs.new('s') }.not_to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should know its text value' do
|
17
|
+
expect(subject.text).to eq('s')
|
18
|
+
end
|
19
|
+
end # context
|
20
|
+
|
21
|
+
context 'Provided services:' do
|
22
|
+
it 'should return the affix during word form generation' do
|
23
|
+
headings = double('fake-headings')
|
24
|
+
lexeme = double('fake-lexeme')
|
25
|
+
values = double('fake-values')
|
26
|
+
expect(subject.generate(headings, lexeme, values)).to eq('s')
|
27
|
+
end
|
28
|
+
end # context
|
29
|
+
end # describe
|
30
|
+
end # module
|
31
|
+
end # module
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../lib/zenlish/wclasses/common_noun'
|
4
|
+
require_relative '../../../lib/zenlish/lex/lexeme'
|
5
|
+
require_relative '../../../lib/zenlish/lex/lexical_entry'
|
6
|
+
require_relative '../../../lib/zenlish/inflect/method_heading'
|
7
|
+
require_relative '../../../lib/zenlish/inflect/formal_argument'
|
8
|
+
# Load the class under test
|
9
|
+
require_relative '../../../lib/zenlish/inflect/matches_pattern'
|
10
|
+
|
11
|
+
module Zenlish
|
12
|
+
module Inflect
|
13
|
+
describe MatchesPattern do
|
14
|
+
let(:an_argument) { FormalArgument.new(1) }
|
15
|
+
let(:patt) { /[^aeiouy]y$/ }
|
16
|
+
subject { MatchesPattern.new(an_argument, patt) }
|
17
|
+
|
18
|
+
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
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should know its argument' do
|
24
|
+
expect(subject.argument).to eq(an_argument)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should know the pattern' do
|
28
|
+
expect(subject.pattern).to eq(patt)
|
29
|
+
end
|
30
|
+
end # context
|
31
|
+
|
32
|
+
context 'Provided services:' do
|
33
|
+
it 'should check the actual argument' do
|
34
|
+
lexeme = double('dummy-lexeme')
|
35
|
+
headings = double('fake-headings')
|
36
|
+
actual_args = [nil, 'cherry', nil]
|
37
|
+
expect(subject.success?(headings, lexeme, actual_args)).to be_truthy
|
38
|
+
actual_args[1] = 'boy'
|
39
|
+
expect(subject.success?(headings, lexeme, actual_args)).to be_falsy
|
40
|
+
actual_args[1] = 'girl'
|
41
|
+
expect(subject.success?(headings, lexeme, actual_args)).to be_falsy
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should test the lexeme' do
|
45
|
+
c_noun = WClasses::CommonNoun.new
|
46
|
+
entry = Lex::LexicalEntry.new('cherry')
|
47
|
+
lexeme = Lex::Lexeme.new(c_noun, entry)
|
48
|
+
headings = [nil, MethodHeading.new('lemma'), nil]
|
49
|
+
expect(subject.success?(headings, lexeme, [])).to be_truthy
|
50
|
+
|
51
|
+
entry2 = Lex::LexicalEntry.new('boy')
|
52
|
+
lexeme2 = Lex::Lexeme.new(c_noun, entry2)
|
53
|
+
expect(subject.success?(headings, lexeme2, [])).to be_falsey
|
54
|
+
|
55
|
+
# instance = EqualsLiteral.new(an_argument, :irregular)
|
56
|
+
# expect(instance.success?(headings, lexeme, [])).to be_falsey
|
57
|
+
end
|
58
|
+
end # context
|
59
|
+
end # describe
|
60
|
+
end # module
|
61
|
+
end # module
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../../lib/zenlish/inflect/method_heading'
|
5
|
+
|
6
|
+
module Zenlish
|
7
|
+
module Inflect
|
8
|
+
describe MethodHeading do
|
9
|
+
let(:method_name) { 'base_form' }
|
10
|
+
subject { MethodHeading.new(method_name) }
|
11
|
+
|
12
|
+
context 'Initialization:' do
|
13
|
+
it 'should be initialized with a method name' do
|
14
|
+
expect { MethodHeading.new(method_name) }.not_to raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should know its label' do
|
18
|
+
expect(subject.label).to eq(method_name)
|
19
|
+
end
|
20
|
+
end # context
|
21
|
+
|
22
|
+
context 'Provided services:' do
|
23
|
+
it 'should obtain the method result from a word' do
|
24
|
+
mocked = double('dummy-lexeme')
|
25
|
+
expect(mocked).to receive(:base_form).and_return('cherry')
|
26
|
+
expect(subject.evaluate_for(mocked)).to eq('cherry')
|
27
|
+
end
|
28
|
+
end # context
|
29
|
+
end # describe
|
30
|
+
end # module
|
31
|
+
end # module
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../lib/zenlish/inflect/formal_argument'
|
4
|
+
require_relative '../../../lib/zenlish/inflect/input_asis'
|
5
|
+
# Load the class under test
|
6
|
+
require_relative '../../../lib/zenlish/inflect/substitution'
|
7
|
+
|
8
|
+
module Zenlish
|
9
|
+
module Inflect
|
10
|
+
describe Substitution do
|
11
|
+
let(:suffix) { LiteralAsIs.new('ies') }
|
12
|
+
let(:sample_argument) { FormalArgument.new(1) }
|
13
|
+
let(:base) { InputAsIs.new(sample_argument) }
|
14
|
+
let(:pattern) { /y$/ }
|
15
|
+
|
16
|
+
|
17
|
+
subject { Substitution.new(base, pattern, suffix) }
|
18
|
+
|
19
|
+
context 'Initialization:' do
|
20
|
+
it 'should be initialized with two arguments' do
|
21
|
+
expect { Substitution.new(base, pattern, suffix) }.not_to raise_error
|
22
|
+
end
|
23
|
+
|
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)
|
28
|
+
end
|
29
|
+
end # context
|
30
|
+
|
31
|
+
context 'Provided services:' do
|
32
|
+
let(:sample_heading) { double('fake-headings') }
|
33
|
+
let(:sample_values) { [nil, 'cherry', nil] }
|
34
|
+
|
35
|
+
it 'should do the concatenation of children results' do
|
36
|
+
lexeme = double('fake-lexeme')
|
37
|
+
|
38
|
+
expect(subject.generate(sample_heading, lexeme, sample_values)).to eq('cherries')
|
39
|
+
end
|
40
|
+
end # context
|
41
|
+
end # describe
|
42
|
+
end # module
|
43
|
+
end # module
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../../lib/zenlish/inflect/unconditionally_true'
|
5
|
+
|
6
|
+
module Zenlish
|
7
|
+
module Inflect
|
8
|
+
describe UnconditionallyTrue do
|
9
|
+
let(:method_name) { 'base_form' }
|
10
|
+
subject { UnconditionallyTrue.new }
|
11
|
+
|
12
|
+
context 'Initialization:' do
|
13
|
+
it 'should be initialized without argument' do
|
14
|
+
expect { UnconditionallyTrue.new}.not_to raise_error
|
15
|
+
end
|
16
|
+
end # context
|
17
|
+
|
18
|
+
context 'Provided services:' do
|
19
|
+
it 'should always return true' do
|
20
|
+
headings = double('dummy-headings')
|
21
|
+
lexeme = double('dummy-lexeme')
|
22
|
+
values = double('dummy-heading-values')
|
23
|
+
expect(subject.success?(headings, lexeme, values)).to be_truthy
|
24
|
+
end
|
25
|
+
end # context
|
26
|
+
end # describe
|
27
|
+
end # module
|
28
|
+
end # module
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../spec_helper' # Use the RSpec framework
|
4
|
+
require_relative '../../../lib/zenlish/wclasses/common_noun'
|
5
|
+
require_relative '../../../lib/zenlish/lang/dictionary' # Load the class under test
|
6
|
+
|
7
|
+
module Zenlish
|
8
|
+
module Lang
|
9
|
+
describe Dictionary do
|
10
|
+
subject { Dictionary }
|
11
|
+
|
12
|
+
context 'Provided services:' do
|
13
|
+
let(:common_nouns) do
|
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)
|
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
|
+
end # context
|
31
|
+
end # describe
|
32
|
+
end # module
|
33
|
+
end # module
|