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
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'regular_verb'
|
2
4
|
|
3
5
|
module Zenlish
|
4
6
|
module WClasses
|
5
7
|
# The `want` verb like `need` allow the construct:
|
6
8
|
# want + to + infinitive or progressive.
|
7
|
-
class RegularVerbWant <
|
9
|
+
class RegularVerbWant < RegularVerb
|
8
10
|
end # class
|
9
11
|
end # module
|
10
|
-
end # module
|
12
|
+
end # module
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'pronoun'
|
2
4
|
|
3
5
|
module Zenlish
|
4
6
|
module WClasses
|
5
7
|
# A relative pronoun refers to a noun that has already been mentionned,
|
6
|
-
# and gives more information about that noun: who, whom, whose
|
8
|
+
# and gives more information about that noun: who, whom, whose
|
7
9
|
# (for people) and which, what, that for things (and animals).
|
8
10
|
# A relative pronoun introduces a relative clause.
|
9
11
|
class RelativePronoun < Pronoun
|
10
12
|
end # class
|
11
13
|
end # module
|
12
|
-
end # module
|
14
|
+
end # module
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'conjunction'
|
2
4
|
|
3
5
|
module Zenlish
|
@@ -5,12 +7,12 @@ module Zenlish
|
|
5
7
|
# A subordinating conjunction is a word or phrase that connects a dependent
|
6
8
|
# clause to a main clause. The subordinating conjunction indicates how the
|
7
9
|
# dependent clause adds informative value to the main clause. For instance,
|
8
|
-
# by signaling a cause-and-effect relation, a shift in time or place between
|
9
|
-
# the two clauses.
|
10
|
-
# Common subordinating conjunctions: after, although, as, because, before,
|
11
|
-
# how, if, once, since, than, that, though, till, until, when, where,
|
10
|
+
# by signaling a cause-and-effect relation, a shift in time or place between
|
11
|
+
# the two clauses.
|
12
|
+
# Common subordinating conjunctions: after, although, as, because, before,
|
13
|
+
# how, if, once, since, than, that, though, till, until, when, where,
|
12
14
|
# whether, while
|
13
|
-
class SubordinatingConjunction < WordClass
|
15
|
+
class SubordinatingConjunction < WordClass
|
14
16
|
end # class
|
15
17
|
end # module
|
16
18
|
end # module
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'word_class'
|
2
4
|
require_relative '../inflect/inflection_table_builder'
|
3
5
|
|
@@ -24,12 +26,12 @@ module Zenlish
|
|
24
26
|
|
25
27
|
def init_feature_defs
|
26
28
|
# Create standard feature definitions for lexical verbs.
|
27
|
-
feature_def_dsl
|
29
|
+
feature_def_dsl do
|
28
30
|
feature_def 'NUMBER' => enumeration(:singular, :plural)
|
29
31
|
feature_def 'PERSON' => enumeration(:first, :second, :third)
|
30
32
|
feature_def 'TIME' => enumeration(:present, :progressive, :past_simple, :past_participle)
|
31
33
|
feature_def 'PARADIGM' => [identifier, 'Regular_inflection'] # 2nd item is default value
|
32
|
-
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
def init_paradigms
|
@@ -37,4 +39,4 @@ module Zenlish
|
|
37
39
|
end
|
38
40
|
end # class
|
39
41
|
end # module
|
40
|
-
end # module
|
42
|
+
end # module
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rley'
|
2
4
|
require_relative '../feature/feature_struct_def_bearer'
|
3
5
|
|
@@ -29,19 +31,19 @@ module Zenlish
|
|
29
31
|
# form.
|
30
32
|
# @return [FalseClass, TrueClass] true iff the words in the class are invariable.
|
31
33
|
def invariable?
|
32
|
-
|
34
|
+
true
|
33
35
|
end
|
34
|
-
|
36
|
+
|
35
37
|
# @return [Module, NilClass]
|
36
38
|
def extension
|
37
39
|
nil
|
38
40
|
end
|
39
|
-
|
41
|
+
|
40
42
|
protected
|
41
43
|
|
42
44
|
def add_paradigm(anInflectionTable)
|
43
45
|
@paradigms[anInflectionTable.name] = anInflectionTable
|
44
|
-
end
|
46
|
+
end
|
45
47
|
end # class
|
46
48
|
end # module
|
47
|
-
end # module
|
49
|
+
end # module
|
data/lib/zenlish.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# This file acts as a jumping-off point for loading dependencies expected
|
4
4
|
# for a Zenlish client.
|
5
5
|
|
6
|
-
require_relative '
|
7
|
-
require_relative '
|
8
|
-
require_relative '
|
6
|
+
require_relative 'zenlish/version'
|
7
|
+
require_relative 'zenlish/lang/dictionary'
|
8
|
+
require_relative 'zenlish/parser/zparser'
|
9
9
|
|
10
10
|
# End of file
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
4
|
require 'rspec' # Use the RSpec framework
|
3
5
|
|
4
6
|
RSpec.configure do |config|
|
5
7
|
# Enable flags like --only-failures and --next-failure
|
6
|
-
config.example_status_persistence_file_path =
|
8
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
7
9
|
|
8
10
|
config.expect_with :rspec do |c|
|
9
11
|
# Disable the `should` syntax
|
@@ -5,34 +5,34 @@ require_relative '../../../lib/zenlish/feature/boolean_domain' # Load the class
|
|
5
5
|
module Zenlish
|
6
6
|
module Feature
|
7
7
|
describe BooleanDomain do
|
8
|
-
subject {
|
8
|
+
subject(:bool_dom) { described_class.instance }
|
9
9
|
|
10
10
|
context 'Initialization:' do
|
11
|
-
it '
|
12
|
-
expect {
|
11
|
+
it 'is initialized without argument' do
|
12
|
+
expect { described_class.instance }.not_to raise_error
|
13
13
|
end
|
14
14
|
end # context
|
15
15
|
|
16
16
|
context 'Provided services:' do
|
17
|
-
it '
|
18
|
-
expect(
|
19
|
-
expect(
|
20
|
-
expect(
|
17
|
+
it 'knows whether a value is in domain' do
|
18
|
+
expect(bool_dom).not_to include('invalid')
|
19
|
+
expect(bool_dom).to include(true)
|
20
|
+
expect(bool_dom).to include(false)
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
24
|
-
expect(
|
25
|
-
expect(
|
23
|
+
it 'provides a factory method for boolean values' do
|
24
|
+
expect(bool_dom.build_value(true)).to be_a(BooleanValue)
|
25
|
+
expect(bool_dom.build_value(false)).to be_a(BooleanValue)
|
26
26
|
end
|
27
|
-
|
28
|
-
it 'should return all valid values in domain when requested' do
|
29
|
-
expect(subject.to_a).to eq([false, true])
|
30
|
-
end
|
31
27
|
|
32
|
-
it '
|
28
|
+
it 'returns all valid values in domain when requested' do
|
29
|
+
expect(bool_dom.to_a).to eq([false, true])
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'complains when asked to build a non-boolean value' do
|
33
33
|
err = StandardError
|
34
34
|
err_msg = 'Expected a boolean instead of String.'
|
35
|
-
expect {
|
35
|
+
expect { bool_dom.build_value('?') }.to raise_error(err, err_msg)
|
36
36
|
end
|
37
37
|
end # context
|
38
38
|
end # describe
|
@@ -7,15 +7,16 @@ module Zenlish
|
|
7
7
|
module Feature
|
8
8
|
describe BooleanValue do
|
9
9
|
let(:its_value) { false }
|
10
|
-
|
10
|
+
|
11
|
+
subject(:boolean) { described_class.new(its_value) }
|
11
12
|
|
12
13
|
context 'Initialization:' do
|
13
|
-
it '
|
14
|
-
expect {
|
14
|
+
it 'is initialized with a value argument' do
|
15
|
+
expect { described_class.new(its_value) }.not_to raise_error
|
15
16
|
end
|
16
|
-
|
17
|
-
it '
|
18
|
-
expect(
|
17
|
+
|
18
|
+
it 'knows its internal value' do
|
19
|
+
expect(boolean.val.class).to eq(FalseClass)
|
19
20
|
end
|
20
21
|
end # context
|
21
22
|
|
@@ -1,44 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Load the class under test
|
4
|
-
require_relative '../../../lib/zenlish/feature/enumeration_domain'
|
4
|
+
require_relative '../../../lib/zenlish/feature/enumeration_domain'
|
5
5
|
|
6
6
|
module Zenlish
|
7
7
|
module Feature
|
8
8
|
describe EnumerationDomain do
|
9
|
-
subject {
|
9
|
+
subject(:enumeration) { described_class.new(:singular, :plural) }
|
10
10
|
|
11
11
|
context 'Initialization:' do
|
12
|
-
it '
|
13
|
-
expect {
|
12
|
+
it 'is initialized with arguments' do
|
13
|
+
expect { described_class.new(:singular, :plural) }.not_to raise_error
|
14
14
|
end
|
15
|
-
|
16
|
-
it '
|
17
|
-
expect(
|
15
|
+
|
16
|
+
it 'knows the values of enumeration' do
|
17
|
+
expect(enumeration.enum).to eq(%i[singular plural])
|
18
18
|
end
|
19
19
|
end # context
|
20
20
|
|
21
21
|
context 'Provided services:' do
|
22
|
-
it '
|
23
|
-
expect(
|
24
|
-
expect(
|
25
|
-
expect(
|
22
|
+
it 'knows whether a value is in domain' do
|
23
|
+
expect(enumeration).not_to include(:dual)
|
24
|
+
expect(enumeration).to include(:singular)
|
25
|
+
expect(enumeration).to include(:plural)
|
26
26
|
end
|
27
|
-
|
28
|
-
it '
|
29
|
-
expect(
|
30
|
-
value =
|
27
|
+
|
28
|
+
it 'provides a factory method for enumerated value' do
|
29
|
+
expect(enumeration.build_value(:plural)).to be_a(SymbolValue)
|
30
|
+
value = enumeration.build_value(:plural)
|
31
31
|
expect(value.val).to eq(:plural)
|
32
32
|
end
|
33
|
-
|
34
|
-
it 'should return all valid values in domain when requested' do
|
35
|
-
expect(subject.to_a).to eq([:singular, :plural])
|
36
|
-
end
|
37
33
|
|
38
|
-
it '
|
34
|
+
it 'returns all valid values in domain when requested' do
|
35
|
+
expect(enumeration.to_a).to eq(%i[singular plural])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'complains when asked to build a non-member value' do
|
39
39
|
err = StandardError
|
40
40
|
err_msg = "dual isn't part of enumeration [singular, plural]."
|
41
|
-
expect {
|
41
|
+
expect { enumeration.build_value(:dual) }.to raise_error(err, err_msg)
|
42
42
|
end
|
43
43
|
end # context
|
44
44
|
end # describe
|
@@ -9,36 +9,37 @@ module Zenlish
|
|
9
9
|
describe FeatureDef do
|
10
10
|
let(:a_name) { 'NUMBER' }
|
11
11
|
let(:a_domain) { EnumerationDomain.new(:singular, :plural) }
|
12
|
-
|
12
|
+
|
13
|
+
subject(:ft_def) { described_class.new(a_name, a_domain) }
|
13
14
|
|
14
15
|
context 'Initialization:' do
|
15
|
-
it '
|
16
|
-
expect {
|
16
|
+
it 'is initialized with at least two arguments' do
|
17
|
+
expect { described_class.new(a_name, a_domain) }.not_to raise_error
|
17
18
|
end
|
18
19
|
|
19
|
-
it '
|
20
|
+
it 'can be initialized with a default value argument' do
|
20
21
|
deflt = double('dummy')
|
21
|
-
expect {
|
22
|
+
expect { described_class.new(a_name, a_domain, deflt) }.not_to raise_error
|
22
23
|
end
|
23
24
|
|
24
|
-
it '
|
25
|
-
expect(
|
25
|
+
it 'knows its name' do
|
26
|
+
expect(ft_def.name).to eq(a_name)
|
26
27
|
end
|
27
28
|
|
28
|
-
it '
|
29
|
-
expect(
|
29
|
+
it 'knows the domain of its values' do
|
30
|
+
expect(ft_def.domain).to eq(a_domain)
|
30
31
|
end
|
31
32
|
|
32
|
-
it '
|
33
|
-
expect(
|
33
|
+
it 'knows the domain of its default value' do
|
34
|
+
expect(ft_def.default).to be_nil
|
34
35
|
deflt = double('dummy')
|
35
|
-
instance =
|
36
|
+
instance = described_class.new(a_name, a_domain, deflt)
|
36
37
|
expect(instance.default).to eq(deflt)
|
37
38
|
end
|
38
39
|
|
39
|
-
it '
|
40
|
+
it 'guesses its default if enumeration has a single member' do
|
40
41
|
basic_domain = EnumerationDomain.new(:plural)
|
41
|
-
instance =
|
42
|
+
instance = described_class.new(a_name, basic_domain)
|
42
43
|
expect(instance.default.val).to eq(:plural)
|
43
44
|
end
|
44
45
|
end # context
|
@@ -14,38 +14,38 @@ module Zenlish
|
|
14
14
|
let(:feat_def) { FeatureDef.new(a_name, a_domain) }
|
15
15
|
let(:plural_value) { a_domain.build_value(:plural) }
|
16
16
|
|
17
|
-
subject {
|
17
|
+
subject(:a_feature) { described_class.new(feat_def) }
|
18
18
|
|
19
19
|
context 'Initialization:' do
|
20
|
-
it '
|
21
|
-
expect {
|
20
|
+
it 'is initialized with one definition argument' do
|
21
|
+
expect { described_class.new(feat_def) }.not_to raise_error
|
22
22
|
end
|
23
23
|
|
24
|
-
it '
|
25
|
-
expect(
|
24
|
+
it 'knows its definition' do
|
25
|
+
expect(a_feature.definition).to eq(feat_def)
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
29
|
-
expect(
|
30
|
-
expect(
|
28
|
+
it "isn't bound yet to a value" do
|
29
|
+
expect(a_feature.binding).to be_nil
|
30
|
+
expect(a_feature).not_to be_bound
|
31
31
|
end
|
32
32
|
end # context
|
33
33
|
|
34
34
|
context 'Provided services:' do
|
35
|
-
it "
|
36
|
-
expect(
|
35
|
+
it "knows the definition's name" do
|
36
|
+
expect(a_feature.name).to eq(feat_def.name)
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
expect(
|
39
|
+
it 'knows the domain of its values' do
|
40
|
+
expect(a_feature.domain).to eq(a_domain)
|
41
41
|
end
|
42
42
|
|
43
|
-
it '
|
44
|
-
expect {
|
45
|
-
expect(
|
46
|
-
|
43
|
+
it 'accepts a value binding' do
|
44
|
+
expect { a_feature.bind_to(plural_value) }.not_to raise_error
|
45
|
+
expect(a_feature).to be_bound
|
46
|
+
expect(a_feature.binding).to eq(plural_value)
|
47
47
|
end
|
48
48
|
end # context
|
49
49
|
end # describe
|
50
50
|
end # module
|
51
|
-
end # module
|
51
|
+
end # module
|
@@ -7,6 +7,7 @@ module Zenlish
|
|
7
7
|
module Feature
|
8
8
|
describe FeatureStructDefBearer do
|
9
9
|
# @nodoc Class created just for testing purposes.
|
10
|
+
# rubocop: disable Lint/ConstantDefinitionInBlock
|
10
11
|
class Dummy
|
11
12
|
include FeatureStructDefBearer
|
12
13
|
|
@@ -20,35 +21,36 @@ module Zenlish
|
|
20
21
|
init_struct_def(aParent, feature_hash)
|
21
22
|
end
|
22
23
|
end # class
|
24
|
+
# rubocop: enable Lint/ConstantDefinitionInBlock
|
23
25
|
|
24
|
-
subject { Dummy.new
|
26
|
+
subject(:bearer) { Dummy.new(nil) }
|
25
27
|
|
26
28
|
context 'Mix-in initialization' do
|
27
|
-
it '
|
29
|
+
it 'has initialized properly the injected data' do
|
28
30
|
expect { Dummy.new(nil) }.not_to raise_error
|
29
|
-
expect(
|
31
|
+
expect(bearer.struct).to be_a(FeatureStructDef)
|
30
32
|
end
|
31
33
|
|
32
|
-
it '
|
33
|
-
expect(
|
34
|
-
expect(
|
35
|
-
ft =
|
36
|
-
expect(ft.domain.enum).to eq([
|
37
|
-
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect(
|
42
|
-
expect(
|
34
|
+
it 'has the feature definitions created' do
|
35
|
+
expect(bearer['NUMBER']).not_to be_nil
|
36
|
+
expect(bearer['NUMBER']).to be_a(FeatureDef)
|
37
|
+
ft = bearer['NUMBER']
|
38
|
+
expect(ft.domain.enum).to eq(%i[singular plural])
|
39
|
+
|
40
|
+
expect(bearer['COUNTABILITY']).to be_a(FeatureDef)
|
41
|
+
expect(bearer['COUNTABILITY'].domain).to be_a(BooleanDomain)
|
42
|
+
expect(bearer['PARADIGM']).to be_a(FeatureDef)
|
43
|
+
expect(bearer['PARADIGM'].domain).to be_a(IdentifierDomain)
|
44
|
+
expect(bearer['PARADIGM'].default).to be_a(IdentifierValue)
|
43
45
|
end
|
44
|
-
|
45
|
-
it '
|
46
|
-
|
47
|
-
|
48
|
-
expect(
|
49
|
-
expect(
|
46
|
+
|
47
|
+
it 'supports the addition of feature def' do
|
48
|
+
bearer.feature_def_dsl { feature_def 'CASE' => boolean }
|
49
|
+
|
50
|
+
expect(bearer['CASE']).to be_a(FeatureDef)
|
51
|
+
expect(bearer['CASE'].domain).to be_a(BooleanDomain)
|
50
52
|
end
|
51
53
|
end # context
|
52
54
|
end # describe
|
53
55
|
end # module
|
54
|
-
end # module
|
56
|
+
end # module
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require_relative '../../../lib/zenlish/feature/boolean_domain'
|
3
4
|
require_relative '../../../lib/zenlish/feature/enumeration_domain'
|
4
5
|
require_relative '../../../lib/zenlish/feature/feature_def'
|
@@ -13,55 +14,55 @@ module Zenlish
|
|
13
14
|
let(:ft_number) { FeatureDef.new('NUMBER', enum_number) }
|
14
15
|
let(:countable_domain) { BooleanDomain.instance }
|
15
16
|
let(:ft_countability) { FeatureDef.new('COUNTABILITY', countable_domain) }
|
16
|
-
let(:sample_parent) {
|
17
|
+
let(:sample_parent) { described_class.new }
|
17
18
|
let(:case_domain) { EnumerationDomain.new(:common, :genitive) }
|
18
19
|
let(:ft_case) { FeatureDef.new('CASE', case_domain) }
|
19
20
|
|
20
|
-
subject {
|
21
|
+
subject(:struct_def) { described_class.new(sample_parent) }
|
21
22
|
|
22
23
|
context 'Initialization:' do
|
23
|
-
it '
|
24
|
-
expect {
|
24
|
+
it 'can be initialized without argument' do
|
25
|
+
expect { described_class.new }.not_to raise_error
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect {
|
28
|
+
it 'can be initialized with a parent struct' do
|
29
|
+
expect { described_class.new(sample_parent) }.not_to raise_error
|
29
30
|
end
|
30
31
|
|
31
|
-
it '
|
32
|
-
expect(
|
32
|
+
it 'has an empty structure at initialization' do
|
33
|
+
expect(struct_def.struct).to be_empty
|
33
34
|
end
|
34
35
|
|
35
|
-
it '
|
36
|
-
expect(
|
37
|
-
instance =
|
36
|
+
it 'knows its parent (if any)' do
|
37
|
+
expect(struct_def.parent).to eq(sample_parent)
|
38
|
+
instance = described_class.new
|
38
39
|
expect(instance.parent).to be_nil
|
39
40
|
end
|
40
41
|
end # context
|
41
42
|
|
42
43
|
context 'Provided services:' do
|
43
|
-
it '
|
44
|
-
expect {
|
45
|
-
expect(
|
46
|
-
expect(
|
44
|
+
it 'accepts the addition of a feature definition' do
|
45
|
+
expect { struct_def.add_feature_def(ft_number) }.not_to raise_error
|
46
|
+
expect(struct_def.struct.size).to eq(1)
|
47
|
+
expect(struct_def['NUMBER']).to eq(ft_number)
|
47
48
|
|
48
|
-
expect {
|
49
|
-
expect(
|
50
|
-
expect(
|
49
|
+
expect { struct_def.add_feature_def(ft_countability) }.not_to raise_error
|
50
|
+
expect(struct_def.struct.size).to eq(2)
|
51
|
+
expect(struct_def['COUNTABILITY']).to eq(ft_countability)
|
51
52
|
end
|
52
53
|
|
53
|
-
it '
|
54
|
+
it 'inherits the feature definition of its parent' do
|
54
55
|
sample_parent.add_feature_def(ft_case)
|
55
|
-
expect(
|
56
|
+
expect(struct_def['CASE']).to eq(ft_case)
|
56
57
|
end
|
57
|
-
|
58
|
-
it "
|
58
|
+
|
59
|
+
it "is able to override parent's feature def" do
|
59
60
|
sample_parent.add_feature_def(ft_case)
|
60
|
-
|
61
|
+
|
61
62
|
other_case_domain = BooleanDomain.instance
|
62
63
|
other_ft_case = FeatureDef.new('CASE', other_case_domain)
|
63
|
-
|
64
|
-
expect(
|
64
|
+
struct_def.add_feature_def(other_ft_case)
|
65
|
+
expect(struct_def['CASE']).to eq(other_ft_case)
|
65
66
|
end
|
66
67
|
end # context
|
67
68
|
end # describe
|
@@ -5,32 +5,32 @@ require_relative '../../../lib/zenlish/feature/identifier_domain' # Load the cla
|
|
5
5
|
module Zenlish
|
6
6
|
module Feature
|
7
7
|
describe IdentifierDomain do
|
8
|
-
subject {
|
8
|
+
subject(:domain) { described_class.instance }
|
9
9
|
|
10
10
|
context 'Initialization:' do
|
11
|
-
it '
|
12
|
-
expect {
|
11
|
+
it 'is instantiated without argument' do
|
12
|
+
expect { described_class.instance }.not_to raise_error
|
13
13
|
end
|
14
14
|
end # context
|
15
15
|
|
16
16
|
context 'Provided services:' do
|
17
|
-
it '
|
18
|
-
expect(
|
19
|
-
expect(
|
20
|
-
expect(
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should provide a factory method for identifier values' do
|
24
|
-
expect(subject.build_value('CommonForm')).to be_kind_of(IdentifierValue)
|
25
|
-
expect(subject.build_value('Common_Form')).to be_kind_of(IdentifierValue)
|
17
|
+
it 'knows whether a value is in domain' do
|
18
|
+
expect(domain).to include('CommonForm')
|
19
|
+
expect(domain).not_to include('Common Form')
|
20
|
+
expect(domain).not_to include('+123')
|
26
21
|
end
|
27
22
|
|
28
|
-
it '
|
23
|
+
it 'provides a factory method for identifier values' do
|
24
|
+
expect(domain.build_value('CommonForm')).to be_a(IdentifierValue)
|
25
|
+
expect(domain.build_value('Common_Form')).to be_a(IdentifierValue)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'complains when asked to build an invalid identifier' do
|
29
29
|
err = StandardError
|
30
30
|
err_msg = "?1234 isn't a valid identifier."
|
31
|
-
expect {
|
31
|
+
expect { domain.build_value('?1234') }.to raise_error(err, err_msg)
|
32
32
|
end
|
33
33
|
end # context
|
34
34
|
end # describe
|
35
35
|
end # module
|
36
|
-
end # module
|
36
|
+
end # module
|
@@ -1,26 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Load the class under test
|
4
|
-
require_relative '../../../lib/zenlish/feature/identifier_value'
|
4
|
+
require_relative '../../../lib/zenlish/feature/identifier_value'
|
5
5
|
|
6
6
|
module Zenlish
|
7
7
|
module Feature
|
8
8
|
describe IdentifierValue do
|
9
9
|
let(:its_value) { 'CommonForm' }
|
10
|
-
|
10
|
+
|
11
|
+
subject(:identifier) { described_class.new(its_value) }
|
11
12
|
|
12
13
|
context 'Initialization:' do
|
13
|
-
it '
|
14
|
-
expect {
|
14
|
+
it 'is initialized with a value argument' do
|
15
|
+
expect { described_class.new(its_value) }.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'knows its internal value' do
|
19
|
+
expect(identifier.val).to eq(its_value)
|
15
20
|
end
|
16
|
-
|
17
|
-
it 'should know its internal value' do
|
18
|
-
expect(subject.val).to eq(its_value)
|
19
|
-
end
|
20
21
|
end # context
|
21
22
|
|
22
23
|
context 'Provided services:' do
|
23
24
|
end # context
|
24
25
|
end # describe
|
25
26
|
end # module
|
26
|
-
end # module
|
27
|
+
end # module
|