lex-situation-model 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.
- checksums.yaml +7 -0
- data/Gemfile +12 -0
- data/LICENSE +21 -0
- data/README.md +75 -0
- data/lex-situation-model.gemspec +29 -0
- data/lib/legion/extensions/situation_model/client.rb +24 -0
- data/lib/legion/extensions/situation_model/helpers/client.rb +19 -0
- data/lib/legion/extensions/situation_model/helpers/constants.rb +36 -0
- data/lib/legion/extensions/situation_model/helpers/situation_engine.rb +69 -0
- data/lib/legion/extensions/situation_model/helpers/situation_event.rb +52 -0
- data/lib/legion/extensions/situation_model/helpers/situation_model.rb +86 -0
- data/lib/legion/extensions/situation_model/runners/situation_model.rb +95 -0
- data/lib/legion/extensions/situation_model/version.rb +9 -0
- data/lib/legion/extensions/situation_model.rb +18 -0
- data/spec/legion/extensions/situation_model/client_spec.rb +51 -0
- data/spec/legion/extensions/situation_model/helpers/constants_spec.rb +56 -0
- data/spec/legion/extensions/situation_model/helpers/situation_engine_spec.rb +203 -0
- data/spec/legion/extensions/situation_model/helpers/situation_event_spec.rb +94 -0
- data/spec/legion/extensions/situation_model/helpers/situation_model_spec.rb +235 -0
- data/spec/legion/extensions/situation_model/runners/situation_model_spec.rb +204 -0
- data/spec/spec_helper.rb +23 -0
- metadata +81 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/situation_model/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::SituationModel::Runners::SituationModel do
|
|
6
|
+
let(:client) { Legion::Extensions::SituationModel::Client.new }
|
|
7
|
+
|
|
8
|
+
def create_model(label: 'test')
|
|
9
|
+
client.create_situation_model(label: label)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_event(model_id, content: 'test event', **dims)
|
|
13
|
+
defaults = { space: 0.5, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5 }
|
|
14
|
+
client.add_situation_event(model_id: model_id, content: content, **defaults.merge(dims))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#create_situation_model' do
|
|
18
|
+
it 'returns success: true' do
|
|
19
|
+
result = create_model
|
|
20
|
+
expect(result[:success]).to be(true)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'returns a model hash with id and label' do
|
|
24
|
+
result = create_model(label: 'story')
|
|
25
|
+
expect(result[:model][:label]).to eq('story')
|
|
26
|
+
expect(result[:model][:id]).to match(/\A[0-9a-f-]{36}\z/)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '#add_situation_event' do
|
|
31
|
+
it 'returns success: true for known model' do
|
|
32
|
+
model_id = create_model[:model][:id]
|
|
33
|
+
result = add_event(model_id)
|
|
34
|
+
expect(result[:success]).to be(true)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'returns success: false for unknown model' do
|
|
38
|
+
result = add_event('nonexistent')
|
|
39
|
+
expect(result[:success]).to be(false)
|
|
40
|
+
expect(result[:error]).to eq('model not found')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'returns coherence after adding event' do
|
|
44
|
+
model_id = create_model[:model][:id]
|
|
45
|
+
result = add_event(model_id)
|
|
46
|
+
expect(result[:coherence]).to be_a(Float)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'accepts custom dimension values' do
|
|
50
|
+
model_id = create_model[:model][:id]
|
|
51
|
+
result = client.add_situation_event(model_id: model_id, content: 'scene',
|
|
52
|
+
space: 0.9, time: 0.1,
|
|
53
|
+
causation: 0.5, intentionality: 0.5, protagonist: 0.5)
|
|
54
|
+
expect(result[:success]).to be(true)
|
|
55
|
+
expect(result[:event][:dimension_values][:space]).to be_within(0.001).of(0.9)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#situation_model_coherence' do
|
|
60
|
+
it 'returns success: true for known model' do
|
|
61
|
+
model_id = create_model[:model][:id]
|
|
62
|
+
result = client.situation_model_coherence(model_id: model_id)
|
|
63
|
+
expect(result[:success]).to be(true)
|
|
64
|
+
expect(result[:coherence]).to be_a(Float)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'returns success: false for unknown model' do
|
|
68
|
+
result = client.situation_model_coherence(model_id: 'bad')
|
|
69
|
+
expect(result[:success]).to be(false)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe '#find_situation_boundaries' do
|
|
74
|
+
it 'returns success: true for known model' do
|
|
75
|
+
model_id = create_model[:model][:id]
|
|
76
|
+
add_event(model_id)
|
|
77
|
+
result = client.find_situation_boundaries(model_id: model_id)
|
|
78
|
+
expect(result[:success]).to be(true)
|
|
79
|
+
expect(result[:boundaries]).to be_an(Array)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'returns success: false for unknown model' do
|
|
83
|
+
result = client.find_situation_boundaries(model_id: 'bad')
|
|
84
|
+
expect(result[:success]).to be(false)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'uses custom threshold' do
|
|
88
|
+
model_id = create_model[:model][:id]
|
|
89
|
+
result = client.find_situation_boundaries(model_id: model_id, threshold: 0.5)
|
|
90
|
+
expect(result[:threshold]).to eq(0.5)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'detects discontinuity boundary' do
|
|
94
|
+
model_id = create_model[:model][:id]
|
|
95
|
+
client.add_situation_event(model_id: model_id, content: 'high',
|
|
96
|
+
space: 0.9, time: 0.9, causation: 0.9, intentionality: 0.9, protagonist: 0.9)
|
|
97
|
+
client.add_situation_event(model_id: model_id, content: 'low',
|
|
98
|
+
space: 0.0, time: 0.0, causation: 0.0, intentionality: 0.0, protagonist: 0.0)
|
|
99
|
+
result = client.find_situation_boundaries(model_id: model_id, threshold: 0.3)
|
|
100
|
+
expect(result[:boundaries]).to include(1)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe '#situation_dimension_trajectory' do
|
|
105
|
+
it 'returns success: true for known model and dimension' do
|
|
106
|
+
model_id = create_model[:model][:id]
|
|
107
|
+
add_event(model_id, space: 0.7)
|
|
108
|
+
result = client.situation_dimension_trajectory(model_id: model_id, dimension: :space)
|
|
109
|
+
expect(result[:success]).to be(true)
|
|
110
|
+
expect(result[:trajectory]).to be_an(Array)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'accepts string dimensions (converts to symbol)' do
|
|
114
|
+
model_id = create_model[:model][:id]
|
|
115
|
+
add_event(model_id)
|
|
116
|
+
result = client.situation_dimension_trajectory(model_id: model_id, dimension: 'time')
|
|
117
|
+
expect(result[:success]).to be(true)
|
|
118
|
+
expect(result[:dimension]).to eq(:time)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'returns success: false for unknown model' do
|
|
122
|
+
result = client.situation_dimension_trajectory(model_id: 'bad', dimension: :space)
|
|
123
|
+
expect(result[:success]).to be(false)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'tracks trajectory over multiple events' do
|
|
127
|
+
model_id = create_model[:model][:id]
|
|
128
|
+
client.add_situation_event(model_id: model_id, content: 'a',
|
|
129
|
+
space: 0.2, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5)
|
|
130
|
+
client.add_situation_event(model_id: model_id, content: 'b',
|
|
131
|
+
space: 0.8, time: 0.5, causation: 0.5, intentionality: 0.5, protagonist: 0.5)
|
|
132
|
+
result = client.situation_dimension_trajectory(model_id: model_id, dimension: :space)
|
|
133
|
+
expect(result[:trajectory]).to eq([0.2, 0.8])
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
describe '#most_coherent_situations' do
|
|
138
|
+
it 'returns success: true' do
|
|
139
|
+
result = client.most_coherent_situations
|
|
140
|
+
expect(result[:success]).to be(true)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it 'returns models array' do
|
|
144
|
+
create_model(label: 'a')
|
|
145
|
+
create_model(label: 'b')
|
|
146
|
+
result = client.most_coherent_situations(limit: 2)
|
|
147
|
+
expect(result[:models]).to be_an(Array)
|
|
148
|
+
expect(result[:count]).to be <= 2
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it 'respects limit' do
|
|
152
|
+
5.times { |i| create_model(label: "m#{i}") }
|
|
153
|
+
result = client.most_coherent_situations(limit: 3)
|
|
154
|
+
expect(result[:models].size).to be <= 3
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
describe '#situations_by_label' do
|
|
159
|
+
it 'returns models with matching label' do
|
|
160
|
+
create_model(label: 'target')
|
|
161
|
+
create_model(label: 'target')
|
|
162
|
+
create_model(label: 'other')
|
|
163
|
+
result = client.situations_by_label(label: 'target')
|
|
164
|
+
expect(result[:success]).to be(true)
|
|
165
|
+
expect(result[:count]).to eq(2)
|
|
166
|
+
expect(result[:models].all? { |m| m[:label] == 'target' }).to be(true)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it 'returns empty for unknown label' do
|
|
170
|
+
result = client.situations_by_label(label: 'unknown')
|
|
171
|
+
expect(result[:count]).to eq(0)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
describe '#update_situation_models' do
|
|
176
|
+
it 'returns success: true' do
|
|
177
|
+
result = client.update_situation_models
|
|
178
|
+
expect(result[:success]).to be(true)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'returns pruned_count' do
|
|
182
|
+
result = client.update_situation_models
|
|
183
|
+
expect(result[:pruned_count]).to be_a(Integer)
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
describe '#situation_model_stats' do
|
|
188
|
+
it 'returns success: true' do
|
|
189
|
+
result = client.situation_model_stats
|
|
190
|
+
expect(result[:success]).to be(true)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it 'includes model_count' do
|
|
194
|
+
create_model
|
|
195
|
+
result = client.situation_model_stats
|
|
196
|
+
expect(result[:model_count]).to be >= 1
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it 'includes models array' do
|
|
200
|
+
result = client.situation_model_stats
|
|
201
|
+
expect(result[:models]).to be_an(Array)
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Logging
|
|
7
|
+
def self.debug(_msg); end
|
|
8
|
+
|
|
9
|
+
def self.info(_msg); end
|
|
10
|
+
|
|
11
|
+
def self.warn(_msg); end
|
|
12
|
+
|
|
13
|
+
def self.error(_msg); end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
require 'legion/extensions/situation_model'
|
|
18
|
+
|
|
19
|
+
RSpec.configure do |config|
|
|
20
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
|
21
|
+
config.disable_monkey_patching!
|
|
22
|
+
config.expect_with(:rspec) { |c| c.syntax = :expect }
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lex-situation-model
|
|
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: 'Zwaan Event Indexing Model for brain-modeled agentic AI: tracks 5-dimensional
|
|
27
|
+
situation models across narrative events'
|
|
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-situation-model.gemspec
|
|
38
|
+
- lib/legion/extensions/situation_model.rb
|
|
39
|
+
- lib/legion/extensions/situation_model/client.rb
|
|
40
|
+
- lib/legion/extensions/situation_model/helpers/client.rb
|
|
41
|
+
- lib/legion/extensions/situation_model/helpers/constants.rb
|
|
42
|
+
- lib/legion/extensions/situation_model/helpers/situation_engine.rb
|
|
43
|
+
- lib/legion/extensions/situation_model/helpers/situation_event.rb
|
|
44
|
+
- lib/legion/extensions/situation_model/helpers/situation_model.rb
|
|
45
|
+
- lib/legion/extensions/situation_model/runners/situation_model.rb
|
|
46
|
+
- lib/legion/extensions/situation_model/version.rb
|
|
47
|
+
- spec/legion/extensions/situation_model/client_spec.rb
|
|
48
|
+
- spec/legion/extensions/situation_model/helpers/constants_spec.rb
|
|
49
|
+
- spec/legion/extensions/situation_model/helpers/situation_engine_spec.rb
|
|
50
|
+
- spec/legion/extensions/situation_model/helpers/situation_event_spec.rb
|
|
51
|
+
- spec/legion/extensions/situation_model/helpers/situation_model_spec.rb
|
|
52
|
+
- spec/legion/extensions/situation_model/runners/situation_model_spec.rb
|
|
53
|
+
- spec/spec_helper.rb
|
|
54
|
+
homepage: https://github.com/LegionIO/lex-situation-model
|
|
55
|
+
licenses:
|
|
56
|
+
- MIT
|
|
57
|
+
metadata:
|
|
58
|
+
homepage_uri: https://github.com/LegionIO/lex-situation-model
|
|
59
|
+
source_code_uri: https://github.com/LegionIO/lex-situation-model
|
|
60
|
+
documentation_uri: https://github.com/LegionIO/lex-situation-model
|
|
61
|
+
changelog_uri: https://github.com/LegionIO/lex-situation-model
|
|
62
|
+
bug_tracker_uri: https://github.com/LegionIO/lex-situation-model/issues
|
|
63
|
+
rubygems_mfa_required: 'true'
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '3.4'
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
requirements: []
|
|
78
|
+
rubygems_version: 3.6.9
|
|
79
|
+
specification_version: 4
|
|
80
|
+
summary: LEX Situation Model
|
|
81
|
+
test_files: []
|