Module: Legion::Extensions::Agentic::Language::ConceptualBlending::Runners::ConceptualBlending

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb

Instance Method Summary collapse

Instance Method Details

#add_space_element(space_id:, name:, properties: {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 22

def add_space_element(space_id:, name:, properties: {}, **)
  log.debug "[conceptual_blending] add_element: space=#{space_id} name=#{name}"
  engine.add_element_to_space(space_id: space_id, name: name, properties: properties)
  { success: true, space_id: space_id, element: name }
rescue ArgumentError => e
  log.debug "[conceptual_blending] add_element failed: #{e.message}"
  { success: false, error: e.message }
end

#add_space_relation(space_id:, from:, to:, type:) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 31

def add_space_relation(space_id:, from:, to:, type:, **)
  log.debug "[conceptual_blending] add_relation: space=#{space_id} #{from}->#{to} type=#{type}"
  engine.add_relation_to_space(space_id: space_id, from: from, to: to, type: type)
  { success: true, space_id: space_id, relation: { from: from, to: to, type: type } }
rescue ArgumentError => e
  log.debug "[conceptual_blending] add_relation failed: #{e.message}"
  { success: false, error: e.message }
end

#best_blends(limit: 5) ⇒ Object



69
70
71
72
73
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 69

def best_blends(limit: 5, **)
  log.debug "[conceptual_blending] best_blends: limit=#{limit}"
  blends = engine.best_blends(limit: limit)
  { success: true, blends: blends.map(&:to_h), count: blends.size }
end

#blend_quality(blend_id:) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 75

def blend_quality(blend_id:, **)
  log.debug "[conceptual_blending] blend_quality: blend=#{blend_id}"
  quality = engine.blend_quality(blend_id: blend_id)
  { success: true }.merge(quality)
rescue ArgumentError => e
  log.debug "[conceptual_blending] blend_quality failed: #{e.message}"
  { success: false, error: e.message }
end

#compress_blend(blend_id:, removed_element:) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 60

def compress_blend(blend_id:, removed_element:, **)
  log.debug "[conceptual_blending] compress: blend=#{blend_id} remove=#{removed_element}"
  blend = engine.compress_blend(blend_id: blend_id, removed_element: removed_element)
  { success: true, blend: blend.to_h }
rescue ArgumentError => e
  log.debug "[conceptual_blending] compress failed: #{e.message}"
  { success: false, error: e.message }
end

#conceptual_blending_statsObject



91
92
93
94
95
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 91

def conceptual_blending_stats(**)
  log.debug '[conceptual_blending] stats'
  stats = engine.to_h
  { success: true }.merge(stats)
end

#create_blend(space_a_id:, space_b_id:, blend_type: :double_scope) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 40

def create_blend(space_a_id:, space_b_id:, blend_type: :double_scope, **)
  log.debug "[conceptual_blending] blend: a=#{space_a_id} b=#{space_b_id} type=#{blend_type}"
  blend = engine.blend(space_a_id: space_a_id, space_b_id: space_b_id, blend_type: blend_type)
  return { success: false, reason: :invalid_blend_type } unless blend

  { success: true, blend: blend.to_h }
rescue ArgumentError => e
  log.debug "[conceptual_blending] blend failed: #{e.message}"
  { success: false, error: e.message }
end

#create_mental_space(name:, domain:) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 13

def create_mental_space(name:, domain:, **)
  log.debug "[conceptual_blending] create_space: name=#{name} domain=#{domain}"
  space = engine.create_space(name: name, domain: domain)
  { success: true, space: space.to_h }
rescue ArgumentError => e
  log.debug "[conceptual_blending] create_space failed: #{e.message}"
  { success: false, error: e.message }
end

#elaborate_blend(blend_id:, emergent_property:) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 51

def elaborate_blend(blend_id:, emergent_property:, **)
  log.debug "[conceptual_blending] elaborate: blend=#{blend_id} property=#{emergent_property}"
  blend = engine.elaborate_blend(blend_id: blend_id, emergent_property: emergent_property)
  { success: true, blend: blend.to_h }
rescue ArgumentError => e
  log.debug "[conceptual_blending] elaborate failed: #{e.message}"
  { success: false, error: e.message }
end

#update_conceptual_blendingObject



84
85
86
87
88
89
# File 'lib/legion/extensions/agentic/language/conceptual_blending/runners/conceptual_blending.rb', line 84

def update_conceptual_blending(**)
  log.debug '[conceptual_blending] update: decay + prune cycle'
  decayed = engine.decay_stale
  pruned  = engine.prune_weak
  { success: true, decayed: decayed, pruned: pruned }
end