Class: Legion::Extensions::Agentic::Language::ConceptualBlending::Helpers::Blend
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Language::ConceptualBlending::Helpers::Blend
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb
Constant Summary
Constants included from Constants
Constants::BLEND_TYPES, Constants::COMPRESSION_PENALTY, Constants::DECAY_RATE, Constants::DEFAULT_STRENGTH, Constants::ELABORATION_BOOST, Constants::MAX_BLENDS, Constants::MAX_HISTORY, Constants::MAX_MAPPINGS, Constants::MAX_SPACES, Constants::QUALITY_LABELS, Constants::STALE_THRESHOLD, Constants::STRENGTH_CEILING, Constants::STRENGTH_FLOOR
Instance Attribute Summary collapse
-
#blend_type ⇒ Object
readonly
Returns the value of attribute blend_type.
-
#blended_elements ⇒ Object
readonly
Returns the value of attribute blended_elements.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#generic_space ⇒ Object
readonly
Returns the value of attribute generic_space.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#input_space_ids ⇒ Object
readonly
Returns the value of attribute input_space_ids.
-
#last_used_at ⇒ Object
readonly
Returns the value of attribute last_used_at.
-
#strength ⇒ Object
readonly
Returns the value of attribute strength.
-
#use_count ⇒ Object
readonly
Returns the value of attribute use_count.
Instance Method Summary collapse
- #compress(removed_element:) ⇒ Object
- #elaborate(emergent_property:) ⇒ Object
-
#initialize(input_space_ids:, generic_space:, blended_elements:, blend_type: :double_scope) ⇒ Blend
constructor
A new instance of Blend.
- #quality_label ⇒ Object
- #quality_score ⇒ Object
- #stale? ⇒ Boolean
- #to_h ⇒ Object
- #use! ⇒ Object
Constructor Details
#initialize(input_space_ids:, generic_space:, blended_elements:, blend_type: :double_scope) ⇒ Blend
Returns a new instance of Blend.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 15 def initialize(input_space_ids:, generic_space:, blended_elements:, blend_type: :double_scope) @id = ::SecureRandom.uuid @input_space_ids = input_space_ids @generic_space = generic_space @blended_elements = blended_elements @blend_type = blend_type @strength = DEFAULT_STRENGTH @use_count = 0 @created_at = Time.now.utc @last_used_at = Time.now.utc end |
Instance Attribute Details
#blend_type ⇒ Object (readonly)
Returns the value of attribute blend_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 12 def blend_type @blend_type end |
#blended_elements ⇒ Object (readonly)
Returns the value of attribute blended_elements.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 12 def blended_elements @blended_elements end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 12 def created_at @created_at end |
#generic_space ⇒ Object (readonly)
Returns the value of attribute generic_space.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 12 def generic_space @generic_space end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 12 def id @id end |
#input_space_ids ⇒ Object (readonly)
Returns the value of attribute input_space_ids.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 12 def input_space_ids @input_space_ids end |
#last_used_at ⇒ Object (readonly)
Returns the value of attribute last_used_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 12 def last_used_at @last_used_at end |
#strength ⇒ Object (readonly)
Returns the value of attribute strength.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 12 def strength @strength end |
#use_count ⇒ Object (readonly)
Returns the value of attribute use_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 12 def use_count @use_count end |
Instance Method Details
#compress(removed_element:) ⇒ Object
40 41 42 43 44 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 40 def compress(removed_element:) @blended_elements[:merged_elements]&.delete(removed_element) @strength = (@strength - COMPRESSION_PENALTY).clamp(STRENGTH_FLOOR, STRENGTH_CEILING) self end |
#elaborate(emergent_property:) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 33 def elaborate(emergent_property:) @blended_elements[:emergent_properties] ||= [] @blended_elements[:emergent_properties] << emergent_property @strength = (@strength + ELABORATION_BOOST).clamp(STRENGTH_FLOOR, STRENGTH_CEILING) self end |
#quality_label ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 57 def quality_label score = quality_score QUALITY_LABELS.each do |range, label| return label if range.cover?(score) end :trivial end |
#quality_score ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 46 def quality_score element_count = Array(@blended_elements[:merged_elements]).size emergent_count = Array(@blended_elements[:emergent_properties]).size use_factor = [@use_count / 10.0, 1.0].min raw = ((element_count / 10.0) * 0.4) + ((emergent_count / 5.0) * 0.4) + (use_factor * 0.2) raw.clamp(STRENGTH_FLOOR, STRENGTH_CEILING) end |
#stale? ⇒ Boolean
65 66 67 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 65 def stale? (Time.now.utc - @last_used_at).to_i > STALE_THRESHOLD end |
#to_h ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 69 def to_h { id: @id, input_space_ids: @input_space_ids, generic_space: @generic_space, blended_elements: @blended_elements, blend_type: @blend_type, strength: @strength, use_count: @use_count, quality_score: quality_score, quality_label: quality_label, stale: stale?, created_at: @created_at, last_used_at: @last_used_at } end |
#use! ⇒ Object
27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/language/conceptual_blending/helpers/blend.rb', line 27 def use! @use_count += 1 @last_used_at = Time.now.utc self end |