Module: Legion::Extensions::Agentic::Language::PragmaticInference::Runners::PragmaticInference
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb
Instance Method Summary collapse
- #analyze_utterance(content:, speaker:, speech_act:, literal_meaning: nil, domain: nil, maxim_scores: {}) ⇒ Object
- #detect_maxim_violations(utterance_id:) ⇒ Object
- #generate_pragmatic_implicature(utterance_id:, inferred_meaning:) ⇒ Object
- #most_violated_maxim ⇒ Object
- #overall_cooperative_compliance ⇒ Object
- #pragmatic_inference_stats ⇒ Object
- #speaker_pragmatic_profile(speaker:) ⇒ Object
- #update_pragmatic_inference ⇒ Object
- #utterances_by_speaker(speaker:) ⇒ Object
- #utterances_by_speech_act(speech_act:) ⇒ Object
Instance Method Details
#analyze_utterance(content:, speaker:, speech_act:, literal_meaning: nil, domain: nil, maxim_scores: {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 13 def analyze_utterance(content:, speaker:, speech_act:, literal_meaning: nil, domain: nil, maxim_scores: {}, **) return { success: false, error: :invalid_speech_act } unless Helpers::Constants.valid_speech_act?(speech_act) utterance = engine.analyze_utterance( content: content, speaker: speaker, speech_act: speech_act, literal_meaning: literal_meaning, domain: domain, maxim_scores: maxim_scores ) log.debug "[pragmatic_inference] analyzed utterance id=#{utterance.id[0..7]} " \ "speaker=#{speaker} speech_act=#{speech_act} " \ "compliance=#{utterance.overall_compliance.round(2)}" { success: true, utterance_id: utterance.id, overall_compliance: utterance.overall_compliance, violated_maxims: utterance.violated_maxims } end |
#detect_maxim_violations(utterance_id:) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 34 def detect_maxim_violations(utterance_id:, **) return { success: false, error: :invalid_utterance_id } if utterance_id.to_s.length < 3 violations = engine.detect_violations(utterance_id: utterance_id) log.debug "[pragmatic_inference] violations detected id=#{utterance_id[0..7]} count=#{violations.size}" { success: true, utterance_id: utterance_id, violations: violations, violation_count: violations.size } end |
#generate_pragmatic_implicature(utterance_id:, inferred_meaning:) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 44 def generate_pragmatic_implicature(utterance_id:, inferred_meaning:, **) return { success: false, error: :invalid_utterance_id } if utterance_id.to_s.length < 3 return { success: false, error: :invalid_inferred_meaning } if inferred_meaning.to_s.length < 3 result = engine.generate_implicature(utterance_id: utterance_id, inferred_meaning: inferred_meaning) if result log.debug "[pragmatic_inference] implicature added id=#{utterance_id[0..7]}" { success: true, utterance_id: utterance_id, inferred_meaning: result } else log.debug "[pragmatic_inference] implicature failed: utterance not found id=#{utterance_id[0..7]}" { success: false, error: :utterance_not_found } end end |
#most_violated_maxim ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 90 def most_violated_maxim(**) maxim = engine.most_violated_maxim log.debug "[pragmatic_inference] most violated maxim=#{maxim.inspect}" { success: true, maxim: maxim, description: maxim ? Helpers::Constants::MAXIM_DESCRIPTIONS[maxim] : nil } end |
#overall_cooperative_compliance ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 99 def overall_cooperative_compliance(**) cooperation = engine.overall_cooperation total = engine.count log.debug "[pragmatic_inference] cooperation=#{cooperation.round(2)} total=#{total}" { success: true, cooperation: cooperation, utterance_count: total } end |
#pragmatic_inference_stats ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 116 def pragmatic_inference_stats(**) stats = engine.to_h log.debug "[pragmatic_inference] stats: utterances=#{stats[:utterance_count]} " \ "cooperation=#{stats[:overall_cooperation]}" { success: true, **stats } end |
#speaker_pragmatic_profile(speaker:) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 59 def speaker_pragmatic_profile(speaker:, **) return { success: false, error: :invalid_speaker } if speaker.to_s.length < 3 profile = engine.speaker_profile(speaker: speaker) log.debug "[pragmatic_inference] speaker profile speaker=#{speaker} " \ "utterances=#{profile[:utterance_count]}" { success: true, **profile } end |
#update_pragmatic_inference ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 108 def update_pragmatic_inference(**) engine.decay_all log.debug "[pragmatic_inference] decay applied to #{engine.count} utterances" { success: true, decayed_count: engine.count, decay_rate: Helpers::Constants::DECAY_RATE } end |
#utterances_by_speaker(speaker:) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 80 def utterances_by_speaker(speaker:, **) return { success: false, error: :invalid_speaker } if speaker.to_s.length < 3 utterances = engine.by_speaker(speaker: speaker) log.debug "[pragmatic_inference] by_speaker speaker=#{speaker} count=#{utterances.size}" { success: true, speaker: speaker, utterances: utterances.map(&:to_h), count: utterances.size } end |
#utterances_by_speech_act(speech_act:) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/legion/extensions/agentic/language/pragmatic_inference/runners/pragmatic_inference.rb', line 70 def utterances_by_speech_act(speech_act:, **) return { success: false, error: :invalid_speech_act } unless Helpers::Constants.valid_speech_act?(speech_act) utterances = engine.by_speech_act(speech_act: speech_act) log.debug "[pragmatic_inference] by_speech_act act=#{speech_act} count=#{utterances.size}" { success: true, speech_act: speech_act, utterances: utterances.map(&:to_h), count: utterances.size } end |