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
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../spec_helper' # Use the RSpec framework
|
4
|
+
require_relative '../../../lib/zenlish/lang/dictionary'
|
5
|
+
|
6
|
+
# Load the class under test
|
7
|
+
require_relative '../../../lib/zenlish/lang/lemmatizer'
|
8
|
+
|
9
|
+
module Zenlish
|
10
|
+
module Lang
|
11
|
+
describe Lemmatizer do
|
12
|
+
subject { described_class.new(Dictionary) }
|
13
|
+
|
14
|
+
context 'Initialization:' do
|
15
|
+
# it 'is initialized with a lexicon argument' do
|
16
|
+
# expect { described_class.new(Dictionary) }.not_to raise_error
|
17
|
+
# end
|
18
|
+
end # context
|
19
|
+
|
20
|
+
context 'Provided services:' do
|
21
|
+
# it 'retrieves an unambiguous word form' do
|
22
|
+
# # Coordinator
|
23
|
+
# found = described_class.lemmatize('and')
|
24
|
+
# expect(found).to be_a(Lex::Lexeme)
|
25
|
+
# expect(found.lemma).to eq('and')
|
26
|
+
# expect(found.wclass).to be_a(WClasses::Coordinator)
|
27
|
+
#
|
28
|
+
# # Common noun
|
29
|
+
# found = described_class.lemmatize('surfaces')
|
30
|
+
# expect(found).to be_a(Lex::Lexeme)
|
31
|
+
# expect(found.lemma).to eq('surface')
|
32
|
+
# expect(found.wclass).to be_a(WClasses::CommonNoun)
|
33
|
+
#
|
34
|
+
# # Verb
|
35
|
+
# found = described_class.lemmatize('seeing')
|
36
|
+
# expect(found).to be_a(Lex::Lexeme)
|
37
|
+
# expect(found.lemma).to eq('see')
|
38
|
+
# expect(found.wclass).to be_a(WClasses::IrregularVerb)
|
39
|
+
# end
|
40
|
+
end # context
|
41
|
+
end # describe
|
42
|
+
end # module
|
43
|
+
end # module
|
@@ -4,13 +4,13 @@ require_relative '../../spec_helper' # Use the RSpec framework
|
|
4
4
|
require_relative '../../../lib/zenlish/lang/zenlish_grammar' # Load the class under test
|
5
5
|
|
6
6
|
module Zenlish
|
7
|
-
module
|
7
|
+
module Lang
|
8
8
|
describe ZenlishGrammar do
|
9
|
-
subject {
|
9
|
+
subject(:grammar) { described_class }
|
10
10
|
|
11
11
|
context 'Initialization:' do
|
12
|
-
it '
|
13
|
-
expect {
|
12
|
+
it 'knows its terminal symbols' do
|
13
|
+
expect { grammar.name2symbol['CommonNoun'] }.not_to raise_error
|
14
14
|
end
|
15
15
|
end # context
|
16
16
|
|
@@ -18,4 +18,4 @@ module Zenlish
|
|
18
18
|
end # context
|
19
19
|
end # describe
|
20
20
|
end # module
|
21
|
-
end # module
|
21
|
+
end # module
|
@@ -8,24 +8,24 @@ require_relative '../../../lib/zenlish/lex/empty_lexicon_factory'
|
|
8
8
|
module Zenlish
|
9
9
|
module Lex
|
10
10
|
describe EmptyLexiconFactory do
|
11
|
-
subject do
|
11
|
+
subject(:factory) do
|
12
12
|
obj = Object.new
|
13
|
-
obj.extend(
|
13
|
+
obj.extend(described_class)
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'Mix-in integration:' do
|
17
|
-
it '
|
18
|
-
expect(
|
17
|
+
it 'acquires the methods of the mix-in module' do
|
18
|
+
expect(factory).to respond_to(:create_empty_lexicon)
|
19
19
|
end
|
20
20
|
end # context
|
21
21
|
|
22
22
|
context 'Created lexicon:' do
|
23
|
-
it '
|
24
|
-
expect(
|
23
|
+
it 'allows the creation of empty lexicon' do
|
24
|
+
expect(factory.create_empty_lexicon).to be_a(Lexicon)
|
25
25
|
end
|
26
26
|
|
27
|
-
it '
|
28
|
-
lexicon =
|
27
|
+
it 'initializes lexicon with terminal symbols of the language' do
|
28
|
+
lexicon = factory.create_empty_lexicon
|
29
29
|
found = lexicon.terminals.find { |symb| symb.kind_of?(WClasses::CommonNoun) }
|
30
30
|
expect(found).to be_truthy
|
31
31
|
end
|
@@ -10,55 +10,54 @@ module Zenlish
|
|
10
10
|
module Lex
|
11
11
|
describe Lexeme do
|
12
12
|
include Feature::FeatureStructDefBearer
|
13
|
-
|
13
|
+
|
14
14
|
let(:a_wclass) { WClasses::CommonNoun.new }
|
15
15
|
let(:a_lemma) { 'people' }
|
16
16
|
let(:an_entry) { LexicalEntry.new(a_lemma) }
|
17
|
-
let(:a_feat_struct_def)
|
17
|
+
let(:a_feat_struct_def) do
|
18
18
|
{ 'NUMBER' => enumeration(:plural),
|
19
19
|
'PARADIGM' => [identifier, 'Plural_only'] }
|
20
|
-
|
20
|
+
end
|
21
21
|
|
22
|
-
subject {
|
22
|
+
subject(:a_lexeme) { described_class.new(a_wclass, an_entry) }
|
23
23
|
|
24
24
|
context 'Initialization:' do
|
25
|
-
it '
|
26
|
-
expect {
|
25
|
+
it 'can be initialized with a word class and a lexical entry' do
|
26
|
+
expect { described_class.new(a_wclass, an_entry) }.not_to raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can be initialized with a w. class, lexical ent., feature hash' do
|
30
|
+
expect { described_class.new(a_wclass, an_entry, a_feat_struct_def) }.not_to raise_error
|
27
31
|
end
|
28
|
-
|
29
|
-
it 'could be initialized with a w. class, lexical ent., feature hash' do
|
30
|
-
expect { Lexeme.new(a_wclass, an_entry, a_feat_struct_def) }.not_to raise_error
|
31
|
-
end
|
32
32
|
|
33
|
-
it '
|
34
|
-
expect(
|
33
|
+
it 'knows its word class' do
|
34
|
+
expect(a_lexeme.wclass).to eq(a_wclass)
|
35
35
|
end
|
36
36
|
|
37
|
-
it '
|
38
|
-
expect(
|
37
|
+
it 'knows its lexical entry' do
|
38
|
+
expect(a_lexeme.entry).to eq(an_entry)
|
39
39
|
end
|
40
40
|
end # context
|
41
41
|
|
42
42
|
context 'Provided services:' do
|
43
|
-
subject {
|
44
|
-
it '
|
45
|
-
expect(
|
43
|
+
subject(:a_lexeme) { described_class.new(a_wclass, an_entry, a_feat_struct_def) }
|
44
|
+
it 'knows its lemma' do
|
45
|
+
expect(a_lexeme.lemma).to eq(a_lemma)
|
46
46
|
end
|
47
|
-
|
48
|
-
it '
|
49
|
-
instance =
|
47
|
+
|
48
|
+
it 'knows its own feature defs' do
|
49
|
+
instance = described_class.new(a_wclass, an_entry, a_feat_struct_def)
|
50
50
|
expect(instance['NUMBER'].default.val).to eq(:plural)
|
51
51
|
end
|
52
|
-
|
53
|
-
it '
|
54
|
-
expect(
|
52
|
+
|
53
|
+
it 'knows its inflection paradigm' do
|
54
|
+
expect(a_lexeme.paradigm).to be_a(Inflect::InflectionTable)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'knows all its inflections' do
|
58
|
+
expect(a_lexeme.all_inflections).to eq(['people'])
|
55
59
|
end
|
56
|
-
|
57
|
-
it 'should know all its inflections' do
|
58
|
-
expect(subject.all_inflections).to eq(['people'])
|
59
|
-
end
|
60
60
|
end # context
|
61
61
|
end # describe
|
62
62
|
end # module
|
63
63
|
end # module
|
64
|
-
|
@@ -9,38 +9,38 @@ module Zenlish
|
|
9
9
|
let(:sample_lemma) { 'other' }
|
10
10
|
let(:sample_lexeme1) { double('other-as-adjective') }
|
11
11
|
let(:sample_lexeme2) { double('other-as-pronoun') }
|
12
|
-
|
12
|
+
|
13
|
+
subject(:lex_entry) { described_class.new(sample_lemma) }
|
13
14
|
|
14
15
|
context 'Initialization:' do
|
15
16
|
it 'can be initialized with a lemma only' do
|
16
|
-
expect {
|
17
|
+
expect { described_class.new(sample_lemma) }.not_to raise_error
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'can be initialized with a lemma and a word class' do
|
20
|
-
expect {
|
21
|
+
expect { described_class.new(sample_lemma, sample_lexeme1) }.not_to raise_error
|
21
22
|
end
|
22
23
|
|
23
|
-
it '
|
24
|
-
expect(
|
24
|
+
it 'knows its lemma' do
|
25
|
+
expect(lex_entry.lemma).to eq(sample_lemma)
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
-
expect(
|
29
|
-
instance =
|
28
|
+
it 'knows its lexeme (if any)' do
|
29
|
+
expect(lex_entry.lexemes).to be_empty
|
30
|
+
instance = described_class.new(sample_lemma, sample_lexeme1)
|
30
31
|
expect(instance.lexemes).to eq([sample_lexeme1])
|
31
32
|
end
|
32
33
|
end # context
|
33
34
|
|
34
35
|
context 'Provided services:' do
|
36
|
+
it 'accepts links with lexeme(s)' do
|
37
|
+
lex_entry.add_lexeme(sample_lexeme1)
|
38
|
+
expect(lex_entry.lexemes).to eq([sample_lexeme1])
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
expect(subject.lexemes).to eq([sample_lexeme1])
|
39
|
-
|
40
|
-
subject.add_lexeme(sample_lexeme2)
|
41
|
-
expect(subject.lexemes).to eq([sample_lexeme1, sample_lexeme2])
|
40
|
+
lex_entry.add_lexeme(sample_lexeme2)
|
41
|
+
expect(lex_entry.lexemes).to eq([sample_lexeme1, sample_lexeme2])
|
42
42
|
end
|
43
43
|
end # context
|
44
44
|
end # describe
|
45
45
|
end # module
|
46
|
-
end # module
|
46
|
+
end # module
|
@@ -12,7 +12,8 @@ module Zenlish
|
|
12
12
|
describe Lexicon do
|
13
13
|
def create_entry(aLemma, aWordClass)
|
14
14
|
entry = Zenlish::Lex::LexicalEntry.new(aLemma)
|
15
|
-
lexeme =
|
15
|
+
# lexeme =
|
16
|
+
Zenlish::Lex::Lexeme.new(aWordClass, entry)
|
16
17
|
entry
|
17
18
|
end
|
18
19
|
|
@@ -23,78 +24,79 @@ module Zenlish
|
|
23
24
|
let(:sample_entry) { create_entry('other', adjective) }
|
24
25
|
let(:similar_entry) { create_entry('other', pronoun) }
|
25
26
|
let(:distinct_entry) { create_entry('hope', irregular_verb) }
|
26
|
-
|
27
|
+
|
28
|
+
subject(:lexicon) { described_class.new }
|
27
29
|
|
28
30
|
context 'Initialization:' do
|
29
|
-
it '
|
30
|
-
expect {
|
31
|
+
it 'is initialized without parameter' do
|
32
|
+
expect { described_class.new }.not_to raise_error
|
31
33
|
end
|
32
34
|
|
33
|
-
it '
|
34
|
-
expect(
|
35
|
+
it 'has no registered terminals at initialization' do
|
36
|
+
expect(lexicon.terminals).to be_empty
|
35
37
|
end
|
36
38
|
|
37
|
-
it '
|
38
|
-
expect(
|
39
|
-
expect(
|
39
|
+
it 'has no entry at initialization' do
|
40
|
+
expect(lexicon.entries).to be_empty
|
41
|
+
expect(lexicon.lemma2entry).to be_empty
|
40
42
|
end
|
41
43
|
end # context
|
42
44
|
|
43
45
|
context 'Provided services:' do
|
44
|
-
it '
|
46
|
+
it 'accepts the addition of terminals' do
|
45
47
|
terminal1 = pronoun
|
46
48
|
terminal2 = irregular_verb
|
47
49
|
terminal3 = adjective
|
48
50
|
|
49
|
-
|
50
|
-
expect(
|
51
|
-
|
52
|
-
expect(
|
53
|
-
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
expect(
|
57
|
-
expect(
|
51
|
+
lexicon.add_terminal(terminal1)
|
52
|
+
expect(lexicon.terminals).to eq([terminal1])
|
53
|
+
lexicon.add_terminal(terminal2)
|
54
|
+
expect(lexicon.terminals).to eq([terminal1, terminal2])
|
55
|
+
lexicon.add_terminal(terminal3)
|
56
|
+
expect(lexicon.terminals).to eq([terminal1, terminal2, terminal3])
|
57
|
+
expect(lexicon.name2terminal['Pronoun']).to eq(terminal1)
|
58
|
+
expect(lexicon.name2terminal['IrregularVerb']).to eq(terminal2)
|
59
|
+
expect(lexicon.name2terminal['Adjective']).to eq(terminal3)
|
58
60
|
end
|
59
61
|
|
60
|
-
it '
|
61
|
-
|
62
|
-
expect(
|
63
|
-
expect(
|
62
|
+
it 'accepts the addition of entries' do
|
63
|
+
lexicon.add_entry(sample_entry)
|
64
|
+
expect(lexicon.entries).to eq([sample_entry])
|
65
|
+
expect(lexicon.lemma2entry['other']).to eq(sample_entry)
|
64
66
|
|
65
67
|
# Add dissimilar entry
|
66
|
-
|
67
|
-
expect(
|
68
|
-
expect(
|
68
|
+
lexicon.add_entry(distinct_entry)
|
69
|
+
expect(lexicon.entries).to eq([sample_entry, distinct_entry])
|
70
|
+
expect(lexicon.lemma2entry['hope']).to eq(distinct_entry)
|
69
71
|
|
70
72
|
# Add "homonym" entry
|
71
|
-
|
72
|
-
expect(
|
73
|
-
expect(
|
73
|
+
lexicon.add_entry(similar_entry)
|
74
|
+
expect(lexicon.entries).to eq([sample_entry, distinct_entry, similar_entry])
|
75
|
+
expect(lexicon.lemma2entry['other']).to eq([sample_entry, similar_entry])
|
74
76
|
end
|
75
|
-
|
76
|
-
it '
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
lexeme =
|
82
|
-
expect(lexeme.wclass).to
|
77
|
+
|
78
|
+
it 'retrieves the lexeme of an entry with unique lemma' do
|
79
|
+
lexicon.add_entry(sample_entry)
|
80
|
+
lexicon.add_entry(distinct_entry)
|
81
|
+
lexicon.add_entry(similar_entry)
|
82
|
+
|
83
|
+
lexeme = lexicon.get_lexeme('hope')
|
84
|
+
expect(lexeme.wclass).to be_a(Zenlish::WClasses::IrregularVerb)
|
83
85
|
end
|
84
|
-
|
85
|
-
it '
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
lexeme =
|
91
|
-
expect(lexeme).to
|
92
|
-
end
|
93
|
-
|
94
|
-
it '
|
95
|
-
|
86
|
+
|
87
|
+
it 'retrieves the lexeme of an entry with duplicate lemma' do
|
88
|
+
lexicon.add_entry(sample_entry)
|
89
|
+
lexicon.add_entry(distinct_entry)
|
90
|
+
lexicon.add_entry(similar_entry)
|
91
|
+
|
92
|
+
lexeme = lexicon.get_lexeme('other', Zenlish::WClasses::Pronoun)
|
93
|
+
expect(lexeme).to be_a(Zenlish::Lex::Lexeme)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'complains when retrieving an non-existing entry' do
|
97
|
+
lexicon.add_entry(sample_entry)
|
96
98
|
err_msg = 'key not found: "hapax"'
|
97
|
-
expect {
|
99
|
+
expect { lexicon.get_lexeme('hapax') }.to raise_error(KeyError, err_msg)
|
98
100
|
end
|
99
101
|
end # context
|
100
102
|
end # describe
|
@@ -8,24 +8,24 @@ require_relative '../../../lib/zenlish/lex/literal' # Load the class under test
|
|
8
8
|
|
9
9
|
module Zenlish
|
10
10
|
module Lex
|
11
|
-
describe
|
11
|
+
describe Literal do
|
12
12
|
let(:sample_wclass) { WClasses::CommonNoun.new }
|
13
13
|
let(:sample_lemma) { 'thing' }
|
14
14
|
let(:sample_entry) { LexicalEntry.new(sample_lemma) }
|
15
|
-
let(:sample_position) {
|
16
|
-
let(:sample_lexeme) { Lexeme.new(sample_wclass, sample_entry)
|
15
|
+
let(:sample_position) { instance_double(Rley::Lexical::Position) }
|
16
|
+
let(:sample_lexeme) { Lexeme.new(sample_wclass, sample_entry) }
|
17
17
|
|
18
|
-
subject {
|
18
|
+
subject(:literal) { described_class.new('things', sample_lexeme, sample_position) }
|
19
19
|
|
20
20
|
context 'Initialization:' do
|
21
|
-
it '
|
22
|
-
expect {
|
21
|
+
it 'is initialized with a string, a lexeme and a position' do
|
22
|
+
expect { described_class.new('things', sample_lexeme, sample_position) }.not_to raise_error
|
23
23
|
end
|
24
24
|
end # context
|
25
25
|
|
26
26
|
context 'Provided services:' do
|
27
|
-
it '
|
28
|
-
expect(
|
27
|
+
it 'knows its lexeme' do
|
28
|
+
expect(literal.zlexeme).to eq(sample_lexeme)
|
29
29
|
end
|
30
30
|
end # context
|
31
31
|
end # describe
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../spec_helper' # Use the RSpec framework
|
4
|
+
require_relative '../../../lib/zenlish/wclasses/all_word_classes'
|
5
|
+
require_relative '../../../lib/zenlish/lex/lexical_entry'
|
6
|
+
require_relative '../../../lib/zenlish/lex/lexeme'
|
7
|
+
|
8
|
+
# Load the class under test
|
9
|
+
require_relative '../../../lib/zenlish/lexer/lexer'
|
10
|
+
|
11
|
+
module Zenlish
|
12
|
+
module Lexer
|
13
|
+
describe Lexer do
|
14
|
+
# let(:sample_wclass) { WClasses::CommonNoun.new }
|
15
|
+
# let(:sample_lemma) { 'thing' }
|
16
|
+
# let(:sample_entry) { LexicalEntry.new(sample_lemma) }
|
17
|
+
# let(:sample_position) { double('position') }
|
18
|
+
# let(:sample_lexeme) { Lexeme.new(sample_wclass, sample_entry) }
|
19
|
+
let(:sample_sentence) { 'Tony sees Lisa.' }
|
20
|
+
|
21
|
+
subject(:lexer) { described_class.new(sample_sentence) }
|
22
|
+
|
23
|
+
context 'Initialization:' do
|
24
|
+
it 'is initialized with Zenlish text' do
|
25
|
+
expect { described_class.new(sample_sentence) }.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'knows its scanner object' do
|
29
|
+
expect(lexer.scanner).not_to be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'has an initial position' do
|
33
|
+
expect(lexer.lineno).to eq(1)
|
34
|
+
expect(lexer.line_start).to eq(0)
|
35
|
+
end
|
36
|
+
end # context
|
37
|
+
|
38
|
+
context 'Provided services:' do
|
39
|
+
it 'returns a sequence of literals' do
|
40
|
+
tokens = lexer.tokens
|
41
|
+
expect(tokens.size).to eq(4)
|
42
|
+
expect(tokens[0].lexeme).to eq('Tony')
|
43
|
+
expect(tokens[0].terminal).to eq('WORD')
|
44
|
+
expect(tokens[1].lexeme).to eq('sees')
|
45
|
+
expect(tokens[2].lexeme).to eq('Lisa')
|
46
|
+
expect(tokens[3].lexeme).to eq('.')
|
47
|
+
expect(tokens[3].terminal).to eq('Period')
|
48
|
+
end
|
49
|
+
end # context
|
50
|
+
end # describe
|
51
|
+
end # module
|
52
|
+
end # module
|