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
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require_relative '../../spec_helper' # Use the RSpec framework
|
3
4
|
require_relative '../support/var2word'
|
4
5
|
require_relative '../../../lib/zenlish/parser/zparser' # Load the class under test
|
@@ -7,7 +8,7 @@ module Zenlish
|
|
7
8
|
module Parser
|
8
9
|
describe ZParser do
|
9
10
|
include Var2Word
|
10
|
-
|
11
|
+
|
11
12
|
subject { ZParser.new }
|
12
13
|
|
13
14
|
context 'Initialization:' do
|
@@ -1,7 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'minimal_lexicon'
|
2
4
|
require_relative '../../../lib/zenlish/lex/literal'
|
3
5
|
|
4
6
|
module Zenlish
|
7
|
+
# rubocop: disable Layout/EmptyLineBetweenDefs
|
8
|
+
# rubocop: disable Layout/SpaceBeforeSemicolon
|
9
|
+
# rubocop: disable Style/SingleLineMethods
|
10
|
+
|
5
11
|
# Utility module. It defines variables that each are assgned a
|
6
12
|
# Literal object.
|
7
13
|
module Var2Word
|
@@ -56,7 +62,7 @@ module Zenlish
|
|
56
62
|
literal2var('body', 'body')
|
57
63
|
literal2var('but', 'but')
|
58
64
|
def can ; Lex::Literal.new('can', get_lexeme('can', WClasses::ModalVerbCan), 0) ; end
|
59
|
-
def can_irregular ; Lex::Literal.new('can', get_lexeme('can', WClasses::
|
65
|
+
def can_irregular ; Lex::Literal.new('can', get_lexeme('can', WClasses::IrregularVerbCan), 0) ; end
|
60
66
|
literal2var('cause', 'cause')
|
61
67
|
literal2var('cause', 'caused')
|
62
68
|
literal2var('cause', 'causes')
|
@@ -69,19 +75,19 @@ module Zenlish
|
|
69
75
|
literal2var('contain', 'contains')
|
70
76
|
literal2var('container', 'container')
|
71
77
|
literal2var('container', 'containers')
|
72
|
-
|
73
|
-
literal2var('damage', 'damaged')
|
78
|
+
def could ; Lex::Literal.new('could', get_lexeme('can', WClasses::ModalVerbCan), 0) ; end
|
79
|
+
literal2var('damage', 'damaged')
|
74
80
|
def did ; Lex::Literal.new('did', get_lexeme('do', WClasses::IrregularVerbDo), 0) ; end
|
75
81
|
literal2var('die', 'die')
|
76
82
|
literal2var('die', 'died')
|
77
83
|
literal2var('die', 'dies')
|
78
84
|
literal2var('different', 'different')
|
79
|
-
literal2var('difficult', 'difficult')
|
85
|
+
literal2var('difficult', 'difficult')
|
80
86
|
def do_ ; Lex::Literal.new('do', get_lexeme('do', WClasses::IrregularVerbDo), 0) ; end
|
81
87
|
def do_aux ; Lex::Literal.new('do', get_lexeme('do', WClasses::AuxiliaryDo), 0) ; end
|
82
88
|
def does ; Lex::Literal.new('does', get_lexeme('do', WClasses::IrregularVerbDo), 0) ; end
|
83
89
|
def does_aux ; Lex::Literal.new('does', get_lexeme('do', WClasses::AuxiliaryDo), 0) ; end
|
84
|
-
def doing ; Lex::Literal.new('doing', get_lexeme('do', WClasses::IrregularVerbDo), 0) ; end
|
90
|
+
def doing ; Lex::Literal.new('doing', get_lexeme('do', WClasses::IrregularVerbDo), 0) ; end
|
85
91
|
literal2var('each', 'each', '_')
|
86
92
|
def each_ ; Lex::Literal.new('each', get_lexeme('each', WClasses::DistributiveDeterminer), 0) ; end
|
87
93
|
def each_as_pronoun ; Lex::Literal.new('each', get_lexeme('each', WClasses::Pronoun), 0) ; end
|
@@ -106,8 +112,8 @@ module Zenlish
|
|
106
112
|
literal2var('hear', 'hear')
|
107
113
|
literal2var('hear', 'heard')
|
108
114
|
literal2var('hear', 'hears')
|
109
|
-
def here ;
|
110
|
-
def here_as_noun ;
|
115
|
+
def here ; Lex::Literal.new('here', get_lexeme('here', WClasses::Adverb), 0) ; end
|
116
|
+
def here_as_noun ; Lex::Literal.new('here', get_lexeme('here', WClasses::CommonNoun), 0) ; end
|
111
117
|
def i_pronoun ; Lex::Literal.new('I', get_lexeme('I'), 0) ; end
|
112
118
|
literal2var('if', 'if', '_')
|
113
119
|
literal2var('in', 'in', '_')
|
@@ -115,7 +121,7 @@ module Zenlish
|
|
115
121
|
literal2var('it', 'it', '_')
|
116
122
|
literal2var('its', 'its')
|
117
123
|
literal2var('J', 'j', '_')
|
118
|
-
def is ;
|
124
|
+
def is ; Lex::Literal.new('is', get_lexeme('be', WClasses::IrregularVerbBe), 0) ; end
|
119
125
|
def is_aux ; Lex::Literal.new('is', get_lexeme('be', WClasses::AuxiliaryBe), 0) ; end
|
120
126
|
literal2var('K', 'k', '_')
|
121
127
|
literal2var('kind', 'kind')
|
@@ -134,7 +140,7 @@ module Zenlish
|
|
134
140
|
literal2var('make', 'make')
|
135
141
|
literal2var('many', 'many')
|
136
142
|
literal2var('maybe', 'maybe')
|
137
|
-
literal2var('
|
143
|
+
literal2var('I', 'me')
|
138
144
|
literal2var('moment', 'moment')
|
139
145
|
def more ; Lex::Literal.new('more', get_lexeme('more', WClasses::Adjective), 0) ; end
|
140
146
|
def more_as_adverb ; Lex::Literal.new('more', get_lexeme('more', WClasses::Adverb), 0) ; end
|
@@ -179,10 +185,10 @@ module Zenlish
|
|
179
185
|
literal2var('something', 'something')
|
180
186
|
literal2var('surface', 'surface')
|
181
187
|
literal2var('the', 'the')
|
182
|
-
literal2var('
|
183
|
-
literal2var('
|
188
|
+
literal2var('its', 'their')
|
189
|
+
literal2var('it', 'them')
|
184
190
|
literal2var('then', 'then', '_')
|
185
|
-
literal2var('
|
191
|
+
literal2var('it', 'they')
|
186
192
|
literal2var('than', 'than')
|
187
193
|
literal2var('that', 'that')
|
188
194
|
literal2var('there', 'there')
|
@@ -216,7 +222,7 @@ module Zenlish
|
|
216
222
|
literal2var('want', 'want')
|
217
223
|
literal2var('want', 'wants')
|
218
224
|
def was ; Lex::Literal.new('was', get_lexeme('be', WClasses::IrregularVerbBe), 0) ; end
|
219
|
-
def were ;
|
225
|
+
def were ; Lex::Literal.new('were', get_lexeme('be', WClasses::IrregularVerbBe), 0) ; end
|
220
226
|
literal2var('what', 'what')
|
221
227
|
literal2var('when', 'when', '_')
|
222
228
|
def where ; Lex::Literal.new('where', get_lexeme('where', WClasses::Adverb), 0) ; end
|
@@ -228,9 +234,12 @@ module Zenlish
|
|
228
234
|
literal2var('you', 'you')
|
229
235
|
literal2var('you', 'your')
|
230
236
|
|
231
|
-
def colon ;
|
232
|
-
def comma ;
|
233
|
-
def dot ;
|
234
|
-
def quote ;
|
237
|
+
def colon ; Lex::Literal.new(':', get_lexeme(':'), 0) ; end
|
238
|
+
def comma ; Lex::Literal.new(',', get_lexeme(','), 0) ; end
|
239
|
+
def dot ; Lex::Literal.new('.', get_lexeme('.'), 0) ; end
|
240
|
+
def quote ; Lex::Literal.new('"', get_lexeme('"'), 0) ; end
|
235
241
|
end # module
|
236
|
-
|
242
|
+
# rubocop: enable Style/SingleLineMethods
|
243
|
+
# rubocop: enable Layout/SpaceBeforeSemicolon
|
244
|
+
# rubocop: enable Layout/EmptyLineBetweenDefs
|
245
|
+
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/trie/base_trie_node' # Load the class under test
|
5
|
+
|
6
|
+
module Zenlish
|
7
|
+
module Trie
|
8
|
+
describe BaseTrieNode do
|
9
|
+
subject { BaseTrieNode.new }
|
10
|
+
|
11
|
+
context 'Initialization:' do
|
12
|
+
it 'should be initialized without argument' do
|
13
|
+
expect { BaseTrieNode.new }.not_to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be a leaf node at start' do
|
17
|
+
expect(subject).to be_leaf
|
18
|
+
end
|
19
|
+
end # context
|
20
|
+
|
21
|
+
context 'Provided services:' do
|
22
|
+
it 'should accept the addition of a successor' do
|
23
|
+
some_node = BaseTrieNode.new
|
24
|
+
|
25
|
+
expect(subject.include?('f')).to be_falsy
|
26
|
+
expect { subject.add_succ('f', some_node) }.not_to raise_error
|
27
|
+
expect(subject.include?('f')).to be_truthy
|
28
|
+
expect(subject.succ['f']).to eq(some_node)
|
29
|
+
end
|
30
|
+
end # context
|
31
|
+
end # describe
|
32
|
+
end # module
|
33
|
+
end # module
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../spec_helper' # Use the RSpec framework
|
4
|
+
require_relative '../../../lib/zenlish/trie/trie' # Load the class under test
|
5
|
+
|
6
|
+
module Zenlish
|
7
|
+
module Trie
|
8
|
+
describe Trie do
|
9
|
+
subject { Trie.new }
|
10
|
+
|
11
|
+
context 'Initialization:' do
|
12
|
+
it 'should be initialized without argument' do
|
13
|
+
expect { Trie.new }.not_to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be a leaf node at start' do
|
17
|
+
expect(subject.root).to be_kind_of(TrieRoot)
|
18
|
+
end
|
19
|
+
end # context
|
20
|
+
|
21
|
+
context 'Provided services:' do
|
22
|
+
it 'should accept the addition of one single node' do
|
23
|
+
expect { subject.add('a', 'OK') }.not_to raise_error
|
24
|
+
expect(subject.root.include?('a')).to be_truthy
|
25
|
+
expect(subject.root.succ['a']).to be_kind_of(TrieNode)
|
26
|
+
expect(subject.root.succ['a'].value).to eq('OK')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should accept the addition of a node string' do
|
30
|
+
expect { subject.add('abc', 'OK') }.not_to raise_error
|
31
|
+
expect(subject.root.include?('a')).to be_truthy
|
32
|
+
expect(subject.root.include?('b')).to be_falsy
|
33
|
+
|
34
|
+
node_a = subject.root.succ['a']
|
35
|
+
expect(node_a).to be_kind_of(TrieNode)
|
36
|
+
expect(node_a.value).to be_nil
|
37
|
+
expect(node_a.include?('b')).to be_truthy
|
38
|
+
expect(node_a.include?('c')).to be_falsy
|
39
|
+
|
40
|
+
node_b = node_a.succ['b']
|
41
|
+
expect(node_b).to be_kind_of(TrieNode)
|
42
|
+
expect(node_b.value).to be_nil
|
43
|
+
expect(node_b.include?('c')).to be_truthy
|
44
|
+
|
45
|
+
node_c = node_b.succ['c']
|
46
|
+
expect(node_c).to be_kind_of(TrieNode)
|
47
|
+
expect(node_c.value).to eq('OK')
|
48
|
+
expect(node_c).to be_leaf
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should accept the addition of multiple node strings' do
|
52
|
+
subject.add('abc', 'ABC')
|
53
|
+
expect { subject.add('abe', 'ABE') }.not_to raise_error
|
54
|
+
root = subject.root
|
55
|
+
expect(root.include?('a')).to be_truthy
|
56
|
+
expect(root.include?('b')).to be_falsy
|
57
|
+
|
58
|
+
node_a = root.succ['a']
|
59
|
+
|
60
|
+
node_b = node_a.succ['b']
|
61
|
+
expect(node_b).to be_kind_of(TrieNode)
|
62
|
+
expect(node_b.value).to be_nil
|
63
|
+
expect(node_b.include?('c')).to be_truthy
|
64
|
+
expect(node_b.include?('e')).to be_truthy
|
65
|
+
|
66
|
+
node_c = node_b.succ['c']
|
67
|
+
expect(node_c).to be_kind_of(TrieNode)
|
68
|
+
expect(node_c.value).to eq('ABC')
|
69
|
+
expect(node_c).to be_leaf
|
70
|
+
|
71
|
+
node_e = node_b.succ['e']
|
72
|
+
expect(node_e).to be_kind_of(TrieNode)
|
73
|
+
expect(node_e.value).to eq('ABE')
|
74
|
+
expect(node_e).to be_leaf
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should retrieve the node matching a given string' do
|
78
|
+
subject.add('abc', 'ABC')
|
79
|
+
subject.add('hello', 'WORLD')
|
80
|
+
subject.add('hellene', 'GREEK')
|
81
|
+
|
82
|
+
hello_node = subject.search('hello')
|
83
|
+
expect(hello_node.key).to eq('o')
|
84
|
+
expect(hello_node.value).to eq('WORLD')
|
85
|
+
hellish = subject.search('hell')
|
86
|
+
expect(hellish.key).to eq('l')
|
87
|
+
expect(hellish.value).to be_nil
|
88
|
+
expect(subject.search('greeting')).to be_nil
|
89
|
+
hellene_node = subject.search('hellene')
|
90
|
+
expect(hellene_node.key).to eq('e')
|
91
|
+
expect(hellene_node.value).to eq('GREEK')
|
92
|
+
expect(subject.search('hellenes')).to be_nil
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should accept the addition of "synonyms"' do
|
96
|
+
subject.add('abd', 'first')
|
97
|
+
subject.add('abduce', 'ABDUCE')
|
98
|
+
|
99
|
+
abd_node = subject.search('abd')
|
100
|
+
expect(abd_node.value).to eq('first')
|
101
|
+
|
102
|
+
subject.add('abd', 'second')
|
103
|
+
expect(abd_node.value).to eq(%w[first second])
|
104
|
+
end
|
105
|
+
end # context
|
106
|
+
end # describe
|
107
|
+
end # module
|
108
|
+
end # module
|
@@ -21,23 +21,35 @@ module Zenlish
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should support the pluralization of common nouns' do
|
24
|
+
samples = %w[animal body people]
|
24
25
|
lexemes = []
|
25
26
|
Lang::Dictionary.entries.each do |ent|
|
26
27
|
lexm = ent.lexemes.select { |lx| lx.wclass.kind_of?(Zenlish::WClasses::CommonNoun) }
|
27
|
-
|
28
|
+
if lexm && samples.include?(ent.lemma)
|
29
|
+
lexemes.concat(lexm)
|
30
|
+
end
|
28
31
|
end
|
29
|
-
samples = %w[ animal body people]
|
30
32
|
plural_sample = { 'animal' => 'animals',
|
31
33
|
'body' => 'bodies',
|
32
|
-
'people' => 'people'}
|
33
|
-
|
34
|
-
|
35
|
-
selection.map do |lx|
|
34
|
+
'people' => 'people' }
|
35
|
+
lexemes.map do |lx|
|
36
36
|
pluralized = lx.inflect([:plural, nil])
|
37
37
|
expect(pluralized).to eq(plural_sample[lx.base_form])
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
it 'should know all its inflections' do
|
42
|
+
samples = %w[animal body people]
|
43
|
+
lexemes = []
|
44
|
+
Lang::Dictionary.entries.each do |ent|
|
45
|
+
lexm = ent.lexemes.select { |lx| lx.wclass.kind_of?(Zenlish::WClasses::CommonNoun) }
|
46
|
+
if lexm && samples.include?(ent.lemma)
|
47
|
+
lexemes.concat(lexm)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
lexemes.map(&:all_inflections)
|
51
|
+
end
|
40
52
|
end # context
|
41
53
|
end # describe
|
42
54
|
end # module
|
43
|
-
end # module
|
55
|
+
end # module
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../spec_helper' # Use the RSpec framework
|
4
|
+
require_relative '../../../lib/zenlish/lex/lexical_entry'
|
5
|
+
require_relative '../../../lib/zenlish/lex/lexeme'
|
6
|
+
require_relative '../../../lib/zenlish/wclasses/demonstrative_determiner' # Load the class under test
|
7
|
+
|
8
|
+
module Zenlish
|
9
|
+
module WClasses
|
10
|
+
describe DemonstrativeDeterminer do
|
11
|
+
subject { DemonstrativeDeterminer.new }
|
12
|
+
|
13
|
+
context 'Initialization:' do
|
14
|
+
it 'should be initialized without argument' do
|
15
|
+
expect { DemonstrativeDeterminer.new }.not_to raise_error
|
16
|
+
end
|
17
|
+
end # context
|
18
|
+
|
19
|
+
context 'Provided services:' do
|
20
|
+
def build_det(aBaseForm)
|
21
|
+
entry = Zenlish::Lex::LexicalEntry.new(aBaseForm)
|
22
|
+
Zenlish::Lex::Lexeme.new(subject, entry)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_all_inflections(det_form, wforms)
|
26
|
+
determiner = build_det(det_form)
|
27
|
+
inflected = determiner.all_inflections
|
28
|
+
expect(inflected.sort).to eq(wforms.sort)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should know that it is inflectable' do
|
32
|
+
expect(subject).not_to be_invariable
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should know its feature definitions' do
|
36
|
+
expect(subject['NUMBER']).to be_kind_of(Feature::FeatureDef)
|
37
|
+
expect(subject['DISTANCE']).to be_kind_of(Feature::FeatureDef)
|
38
|
+
expect(subject['PARADIGM'].default.val).to eq('Demonstrative_det_paradigm')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should give all word forms' do
|
42
|
+
test_all_inflections('this', %w[this that these those])
|
43
|
+
end
|
44
|
+
end # context
|
45
|
+
end # describe
|
46
|
+
end # module
|
47
|
+
end # module
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../spec_helper' # Use the RSpec framework
|
4
|
+
require_relative '../../../lib/zenlish/lex/lexical_entry'
|
5
|
+
require_relative '../../../lib/zenlish/lex/lexeme'
|
6
|
+
|
7
|
+
# Load the class under test
|
8
|
+
require_relative '../../../lib/zenlish/wclasses/irregular_verb_can'
|
9
|
+
|
10
|
+
module Zenlish
|
11
|
+
module WClasses
|
12
|
+
describe IrregularVerbCan do
|
13
|
+
subject { IrregularVerbCan.new }
|
14
|
+
|
15
|
+
context 'Initialization:' do
|
16
|
+
it 'should be initialized without argument' do
|
17
|
+
expect { IrregularVerbCan.new }.not_to raise_error
|
18
|
+
end
|
19
|
+
end # context
|
20
|
+
|
21
|
+
context 'Provided services:' do
|
22
|
+
it 'should know its inherited feature definitions' do
|
23
|
+
expect(subject['NUMBER']).to be_kind_of(Feature::FeatureDef)
|
24
|
+
expect(subject['PERSON']).to be_kind_of(Feature::FeatureDef)
|
25
|
+
expect(subject['PARADIGM'].default.val).to eq('Verb_can_inflection')
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_verb(aBaseForm)
|
29
|
+
entry = Zenlish::Lex::LexicalEntry.new(aBaseForm)
|
30
|
+
Zenlish::Lex::Lexeme.new(subject, entry)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_inflection_of(verb_form, pairs)
|
34
|
+
verb = build_verb(verb_form)
|
35
|
+
pairs.each do |(time, expected_form)|
|
36
|
+
expect(verb.inflect([time])).to eq(expected_form)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_all_inflections(verb_form, wforms)
|
41
|
+
verb = build_verb(verb_form)
|
42
|
+
inflected = verb.all_inflections
|
43
|
+
expect(inflected.sort).to eq(wforms.sort)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should know how to inflect modal verb can' do
|
47
|
+
expectations1 = [
|
48
|
+
[:present, 'can'],
|
49
|
+
[:past_simple, 'could']
|
50
|
+
]
|
51
|
+
test_inflection_of('can', expectations1)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should give all word forms of a given verb' do
|
55
|
+
test_all_inflections('can', %w[can could])
|
56
|
+
end
|
57
|
+
end # context
|
58
|
+
end # describe
|
59
|
+
end # module
|
60
|
+
end # module
|
@@ -46,8 +46,14 @@ module Zenlish
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
def test_all_inflections(verb_form, p_simple, p_participle, wforms)
|
50
|
+
verb = build_verb(verb_form, p_simple, p_participle)
|
51
|
+
inflected = verb.all_inflections
|
52
|
+
expect(inflected.sort).to eq(wforms.sort)
|
53
|
+
end
|
54
|
+
|
49
55
|
it 'should know how to inflect irregular verbs' do
|
50
|
-
|
56
|
+
expectations1 = [
|
51
57
|
[present_1sg, 'see'],
|
52
58
|
[present_3sg, 'sees'],
|
53
59
|
[present_1pl, 'see'],
|
@@ -55,9 +61,9 @@ module Zenlish
|
|
55
61
|
[past_simple, 'saw'],
|
56
62
|
[past_participle, 'seen']
|
57
63
|
]
|
58
|
-
test_inflection_of('see', 'saw', 'seen',
|
64
|
+
test_inflection_of('see', 'saw', 'seen', expectations1)
|
59
65
|
|
60
|
-
|
66
|
+
expectations2 = [
|
61
67
|
[present_1sg, 'make'],
|
62
68
|
[present_3sg, 'makes'],
|
63
69
|
[present_1pl, 'make'],
|
@@ -65,7 +71,11 @@ module Zenlish
|
|
65
71
|
[past_simple, 'made'],
|
66
72
|
[past_participle, 'made']
|
67
73
|
]
|
68
|
-
test_inflection_of('make', 'made', 'made',
|
74
|
+
test_inflection_of('make', 'made', 'made', expectations2)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should give all word forms of a given verb' do
|
78
|
+
test_all_inflections('see', 'saw', 'seen', %w[see sees seeing saw seen])
|
69
79
|
end
|
70
80
|
end # context
|
71
81
|
end # describe
|