Class: Legion::Extensions::Agentic::Language::PragmaticInference::Helpers::Utterance
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Language::PragmaticInference::Helpers::Utterance
- Defined in:
- lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb
Instance Attribute Summary collapse
-
#confidence ⇒ Object
readonly
Returns the value of attribute confidence.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#implicatures ⇒ Object
readonly
Returns the value of attribute implicatures.
-
#literal_meaning ⇒ Object
readonly
Returns the value of attribute literal_meaning.
-
#maxim_scores ⇒ Object
readonly
Returns the value of attribute maxim_scores.
-
#speaker ⇒ Object
readonly
Returns the value of attribute speaker.
-
#speech_act ⇒ Object
readonly
Returns the value of attribute speech_act.
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
- #add_implicature(meaning:) ⇒ Object
-
#initialize(content:, speaker:, speech_act:, literal_meaning: nil, domain: nil, maxim_scores: {}, confidence: Constants::DEFAULT_CONFIDENCE) ⇒ Utterance
constructor
A new instance of Utterance.
- #overall_compliance ⇒ Object
- #to_h ⇒ Object
- #update_confidence(delta) ⇒ Object
- #violated_maxims ⇒ Object
Constructor Details
#initialize(content:, speaker:, speech_act:, literal_meaning: nil, domain: nil, maxim_scores: {}, confidence: Constants::DEFAULT_CONFIDENCE) ⇒ Utterance
Returns a new instance of Utterance.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 26 def initialize(content:, speaker:, speech_act:, literal_meaning: nil, domain: nil, maxim_scores: {}, confidence: Constants::DEFAULT_CONFIDENCE) @id = SecureRandom.uuid @content = content @speaker = speaker @speech_act = speech_act @literal_meaning = literal_meaning @domain = domain @maxim_scores = build_maxim_scores(maxim_scores) @violations = [] @implicatures = [] @confidence = confidence.clamp(Constants::CONFIDENCE_FLOOR, Constants::CONFIDENCE_CEILING) @created_at = Time.now.utc end |
Instance Attribute Details
#confidence ⇒ Object (readonly)
Returns the value of attribute confidence.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def confidence @confidence end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def id @id end |
#implicatures ⇒ Object (readonly)
Returns the value of attribute implicatures.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def implicatures @implicatures end |
#literal_meaning ⇒ Object (readonly)
Returns the value of attribute literal_meaning.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def literal_meaning @literal_meaning end |
#maxim_scores ⇒ Object (readonly)
Returns the value of attribute maxim_scores.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def maxim_scores @maxim_scores end |
#speaker ⇒ Object (readonly)
Returns the value of attribute speaker.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def speaker @speaker end |
#speech_act ⇒ Object (readonly)
Returns the value of attribute speech_act.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def speech_act @speech_act end |
#violations ⇒ Object (readonly)
Returns the value of attribute violations.
22 23 24 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 22 def violations @violations end |
Instance Method Details
#add_implicature(meaning:) ⇒ Object
51 52 53 54 55 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 51 def add_implicature(meaning:) return if @implicatures.size >= Constants::MAX_IMPLICATURES @implicatures << { meaning: meaning, added_at: Time.now.utc } end |
#overall_compliance ⇒ Object
41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 41 def overall_compliance return 0.0 if @maxim_scores.empty? @maxim_scores.values.sum / @maxim_scores.size.to_f end |
#to_h ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 61 def to_h { id: @id, content: @content, speaker: @speaker, speech_act: @speech_act, literal_meaning: @literal_meaning, domain: @domain, maxim_scores: @maxim_scores, violations: @violations, implicatures: @implicatures, confidence: @confidence, overall_compliance: overall_compliance, violated_maxims: violated_maxims, created_at: @created_at } end |
#update_confidence(delta) ⇒ Object
57 58 59 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 57 def update_confidence(delta) @confidence = (@confidence + delta).clamp(Constants::CONFIDENCE_FLOOR, Constants::CONFIDENCE_CEILING) end |
#violated_maxims ⇒ Object
47 48 49 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 47 def violated_maxims @maxim_scores.select { |_maxim, score| score < 0.5 }.keys end |