Class: Legion::Extensions::Agentic::Integration::Gestalt::Helpers::Pattern
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::Gestalt::Helpers::Pattern
- Defined in:
- lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#match_count ⇒ Object
Returns the value of attribute match_count.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#strength ⇒ Object
Returns the value of attribute strength.
Instance Method Summary collapse
- #complete(fragment) ⇒ Object
- #decay ⇒ Object
-
#initialize(name:, elements:, domain: :general) ⇒ Pattern
constructor
A new instance of Pattern.
- #match_ratio(fragment) ⇒ Object
- #missing_elements(fragment) ⇒ Object
- #penalize ⇒ Object
- #reinforce ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name:, elements:, domain: :general) ⇒ Pattern
Returns a new instance of Pattern.
15 16 17 18 19 20 21 22 23 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 15 def initialize(name:, elements:, domain: :general) @id = SecureRandom.uuid @name = name @domain = domain @elements = elements.first(Constants::MAX_PATTERN_SIZE) @strength = 1.0 @match_count = 0 @created_at = Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 12 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 12 def domain @domain end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
12 13 14 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 12 def elements @elements end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 12 def id @id end |
#match_count ⇒ Object
Returns the value of attribute match_count.
13 14 15 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 13 def match_count @match_count end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 12 def name @name end |
#strength ⇒ Object
Returns the value of attribute strength.
13 14 15 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 13 def strength @strength end |
Instance Method Details
#complete(fragment) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 36 def complete(fragment) ratio = match_ratio(fragment) return nil if ratio < Constants::COMPLETION_THRESHOLD confidence = compute_confidence(ratio) missing = missing_elements(fragment) @match_count += 1 { pattern_id: @id, pattern_name: @name, completed: @elements, missing: missing, confidence: confidence.round(4), match_ratio: ratio.round(4) } end |
#decay ⇒ Object
62 63 64 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 62 def decay @strength = [@strength - Constants::PATTERN_DECAY, 0.1].max end |
#match_ratio(fragment) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 25 def match_ratio(fragment) return 0.0 if @elements.empty? || fragment.empty? matches = fragment.count { |e| @elements.include?(e) } matches.to_f / @elements.size end |
#missing_elements(fragment) ⇒ Object
32 33 34 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 32 def missing_elements(fragment) @elements - fragment end |
#penalize ⇒ Object
58 59 60 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 58 def penalize @strength = [@strength - Constants::INCORRECT_PENALTY, 0.1].max end |
#reinforce ⇒ Object
54 55 56 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 54 def reinforce @strength = [@strength + Constants::CORRECT_REINFORCEMENT, 2.0].min end |
#to_h ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb', line 66 def to_h { id: @id, name: @name, domain: @domain, elements: @elements, strength: @strength.round(4), match_count: @match_count, size: @elements.size } end |