Class: Legion::Extensions::Agentic::Language::ConceptualMetaphor::Helpers::Metaphor
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Language::ConceptualMetaphor::Helpers::Metaphor
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb
Constant Summary
Constants included from Constants
Constants::CONVENTIONALITY_LABELS, Constants::CONVENTIONALITY_THRESHOLD, Constants::DECAY_RATE, Constants::DEFAULT_STRENGTH, Constants::MAX_DOMAINS, Constants::MAX_HISTORY, Constants::MAX_MAPPINGS, Constants::MAX_METAPHORS, Constants::METAPHOR_TYPES, Constants::NOVELTY_THRESHOLD, Constants::REINFORCEMENT_BOOST, Constants::STALE_THRESHOLD, Constants::STRENGTH_CEILING, Constants::STRENGTH_FLOOR, Constants::STRENGTH_LABELS
Instance Attribute Summary collapse
-
#conventionality ⇒ Object
readonly
Returns the value of attribute conventionality.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#entailments ⇒ Object
readonly
Returns the value of attribute entailments.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_used_at ⇒ Object
readonly
Returns the value of attribute last_used_at.
-
#mappings ⇒ Object
readonly
Returns the value of attribute mappings.
-
#metaphor_type ⇒ Object
readonly
Returns the value of attribute metaphor_type.
-
#source_domain ⇒ Object
readonly
Returns the value of attribute source_domain.
-
#strength ⇒ Object
readonly
Returns the value of attribute strength.
-
#target_domain ⇒ Object
readonly
Returns the value of attribute target_domain.
-
#use_count ⇒ Object
readonly
Returns the value of attribute use_count.
Instance Method Summary collapse
- #add_entailment(entailment) ⇒ Object
- #conventional? ⇒ Boolean
- #conventionality_label ⇒ Object
- #coverage ⇒ Object
- #decay! ⇒ Object
-
#initialize(source_domain:, target_domain:, metaphor_type:, mappings:, strength: nil, conventionality: nil) ⇒ Metaphor
constructor
A new instance of Metaphor.
- #map_concept(source_concept) ⇒ Object
- #novel? ⇒ Boolean
- #stale? ⇒ Boolean
- #strength_label ⇒ Object
- #to_h ⇒ Object
- #use! ⇒ Object
Constructor Details
#initialize(source_domain:, target_domain:, metaphor_type:, mappings:, strength: nil, conventionality: nil) ⇒ Metaphor
Returns a new instance of Metaphor.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 18 def initialize(source_domain:, target_domain:, metaphor_type:, mappings:, strength: nil, conventionality: nil) @id = SecureRandom.uuid @source_domain = source_domain @target_domain = target_domain @metaphor_type = @mappings = mappings @entailments = [] @strength = (strength || DEFAULT_STRENGTH).to_f.clamp(STRENGTH_FLOOR, STRENGTH_CEILING) @conventionality = (conventionality || DEFAULT_STRENGTH).to_f.clamp(STRENGTH_FLOOR, STRENGTH_CEILING) @use_count = 0 @created_at = Time.now.utc @last_used_at = @created_at end |
Instance Attribute Details
#conventionality ⇒ Object (readonly)
Returns the value of attribute conventionality.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def conventionality @conventionality end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def created_at @created_at end |
#entailments ⇒ Object (readonly)
Returns the value of attribute entailments.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def entailments @entailments end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def id @id end |
#last_used_at ⇒ Object (readonly)
Returns the value of attribute last_used_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def last_used_at @last_used_at end |
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def mappings @mappings end |
#metaphor_type ⇒ Object (readonly)
Returns the value of attribute metaphor_type.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def @metaphor_type end |
#source_domain ⇒ Object (readonly)
Returns the value of attribute source_domain.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def source_domain @source_domain end |
#strength ⇒ Object (readonly)
Returns the value of attribute strength.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def strength @strength end |
#target_domain ⇒ Object (readonly)
Returns the value of attribute target_domain.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def target_domain @target_domain end |
#use_count ⇒ Object (readonly)
Returns the value of attribute use_count.
14 15 16 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 14 def use_count @use_count end |
Instance Method Details
#add_entailment(entailment) ⇒ Object
40 41 42 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 40 def add_entailment(entailment) @entailments << entailment end |
#conventional? ⇒ Boolean
54 55 56 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 54 def conventional? @conventionality >= CONVENTIONALITY_THRESHOLD end |
#conventionality_label ⇒ Object
62 63 64 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 62 def conventionality_label CONVENTIONALITY_LABELS.find { |range, _| range.cover?(@conventionality) }&.last || :unknown end |
#coverage ⇒ Object
48 49 50 51 52 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 48 def coverage return 0.0 if @mappings.empty? @mappings.values.compact.size.to_f / @mappings.size end |
#decay! ⇒ Object
70 71 72 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 70 def decay! @strength = (@strength - DECAY_RATE).clamp(STRENGTH_FLOOR, STRENGTH_CEILING) end |
#map_concept(source_concept) ⇒ Object
44 45 46 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 44 def map_concept(source_concept) @mappings[source_concept] end |
#novel? ⇒ Boolean
58 59 60 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 58 def novel? @conventionality <= NOVELTY_THRESHOLD end |
#stale? ⇒ Boolean
74 75 76 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 74 def stale? (Time.now.utc - @last_used_at) > STALE_THRESHOLD end |
#strength_label ⇒ Object
66 67 68 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 66 def strength_label STRENGTH_LABELS.find { |range, _| range.cover?(@strength) }&.last || :unknown end |
#to_h ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 78 def to_h { id: @id, source_domain: @source_domain, target_domain: @target_domain, metaphor_type: @metaphor_type, mappings: @mappings, entailments: @entailments, strength: @strength, conventionality: @conventionality, conventionality_label: conventionality_label, strength_label: strength_label, use_count: @use_count, coverage: coverage, created_at: @created_at, last_used_at: @last_used_at } end |
#use! ⇒ Object
33 34 35 36 37 38 |
# File 'lib/legion/extensions/agentic/language/conceptual_metaphor/helpers/metaphor.rb', line 33 def use! @use_count += 1 @last_used_at = Time.now.utc @strength = (@strength + REINFORCEMENT_BOOST).clamp(STRENGTH_FLOOR, STRENGTH_CEILING) increase_conventionality end |