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.
- checksums.yaml +4 -4
- data/.rubocop.yml +228 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +5 -3
- data/LICENSE.txt +1 -1
- data/Rakefile +5 -3
- data/lib/zenlish/feature/boolean_domain.rb +6 -4
- data/lib/zenlish/feature/boolean_value.rb +3 -2
- data/lib/zenlish/feature/enumeration_domain.rb +5 -2
- data/lib/zenlish/feature/feature.rb +9 -7
- data/lib/zenlish/feature/feature_def.rb +9 -6
- data/lib/zenlish/feature/feature_domain.rb +4 -2
- data/lib/zenlish/feature/feature_struct.rb +3 -1
- data/lib/zenlish/feature/feature_struct_def.rb +5 -3
- 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 +3 -1
- data/lib/zenlish/inflect/feature_heading.rb +2 -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 +2 -0
- data/lib/zenlish/inflect/inflection_rule.rb +2 -0
- data/lib/zenlish/inflect/inflection_table.rb +6 -4
- data/lib/zenlish/inflect/inflection_table_builder.rb +21 -18
- 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 +3 -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 +6 -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 +19 -16
- data/lib/zenlish/lang/lemmatizer.rb +40 -0
- data/lib/zenlish/lang/zenlish_grammar.rb +6 -4
- data/lib/zenlish/lex/empty_lexicon_factory.rb +3 -2
- data/lib/zenlish/lex/lexeme.rb +6 -4
- data/lib/zenlish/lex/lexical_entry.rb +6 -4
- data/lib/zenlish/lex/lexicon.rb +4 -3
- 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 +4 -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 +3 -1
- data/lib/zenlish/wclasses/article.rb +2 -0
- data/lib/zenlish/wclasses/auxiliary.rb +2 -0
- data/lib/zenlish/wclasses/auxiliary_be.rb +7 -6
- data/lib/zenlish/wclasses/auxiliary_do.rb +6 -5
- 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 +6 -4
- 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 +13 -15
- data/lib/zenlish/wclasses/irregular_verb_be.rb +8 -7
- data/lib/zenlish/wclasses/irregular_verb_can.rb +8 -7
- data/lib/zenlish/wclasses/irregular_verb_do.rb +7 -6
- data/lib/zenlish/wclasses/irregular_verb_extension.rb +8 -7
- data/lib/zenlish/wclasses/irregular_verb_have.rb +12 -11
- 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 +7 -5
- data/lib/zenlish/wclasses/noun.rb +4 -2
- data/lib/zenlish/wclasses/numeral.rb +2 -0
- data/lib/zenlish/wclasses/personal_pronoun.rb +8 -6
- data/lib/zenlish/wclasses/possessive_determiner.rb +13 -12
- 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 +9 -9
- 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 +5 -3
- data/lib/zenlish/wclasses/word_class.rb +7 -5
- data/lib/zenlish.rb +3 -3
- data/spec/spec_helper.rb +3 -1
- data/spec/zenlish/feature/boolean_domain_spec.rb +16 -16
- data/spec/zenlish/feature/boolean_value_spec.rb +7 -6
- data/spec/zenlish/feature/enumeration_domain_spec.rb +21 -21
- data/spec/zenlish/feature/feature_def_spec.rb +15 -14
- data/spec/zenlish/feature/feature_spec.rb +17 -17
- data/spec/zenlish/feature/feature_struct_def_bearer_spec.rb +23 -21
- data/spec/zenlish/feature/feature_struct_def_spec.rb +26 -25
- data/spec/zenlish/feature/identifier_domain_spec.rb +15 -15
- data/spec/zenlish/feature/identifier_value_spec.rb +10 -9
- data/spec/zenlish/feature/symbol_value_spec.rb +9 -8
- data/spec/zenlish/inflect/concatenation_spec.rb +14 -14
- data/spec/zenlish/inflect/equals_literal_spec.rb +17 -16
- data/spec/zenlish/inflect/feature_heading_spec.rb +22 -21
- data/spec/zenlish/inflect/formal_argument_spec.rb +7 -7
- data/spec/zenlish/inflect/function_call_spec.rb +11 -12
- data/spec/zenlish/inflect/inflection_rule_spec.rb +28 -24
- data/spec/zenlish/inflect/inflection_table_builder_spec.rb +62 -57
- data/spec/zenlish/inflect/inflection_table_spec.rb +49 -46
- data/spec/zenlish/inflect/input_asis_spec.rb +12 -15
- data/spec/zenlish/inflect/literal_asis_spec.rb +10 -10
- data/spec/zenlish/inflect/matches_pattern_spec.rb +16 -15
- data/spec/zenlish/inflect/membership_spec.rb +17 -16
- data/spec/zenlish/inflect/method_heading_spec.rb +15 -14
- data/spec/zenlish/inflect/not_equals_literal_spec.rb +17 -16
- data/spec/zenlish/inflect/substitution_spec.rb +10 -11
- data/spec/zenlish/inflect/unconditionally_true_spec.rb +8 -6
- data/spec/zenlish/lang/dictionary_spec.rb +28 -31
- data/spec/zenlish/lang/lemmatizer_spec.rb +43 -0
- data/spec/zenlish/lang/zenlish_grammar_spec.rb +5 -5
- data/spec/zenlish/lex/empty_lexicon_factory_spec.rb +8 -8
- data/spec/zenlish/lex/lexeme_spec.rb +27 -28
- data/spec/zenlish/lex/lexical_entry_spec.rb +15 -15
- data/spec/zenlish/lex/lexicon_spec.rb +52 -50
- data/spec/zenlish/lex/literal_spec.rb +8 -8
- data/spec/zenlish/lexer/lexer_spec.rb +52 -0
- data/spec/zenlish/parser/lesson1_spec.rb +81 -81
- data/spec/zenlish/parser/lesson2_spec.rb +133 -138
- data/spec/zenlish/parser/lesson3_spec.rb +186 -226
- data/spec/zenlish/parser/zparser_spec.rb +8 -7
- data/spec/zenlish/support/minimal_lexicon.rb +2 -0
- data/spec/zenlish/support/var2word.rb +16 -9
- 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 +15 -19
- data/spec/zenlish/wclasses/demonstrative_determiner_spec.rb +12 -12
- data/spec/zenlish/wclasses/irregular_verb_can_spec.rb +18 -18
- data/spec/zenlish/wclasses/irregular_verb_extension_spec.rb +10 -10
- data/spec/zenlish/wclasses/irregular_verb_spec.rb +28 -28
- data/spec/zenlish/wclasses/lexical_verb_spec.rb +9 -9
- data/spec/zenlish/wclasses/modal_verb_can_spec.rb +12 -12
- data/spec/zenlish/wclasses/noun_spec.rb +7 -7
- data/spec/zenlish/wclasses/personal_pronoun_spec.rb +20 -23
- data/spec/zenlish/wclasses/possessive_determiner_spec.rb +28 -31
- data/spec/zenlish/wclasses/preposition_spec.rb +5 -5
- data/spec/zenlish/wclasses/proper_noun_spec.rb +3 -3
- data/spec/zenlish/wclasses/regular_verb_spec.rb +30 -30
- data/spec/zenlish/wclasses/regular_verb_want_spec.rb +30 -0
- data/spec/zenlish/wclasses/verb_spec.rb +9 -9
- data/spec/zenlish_spec.rb +4 -2
- data/zenlish.gemspec +18 -14
- 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
|
-
|
26
|
+
|
27
|
+
subject(:inflection) { described_class.new(table_name) }
|
25
28
|
|
26
29
|
context 'Initialization:' do
|
27
|
-
it '
|
28
|
-
expect {
|
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 '
|
32
|
-
expect(
|
34
|
+
it 'knows its name' do
|
35
|
+
expect(inflection.name).to eq(table_name)
|
33
36
|
end
|
34
37
|
|
35
|
-
it '
|
36
|
-
expect(
|
38
|
+
it "doesn't have headings at start" do
|
39
|
+
expect(inflection.headings).to be_empty
|
37
40
|
end
|
38
41
|
|
39
|
-
it '
|
40
|
-
expect(
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
expect
|
86
|
-
|
87
|
-
|
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 '
|
92
|
-
expect {
|
93
|
-
expect(
|
94
|
-
|
95
|
-
expect(
|
96
|
-
|
97
|
-
expect(
|
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 '
|
122
|
-
init_table(
|
123
|
-
|
124
|
-
expect(
|
125
|
-
|
126
|
-
expect(
|
127
|
-
|
128
|
-
|
129
|
-
expect(
|
130
|
-
|
131
|
-
expect(
|
132
|
-
|
133
|
-
expect(
|
134
|
-
expect(
|
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 '
|
138
|
-
init_table(
|
139
|
-
expect(
|
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
|
-
|
16
|
+
|
17
|
+
subject(:input) { described_class.new(sample_argument) }
|
17
18
|
|
18
19
|
context 'Initialization:' do
|
19
|
-
it '
|
20
|
-
expect {
|
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 '
|
24
|
-
expect(
|
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 '
|
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(
|
33
|
+
expect(input.generate(headings, lexeme, sample_values)).to eq('Hello, world.')
|
33
34
|
end
|
34
|
-
|
35
|
-
it '
|
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(
|
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 {
|
9
|
+
subject(:literal) { described_class.new('s') }
|
10
10
|
|
11
11
|
context 'Initialization:' do
|
12
|
-
it '
|
13
|
-
expect {
|
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 '
|
17
|
-
expect(
|
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 '
|
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(
|
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
|
-
|
16
|
+
|
17
|
+
subject(:pattern) { described_class.new(an_argument, patt) }
|
17
18
|
|
18
19
|
context 'Initialization:' do
|
19
|
-
it '
|
20
|
-
expect {
|
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 '
|
24
|
-
expect(
|
24
|
+
it 'knows its argument' do
|
25
|
+
expect(pattern.argument).to eq(an_argument)
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect(
|
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 '
|
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(
|
38
|
+
expect(pattern).to be_success(headings, lexeme, actual_args)
|
38
39
|
actual_args[1] = 'boy'
|
39
|
-
expect(
|
40
|
+
expect(pattern).not_to be_success(headings, lexeme, actual_args)
|
40
41
|
actual_args[1] = 'girl'
|
41
|
-
expect(
|
42
|
+
expect(pattern).not_to be_success(headings, lexeme, actual_args)
|
42
43
|
end
|
43
44
|
|
44
|
-
it '
|
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(
|
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(
|
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) { [
|
16
|
-
|
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 '
|
20
|
-
expect {
|
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 '
|
24
|
-
expect(
|
24
|
+
it 'knows its argument' do
|
25
|
+
expect(membership.argument).to eq(an_argument)
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect(
|
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 '
|
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(
|
38
|
+
expect(membership).to be_success(headings, lexeme, actual_args)
|
38
39
|
actual_args[1] = :singular
|
39
|
-
expect(
|
40
|
+
expect(membership).to be_success(headings, lexeme, actual_args)
|
40
41
|
actual_args[1] = :dual
|
41
|
-
expect(
|
42
|
+
expect(membership).not_to be_success(headings, lexeme, actual_args)
|
42
43
|
end
|
43
44
|
|
44
|
-
# it '
|
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(
|
50
|
+
# expect(membership.success?(headings, lexeme, [])).to be_truthy
|
50
51
|
|
51
|
-
# instance =
|
52
|
+
# instance = described_class.new(an_argument, :singular)
|
52
53
|
# expect(instance.success?(headings, lexeme, [])).to be_truthy
|
53
54
|
|
54
|
-
# instance =
|
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
|
-
|
10
|
+
|
11
|
+
subject(:heading) { described_class.new(method_name) }
|
11
12
|
|
12
13
|
context 'Initialization:' do
|
13
|
-
it '
|
14
|
-
expect {
|
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 '
|
18
|
-
expect(
|
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 '
|
24
|
+
it 'obtains the method result from a word' do
|
24
25
|
mocked = double('dummy-lexeme')
|
25
|
-
|
26
|
-
expect(
|
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 '
|
29
|
+
|
30
|
+
it 'obtains the method result as an array' do
|
30
31
|
mocked = double('dummy-lexeme')
|
31
|
-
|
32
|
-
expect(
|
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
|
-
|
16
|
+
|
17
|
+
subject(:literal) { described_class.new(an_argument, feat_val) }
|
17
18
|
|
18
19
|
context 'Initialization:' do
|
19
|
-
it '
|
20
|
-
expect {
|
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 '
|
24
|
-
expect(
|
24
|
+
it 'knows its argument' do
|
25
|
+
expect(literal.argument).to eq(an_argument)
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect(
|
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 '
|
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(
|
38
|
+
expect(literal).not_to be_success(headings, lexeme, actual_args)
|
38
39
|
actual_args[1] = :singular
|
39
|
-
expect(
|
40
|
+
expect(literal).to be_success(headings, lexeme, actual_args)
|
40
41
|
end
|
41
42
|
|
42
|
-
it '
|
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(
|
48
|
+
expect(literal).not_to be_success(headings, lexeme, [])
|
48
49
|
|
49
|
-
instance =
|
50
|
-
expect(instance.
|
50
|
+
instance = described_class.new(an_argument, :singular)
|
51
|
+
expect(instance).not_to be_success(headings, lexeme, [])
|
51
52
|
|
52
|
-
instance =
|
53
|
-
expect(instance.
|
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 '
|
21
|
-
expect {
|
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 '
|
25
|
-
expect(
|
26
|
-
expect(
|
27
|
-
expect(
|
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 '
|
34
|
+
it 'concatenates children results' do
|
36
35
|
lexeme = double('fake-lexeme')
|
37
36
|
|
38
|
-
expect(
|
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
|
-
|
10
|
+
|
11
|
+
subject(:u_true) { described_class.new }
|
11
12
|
|
12
13
|
context 'Initialization:' do
|
13
|
-
it '
|
14
|
-
expect {
|
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 '
|
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(
|
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 {
|
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(
|
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
|
-
|
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 '
|
49
|
-
|
50
|
-
|
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,
|
56
|
+
test_inflection_of(lexm, expectations1)
|
59
57
|
|
60
|
-
lexm =
|
61
|
-
|
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,
|
67
|
+
test_inflection_of(lexm, expectations2, true)
|
70
68
|
|
71
|
-
lexm =
|
72
|
-
|
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,
|
78
|
+
test_inflection_of(lexm, expectations3, true)
|
81
79
|
end
|
82
80
|
|
83
|
-
it '
|
81
|
+
it 'knows how to inflect the verb be' do
|
84
82
|
[WClasses::IrregularVerbBe, WClasses::AuxiliaryBe].each do |wclass|
|
85
|
-
lexm =
|
86
|
-
|
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,
|
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
|