tnfr 4.5.2__py3-none-any.whl → 8.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of tnfr might be problematic. Click here for more details.
- tnfr/__init__.py +334 -50
- tnfr/__init__.pyi +33 -0
- tnfr/_compat.py +10 -0
- tnfr/_generated_version.py +34 -0
- tnfr/_version.py +49 -0
- tnfr/_version.pyi +7 -0
- tnfr/alias.py +214 -37
- tnfr/alias.pyi +108 -0
- tnfr/backends/__init__.py +354 -0
- tnfr/backends/jax_backend.py +173 -0
- tnfr/backends/numpy_backend.py +238 -0
- tnfr/backends/optimized_numpy.py +420 -0
- tnfr/backends/torch_backend.py +408 -0
- tnfr/cache.py +149 -556
- tnfr/cache.pyi +13 -0
- tnfr/cli/__init__.py +51 -16
- tnfr/cli/__init__.pyi +26 -0
- tnfr/cli/arguments.py +344 -32
- tnfr/cli/arguments.pyi +29 -0
- tnfr/cli/execution.py +676 -50
- tnfr/cli/execution.pyi +70 -0
- tnfr/cli/interactive_validator.py +614 -0
- tnfr/cli/utils.py +18 -3
- tnfr/cli/utils.pyi +7 -0
- tnfr/cli/validate.py +236 -0
- tnfr/compat/__init__.py +85 -0
- tnfr/compat/dataclass.py +136 -0
- tnfr/compat/jsonschema_stub.py +61 -0
- tnfr/compat/matplotlib_stub.py +73 -0
- tnfr/compat/numpy_stub.py +155 -0
- tnfr/config/__init__.py +224 -0
- tnfr/config/__init__.pyi +10 -0
- tnfr/{constants_glyphs.py → config/constants.py} +26 -20
- tnfr/config/constants.pyi +12 -0
- tnfr/config/defaults.py +54 -0
- tnfr/{constants/core.py → config/defaults_core.py} +59 -6
- tnfr/config/defaults_init.py +33 -0
- tnfr/config/defaults_metric.py +104 -0
- tnfr/config/feature_flags.py +81 -0
- tnfr/config/feature_flags.pyi +16 -0
- tnfr/config/glyph_constants.py +31 -0
- tnfr/config/init.py +77 -0
- tnfr/config/init.pyi +8 -0
- tnfr/config/operator_names.py +254 -0
- tnfr/config/operator_names.pyi +36 -0
- tnfr/config/physics_derivation.py +354 -0
- tnfr/config/presets.py +83 -0
- tnfr/config/presets.pyi +7 -0
- tnfr/config/security.py +927 -0
- tnfr/config/thresholds.py +114 -0
- tnfr/config/tnfr_config.py +498 -0
- tnfr/constants/__init__.py +51 -133
- tnfr/constants/__init__.pyi +92 -0
- tnfr/constants/aliases.py +33 -0
- tnfr/constants/aliases.pyi +27 -0
- tnfr/constants/init.py +3 -1
- tnfr/constants/init.pyi +12 -0
- tnfr/constants/metric.py +9 -15
- tnfr/constants/metric.pyi +19 -0
- tnfr/core/__init__.py +33 -0
- tnfr/core/container.py +226 -0
- tnfr/core/default_implementations.py +329 -0
- tnfr/core/interfaces.py +279 -0
- tnfr/dynamics/__init__.py +213 -633
- tnfr/dynamics/__init__.pyi +83 -0
- tnfr/dynamics/adaptation.py +267 -0
- tnfr/dynamics/adaptation.pyi +7 -0
- tnfr/dynamics/adaptive_sequences.py +189 -0
- tnfr/dynamics/adaptive_sequences.pyi +14 -0
- tnfr/dynamics/aliases.py +23 -0
- tnfr/dynamics/aliases.pyi +19 -0
- tnfr/dynamics/bifurcation.py +232 -0
- tnfr/dynamics/canonical.py +229 -0
- tnfr/dynamics/canonical.pyi +48 -0
- tnfr/dynamics/coordination.py +385 -0
- tnfr/dynamics/coordination.pyi +25 -0
- tnfr/dynamics/dnfr.py +2699 -398
- tnfr/dynamics/dnfr.pyi +26 -0
- tnfr/dynamics/dynamic_limits.py +225 -0
- tnfr/dynamics/feedback.py +252 -0
- tnfr/dynamics/feedback.pyi +24 -0
- tnfr/dynamics/fused_dnfr.py +454 -0
- tnfr/dynamics/homeostasis.py +157 -0
- tnfr/dynamics/homeostasis.pyi +14 -0
- tnfr/dynamics/integrators.py +496 -102
- tnfr/dynamics/integrators.pyi +36 -0
- tnfr/dynamics/learning.py +310 -0
- tnfr/dynamics/learning.pyi +33 -0
- tnfr/dynamics/metabolism.py +254 -0
- tnfr/dynamics/nbody.py +796 -0
- tnfr/dynamics/nbody_tnfr.py +783 -0
- tnfr/dynamics/propagation.py +326 -0
- tnfr/dynamics/runtime.py +908 -0
- tnfr/dynamics/runtime.pyi +77 -0
- tnfr/dynamics/sampling.py +10 -5
- tnfr/dynamics/sampling.pyi +7 -0
- tnfr/dynamics/selectors.py +711 -0
- tnfr/dynamics/selectors.pyi +85 -0
- tnfr/dynamics/structural_clip.py +207 -0
- tnfr/errors/__init__.py +37 -0
- tnfr/errors/contextual.py +492 -0
- tnfr/execution.py +77 -55
- tnfr/execution.pyi +45 -0
- tnfr/extensions/__init__.py +205 -0
- tnfr/extensions/__init__.pyi +18 -0
- tnfr/extensions/base.py +173 -0
- tnfr/extensions/base.pyi +35 -0
- tnfr/extensions/business/__init__.py +71 -0
- tnfr/extensions/business/__init__.pyi +11 -0
- tnfr/extensions/business/cookbook.py +88 -0
- tnfr/extensions/business/cookbook.pyi +8 -0
- tnfr/extensions/business/health_analyzers.py +202 -0
- tnfr/extensions/business/health_analyzers.pyi +9 -0
- tnfr/extensions/business/patterns.py +183 -0
- tnfr/extensions/business/patterns.pyi +8 -0
- tnfr/extensions/medical/__init__.py +73 -0
- tnfr/extensions/medical/__init__.pyi +11 -0
- tnfr/extensions/medical/cookbook.py +88 -0
- tnfr/extensions/medical/cookbook.pyi +8 -0
- tnfr/extensions/medical/health_analyzers.py +181 -0
- tnfr/extensions/medical/health_analyzers.pyi +9 -0
- tnfr/extensions/medical/patterns.py +163 -0
- tnfr/extensions/medical/patterns.pyi +8 -0
- tnfr/flatten.py +29 -50
- tnfr/flatten.pyi +21 -0
- tnfr/gamma.py +66 -53
- tnfr/gamma.pyi +36 -0
- tnfr/glyph_history.py +144 -57
- tnfr/glyph_history.pyi +35 -0
- tnfr/glyph_runtime.py +19 -0
- tnfr/glyph_runtime.pyi +8 -0
- tnfr/immutable.py +70 -30
- tnfr/immutable.pyi +36 -0
- tnfr/initialization.py +22 -16
- tnfr/initialization.pyi +65 -0
- tnfr/io.py +5 -241
- tnfr/io.pyi +13 -0
- tnfr/locking.pyi +7 -0
- tnfr/mathematics/__init__.py +79 -0
- tnfr/mathematics/backend.py +453 -0
- tnfr/mathematics/backend.pyi +99 -0
- tnfr/mathematics/dynamics.py +408 -0
- tnfr/mathematics/dynamics.pyi +90 -0
- tnfr/mathematics/epi.py +391 -0
- tnfr/mathematics/epi.pyi +65 -0
- tnfr/mathematics/generators.py +242 -0
- tnfr/mathematics/generators.pyi +29 -0
- tnfr/mathematics/metrics.py +119 -0
- tnfr/mathematics/metrics.pyi +16 -0
- tnfr/mathematics/operators.py +239 -0
- tnfr/mathematics/operators.pyi +59 -0
- tnfr/mathematics/operators_factory.py +124 -0
- tnfr/mathematics/operators_factory.pyi +11 -0
- tnfr/mathematics/projection.py +87 -0
- tnfr/mathematics/projection.pyi +33 -0
- tnfr/mathematics/runtime.py +182 -0
- tnfr/mathematics/runtime.pyi +64 -0
- tnfr/mathematics/spaces.py +256 -0
- tnfr/mathematics/spaces.pyi +83 -0
- tnfr/mathematics/transforms.py +305 -0
- tnfr/mathematics/transforms.pyi +62 -0
- tnfr/metrics/__init__.py +47 -9
- tnfr/metrics/__init__.pyi +20 -0
- tnfr/metrics/buffer_cache.py +163 -0
- tnfr/metrics/buffer_cache.pyi +24 -0
- tnfr/metrics/cache_utils.py +214 -0
- tnfr/metrics/coherence.py +1510 -330
- tnfr/metrics/coherence.pyi +129 -0
- tnfr/metrics/common.py +23 -16
- tnfr/metrics/common.pyi +35 -0
- tnfr/metrics/core.py +251 -36
- tnfr/metrics/core.pyi +13 -0
- tnfr/metrics/diagnosis.py +709 -110
- tnfr/metrics/diagnosis.pyi +86 -0
- tnfr/metrics/emergence.py +245 -0
- tnfr/metrics/export.py +60 -18
- tnfr/metrics/export.pyi +7 -0
- tnfr/metrics/glyph_timing.py +233 -43
- tnfr/metrics/glyph_timing.pyi +81 -0
- tnfr/metrics/learning_metrics.py +280 -0
- tnfr/metrics/learning_metrics.pyi +21 -0
- tnfr/metrics/phase_coherence.py +351 -0
- tnfr/metrics/phase_compatibility.py +349 -0
- tnfr/metrics/reporting.py +63 -28
- tnfr/metrics/reporting.pyi +25 -0
- tnfr/metrics/sense_index.py +1126 -43
- tnfr/metrics/sense_index.pyi +9 -0
- tnfr/metrics/trig.py +215 -23
- tnfr/metrics/trig.pyi +13 -0
- tnfr/metrics/trig_cache.py +148 -24
- tnfr/metrics/trig_cache.pyi +10 -0
- tnfr/multiscale/__init__.py +32 -0
- tnfr/multiscale/hierarchical.py +517 -0
- tnfr/node.py +646 -140
- tnfr/node.pyi +139 -0
- tnfr/observers.py +160 -45
- tnfr/observers.pyi +31 -0
- tnfr/ontosim.py +23 -19
- tnfr/ontosim.pyi +28 -0
- tnfr/operators/__init__.py +1358 -106
- tnfr/operators/__init__.pyi +31 -0
- tnfr/operators/algebra.py +277 -0
- tnfr/operators/canonical_patterns.py +420 -0
- tnfr/operators/cascade.py +267 -0
- tnfr/operators/cycle_detection.py +358 -0
- tnfr/operators/definitions.py +4108 -0
- tnfr/operators/definitions.pyi +78 -0
- tnfr/operators/grammar.py +1164 -0
- tnfr/operators/grammar.pyi +140 -0
- tnfr/operators/hamiltonian.py +710 -0
- tnfr/operators/health_analyzer.py +809 -0
- tnfr/operators/jitter.py +107 -38
- tnfr/operators/jitter.pyi +11 -0
- tnfr/operators/lifecycle.py +314 -0
- tnfr/operators/metabolism.py +618 -0
- tnfr/operators/metrics.py +2138 -0
- tnfr/operators/network_analysis/__init__.py +27 -0
- tnfr/operators/network_analysis/source_detection.py +186 -0
- tnfr/operators/nodal_equation.py +395 -0
- tnfr/operators/pattern_detection.py +660 -0
- tnfr/operators/patterns.py +669 -0
- tnfr/operators/postconditions/__init__.py +38 -0
- tnfr/operators/postconditions/mutation.py +236 -0
- tnfr/operators/preconditions/__init__.py +1226 -0
- tnfr/operators/preconditions/coherence.py +305 -0
- tnfr/operators/preconditions/dissonance.py +236 -0
- tnfr/operators/preconditions/emission.py +128 -0
- tnfr/operators/preconditions/mutation.py +580 -0
- tnfr/operators/preconditions/reception.py +125 -0
- tnfr/operators/preconditions/resonance.py +364 -0
- tnfr/operators/registry.py +74 -0
- tnfr/operators/registry.pyi +9 -0
- tnfr/operators/remesh.py +1415 -91
- tnfr/operators/remesh.pyi +26 -0
- tnfr/operators/structural_units.py +268 -0
- tnfr/operators/unified_grammar.py +105 -0
- tnfr/parallel/__init__.py +54 -0
- tnfr/parallel/auto_scaler.py +234 -0
- tnfr/parallel/distributed.py +384 -0
- tnfr/parallel/engine.py +238 -0
- tnfr/parallel/gpu_engine.py +420 -0
- tnfr/parallel/monitoring.py +248 -0
- tnfr/parallel/partitioner.py +459 -0
- tnfr/py.typed +0 -0
- tnfr/recipes/__init__.py +22 -0
- tnfr/recipes/cookbook.py +743 -0
- tnfr/rng.py +75 -151
- tnfr/rng.pyi +26 -0
- tnfr/schemas/__init__.py +8 -0
- tnfr/schemas/grammar.json +94 -0
- tnfr/sdk/__init__.py +107 -0
- tnfr/sdk/__init__.pyi +19 -0
- tnfr/sdk/adaptive_system.py +173 -0
- tnfr/sdk/adaptive_system.pyi +21 -0
- tnfr/sdk/builders.py +370 -0
- tnfr/sdk/builders.pyi +51 -0
- tnfr/sdk/fluent.py +1121 -0
- tnfr/sdk/fluent.pyi +74 -0
- tnfr/sdk/templates.py +342 -0
- tnfr/sdk/templates.pyi +41 -0
- tnfr/sdk/utils.py +341 -0
- tnfr/secure_config.py +46 -0
- tnfr/security/__init__.py +70 -0
- tnfr/security/database.py +514 -0
- tnfr/security/subprocess.py +503 -0
- tnfr/security/validation.py +290 -0
- tnfr/selector.py +59 -22
- tnfr/selector.pyi +19 -0
- tnfr/sense.py +92 -67
- tnfr/sense.pyi +23 -0
- tnfr/services/__init__.py +17 -0
- tnfr/services/orchestrator.py +325 -0
- tnfr/sparse/__init__.py +39 -0
- tnfr/sparse/representations.py +492 -0
- tnfr/structural.py +639 -263
- tnfr/structural.pyi +83 -0
- tnfr/telemetry/__init__.py +35 -0
- tnfr/telemetry/cache_metrics.py +226 -0
- tnfr/telemetry/cache_metrics.pyi +64 -0
- tnfr/telemetry/nu_f.py +422 -0
- tnfr/telemetry/nu_f.pyi +108 -0
- tnfr/telemetry/verbosity.py +36 -0
- tnfr/telemetry/verbosity.pyi +15 -0
- tnfr/tokens.py +2 -4
- tnfr/tokens.pyi +36 -0
- tnfr/tools/__init__.py +20 -0
- tnfr/tools/domain_templates.py +478 -0
- tnfr/tools/sequence_generator.py +846 -0
- tnfr/topology/__init__.py +13 -0
- tnfr/topology/asymmetry.py +151 -0
- tnfr/trace.py +300 -126
- tnfr/trace.pyi +42 -0
- tnfr/tutorials/__init__.py +38 -0
- tnfr/tutorials/autonomous_evolution.py +285 -0
- tnfr/tutorials/interactive.py +1576 -0
- tnfr/tutorials/structural_metabolism.py +238 -0
- tnfr/types.py +743 -12
- tnfr/types.pyi +357 -0
- tnfr/units.py +68 -0
- tnfr/units.pyi +13 -0
- tnfr/utils/__init__.py +282 -0
- tnfr/utils/__init__.pyi +215 -0
- tnfr/utils/cache.py +4223 -0
- tnfr/utils/cache.pyi +470 -0
- tnfr/{callback_utils.py → utils/callbacks.py} +26 -39
- tnfr/utils/callbacks.pyi +49 -0
- tnfr/utils/chunks.py +108 -0
- tnfr/utils/chunks.pyi +22 -0
- tnfr/utils/data.py +428 -0
- tnfr/utils/data.pyi +74 -0
- tnfr/utils/graph.py +85 -0
- tnfr/utils/graph.pyi +10 -0
- tnfr/utils/init.py +821 -0
- tnfr/utils/init.pyi +80 -0
- tnfr/utils/io.py +559 -0
- tnfr/utils/io.pyi +66 -0
- tnfr/{helpers → utils}/numeric.py +51 -24
- tnfr/utils/numeric.pyi +21 -0
- tnfr/validation/__init__.py +257 -0
- tnfr/validation/__init__.pyi +85 -0
- tnfr/validation/compatibility.py +460 -0
- tnfr/validation/compatibility.pyi +6 -0
- tnfr/validation/config.py +73 -0
- tnfr/validation/graph.py +139 -0
- tnfr/validation/graph.pyi +18 -0
- tnfr/validation/input_validation.py +755 -0
- tnfr/validation/invariants.py +712 -0
- tnfr/validation/rules.py +253 -0
- tnfr/validation/rules.pyi +44 -0
- tnfr/validation/runtime.py +279 -0
- tnfr/validation/runtime.pyi +28 -0
- tnfr/validation/sequence_validator.py +162 -0
- tnfr/validation/soft_filters.py +170 -0
- tnfr/validation/soft_filters.pyi +32 -0
- tnfr/validation/spectral.py +164 -0
- tnfr/validation/spectral.pyi +42 -0
- tnfr/validation/validator.py +1266 -0
- tnfr/validation/window.py +39 -0
- tnfr/validation/window.pyi +1 -0
- tnfr/visualization/__init__.py +98 -0
- tnfr/visualization/cascade_viz.py +256 -0
- tnfr/visualization/hierarchy.py +284 -0
- tnfr/visualization/sequence_plotter.py +784 -0
- tnfr/viz/__init__.py +60 -0
- tnfr/viz/matplotlib.py +278 -0
- tnfr/viz/matplotlib.pyi +35 -0
- tnfr-8.5.0.dist-info/METADATA +573 -0
- tnfr-8.5.0.dist-info/RECORD +353 -0
- {tnfr-4.5.2.dist-info → tnfr-8.5.0.dist-info}/entry_points.txt +1 -0
- {tnfr-4.5.2.dist-info → tnfr-8.5.0.dist-info}/licenses/LICENSE.md +1 -1
- tnfr/collections_utils.py +0 -300
- tnfr/config.py +0 -32
- tnfr/grammar.py +0 -344
- tnfr/graph_utils.py +0 -84
- tnfr/helpers/__init__.py +0 -71
- tnfr/import_utils.py +0 -228
- tnfr/json_utils.py +0 -162
- tnfr/logging_utils.py +0 -116
- tnfr/presets.py +0 -60
- tnfr/validators.py +0 -84
- tnfr/value_utils.py +0 -59
- tnfr-4.5.2.dist-info/METADATA +0 -379
- tnfr-4.5.2.dist-info/RECORD +0 -67
- {tnfr-4.5.2.dist-info → tnfr-8.5.0.dist-info}/WHEEL +0 -0
- {tnfr-4.5.2.dist-info → tnfr-8.5.0.dist-info}/top_level.txt +0 -0
tnfr/recipes/cookbook.py
ADDED
|
@@ -0,0 +1,743 @@
|
|
|
1
|
+
"""TNFR Pattern Cookbook - Programmatic access to validated recipes.
|
|
2
|
+
|
|
3
|
+
This module provides a comprehensive library of pre-validated operator sequences
|
|
4
|
+
organized by domain. All recipes are validated against TNFR Grammar 2.0 and
|
|
5
|
+
include health metrics, use cases, and variations.
|
|
6
|
+
|
|
7
|
+
Examples
|
|
8
|
+
--------
|
|
9
|
+
>>> from tnfr.recipes import TNFRCookbook
|
|
10
|
+
>>> cookbook = TNFRCookbook()
|
|
11
|
+
>>> recipe = cookbook.get_recipe("therapeutic", "crisis_intervention")
|
|
12
|
+
>>> print(recipe.sequence)
|
|
13
|
+
['emission', 'reception', 'coherence', 'dissonance', 'contraction', 'coherence', 'coupling', 'silence']
|
|
14
|
+
>>> print(recipe.health_metrics.overall_health)
|
|
15
|
+
0.786
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from typing import List, Dict, Optional, Any
|
|
21
|
+
from ..compat.dataclass import dataclass
|
|
22
|
+
from ..operators.health_analyzer import SequenceHealthMetrics, SequenceHealthAnalyzer
|
|
23
|
+
from ..operators.grammar import validate_sequence_with_health
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"CookbookRecipe",
|
|
28
|
+
"RecipeVariation",
|
|
29
|
+
"TNFRCookbook",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class RecipeVariation:
|
|
35
|
+
"""A variation of a cookbook recipe for specific contexts.
|
|
36
|
+
|
|
37
|
+
Attributes
|
|
38
|
+
----------
|
|
39
|
+
name : str
|
|
40
|
+
Name of the variation
|
|
41
|
+
description : str
|
|
42
|
+
What changes in this variation
|
|
43
|
+
sequence : List[str]
|
|
44
|
+
Modified operator sequence
|
|
45
|
+
health_impact : float
|
|
46
|
+
Expected change in health score (positive or negative)
|
|
47
|
+
context : str
|
|
48
|
+
When to use this variation
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
name: str
|
|
52
|
+
description: str
|
|
53
|
+
sequence: List[str]
|
|
54
|
+
health_impact: float
|
|
55
|
+
context: str
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass
|
|
59
|
+
class CookbookRecipe:
|
|
60
|
+
"""A validated TNFR operator sequence recipe with full context.
|
|
61
|
+
|
|
62
|
+
Attributes
|
|
63
|
+
----------
|
|
64
|
+
name : str
|
|
65
|
+
Recipe name (e.g., "Crisis Intervention")
|
|
66
|
+
domain : str
|
|
67
|
+
Application domain (therapeutic, educational, organizational, creative)
|
|
68
|
+
sequence : List[str]
|
|
69
|
+
Validated operator sequence
|
|
70
|
+
health_metrics : SequenceHealthMetrics
|
|
71
|
+
Computed health metrics for the sequence
|
|
72
|
+
use_cases : List[str]
|
|
73
|
+
Specific real-world applications
|
|
74
|
+
when_to_use : str
|
|
75
|
+
Context description for applying this pattern
|
|
76
|
+
structural_flow : List[str]
|
|
77
|
+
Operator-by-operator explanation of structural effects
|
|
78
|
+
key_insights : List[str]
|
|
79
|
+
Critical success factors and mechanisms
|
|
80
|
+
variations : List[RecipeVariation]
|
|
81
|
+
Adaptations for related contexts
|
|
82
|
+
pattern_type : str
|
|
83
|
+
Detected TNFR pattern type
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
name: str
|
|
87
|
+
domain: str
|
|
88
|
+
sequence: List[str]
|
|
89
|
+
health_metrics: SequenceHealthMetrics
|
|
90
|
+
use_cases: List[str]
|
|
91
|
+
when_to_use: str
|
|
92
|
+
structural_flow: List[str]
|
|
93
|
+
key_insights: List[str]
|
|
94
|
+
variations: List[RecipeVariation]
|
|
95
|
+
pattern_type: str
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class TNFRCookbook:
|
|
99
|
+
"""Library of validated TNFR operator sequence recipes.
|
|
100
|
+
|
|
101
|
+
Provides programmatic access to the pattern cookbook with search,
|
|
102
|
+
filtering, and recommendation capabilities.
|
|
103
|
+
|
|
104
|
+
Examples
|
|
105
|
+
--------
|
|
106
|
+
>>> cookbook = TNFRCookbook()
|
|
107
|
+
>>> # Get specific recipe
|
|
108
|
+
>>> recipe = cookbook.get_recipe("therapeutic", "crisis_intervention")
|
|
109
|
+
>>> print(f"Health: {recipe.health_metrics.overall_health:.3f}")
|
|
110
|
+
Health: 0.786
|
|
111
|
+
|
|
112
|
+
>>> # List all recipes in domain
|
|
113
|
+
>>> therapeutic = cookbook.list_recipes(domain="therapeutic")
|
|
114
|
+
>>> len(therapeutic)
|
|
115
|
+
5
|
|
116
|
+
|
|
117
|
+
>>> # Search by keyword
|
|
118
|
+
>>> results = cookbook.search_recipes("team")
|
|
119
|
+
>>> [r.name for r in results]
|
|
120
|
+
['Team Formation', 'Strategic Planning']
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
def __init__(self) -> None:
|
|
124
|
+
"""Initialize the cookbook with all validated recipes."""
|
|
125
|
+
self._recipes: Dict[str, Dict[str, CookbookRecipe]] = {}
|
|
126
|
+
self._analyzer = SequenceHealthAnalyzer()
|
|
127
|
+
self._load_recipes()
|
|
128
|
+
|
|
129
|
+
def _load_recipes(self) -> None:
|
|
130
|
+
"""Load all recipes from domain pattern modules."""
|
|
131
|
+
# Import domain patterns
|
|
132
|
+
try:
|
|
133
|
+
from examples.domain_applications import therapeutic_patterns
|
|
134
|
+
from examples.domain_applications import educational_patterns
|
|
135
|
+
from examples.domain_applications import organizational_patterns
|
|
136
|
+
from examples.domain_applications import creative_patterns
|
|
137
|
+
except ImportError:
|
|
138
|
+
# Fallback for when examples are not in path
|
|
139
|
+
import sys
|
|
140
|
+
from pathlib import Path
|
|
141
|
+
|
|
142
|
+
examples_path = (
|
|
143
|
+
Path(__file__).parent.parent.parent.parent
|
|
144
|
+
/ "examples"
|
|
145
|
+
/ "domain_applications"
|
|
146
|
+
)
|
|
147
|
+
sys.path.insert(0, str(examples_path))
|
|
148
|
+
import therapeutic_patterns
|
|
149
|
+
import educational_patterns
|
|
150
|
+
import organizational_patterns
|
|
151
|
+
import creative_patterns
|
|
152
|
+
|
|
153
|
+
# Load therapeutic recipes
|
|
154
|
+
self._load_domain_recipes(
|
|
155
|
+
"therapeutic",
|
|
156
|
+
therapeutic_patterns,
|
|
157
|
+
[
|
|
158
|
+
(
|
|
159
|
+
"crisis_intervention",
|
|
160
|
+
"Crisis Intervention",
|
|
161
|
+
[
|
|
162
|
+
"Panic attack management",
|
|
163
|
+
"Acute grief response",
|
|
164
|
+
"Immediate post-trauma stabilization",
|
|
165
|
+
"Emergency emotional support",
|
|
166
|
+
],
|
|
167
|
+
"Immediate stabilization needed, limited time available, high-intensity crisis requiring rapid containment.",
|
|
168
|
+
),
|
|
169
|
+
(
|
|
170
|
+
"process_therapy",
|
|
171
|
+
"Process Therapy",
|
|
172
|
+
[
|
|
173
|
+
"Long-term psychotherapy processes",
|
|
174
|
+
"Personal transformation work",
|
|
175
|
+
"Complex trauma resolution",
|
|
176
|
+
"Deep character structure change",
|
|
177
|
+
],
|
|
178
|
+
"Deep change required, sufficient time and resources available, client readiness for transformative work established.",
|
|
179
|
+
),
|
|
180
|
+
(
|
|
181
|
+
"regenerative_healing",
|
|
182
|
+
"Regenerative Healing",
|
|
183
|
+
[
|
|
184
|
+
"Chronic condition management",
|
|
185
|
+
"Ongoing recovery processes",
|
|
186
|
+
"Building resilience patterns",
|
|
187
|
+
"Preventive mental health work",
|
|
188
|
+
],
|
|
189
|
+
"Long-term healing journey, building sustainable coping patterns, emphasis on self-renewal capacity.",
|
|
190
|
+
),
|
|
191
|
+
(
|
|
192
|
+
"insight_integration",
|
|
193
|
+
"Insight Integration",
|
|
194
|
+
[
|
|
195
|
+
"Post-breakthrough consolidation",
|
|
196
|
+
"Integrate therapeutic insights into daily life",
|
|
197
|
+
"Stabilize sudden understanding or awareness",
|
|
198
|
+
"Connect insights to behavioral change",
|
|
199
|
+
],
|
|
200
|
+
"After significant therapeutic breakthrough, to anchor and propagate new understanding across life domains.",
|
|
201
|
+
),
|
|
202
|
+
(
|
|
203
|
+
"relapse_prevention",
|
|
204
|
+
"Relapse Prevention",
|
|
205
|
+
[
|
|
206
|
+
"Addiction recovery maintenance",
|
|
207
|
+
"Prevent regression after therapy",
|
|
208
|
+
"Maintain behavioral changes",
|
|
209
|
+
"Strengthen therapeutic gains",
|
|
210
|
+
],
|
|
211
|
+
"Post-treatment phase, building relapse prevention skills, strengthening recovery patterns.",
|
|
212
|
+
),
|
|
213
|
+
],
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
# Load educational recipes
|
|
217
|
+
self._load_domain_recipes(
|
|
218
|
+
"educational",
|
|
219
|
+
educational_patterns,
|
|
220
|
+
[
|
|
221
|
+
(
|
|
222
|
+
"conceptual_breakthrough",
|
|
223
|
+
"Conceptual Breakthrough",
|
|
224
|
+
[
|
|
225
|
+
"Mathematical concept breakthroughs",
|
|
226
|
+
"Scientific paradigm shifts",
|
|
227
|
+
"Language structure insights",
|
|
228
|
+
"Artistic technique breakthroughs",
|
|
229
|
+
],
|
|
230
|
+
"Facilitating 'aha!' moments, paradigm shifts in understanding, sudden insight into complex concepts.",
|
|
231
|
+
),
|
|
232
|
+
(
|
|
233
|
+
"competency_development",
|
|
234
|
+
"Competency Development",
|
|
235
|
+
[
|
|
236
|
+
"Sustained learning processes",
|
|
237
|
+
"Professional skill development",
|
|
238
|
+
"Complex skill acquisition",
|
|
239
|
+
"Career-long competency building",
|
|
240
|
+
],
|
|
241
|
+
"Long-term skill building, step-by-step mastery progression, comprehensive competency development.",
|
|
242
|
+
),
|
|
243
|
+
(
|
|
244
|
+
"knowledge_spiral",
|
|
245
|
+
"Knowledge Spiral",
|
|
246
|
+
[
|
|
247
|
+
"Iterative knowledge deepening cycles",
|
|
248
|
+
"Research and scholarly inquiry",
|
|
249
|
+
"Progressive understanding development",
|
|
250
|
+
"Cumulative learning trajectories",
|
|
251
|
+
],
|
|
252
|
+
"Building knowledge over time, spiral curriculum design, regenerative learning cycles.",
|
|
253
|
+
),
|
|
254
|
+
(
|
|
255
|
+
"collaborative_learning",
|
|
256
|
+
"Collaborative Learning",
|
|
257
|
+
[
|
|
258
|
+
"Group project work",
|
|
259
|
+
"Peer tutoring",
|
|
260
|
+
"Learning communities",
|
|
261
|
+
"Collaborative knowledge construction",
|
|
262
|
+
],
|
|
263
|
+
"Peer learning contexts, group work, social learning environments.",
|
|
264
|
+
),
|
|
265
|
+
(
|
|
266
|
+
"practice_mastery",
|
|
267
|
+
"Practice Mastery",
|
|
268
|
+
[
|
|
269
|
+
"Deliberate practice routines",
|
|
270
|
+
"Skill refinement",
|
|
271
|
+
"Performance improvement cycles",
|
|
272
|
+
"Expertise development",
|
|
273
|
+
],
|
|
274
|
+
"Focused practice sessions, skill refinement work, performance optimization.",
|
|
275
|
+
),
|
|
276
|
+
],
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
# Load organizational recipes
|
|
280
|
+
self._load_domain_recipes(
|
|
281
|
+
"organizational",
|
|
282
|
+
organizational_patterns,
|
|
283
|
+
[
|
|
284
|
+
(
|
|
285
|
+
"crisis_management",
|
|
286
|
+
"Crisis Management",
|
|
287
|
+
[
|
|
288
|
+
"Market disruption response",
|
|
289
|
+
"Leadership transition crisis",
|
|
290
|
+
"Operational emergency management",
|
|
291
|
+
"Reputation crisis containment",
|
|
292
|
+
],
|
|
293
|
+
"Immediate organizational crisis, emergency institutional response, acute disruption requiring rapid coordination.",
|
|
294
|
+
),
|
|
295
|
+
(
|
|
296
|
+
"team_formation",
|
|
297
|
+
"Team Formation",
|
|
298
|
+
[
|
|
299
|
+
"New team assembly",
|
|
300
|
+
"Cross-functional project initiation",
|
|
301
|
+
"Department reorganization",
|
|
302
|
+
"Merger integration",
|
|
303
|
+
],
|
|
304
|
+
"Building new teams, establishing group coherence, creating high-performing collaborative units.",
|
|
305
|
+
),
|
|
306
|
+
(
|
|
307
|
+
"strategic_planning",
|
|
308
|
+
"Strategic Planning",
|
|
309
|
+
[
|
|
310
|
+
"Comprehensive strategic planning",
|
|
311
|
+
"Vision development",
|
|
312
|
+
"Major transformation initiatives",
|
|
313
|
+
"Long-term change management",
|
|
314
|
+
],
|
|
315
|
+
"Strategic planning processes, long-term organizational transformation, vision-driven institutional evolution.",
|
|
316
|
+
),
|
|
317
|
+
(
|
|
318
|
+
"innovation_cycle",
|
|
319
|
+
"Innovation Cycle",
|
|
320
|
+
[
|
|
321
|
+
"Innovation programs",
|
|
322
|
+
"R&D project cycles",
|
|
323
|
+
"Product development sprints",
|
|
324
|
+
"Process innovation",
|
|
325
|
+
],
|
|
326
|
+
"Innovation projects from ideation through implementation, systematic innovation programs.",
|
|
327
|
+
),
|
|
328
|
+
(
|
|
329
|
+
"organizational_transformation",
|
|
330
|
+
"Organizational Transformation",
|
|
331
|
+
[
|
|
332
|
+
"Major restructuring",
|
|
333
|
+
"Culture transformation",
|
|
334
|
+
"Digital transformation",
|
|
335
|
+
"Business model evolution",
|
|
336
|
+
],
|
|
337
|
+
"Comprehensive institutional change, transforming organizational culture and structure, fundamental business model shifts.",
|
|
338
|
+
),
|
|
339
|
+
(
|
|
340
|
+
"change_resistance_resolution",
|
|
341
|
+
"Change Resistance Resolution",
|
|
342
|
+
[
|
|
343
|
+
"Overcoming resistance",
|
|
344
|
+
"Addressing opposition",
|
|
345
|
+
"Building change adoption",
|
|
346
|
+
"Managing transition conflicts",
|
|
347
|
+
],
|
|
348
|
+
"High resistance to organizational change, need to transform opposition into engagement.",
|
|
349
|
+
),
|
|
350
|
+
],
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
# Load creative recipes
|
|
354
|
+
self._load_domain_recipes(
|
|
355
|
+
"creative",
|
|
356
|
+
creative_patterns,
|
|
357
|
+
[
|
|
358
|
+
(
|
|
359
|
+
"artistic_creation",
|
|
360
|
+
"Artistic Creation",
|
|
361
|
+
[
|
|
362
|
+
"Painting/sculpture creation",
|
|
363
|
+
"Musical composition",
|
|
364
|
+
"Novel/screenplay writing",
|
|
365
|
+
"Choreography",
|
|
366
|
+
"Architectural design",
|
|
367
|
+
],
|
|
368
|
+
"Complete artistic projects, major creative works requiring full creative cycle from impulse through consolidation.",
|
|
369
|
+
),
|
|
370
|
+
(
|
|
371
|
+
"design_thinking",
|
|
372
|
+
"Design Thinking",
|
|
373
|
+
[
|
|
374
|
+
"Product design",
|
|
375
|
+
"Service design",
|
|
376
|
+
"UX design",
|
|
377
|
+
"Human-centered innovation",
|
|
378
|
+
"Design sprints",
|
|
379
|
+
],
|
|
380
|
+
"Design thinking processes, human-centered problem solving, empathy-driven innovation.",
|
|
381
|
+
),
|
|
382
|
+
(
|
|
383
|
+
"innovation_cycle",
|
|
384
|
+
"Innovation Cycle",
|
|
385
|
+
[
|
|
386
|
+
"Continuous innovation programs",
|
|
387
|
+
"Product pipelines",
|
|
388
|
+
"Creative R&D cycles",
|
|
389
|
+
"Innovation portfolio management",
|
|
390
|
+
],
|
|
391
|
+
"Sustained innovation work, regenerative innovation capability building, ongoing creative renewal.",
|
|
392
|
+
),
|
|
393
|
+
(
|
|
394
|
+
"creative_flow",
|
|
395
|
+
"Creative Flow",
|
|
396
|
+
[
|
|
397
|
+
"Maintaining creative momentum",
|
|
398
|
+
"Flow state cultivation",
|
|
399
|
+
"Sustained artistic practice",
|
|
400
|
+
"Creative productivity optimization",
|
|
401
|
+
],
|
|
402
|
+
"Developing sustained creative practice, maintaining flow states, building creative momentum.",
|
|
403
|
+
),
|
|
404
|
+
(
|
|
405
|
+
"creative_block_resolution",
|
|
406
|
+
"Creative Block Resolution",
|
|
407
|
+
[
|
|
408
|
+
"Overcoming writer's block",
|
|
409
|
+
"Resolving stagnation",
|
|
410
|
+
"Reinvigorating work",
|
|
411
|
+
"Breaking through plateaus",
|
|
412
|
+
],
|
|
413
|
+
"Stuck in creative process, experiencing creative block, need breakthrough to restart creative flow.",
|
|
414
|
+
),
|
|
415
|
+
],
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
def _load_domain_recipes(
|
|
419
|
+
self, domain: str, module: Any, recipe_specs: List[tuple]
|
|
420
|
+
) -> None:
|
|
421
|
+
"""Load recipes for a specific domain.
|
|
422
|
+
|
|
423
|
+
Parameters
|
|
424
|
+
----------
|
|
425
|
+
domain : str
|
|
426
|
+
Domain name (therapeutic, educational, organizational, creative)
|
|
427
|
+
module : module
|
|
428
|
+
Python module containing pattern functions
|
|
429
|
+
recipe_specs : List[tuple]
|
|
430
|
+
List of (function_suffix, display_name, use_cases, when_to_use) tuples
|
|
431
|
+
"""
|
|
432
|
+
if domain not in self._recipes:
|
|
433
|
+
self._recipes[domain] = {}
|
|
434
|
+
|
|
435
|
+
for spec in recipe_specs:
|
|
436
|
+
func_suffix, display_name, use_cases, when_to_use = spec
|
|
437
|
+
|
|
438
|
+
# Get sequence function
|
|
439
|
+
func_name = f"get_{func_suffix}_sequence"
|
|
440
|
+
if not hasattr(module, func_name):
|
|
441
|
+
continue
|
|
442
|
+
|
|
443
|
+
func = getattr(module, func_name)
|
|
444
|
+
sequence = func()
|
|
445
|
+
|
|
446
|
+
# Validate and get health metrics
|
|
447
|
+
result = validate_sequence_with_health(sequence)
|
|
448
|
+
if not result.passed:
|
|
449
|
+
continue
|
|
450
|
+
|
|
451
|
+
# Create recipe
|
|
452
|
+
recipe = CookbookRecipe(
|
|
453
|
+
name=display_name,
|
|
454
|
+
domain=domain,
|
|
455
|
+
sequence=sequence,
|
|
456
|
+
health_metrics=result.health_metrics,
|
|
457
|
+
use_cases=use_cases,
|
|
458
|
+
when_to_use=when_to_use,
|
|
459
|
+
structural_flow=[], # Could be extracted from docstring
|
|
460
|
+
key_insights=[], # Could be extracted from docstring
|
|
461
|
+
variations=[], # Future enhancement
|
|
462
|
+
pattern_type=result.health_metrics.dominant_pattern,
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
self._recipes[domain][func_suffix] = recipe
|
|
466
|
+
|
|
467
|
+
def get_recipe(self, domain: str, use_case: str) -> CookbookRecipe:
|
|
468
|
+
"""Get a specific recipe by domain and use case identifier.
|
|
469
|
+
|
|
470
|
+
Parameters
|
|
471
|
+
----------
|
|
472
|
+
domain : str
|
|
473
|
+
Domain name: "therapeutic", "educational", "organizational", "creative"
|
|
474
|
+
use_case : str
|
|
475
|
+
Use case identifier (e.g., "crisis_intervention", "team_formation")
|
|
476
|
+
|
|
477
|
+
Returns
|
|
478
|
+
-------
|
|
479
|
+
CookbookRecipe
|
|
480
|
+
The requested recipe with full context and metrics
|
|
481
|
+
|
|
482
|
+
Raises
|
|
483
|
+
------
|
|
484
|
+
KeyError
|
|
485
|
+
If domain or use_case not found
|
|
486
|
+
|
|
487
|
+
Examples
|
|
488
|
+
--------
|
|
489
|
+
>>> cookbook = TNFRCookbook()
|
|
490
|
+
>>> recipe = cookbook.get_recipe("therapeutic", "crisis_intervention")
|
|
491
|
+
>>> print(recipe.name)
|
|
492
|
+
Crisis Intervention
|
|
493
|
+
"""
|
|
494
|
+
if domain not in self._recipes:
|
|
495
|
+
raise KeyError(
|
|
496
|
+
f"Domain '{domain}' not found. Available: {list(self._recipes.keys())}"
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
if use_case not in self._recipes[domain]:
|
|
500
|
+
raise KeyError(
|
|
501
|
+
f"Use case '{use_case}' not found in '{domain}'. "
|
|
502
|
+
f"Available: {list(self._recipes[domain].keys())}"
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
return self._recipes[domain][use_case]
|
|
506
|
+
|
|
507
|
+
def list_recipes(
|
|
508
|
+
self,
|
|
509
|
+
domain: Optional[str] = None,
|
|
510
|
+
min_health: float = 0.0,
|
|
511
|
+
max_length: Optional[int] = None,
|
|
512
|
+
pattern_type: Optional[str] = None,
|
|
513
|
+
) -> List[CookbookRecipe]:
|
|
514
|
+
"""List recipes with optional filtering.
|
|
515
|
+
|
|
516
|
+
Parameters
|
|
517
|
+
----------
|
|
518
|
+
domain : str, optional
|
|
519
|
+
Filter by domain (therapeutic, educational, organizational, creative)
|
|
520
|
+
min_health : float, default=0.0
|
|
521
|
+
Minimum health score threshold
|
|
522
|
+
max_length : int, optional
|
|
523
|
+
Maximum sequence length
|
|
524
|
+
pattern_type : str, optional
|
|
525
|
+
Filter by pattern type (activation, therapeutic, regenerative, etc.)
|
|
526
|
+
|
|
527
|
+
Returns
|
|
528
|
+
-------
|
|
529
|
+
List[CookbookRecipe]
|
|
530
|
+
Filtered list of recipes
|
|
531
|
+
|
|
532
|
+
Examples
|
|
533
|
+
--------
|
|
534
|
+
>>> cookbook = TNFRCookbook()
|
|
535
|
+
>>> # Get all high-quality therapeutic recipes
|
|
536
|
+
>>> recipes = cookbook.list_recipes(domain="therapeutic", min_health=0.80)
|
|
537
|
+
>>> [r.name for r in recipes]
|
|
538
|
+
['Process Therapy', 'Regenerative Healing']
|
|
539
|
+
"""
|
|
540
|
+
results = []
|
|
541
|
+
|
|
542
|
+
domains = [domain] if domain else list(self._recipes.keys())
|
|
543
|
+
|
|
544
|
+
for dom in domains:
|
|
545
|
+
if dom not in self._recipes:
|
|
546
|
+
continue
|
|
547
|
+
|
|
548
|
+
for recipe in self._recipes[dom].values():
|
|
549
|
+
# Apply filters
|
|
550
|
+
if recipe.health_metrics.overall_health < min_health:
|
|
551
|
+
continue
|
|
552
|
+
|
|
553
|
+
if max_length and len(recipe.sequence) > max_length:
|
|
554
|
+
continue
|
|
555
|
+
|
|
556
|
+
if pattern_type and recipe.pattern_type != pattern_type:
|
|
557
|
+
continue
|
|
558
|
+
|
|
559
|
+
results.append(recipe)
|
|
560
|
+
|
|
561
|
+
# Sort by health score descending
|
|
562
|
+
results.sort(key=lambda r: r.health_metrics.overall_health, reverse=True)
|
|
563
|
+
|
|
564
|
+
return results
|
|
565
|
+
|
|
566
|
+
def search_recipes(self, query: str) -> List[CookbookRecipe]:
|
|
567
|
+
"""Search recipes by text query across names, use cases, and context.
|
|
568
|
+
|
|
569
|
+
Parameters
|
|
570
|
+
----------
|
|
571
|
+
query : str
|
|
572
|
+
Search query string (case-insensitive)
|
|
573
|
+
|
|
574
|
+
Returns
|
|
575
|
+
-------
|
|
576
|
+
List[CookbookRecipe]
|
|
577
|
+
Recipes matching the query, sorted by relevance
|
|
578
|
+
|
|
579
|
+
Examples
|
|
580
|
+
--------
|
|
581
|
+
>>> cookbook = TNFRCookbook()
|
|
582
|
+
>>> results = cookbook.search_recipes("crisis")
|
|
583
|
+
>>> [r.name for r in results]
|
|
584
|
+
['Crisis Intervention', 'Crisis Management']
|
|
585
|
+
"""
|
|
586
|
+
query_lower = query.lower()
|
|
587
|
+
results = []
|
|
588
|
+
|
|
589
|
+
for domain_recipes in self._recipes.values():
|
|
590
|
+
for recipe in domain_recipes.values():
|
|
591
|
+
# Search in name
|
|
592
|
+
if query_lower in recipe.name.lower():
|
|
593
|
+
results.append((recipe, 3)) # High relevance
|
|
594
|
+
continue
|
|
595
|
+
|
|
596
|
+
# Search in use cases
|
|
597
|
+
if any(query_lower in uc.lower() for uc in recipe.use_cases):
|
|
598
|
+
results.append((recipe, 2)) # Medium relevance
|
|
599
|
+
continue
|
|
600
|
+
|
|
601
|
+
# Search in when_to_use
|
|
602
|
+
if query_lower in recipe.when_to_use.lower():
|
|
603
|
+
results.append((recipe, 1)) # Low relevance
|
|
604
|
+
continue
|
|
605
|
+
|
|
606
|
+
# Sort by relevance then health
|
|
607
|
+
results.sort(
|
|
608
|
+
key=lambda x: (x[1], x[0].health_metrics.overall_health), reverse=True
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
return [r[0] for r in results]
|
|
612
|
+
|
|
613
|
+
def recommend_recipe(
|
|
614
|
+
self,
|
|
615
|
+
context: str,
|
|
616
|
+
constraints: Optional[Dict[str, Any]] = None,
|
|
617
|
+
) -> Optional[CookbookRecipe]:
|
|
618
|
+
"""Recommend a recipe based on context description and constraints.
|
|
619
|
+
|
|
620
|
+
Uses keyword matching and constraint satisfaction to find the best
|
|
621
|
+
matching recipe for the described context.
|
|
622
|
+
|
|
623
|
+
Parameters
|
|
624
|
+
----------
|
|
625
|
+
context : str
|
|
626
|
+
Description of the situation or need
|
|
627
|
+
constraints : Dict[str, Any], optional
|
|
628
|
+
Additional constraints:
|
|
629
|
+
- max_length: int - maximum sequence length
|
|
630
|
+
- min_health: float - minimum health score
|
|
631
|
+
- domain: str - restrict to specific domain
|
|
632
|
+
- prefer_pattern: str - preferred pattern type
|
|
633
|
+
|
|
634
|
+
Returns
|
|
635
|
+
-------
|
|
636
|
+
CookbookRecipe or None
|
|
637
|
+
Best matching recipe, or None if no good match found
|
|
638
|
+
|
|
639
|
+
Examples
|
|
640
|
+
--------
|
|
641
|
+
>>> cookbook = TNFRCookbook()
|
|
642
|
+
>>> recipe = cookbook.recommend_recipe(
|
|
643
|
+
... context="Need to help team work together on new project",
|
|
644
|
+
... constraints={"min_health": 0.80, "max_length": 10}
|
|
645
|
+
... )
|
|
646
|
+
>>> recipe.name
|
|
647
|
+
'Team Formation'
|
|
648
|
+
"""
|
|
649
|
+
constraints = constraints or {}
|
|
650
|
+
|
|
651
|
+
# Start with all recipes matching constraints
|
|
652
|
+
candidates = self.list_recipes(
|
|
653
|
+
domain=constraints.get("domain"),
|
|
654
|
+
min_health=constraints.get("min_health", 0.75),
|
|
655
|
+
max_length=constraints.get("max_length"),
|
|
656
|
+
pattern_type=constraints.get("prefer_pattern"),
|
|
657
|
+
)
|
|
658
|
+
|
|
659
|
+
if not candidates:
|
|
660
|
+
return None
|
|
661
|
+
|
|
662
|
+
# Extract keywords from context
|
|
663
|
+
context_lower = context.lower()
|
|
664
|
+
keywords = set(context_lower.split())
|
|
665
|
+
|
|
666
|
+
# Score each candidate by keyword overlap
|
|
667
|
+
scored_candidates = []
|
|
668
|
+
for recipe in candidates:
|
|
669
|
+
score = 0
|
|
670
|
+
|
|
671
|
+
# Check name overlap
|
|
672
|
+
name_words = set(recipe.name.lower().split())
|
|
673
|
+
score += len(keywords & name_words) * 5
|
|
674
|
+
|
|
675
|
+
# Check use cases overlap
|
|
676
|
+
for use_case in recipe.use_cases:
|
|
677
|
+
use_case_words = set(use_case.lower().split())
|
|
678
|
+
score += len(keywords & use_case_words) * 3
|
|
679
|
+
|
|
680
|
+
# Check when_to_use overlap
|
|
681
|
+
when_words = set(recipe.when_to_use.lower().split())
|
|
682
|
+
score += len(keywords & when_words) * 2
|
|
683
|
+
|
|
684
|
+
# Boost by health score
|
|
685
|
+
score += recipe.health_metrics.overall_health * 10
|
|
686
|
+
|
|
687
|
+
scored_candidates.append((recipe, score))
|
|
688
|
+
|
|
689
|
+
if not scored_candidates:
|
|
690
|
+
return None
|
|
691
|
+
|
|
692
|
+
# Return highest scoring recipe
|
|
693
|
+
scored_candidates.sort(key=lambda x: x[1], reverse=True)
|
|
694
|
+
return scored_candidates[0][0]
|
|
695
|
+
|
|
696
|
+
def get_all_domains(self) -> List[str]:
|
|
697
|
+
"""Get list of all available domains.
|
|
698
|
+
|
|
699
|
+
Returns
|
|
700
|
+
-------
|
|
701
|
+
List[str]
|
|
702
|
+
List of domain names
|
|
703
|
+
"""
|
|
704
|
+
return list(self._recipes.keys())
|
|
705
|
+
|
|
706
|
+
def get_domain_summary(self, domain: str) -> Dict[str, Any]:
|
|
707
|
+
"""Get summary statistics for a domain.
|
|
708
|
+
|
|
709
|
+
Parameters
|
|
710
|
+
----------
|
|
711
|
+
domain : str
|
|
712
|
+
Domain name
|
|
713
|
+
|
|
714
|
+
Returns
|
|
715
|
+
-------
|
|
716
|
+
Dict[str, Any]
|
|
717
|
+
Summary with recipe count, average health, patterns, etc.
|
|
718
|
+
"""
|
|
719
|
+
if domain not in self._recipes:
|
|
720
|
+
raise KeyError(f"Domain '{domain}' not found")
|
|
721
|
+
|
|
722
|
+
recipes = list(self._recipes[domain].values())
|
|
723
|
+
|
|
724
|
+
if not recipes:
|
|
725
|
+
return {
|
|
726
|
+
"domain": domain,
|
|
727
|
+
"recipe_count": 0,
|
|
728
|
+
"average_health": 0.0,
|
|
729
|
+
"health_range": (0.0, 0.0),
|
|
730
|
+
"patterns": [],
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
healths = [r.health_metrics.overall_health for r in recipes]
|
|
734
|
+
patterns = [r.pattern_type for r in recipes]
|
|
735
|
+
|
|
736
|
+
return {
|
|
737
|
+
"domain": domain,
|
|
738
|
+
"recipe_count": len(recipes),
|
|
739
|
+
"average_health": sum(healths) / len(healths),
|
|
740
|
+
"health_range": (min(healths), max(healths)),
|
|
741
|
+
"patterns": list(set(patterns)),
|
|
742
|
+
"recipes": [r.name for r in recipes],
|
|
743
|
+
}
|