Class: Legion::Extensions::Agentic::Language::FrameSemantics::Helpers::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, domain:) ⇒ Frame

Returns a new instance of Frame.



14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 14

def initialize(name:, domain:)
  @id               = SecureRandom.uuid
  @name             = name
  @domain           = domain
  @slots            = {}
  @relations        = []
  @activation       = DEFAULT_ACTIVATION
  @activation_count = 0
  @created_at       = Time.now.utc
end

Instance Attribute Details

#activationObject (readonly)

Returns the value of attribute activation.



12
13
14
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 12

def activation
  @activation
end

#activation_countObject (readonly)

Returns the value of attribute activation_count.



12
13
14
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 12

def activation_count
  @activation_count
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 12

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 12

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 12

def name
  @name
end

#relationsObject (readonly)

Returns the value of attribute relations.



12
13
14
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 12

def relations
  @relations
end

#slotsObject (readonly)

Returns the value of attribute slots.



12
13
14
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 12

def slots
  @slots
end

Instance Method Details

#activate!Object



67
68
69
70
71
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 67

def activate!
  @activation = [@activation + ACTIVATION_BOOST, 1.0].min
  @activation_count += 1
  self
end

#activation_labelObject



78
79
80
81
82
83
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 78

def activation_label
  ACTIVATION_LABELS.each do |range, label|
    return label if range.cover?(@activation)
  end
  :inactive
end

#add_relation(relation:, target_frame_id:) ⇒ Object



85
86
87
88
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 85

def add_relation(relation:, target_frame_id:)
  @relations << { relation: relation, target_frame_id: target_frame_id }
  self
end

#add_slot(name:, slot_type: :core, required: true) ⇒ Object



25
26
27
28
29
30
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 25

def add_slot(name:, slot_type: :core, required: true)
  return nil unless SLOT_TYPES.include?(slot_type.to_sym)

  @slots[name] = { type: slot_type, filler: nil, required: required }
  self
end

#clear_slot(name:) ⇒ Object



40
41
42
43
44
45
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 40

def clear_slot(name:)
  return false unless @slots.key?(name)

  @slots[name][:filler] = nil
  true
end

#complete?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 63

def complete?
  completion_ratio >= COMPLETION_THRESHOLD
end

#completion_ratioObject



55
56
57
58
59
60
61
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 55

def completion_ratio
  cs = core_slots
  return 0.0 if cs.empty?

  filled_core = cs.count { |_k, v| !v[:filler].nil? }
  filled_core.to_f / cs.size
end

#core_slotsObject



47
48
49
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 47

def core_slots
  @slots.select { |_k, v| v[:type] == :core }
end

#decay!Object



73
74
75
76
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 73

def decay!
  @activation = [@activation - ACTIVATION_DECAY, 0.0].max
  self
end

#fill_slot(name:, filler:) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 32

def fill_slot(name:, filler:)
  return false unless @slots.key?(name)

  @slots[name][:filler] = filler
  @activation = [@activation + SLOT_FILL_BOOST, 1.0].min
  true
end

#filled_slotsObject



51
52
53
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 51

def filled_slots
  @slots.reject { |_k, v| v[:filler].nil? }
end

#to_hObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/legion/extensions/agentic/language/frame_semantics/helpers/frame.rb', line 90

def to_h
  {
    id:               @id,
    name:             @name,
    domain:           @domain,
    slots:            @slots,
    relations:        @relations,
    activation:       @activation,
    activation_label: activation_label,
    activation_count: @activation_count,
    completion_ratio: completion_ratio,
    complete:         complete?,
    created_at:       @created_at
  }
end