lex-cognitive-chunking 0.1.0

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.
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/cognitive_chunking/client'
4
+
5
+ RSpec.describe Legion::Extensions::CognitiveChunking::Runners::CognitiveChunking do
6
+ let(:engine) { Legion::Extensions::CognitiveChunking::Helpers::ChunkingEngine.new }
7
+ let(:client) { Legion::Extensions::CognitiveChunking::Client.new }
8
+
9
+ def add_items_to(target_engine, count)
10
+ count.times.map { |i| target_engine.add_item(content: "item #{i}")[:item_id] }
11
+ end
12
+
13
+ describe '#add_item' do
14
+ it 'returns success' do
15
+ result = client.add_item(content: 'knight fork', domain: :chess)
16
+ expect(result[:success]).to be true
17
+ end
18
+
19
+ it 'accepts injected engine' do
20
+ result = client.add_item(content: 'test', engine: engine)
21
+ expect(result[:success]).to be true
22
+ expect(engine.items.size).to eq(1)
23
+ end
24
+
25
+ it 'returns item_id' do
26
+ result = client.add_item(content: 'fork threat')
27
+ expect(result[:item_id]).to be_a(String)
28
+ end
29
+ end
30
+
31
+ describe '#create_chunk' do
32
+ let(:item_ids) { add_items_to(engine, 3) }
33
+
34
+ it 'creates a chunk via injected engine' do
35
+ result = client.create_chunk(label: 'chess tactics', item_ids: item_ids, engine: engine)
36
+ expect(result[:success]).to be true
37
+ end
38
+
39
+ it 'returns chunk_id' do
40
+ result = client.create_chunk(label: 'tactics', item_ids: item_ids, engine: engine)
41
+ expect(result[:chunk_id]).to be_a(String)
42
+ end
43
+
44
+ it 'fails for empty item_ids' do
45
+ result = client.create_chunk(label: 'empty', item_ids: [], engine: engine)
46
+ expect(result[:success]).to be false
47
+ end
48
+ end
49
+
50
+ describe '#merge_chunks' do
51
+ let(:item_ids_a) { add_items_to(engine, 2) }
52
+ let(:item_ids_b) { add_items_to(engine, 2) }
53
+ let(:chunk_a_id) { engine.create_chunk(label: 'A', item_ids: item_ids_a)[:chunk_id] }
54
+ let(:chunk_b_id) { engine.create_chunk(label: 'B', item_ids: item_ids_b)[:chunk_id] }
55
+
56
+ it 'merges two chunks' do
57
+ result = client.merge_chunks(chunk_ids: [chunk_a_id, chunk_b_id], label: 'AB', engine: engine)
58
+ expect(result[:success]).to be true
59
+ end
60
+
61
+ it 'marks parent as hierarchical' do
62
+ result = client.merge_chunks(chunk_ids: [chunk_a_id, chunk_b_id], label: 'AB', engine: engine)
63
+ parent = engine.chunks[result[:chunk_id]]
64
+ expect(parent.hierarchical?).to be true
65
+ end
66
+ end
67
+
68
+ describe '#load_to_working_memory' do
69
+ let(:item_id) { engine.add_item(content: 'wm item')[:item_id] }
70
+ let(:chunk_id) { engine.create_chunk(label: 'wm', item_ids: [item_id])[:chunk_id] }
71
+
72
+ it 'loads chunk to working memory' do
73
+ result = client.load_to_working_memory(chunk_id: chunk_id, engine: engine)
74
+ expect(result[:success]).to be true
75
+ end
76
+
77
+ it 'returns working_memory_size' do
78
+ result = client.load_to_working_memory(chunk_id: chunk_id, engine: engine)
79
+ expect(result[:working_memory_size]).to eq(1)
80
+ end
81
+ end
82
+
83
+ describe '#unload_from_working_memory' do
84
+ let(:item_id) { engine.add_item(content: 'unload item')[:item_id] }
85
+ let(:chunk_id) { engine.create_chunk(label: 'unload', item_ids: [item_id])[:chunk_id] }
86
+
87
+ before { engine.load_to_working_memory(chunk_id: chunk_id) }
88
+
89
+ it 'unloads chunk from working memory' do
90
+ result = client.unload_from_working_memory(chunk_id: chunk_id, engine: engine)
91
+ expect(result[:success]).to be true
92
+ expect(engine.working_memory).not_to include(chunk_id)
93
+ end
94
+ end
95
+
96
+ describe '#working_memory_status' do
97
+ it 'returns success with capacity info' do
98
+ result = client.working_memory_status(engine: engine)
99
+ expect(result[:success]).to be true
100
+ expect(result[:capacity]).to eq(7)
101
+ end
102
+
103
+ it 'returns a capacity label' do
104
+ result = client.working_memory_status(engine: engine)
105
+ expect(result[:label]).to be_a(Symbol)
106
+ end
107
+
108
+ it 'reports not overloaded for empty working memory' do
109
+ result = client.working_memory_status(engine: engine)
110
+ expect(result[:overloaded]).to be false
111
+ end
112
+ end
113
+
114
+ describe '#decay_all' do
115
+ it 'returns success' do
116
+ result = client.decay_all(engine: engine)
117
+ expect(result[:success]).to be true
118
+ end
119
+
120
+ it 'decays chunks in the engine' do
121
+ id = engine.add_item(content: 'decay me')[:item_id]
122
+ cid = engine.create_chunk(label: 'decay', item_ids: [id])[:chunk_id]
123
+ before_recall = engine.chunks[cid].recall_strength
124
+ client.decay_all(engine: engine)
125
+ expect(engine.chunks[cid].recall_strength).to be < before_recall
126
+ end
127
+ end
128
+
129
+ describe '#reinforce_chunk' do
130
+ let(:item_id) { engine.add_item(content: 'reinforce')[:item_id] }
131
+ let(:chunk_id) { engine.create_chunk(label: 'r', item_ids: [item_id])[:chunk_id] }
132
+
133
+ it 'returns success' do
134
+ result = client.reinforce_chunk(chunk_id: chunk_id, engine: engine)
135
+ expect(result[:success]).to be true
136
+ end
137
+
138
+ it 'boosts the chunk recall' do
139
+ before_recall = engine.chunks[chunk_id].recall_strength
140
+ client.reinforce_chunk(chunk_id: chunk_id, engine: engine)
141
+ expect(engine.chunks[chunk_id].recall_strength).to be > before_recall
142
+ end
143
+ end
144
+
145
+ describe '#chunking_report' do
146
+ it 'returns success with report' do
147
+ result = client.chunking_report(engine: engine)
148
+ expect(result[:success]).to be true
149
+ expect(result[:report]).to have_key(:total_items)
150
+ end
151
+ end
152
+
153
+ describe '#strongest_chunks' do
154
+ it 'returns success with chunks array' do
155
+ result = client.strongest_chunks(engine: engine)
156
+ expect(result[:success]).to be true
157
+ expect(result[:chunks]).to be_an(Array)
158
+ end
159
+ end
160
+
161
+ describe '#unchunked_items' do
162
+ it 'returns success with items array' do
163
+ engine.add_item(content: 'free item')
164
+ result = client.unchunked_items(engine: engine)
165
+ expect(result[:success]).to be true
166
+ expect(result[:items].size).to eq(1)
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ module Legion
6
+ module Logging
7
+ def self.debug(_msg); end
8
+ def self.info(_msg); end
9
+ def self.warn(_msg); end
10
+ def self.error(_msg); end
11
+ end
12
+ end
13
+
14
+ require 'legion/extensions/cognitive_chunking'
15
+
16
+ RSpec.configure do |config|
17
+ config.example_status_persistence_file_path = '.rspec_status'
18
+ config.disable_monkey_patching!
19
+ config.expect_with(:rspec) { |c| c.syntax = :expect }
20
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-cognitive-chunking
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: legion-gaia
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: 'George Miller''s 7+/-2 principle: groups information items into hierarchical
27
+ chunks to model working memory capacity'
28
+ email:
29
+ - matthewdiverson@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.md
37
+ - lex-cognitive-chunking.gemspec
38
+ - lib/legion/extensions/cognitive_chunking.rb
39
+ - lib/legion/extensions/cognitive_chunking/client.rb
40
+ - lib/legion/extensions/cognitive_chunking/helpers/chunk.rb
41
+ - lib/legion/extensions/cognitive_chunking/helpers/chunking_engine.rb
42
+ - lib/legion/extensions/cognitive_chunking/helpers/constants.rb
43
+ - lib/legion/extensions/cognitive_chunking/helpers/information_item.rb
44
+ - lib/legion/extensions/cognitive_chunking/runners/cognitive_chunking.rb
45
+ - lib/legion/extensions/cognitive_chunking/version.rb
46
+ - spec/legion/extensions/cognitive_chunking/client_spec.rb
47
+ - spec/legion/extensions/cognitive_chunking/helpers/chunk_spec.rb
48
+ - spec/legion/extensions/cognitive_chunking/helpers/chunking_engine_spec.rb
49
+ - spec/legion/extensions/cognitive_chunking/helpers/constants_spec.rb
50
+ - spec/legion/extensions/cognitive_chunking/helpers/information_item_spec.rb
51
+ - spec/legion/extensions/cognitive_chunking/runners/cognitive_chunking_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: https://github.com/LegionIO/lex-cognitive-chunking
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/LegionIO/lex-cognitive-chunking
58
+ source_code_uri: https://github.com/LegionIO/lex-cognitive-chunking
59
+ documentation_uri: https://github.com/LegionIO/lex-cognitive-chunking
60
+ changelog_uri: https://github.com/LegionIO/lex-cognitive-chunking
61
+ bug_tracker_uri: https://github.com/LegionIO/lex-cognitive-chunking/issues
62
+ rubygems_mfa_required: 'true'
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '3.4'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.6.9
78
+ specification_version: 4
79
+ summary: LEX Cognitive Chunking
80
+ test_files: []