Class: Legion::Extensions::Agentic::Language::PragmaticInference::Helpers::Utterance

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/language/pragmatic_inference/helpers/utterance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#confidenceObject (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

#contentObject (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_atObject (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

#domainObject (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

#idObject (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

#implicaturesObject (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_meaningObject (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_scoresObject (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

#speakerObject (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_actObject (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

#violationsObject (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_complianceObject



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_hObject



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_maximsObject



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