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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 16 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.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 12 def confidence @confidence end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 12 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.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/language/pragmatic_inference/helpers/utterance.rb', line 12 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 12 def id @id end |
#implicatures ⇒ Object (readonly)
Returns the value of attribute implicatures.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 12 def implicatures @implicatures end |
#literal_meaning ⇒ Object (readonly)
Returns the value of attribute literal_meaning.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 12 def literal_meaning @literal_meaning end |
#maxim_scores ⇒ Object (readonly)
Returns the value of attribute maxim_scores.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 12 def maxim_scores @maxim_scores end |
#speaker ⇒ Object (readonly)
Returns the value of attribute speaker.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 12 def speaker @speaker end |
#speech_act ⇒ Object (readonly)
Returns the value of attribute speech_act.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 12 def speech_act @speech_act end |
#violations ⇒ Object (readonly)
Returns the value of attribute violations.
12 13 14 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 12 def violations @violations end |
Instance Method Details
#add_implicature(meaning:) ⇒ Object
41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 41 def add_implicature(meaning:) return if @implicatures.size >= Constants::MAX_IMPLICATURES @implicatures << { meaning: meaning, added_at: Time.now.utc } end |
#overall_compliance ⇒ Object
31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 31 def overall_compliance return 0.0 if @maxim_scores.empty? @maxim_scores.values.sum / @maxim_scores.size.to_f end |
#to_h ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 51 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
47 48 49 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 47 def update_confidence(delta) @confidence = (@confidence + delta).clamp(Constants::CONFIDENCE_FLOOR, Constants::CONFIDENCE_CEILING) end |
#violated_maxims ⇒ Object
37 38 39 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb', line 37 def violated_maxims @maxim_scores.select { |_maxim, score| score < 0.5 }.keys end |