Class: Legion::Extensions::Agentic::Language::Grammar::Helpers::GrammarEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Language::Grammar::Helpers::GrammarEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb
Constant Summary
Constants included
from Constants
Constants::ACTIVATION_BOOST, Constants::ACTIVATION_DECAY, Constants::ACTIVATION_LABELS, Constants::CONSTRUAL_OPERATIONS, Constants::DEFAULT_ACTIVATION, Constants::ENTRENCHMENT_THRESHOLD, Constants::EXPRESSION_TYPES, Constants::MAX_CONSTRUALS, Constants::MAX_CONSTRUCTIONS, Constants::MAX_HISTORY, Constants::PROMINENCE_TYPES, Constants::SCOPE_LEVELS, Constants::SPECIFICITY_LEVELS
Instance Method Summary
collapse
-
#construals_for_scene(scene:) ⇒ Object
-
#constructions_by_domain(domain:) ⇒ Object
-
#constructions_by_type(expression_type:) ⇒ Object
-
#create_construal(scene:, perspective:, figure:, ground:, specificity: :intermediate, scope: :local, dynamicity: 0.5, construction_id: nil) ⇒ Object
-
#create_construction(form:, meaning:, expression_type:, domain:, activation: DEFAULT_ACTIVATION) ⇒ Object
-
#decay_all ⇒ Object
-
#entrenched_constructions ⇒ Object
-
#initialize ⇒ GrammarEngine
constructor
A new instance of GrammarEngine.
-
#most_activated(limit: 5) ⇒ Object
-
#most_used(limit: 5) ⇒ Object
-
#prune_inactive ⇒ Object
-
#to_h ⇒ Object
-
#use_construction(construction_id:) ⇒ Object
Constructor Details
Returns a new instance of GrammarEngine.
12
13
14
15
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 12
def initialize
@constructions = {}
@construals = {}
end
|
Instance Method Details
#construals_for_scene(scene:) ⇒ Object
60
61
62
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 60
def construals_for_scene(scene:)
@construals.values.select { |c| c.scene == scene }
end
|
#constructions_by_domain(domain:) ⇒ Object
68
69
70
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 68
def constructions_by_domain(domain:)
@constructions.values.select { |c| c.domain == domain }
end
|
#constructions_by_type(expression_type:) ⇒ Object
72
73
74
75
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 72
def constructions_by_type(expression_type:)
type = expression_type.to_sym
@constructions.values.select { |c| c.expression_type == type }
end
|
#create_construal(scene:, perspective:, figure:, ground:, specificity: :intermediate, scope: :local, dynamicity: 0.5, construction_id: nil) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 32
def create_construal(scene:, perspective:, figure:, ground:,
specificity: :intermediate, scope: :local,
dynamicity: 0.5, construction_id: nil)
return nil unless SPECIFICITY_LEVELS.include?(specificity.to_sym)
return nil unless SCOPE_LEVELS.include?(scope.to_sym)
prune_construals_if_needed
construal = Construal.new(
scene: scene,
perspective: perspective,
figure: figure,
ground: ground,
specificity: specificity,
scope: scope,
dynamicity: dynamicity,
construction_id: construction_id
)
@construals[construal.id] = construal
construal
end
|
#create_construction(form:, meaning:, expression_type:, domain:, activation: DEFAULT_ACTIVATION) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 17
def create_construction(form:, meaning:, expression_type:, domain:, activation: DEFAULT_ACTIVATION)
return nil unless EXPRESSION_TYPES.include?(expression_type.to_sym)
prune_constructions_if_needed
construction = Construction.new(
form: form,
meaning: meaning,
expression_type: expression_type,
domain: domain,
activation: activation
)
@constructions[construction.id] = construction
construction
end
|
#decay_all ⇒ Object
85
86
87
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 85
def decay_all
@constructions.each_value(&:decay!)
end
|
#entrenched_constructions ⇒ Object
64
65
66
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 64
def entrenched_constructions
@constructions.values.select(&:entrenched?)
end
|
#most_activated(limit: 5) ⇒ Object
81
82
83
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 81
def most_activated(limit: 5)
@constructions.values.sort_by { |c| -c.activation }.first(limit)
end
|
#most_used(limit: 5) ⇒ Object
77
78
79
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 77
def most_used(limit: 5)
@constructions.values.sort_by { |c| -c.usage_count }.first(limit)
end
|
#prune_inactive ⇒ Object
89
90
91
92
93
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 89
def prune_inactive
before = @constructions.size
@constructions.delete_if { |_, c| c.activation <= 0.05 }
before - @constructions.size
end
|
#to_h ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 95
def to_h
{
constructions_count: @constructions.size,
construals_count: @construals.size,
entrenched_count: entrenched_constructions.size
}
end
|
#use_construction(construction_id:) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/legion/extensions/agentic/language/grammar/helpers/grammar_engine.rb', line 53
def use_construction(construction_id:)
construction = @constructions[construction_id]
return nil unless construction
construction.use!
end
|