Module: Legion::Extensions::Agentic::Language::Grammar::Runners::CognitiveGrammar
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb
Instance Method Summary collapse
- #cognitive_grammar_stats ⇒ Object
- #construals_for_scene_report(scene:) ⇒ Object
- #constructions_by_domain_report(domain:) ⇒ Object
-
#create_grammar_construal(scene:, perspective:, figure:, ground:, specificity: :intermediate, scope: :local, dynamicity: 0.5, construction_id: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- #create_grammar_construction(form:, meaning:, expression_type:, domain:) ⇒ Object
- #entrenched_constructions_report ⇒ Object
- #most_used_constructions(limit: 5) ⇒ Object
- #update_cognitive_grammar ⇒ Object
- #use_grammar_construction(construction_id:) ⇒ Object
Instance Method Details
#cognitive_grammar_stats ⇒ Object
83 84 85 86 87 |
# File 'lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb', line 83 def cognitive_grammar_stats(**) stats = engine.to_h log.debug "[cognitive_grammar] stats constructions=#{stats[:constructions_count]} construals=#{stats[:construals_count]}" stats end |
#construals_for_scene_report(scene:) ⇒ Object
51 52 53 54 55 |
# File 'lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb', line 51 def construals_for_scene_report(scene:, **) construals = engine.construals_for_scene(scene: scene) log.debug "[cognitive_grammar] construals_for_scene scene=#{scene} count=#{construals.size}" { scene: scene, count: construals.size, construals: construals.map(&:to_h) } end |
#constructions_by_domain_report(domain:) ⇒ Object
63 64 65 66 67 |
# File 'lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb', line 63 def constructions_by_domain_report(domain:, **) constructions = engine.constructions_by_domain(domain: domain) log.debug "[cognitive_grammar] constructions_by_domain domain=#{domain} count=#{constructions.size}" { domain: domain, count: constructions.size, constructions: constructions.map(&:to_h) } end |
#create_grammar_construal(scene:, perspective:, figure:, ground:, specificity: :intermediate, scope: :local, dynamicity: 0.5, construction_id: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb', line 24 def create_grammar_construal(scene:, perspective:, figure:, ground:, # rubocop:disable Metrics/ParameterLists specificity: :intermediate, scope: :local, dynamicity: 0.5, construction_id: nil, **) construal = engine.create_construal( scene: scene, perspective: perspective, figure: figure, ground: ground, specificity: specificity, scope: scope, dynamicity: dynamicity, construction_id: construction_id ) log.debug "[cognitive_grammar] created construal scene=#{scene} figure=#{figure}" construal.to_h end |
#create_grammar_construction(form:, meaning:, expression_type:, domain:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb', line 13 def create_grammar_construction(form:, meaning:, expression_type:, domain:, **) construction = engine.create_construction( form: form, meaning: meaning, expression_type: expression_type, domain: domain ) log.debug "[cognitive_grammar] created construction form=#{form} type=#{expression_type} domain=#{domain}" construction.to_h end |
#entrenched_constructions_report ⇒ Object
57 58 59 60 61 |
# File 'lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb', line 57 def entrenched_constructions_report(**) constructions = engine.entrenched_constructions log.debug "[cognitive_grammar] entrenched constructions count=#{constructions.size}" { count: constructions.size, constructions: constructions.map(&:to_h) } end |
#most_used_constructions(limit: 5) ⇒ Object
69 70 71 72 73 |
# File 'lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb', line 69 def most_used_constructions(limit: 5, **) constructions = engine.most_used(limit: limit) log.debug "[cognitive_grammar] most_used limit=#{limit} count=#{constructions.size}" { limit: limit, count: constructions.size, constructions: constructions.map(&:to_h) } end |
#update_cognitive_grammar ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb', line 75 def update_cognitive_grammar(**) engine.decay_all pruned = engine.prune_inactive stats = engine.to_h log.debug "[cognitive_grammar] update: pruned=#{pruned} remaining=#{stats[:constructions_count]}" { pruned: pruned, stats: stats } end |
#use_grammar_construction(construction_id:) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/legion/extensions/agentic/language/grammar/runners/cognitive_grammar.rb', line 41 def use_grammar_construction(construction_id:, **) construction = engine.use_construction(construction_id: construction_id) return { found: false, construction_id: construction_id } unless construction msg = "[cognitive_grammar] used construction id=#{construction_id[0..7]} " \ "usage_count=#{construction.usage_count} activation=#{construction.activation.round(3)}" log.debug msg { found: true, construction: construction.to_h } end |