cogant.translate
The cogant.translate package is the semantic-mapping engine: it takes the typed program graph produced by cogant.graph, applies a priority-ordered rule set, runs a bounded fixpoint loop, and emits a set of SemanticMapping records annotated with MappingKind (HIDDEN_STATE / OBSERVATION / ACTION / POLICY / CONSTRAINT / ...) and a confidence score.
Package
cogant.translate
Translation module for converting program graphs to semantic concepts.
ActionRule
Bases: TranslationRule
Maps setter/mutator functions to action modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80)
alongside PolicyRule, ContextRule, OrchestratorRule
and CircuitBreakerRule. Rationale: action semantics are
slightly less specific than PreferenceRule/TestAssertionRule
(0.85) because CRUD verbs are the most overloaded lexical
category in real codebases. The edge-based fallback
writes_only >= 2 was added (commit e1eb463) to recover
recall on functional codebases where writes are named
apply/reduce rather than set/update.
TODO(calibration): sweep the >=2 writes threshold in
{1, 2, 3} on the 20-repo corpus.
Source code in py/cogant/translate/rules/semantic.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create action mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for action. |
Source code in py/cogant/translate/rules/semantic.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
explain(node, graph, query)
Explain whether this node performs an action.
Mirrors the :meth:matches decision by checking for action
keywords in the node name and counting outgoing WRITES/MUTATES
edges. The rule fires when either (a) the name contains an
action keyword, or (b) at least 1 outgoing WRITES/MUTATES edge
exists (the functional-codebase recall threshold).
Source code in py/cogant/translate/rules/semantic.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
matches(graph, query)
Find functions/methods that mutate state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched action functions/methods. |
Source code in py/cogant/translate/rules/semantic.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
to_gnn_role()
Return the GNN role string for action mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
544 545 546 547 548 549 550 | |
CircuitBreakerRule
Bases: TranslationRule
Maps circuit breaker patterns to circuit-breaker modality.
Detects functions/classes that contain both a GUARDS edge and a retry/fallback pattern (name contains retry/fallback/circuit/breaker keywords or has metadata indicating retry logic).
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80),
tied with ActionRule/PolicyRule/ContextRule/
OrchestratorRule. Rationale: the combined signal of
GUARDS edge + retry keyword (or metadata hit) is much
stronger than the keyword-only RetryPatternRule (0.70),
so CircuitBreakerRule correctly wins on overlapping
fragments. The composite requirement keeps false positives
low — a function named retry_helper alone won't fire
without a GUARDS edge.
Source code in py/cogant/translate/rules/resilience.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create circuit-breaker mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for circuit breaker. |
Source code in py/cogant/translate/rules/resilience.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
matches(graph, query)
Find nodes with GUARDS edges and retry/fallback indicators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched circuit breaker nodes. |
Source code in py/cogant/translate/rules/resilience.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
ConfidenceModel
Computes and manages confidence scores for semantic mappings.
Combines evidence count, diversity, parser certainty, and conflict penalties to produce confidence tiers and scores.
Source code in py/cogant/translate/confidence.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
__init__()
Initialize the confidence model.
Source code in py/cogant/translate/confidence.py
263 264 265 | |
clear_log()
Clear the scoring log.
Source code in py/cogant/translate/confidence.py
583 584 585 | |
compute(mapping)
Convenience alias for compute_confidence_score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to score. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Confidence score between 0.0 and 1.0. |
Source code in py/cogant/translate/confidence.py
267 268 269 270 271 272 273 274 275 276 | |
compute_confidence_score(mapping)
Compute overall confidence score from evidence and metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to score. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Confidence score between 0.0 and 1.0. |
Source code in py/cogant/translate/confidence.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
detect_conflicts(mapping)
Detect and score conflicts in evidence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to check. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
List of conflict penalty scores. |
Source code in py/cogant/translate/confidence.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
determine_confidence_tier(mapping, score=None)
Determine confidence tier based on evidence sources and score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to tier. |
required |
score
|
float | None
|
Optional precomputed confidence score. |
None
|
Returns:
| Type | Description |
|---|---|
ConfidenceTier
|
ConfidenceTier for the mapping. |
Source code in py/cogant/translate/confidence.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
get_conflicted_mappings(mappings)
Find mappings with detected conflicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
list[SemanticMapping]
|
List of mappings. |
required |
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of mappings with conflict penalties. |
Source code in py/cogant/translate/confidence.py
545 546 547 548 549 550 551 552 553 554 555 556 557 | |
get_high_confidence_mappings(mappings, threshold=0.7)
Filter mappings by minimum confidence score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
list[SemanticMapping]
|
List of mappings. |
required |
threshold
|
float
|
Minimum confidence threshold. Default 0.7 is a
principled "trust without review" bar — safely above
|
0.7
|
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
Filtered list of high-confidence mappings. |
Source code in py/cogant/translate/confidence.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
get_low_confidence_mappings(mappings, threshold=0.6)
Find mappings below confidence threshold that may need review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
list[SemanticMapping]
|
List of mappings. |
required |
threshold
|
float
|
Maximum confidence threshold. Default 0.6 is a
principled "needs reviewer attention" bar — halfway
between |
0.6
|
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
Filtered list of low-confidence mappings. |
Source code in py/cogant/translate/confidence.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | |
get_scoring_report()
Generate a report of confidence scoring.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with scoring statistics. |
Source code in py/cogant/translate/confidence.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
score_batch(mappings)
Update confidence for a batch of mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
list[SemanticMapping]
|
List of mappings to score. |
required |
Source code in py/cogant/translate/confidence.py
492 493 494 495 496 497 498 499 | |
score_evidence_diversity(mapping)
Compute diversity score of evidence sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping with provenance. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Diversity score between 0.0 and 1.0. |
Source code in py/cogant/translate/confidence.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
update_mapping_confidence(mapping)
Update all confidence fields of a mapping in-place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to update. |
required |
Source code in py/cogant/translate/confidence.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
ConfigRule
Bases: TranslationRule
Maps configuration files and structures to context priors.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.90). Top band (0.90) —
the highest confidence score in the entire translation rule
family. Rationale: ConfigRule fires only when the
upstream parser has already classified a node as
NodeKind.CONFIGURATION (yaml/toml/ini/json config files,
module-level CONFIG = {...} dicts, Settings subclasses).
That classification is itself strongly evidenced, so the
confidence stacks: parser_certainty 0.95 (highest) plus
confidence 0.90 makes this rule effectively unbeatable by
heuristic rules, which is correct — explicit config is
ground truth for context. TODO(calibration): confirm that
NodeKind.CONFIGURATION extraction has <5% false-positive
rate on the 20-repo corpus.
Source code in py/cogant/translate/rules/control.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create context mapping for configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for context. |
Source code in py/cogant/translate/rules/control.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
matches(graph, query)
Find configuration nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched configuration nodes. |
Source code in py/cogant/translate/rules/control.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
ContainmentRule
Bases: TranslationRule
Analyzes methods within classes to extract observation vs action vs policy roles.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.75). Mid band (0.75).
Stronger than pure-structural InheritanceRule (0.70)
because it aggregates lexical evidence across 5+ methods
(majority-vote classification), but weaker than per-function
ObservationRule/ActionRule keyword hits (0.80+)
because the class-level aggregate can mask mixed-role classes.
Method-count threshold = 5 (see matches). TODO(calibration):
sweep {3, 5, 8} method thresholds and the
max(actions, observations) tie-breaking rule.
Source code in py/cogant/translate/rules/structural.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create containment analysis mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping summarizing method roles. |
Source code in py/cogant/translate/rules/structural.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
matches(graph, query)
Find classes with multiple methods for detailed analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched containment patterns. |
Source code in py/cogant/translate/rules/structural.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
ContextRule
Bases: TranslationRule
Maps configuration and parameter classes to context modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80),
tied with ActionRule/PolicyRule. Rationale: context
keywords config/settings/env/options/params
are specific but less strong than a validate/test_
prefix (which get 0.85); they correlate well with
configuration roles but also occasionally appear in
orchestrators. Note: the dedicated ConfigRule (control.py,
confidence 0.90) supersedes this rule when config is in
the name — this rule provides the broader
settings/params/env fallback.
Source code in py/cogant/translate/rules/semantic.py
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create context mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for context. |
Source code in py/cogant/translate/rules/semantic.py
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 | |
matches(graph, query)
Find context/configuration classes and functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched context nodes. |
Source code in py/cogant/translate/rules/semantic.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 | |
to_gnn_role()
Return the GNN role string for context mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
971 972 973 974 975 976 977 | |
DataPipelineRule
Bases: TranslationRule
Maps data transformation chains to data-flow modality.
Detects functions that read from one source, transform, and write to another. Pattern: node with both READS and WRITES edges where read sources differ from write targets.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.75). Mid band (0.75). The
"reads-from-A, writes-to-B (A≠B)" pattern is a strong
structural cue for data flow, but we keep it at 0.75 rather
than 0.80+ because edge-level precision is lower than
name-level precision (tree-sitter occasionally over-reports
READS on attribute-chain accesses). TODO(calibration):
measure false-positive rate on the 20-repo corpus; if <5%,
promote to 0.80.
Source code in py/cogant/translate/rules/structural.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create data-flow mapping for data pipeline node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for data flow. |
Source code in py/cogant/translate/rules/structural.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | |
matches(graph, query)
Find functions with both read and write edges to different targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched data pipeline nodes. |
Source code in py/cogant/translate/rules/structural.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
ErrorBoundaryRule
Bases: TranslationRule
Maps error handling boundaries to error-handling modality.
Detects functions/methods with CATCHES or THROWS edges, representing error boundaries in the system.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.70). Bottom band (0.70).
Rationale: CATCHES/THROWS edges are directly extracted from
try/except / raise Python constructs (high structural
precision) but the semantic meaning — "this is an error
boundary worth modeling" — is weak because most non-trivial
functions have at least one try/except for cleanup. Parser
certainty 0.75 (below the 0.80 norm) reflects the fact that
tree-sitter does not resolve exception-type hierarchies.
Source code in py/cogant/translate/rules/resilience.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create error-handling mapping for error boundary node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for error handling. |
Source code in py/cogant/translate/rules/resilience.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
matches(graph, query)
Find nodes with CATCHES or THROWS edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched error boundary nodes. |
Source code in py/cogant/translate/rules/resilience.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
EventBusRule
Bases: TranslationRule
Maps event/subscription systems to observation-action coupling.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.75). Mid band (0.75),
tied with MutatingSubsystemRule/ContainmentRule/
DataPipelineRule. Rationale: event-bus detection depends
on the upstream parser recognizing EVENT node kinds,
which is only done for patterns the tree-sitter queries
understand (decorator-driven pub/sub). Confidence tier is
set to STATIC_PLUS_RUNTIME (not STATIC_ONLY) as a hint that
dynamic trace corroboration is especially valuable for
event-driven code. TODO(calibration): measure EVENT-node
coverage across the 20-repo corpus.
Source code in py/cogant/translate/rules/behavioral.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create observation-action coupling mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for event bus. |
Source code in py/cogant/translate/rules/behavioral.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
matches(graph, query)
Find event bus and subscription patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched event bus patterns. |
Source code in py/cogant/translate/rules/behavioral.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
FeatureFlagRule
Bases: TranslationRule
Maps feature flags to latent context selectors.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.85). High band (0.85),
tied with PreferenceRule/TestAssertionRule and the
keyword branch of ObservationRule. Rationale: feature
flags are specific but slightly less unambiguous than raw
configuration (which gets 0.90); some "feature flag"
patterns are actually dynamic toggles rather than static
context selectors. The rule relies on upstream
NodeKind.FEATURE_FLAG classification.
Source code in py/cogant/translate/rules/control.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create context selector mapping for feature flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for feature flag. |
Source code in py/cogant/translate/rules/control.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
matches(graph, query)
Find feature flag nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched feature flag nodes. |
Source code in py/cogant/translate/rules/control.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
InheritanceRule
Bases: TranslationRule
Maps class inheritance to inform semantic roles via base class hierarchy.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.7). Bottom band (0.70)
alongside ReadOnlyInputRule and the resilience rules.
Rationale: inheritance is a structural hint, not evidence —
a subclass of AbstractHandler might be a controller or a
test double or a stub. We use the lexical shortcut "name
starts with Abstract/Base => POLICY" because Python
convention strongly correlates those prefixes with abstract
base classes (PEP 3119). Parser certainty 0.75 is slightly
below the 0.80 edge-precision band because tree-sitter has
known gaps on multi-base metaclass hierarchies.
TODO(calibration): measure tier-disagreement rate vs.
behavioral rules on the 20-repo corpus; if inheritance
routinely gets overruled, demote to an "explanation only"
rule that never writes a mapping.
Source code in py/cogant/translate/rules/structural.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create semantic mapping based on inheritance pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for inheritance-informed role. |
Source code in py/cogant/translate/rules/structural.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
matches(graph, query)
Find classes with inheritance relationships.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched inheritance patterns. |
Source code in py/cogant/translate/rules/structural.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
MutatingSubsystemRule
Bases: TranslationRule
Maps objects with frequent internal mutations to hidden-state modality.
Rule priority (audit 2026-04-09):
:meth:priority returns 1 (see override below) so
HIDDEN_STATE wins class-level overlaps against aggregate
POLICY from :class:InheritanceRule at default priority 0
when both fire on the same CLASS node. The confidence score
remains mid band (0.75): a class touched by any
WRITES/MUTATES edge is a mild structural cue for hidden
state, stronger than a pure read-only module (0.70) but weaker
than a lexical action match (0.80) or a configuration hit
(0.85+). The mutation-count threshold is deliberately >=1.
TODO(calibration): sweep the threshold in {1, 2, 3} on the
20-repo corpus; a higher floor would likely raise precision at
the cost of recall on under-instrumented fixtures.
Source code in py/cogant/translate/rules/structural.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
priority
property
Above class-level aggregate rules (e.g. ContainmentRule at 0).
ContainmentRule can emit a class-scoped mapping that overlaps the
same CLASS node as this rule. Equal (priority, confidence)
ties previously dropped the hidden-state mapping lexicographically.
Hidden-state evidence from WRITES/MUTATES edges should win that tie.
apply(graph, match)
Create hidden-state mapping for mutating subsystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for hidden-state. |
Source code in py/cogant/translate/rules/structural.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
explain(node, graph, query)
Explain whether this class is a hidden-state / mutating subsystem.
The rule only applies to CLASS nodes and fires when the class
has at least one edge of kind WRITES or MUTATES touching
it (either as source or as target). This mirrors the match logic
in :meth:matches so the explain report stays honest.
Source code in py/cogant/translate/rules/structural.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
matches(graph, query)
Find objects/classes with high mutation frequency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched class/object nodes. |
Source code in py/cogant/translate/rules/structural.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
ObservationRule
Bases: TranslationRule
Maps getter/query functions and read-only methods to observation modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.85) on keyword match, or
(0, 0.70) on the edge-based read-only fallback.
- Keyword band: high band (0.85), same as
PreferenceRule and TestAssertionRule, tied second
only to ConfigRule (0.90). Rationale: lexical matches
on get_/read_/fetch_ prefixes carry strong
prior probability of observation semantics based on PEP 8
naming convention.
- Fallback band: bottom band (0.70). The structural "reads,
no writes" signal alone is weaker because pure-read helpers
are also ubiquitous in private utility code.
The bimodal confidence lets conflict resolution automatically
prefer keyword-driven observations over structural ones.
TODO(calibration): empirically validate the 0.85/0.70 split
against a hand-labeled observation fixture.
Source code in py/cogant/translate/rules/semantic.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create observation mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for observation. |
Source code in py/cogant/translate/rules/semantic.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
explain(node, graph, query)
Explain whether this node is an observation.
Walks the same decision path used by :meth:matches, but
collects concrete evidence snippets (keyword matches and
READS/WRITES edge counts) into a :class:RuleExplanation so the
cogant explain CLI can render a justification report.
Source code in py/cogant/translate/rules/semantic.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
matches(graph, query)
Find functions/methods that observe state without mutation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched observation functions/methods. |
Source code in py/cogant/translate/rules/semantic.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
to_gnn_role()
Return the GNN role string for observation mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
332 333 334 335 336 337 338 | |
OrchestratorRule
Bases: TranslationRule
Maps schedulers and controllers to policy/action structure.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80),
tied with ActionRule/PolicyRule/ContextRule/
CircuitBreakerRule. Rationale: high call fan-out is a
reliable structural signal for orchestration but not
unambiguous — utility modules can also have many calls.
Call-count threshold = 3 (see matches): below 3, the
pattern is indistinguishable from simple helpers.
TODO(calibration): sweep {2, 3, 5, 8} on the 20-repo corpus.
Source code in py/cogant/translate/rules/behavioral.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create orchestration mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for orchestration. |
Source code in py/cogant/translate/rules/behavioral.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
matches(graph, query)
Find orchestrator patterns (high out-degree controllers).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched orchestrator nodes. |
Source code in py/cogant/translate/rules/behavioral.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
PolicyRule
Bases: TranslationRule
Maps controllers, handlers, and routers to policy modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80),
tied with ActionRule, ContextRule, OrchestratorRule,
CircuitBreakerRule. Rationale: controller/handler/router
vocabulary is a strong web-framework signal (Flask, Django,
FastAPI) but carries real ambiguity — "handler" also appears
in action and retry contexts. Confidence tie-breaking between
policy and action on handle/dispatch is delegated to
per-match context. TODO(calibration): measure the
policy↔action collision rate on handle/dispatch in
the 20-repo corpus.
Source code in py/cogant/translate/rules/semantic.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create policy mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for policy. |
Source code in py/cogant/translate/rules/semantic.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | |
matches(graph, query)
Find classes and functions that implement policy/control logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched policy nodes. |
Source code in py/cogant/translate/rules/semantic.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | |
to_gnn_role()
Return the GNN role string for policy mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
710 711 712 713 714 715 716 | |
PreferenceRule
Bases: TranslationRule
Maps validators and test functions to preference/constraint modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.85). High band (0.85), tied
with TestAssertionRule and the keyword branch of
ObservationRule. Rationale: validate/check/
Validator/test_ are exceptionally strong lexical
signals — there is essentially no non-constraint use of
test_ prefixes in well-formed Python, and PEP 8 +
pytest/unittest conventions anchor the other patterns.
Parser certainty 0.90 is the highest in the rule family
because name-only matching doesn't depend on edge extraction.
Source code in py/cogant/translate/rules/semantic.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create preference/constraint mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for constraint. |
Source code in py/cogant/translate/rules/semantic.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
matches(graph, query)
Find validation and test functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched preference/constraint nodes. |
Source code in py/cogant/translate/rules/semantic.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | |
to_gnn_role()
Return the GNN role string for preference/constraint mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
841 842 843 844 845 846 847 | |
ReadOnlyInputRule
Bases: TranslationRule
Maps modules with many read-only external inputs to observation modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.7) via the flat-priority=0 design
documented in :class:TranslationRule.priority, so conflict
resolution falls through to confidence_score = 0.7. This
places the rule in the bottom band (0.70) alongside
InheritanceRule, RetryPatternRule, ErrorBoundaryRule
and the ObservationRule lexical-fallback branch. Rationale:
module-level "all reads, no writes" is a weak structural signal
(modules nearly always expose some read API), so it should
cleanly lose to any function/method-level rule that also fires
on the same fragment. TODO(calibration): measure the
ReadOnlyInputRule→ObservationRule conflict-loss rate on the
20-repo corpus and promote to a dedicated priority tier only
if the loss rate exceeds ~20%.
Source code in py/cogant/translate/rules/structural.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create observation mapping for read-only module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for observation modality. |
Source code in py/cogant/translate/rules/structural.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
matches(graph, query)
Find modules with predominance of read operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched module nodes. |
Source code in py/cogant/translate/rules/structural.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
RetryPatternRule
Bases: TranslationRule
Maps retry/backoff/circuit breaker patterns to policy under uncertainty.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.70). Bottom band (0.70),
tied with ReadOnlyInputRule, InheritanceRule,
ErrorBoundaryRule, and the lexical fallback of
ObservationRule. Rationale: keyword matching alone is
a weak signal for retry logic — a function named
retry_count might be a counter, not a retry executor.
This rule intentionally loses to the stronger
CircuitBreakerRule (0.80) when both fire. Parser
certainty 0.70 is the lowest in the family because tree-
sitter pattern detection for retry decorators is
incomplete. TODO(calibration): promote to 0.80 if GUARDS
edge coverage improves in the parser.
Source code in py/cogant/translate/rules/resilience.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create policy mapping for retry pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for policy. |
Source code in py/cogant/translate/rules/resilience.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
matches(graph, query)
Find retry and circuit breaker patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched pattern nodes. |
Source code in py/cogant/translate/rules/resilience.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
ReviewManager
Manages human review of semantic mappings.
Accepts, rejects, edits, splits, and merges mappings while tracking all provenance and changes.
Source code in py/cogant/translate/review.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
__init__()
Initialize the review manager.
Source code in py/cogant/translate/review.py
16 17 18 19 | |
accept_mapping(mapping_id, reviewer, feedback=None)
Accept a mapping as valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping to accept. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
feedback
|
str | None
|
Optional review feedback. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False if mapping not found. |
Source code in py/cogant/translate/review.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
add_mapping(mapping)
Add a mapping for potential review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
Mapping to add. |
required |
Source code in py/cogant/translate/review.py
21 22 23 24 25 26 27 | |
edit_mapping(mapping_id, reviewer, updates)
Edit a mapping based on review feedback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping to edit. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
updates
|
dict[str, Any]
|
Dictionary of fields to update. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False if mapping not found. |
Source code in py/cogant/translate/review.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
export_reviewed_mappings()
Export all mappings that have been accepted or edited by reviewers.
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of reviewed and approved mappings. |
Source code in py/cogant/translate/review.py
312 313 314 315 316 317 318 | |
get_mapping_for_review(mapping_id)
Get a mapping for review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
Mapping if found, None otherwise. |
Source code in py/cogant/translate/review.py
237 238 239 240 241 242 243 244 245 246 | |
get_mappings_by_status(status)
Get all mappings with a specific status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
Status to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of mappings with that status. |
Source code in py/cogant/translate/review.py
248 249 250 251 252 253 254 255 256 257 | |
get_review_history()
Get the complete review history.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of review events. |
Source code in py/cogant/translate/review.py
304 305 306 307 308 309 310 | |
get_review_summary()
Get a summary of review status.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with review statistics. |
Source code in py/cogant/translate/review.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
get_unreviewed_mappings()
Get all mappings that haven't been reviewed.
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of unreviewed mappings. |
Source code in py/cogant/translate/review.py
259 260 261 262 263 264 265 | |
merge_mappings(mapping_ids, reviewer, merged_definition)
Merge multiple mappings into one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_ids
|
list[str]
|
IDs of mappings to merge. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
merged_definition
|
dict[str, Any]
|
Definition of merged mapping. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
ID of new merged mapping, or None if invalid. |
Source code in py/cogant/translate/review.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
reject_mapping(mapping_id, reviewer, reason)
Reject a mapping as invalid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping to reject. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
reason
|
str
|
Reason for rejection. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False if mapping not found. |
Source code in py/cogant/translate/review.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
split_mapping(mapping_id, reviewer, split_definitions)
Split a mapping into multiple mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping to split. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
split_definitions
|
list[dict[str, Any]]
|
List of definitions for new mappings. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of IDs of new mappings. |
Source code in py/cogant/translate/review.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
RuleExplanation
dataclass
Explanation of why a translation rule did or did not fire on a node.
Produced by :meth:TranslationRule.explain during the
cogant explain workflow. Each instance records a single
(rule, node) decision: the rule's name and priority, whether it
fired, a short human-readable reason, and the list of concrete
evidence snippets (edge kinds, keyword matches, qualified
identifiers) that backed the decision.
The dataclass is deliberately JSON-serialization friendly via
:meth:to_dict so the explain CLI can emit either a rich text
report or a machine-readable JSON blob without duplicating the
payload logic.
Attributes:
| Name | Type | Description |
|---|---|---|
rule_name |
str
|
Stable rule identifier ( |
priority |
int
|
Rule priority tier (higher fires first). |
fired |
bool
|
True when the rule actually produced a mapping for this node, False when it was considered but skipped. |
reason |
str
|
One-line explanation of the decision. |
evidence |
list[str]
|
Concrete evidence strings collected during matching
(e.g. |
mapping_kind |
str | None
|
Semantic kind the rule would have produced, or None when the rule did not fire. |
confidence |
float
|
Confidence score (0.0–1.0) if rule fired, 0.0 if not fired. |
contradictions |
list[str]
|
List of contradictory evidence or rule conflicts that might lower confidence in this mapping. |
Source code in py/cogant/translate/engine.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
to_dict()
Serialize to a plain JSON-ready dict.
Source code in py/cogant/translate/engine.py
60 61 62 | |
SingletonAccessRule
Bases: TranslationRule
Maps singleton/global state access to context modality.
Detects variables or classes that are read by many different modules (high in-degree of READS edges from diverse paths). Threshold: 3+ readers from different modules.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.65). Lowest band (0.65) —
the lowest confidence score in the entire rule family.
Rationale: "accessed by many modules" is a very weak signal
(logging facilities, common types, and enum constants all
trigger it), so this rule is explicitly the last to win in
any conflict. Thresholds: read_edges >= 3 and
len(reader_modules) >= 3. The module-diversity check
prevents the rule from firing on intra-module utilities.
TODO(calibration): if the false-positive rate on the
20-repo corpus exceeds 30%, raise the module-diversity
threshold to 5 or combine with a "not in typing/stdlib
whitelist" filter.
Source code in py/cogant/translate/rules/resilience.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create context mapping for singleton/global state node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for context. |
Source code in py/cogant/translate/rules/resilience.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
matches(graph, query)
Find nodes with high in-degree READS from diverse modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched singleton/global state nodes. |
Source code in py/cogant/translate/rules/resilience.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
TestAssertionRule
Bases: TranslationRule
Maps test assertions to preference/constraint modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.85). High band (0.85), tied
with PreferenceRule and the keyword branch of
ObservationRule. Rationale: a function with "test" in its
name plus at least one CALLS edge (proxy for assertion)
is one of the most reliable static signals in the entire
rule family — pytest/unittest conventions are nearly
universal. Parser certainty 0.95 is the highest in the
family because both the name match and the call extraction
are handled by the native Python AST with minimal ambiguity.
Source code in py/cogant/translate/rules/behavioral.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create constraint mapping from test assertions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for constraint. |
Source code in py/cogant/translate/rules/behavioral.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
matches(graph, query)
Find test nodes and assertion calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched test nodes. |
Source code in py/cogant/translate/rules/behavioral.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
TranslationEngine
Orchestrates translation of program graphs to semantic concepts.
Applies the registered translation rules with iterative rule
application plus an idempotent confirmation pass. Rules do not consume
prior mappings (TranslationRule.apply only receives the graph and
a single match), so a true semantic fixpoint is NOT performed: the
first pass produces every mapping the rules can produce, and the
second pass exists solely to confirm idempotence (no new mappings)
before conflict resolution. max_iterations bounds the loop as a
safety margin only. Resolves conflicts when multiple mappings target
overlapping node sets.
Source code in py/cogant/translate/engine.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
__init__(max_iterations=10)
Initialize the translation engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_iterations
|
int
|
Maximum rule-application passes (default 10). |
10
|
Rationale for default max_iterations=10:
Because rules do not consume prior mappings, the second pass
never produces new mappings; in practice the loop exits after
the first pass plus one idempotent confirmation pass (<=2
passes) on control-positive fixtures and typical corpora. 10
is a generous safety margin, not an expected iteration count.
See docs/evaluation/CALIBRATION.md.
Source code in py/cogant/translate/engine.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
explain()
Produce human-readable explanations of which rules fired and why.
Returns a list of formatted explanation strings describing the
translation decisions. Each string covers one (rule, node) pair
that was evaluated during the most recent :meth:translate call.
Empty list if no translation has been run yet.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of explanation strings (one per rule evaluation). |
Source code in py/cogant/translate/engine.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | |
get_convergence_info()
Get information about translation-pass convergence.
"Converged" here means the loop reached a pass that produced no new mappings (idempotent confirmation pass) — it does NOT mean a semantic fixpoint was computed, since rules do not consume prior mappings. The dict keys are kept stable for callers/tests.
Returns a dictionary with: - converged: Whether an idempotent (zero-new-mapping) pass was reached - iterations: Number of passes until idempotence (or max_iterations) - final_mapping_count: Number of mappings in final result
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with pass-convergence metadata. |
Source code in py/cogant/translate/engine.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
get_coverage_report(graph)
Report what percentage of graph nodes received at least one mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
The program graph that was translated. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with coverage statistics including total nodes, |
dict[str, Any]
|
covered nodes, uncovered node IDs, and coverage percentage. |
Source code in py/cogant/translate/engine.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
get_mapping(mapping_id)
Get a mapping by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping if found, None otherwise. |
Source code in py/cogant/translate/engine.py
659 660 661 662 663 664 665 666 667 668 | |
get_mappings_by_confidence(tier)
Get all mappings with a specific confidence tier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tier
|
ConfidenceTier
|
Confidence tier to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of mappings at that tier. |
Source code in py/cogant/translate/engine.py
645 646 647 648 649 650 651 652 653 654 655 656 657 | |
get_mappings_by_kind(kind)
Get all mappings of a specific kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
MappingKind
|
Kind of mapping to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of matching mappings. |
Source code in py/cogant/translate/engine.py
634 635 636 637 638 639 640 641 642 643 | |
get_match_log()
Get the match log.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of match events. |
Source code in py/cogant/translate/engine.py
686 687 688 689 690 691 692 | |
get_statistics()
Get statistics about translations.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with statistics. |
Source code in py/cogant/translate/engine.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
register_rule(rule)
Register a translation rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
TranslationRule
|
Rule to register. |
required |
Source code in py/cogant/translate/engine.py
244 245 246 247 248 249 250 | |
translate(graph, rule_filter=None)
Translate a program graph using iterative rule application.
Rules are applied in repeated passes until a pass produces no new
mappings or max_iterations is reached, whichever comes first.
Because rules do not consume prior mappings, this is single-pass
rule application followed by one idempotent confirmation pass
(the second pass re-runs the rules and is expected to add nothing)
— it is NOT a semantic fixpoint. After the loop exits, conflict
resolution picks a single winning mapping per node set using
priority then confidence as the tiebreaker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph to translate. Must have been built by
the graph stage; in particular, |
required |
rule_filter
|
list[str] | None
|
Optional list of rule names to apply. |
None
|
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of |
list[SemanticMapping]
|
resolution, in insertion order. May be empty if no rule |
list[SemanticMapping]
|
matched. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a registered rule raises an unhandled exception. The engine catches and logs per-rule errors but re-raises engine-level invariant violations. |
Example
engine = TranslationEngine() engine.register_rule(ObservationRule()) mappings = engine.translate(graph) all(hasattr(m.kind, "name") for m in mappings) True
Source code in py/cogant/translate/engine.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
translate_with_confidence(graph, rule_filter=None)
Translate and rescore all mappings using the ConfidenceModel.
Runs the standard iterative-pass translation, then applies the ConfidenceModel to update confidence scores, tiers, and conflict penalties on every resulting mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph to translate. |
required |
rule_filter
|
list[str] | None
|
Optional list of rule names to apply (None = all). |
None
|
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of semantic mappings with updated confidence scores. |
Source code in py/cogant/translate/engine.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
validate()
Validate SemanticMappings for internal consistency.
Checks all mappings in :attr:mappings for:
- Non-empty node IDs
- Valid confidence scores (0.0–1.0)
- Consistent mapping kinds
- No orphaned node references (node exists in graph)
Returns:
| Type | Description |
|---|---|
list[str]
|
List of validation issues (empty = valid). Each string |
list[str]
|
describes one inconsistency or violation. |
Source code in py/cogant/translate/engine.py
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | |
TranslationRule
Bases: ABC
Base class for translation rules.
Source code in py/cogant/translate/engine.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
mapping_kind
abstractmethod
property
Kind of semantic mapping produced.
name
abstractmethod
property
Name of this rule.
priority
property
Priority of this rule (higher = applied first). Default 0.
Rationale for default priority=0:
Most shipped rules keep the default 0 and are applied in
registration order within a single translation pass.
:class:~cogant.translate.rules.structural.MutatingSubsystemRule
overrides this property to return 1 so class-level hidden-state
evidence wins ties against overlapping class-scoped mappings from
aggregate rules at equal confidence. Aside from that exception,
conflict resolution between overlapping mappings falls through to
the (priority, confidence_score) lexicographic comparison in
:meth:TranslationEngine._resolve_conflicts. See
docs/evaluation/CALIBRATION.md for the full rule priority audit.
TODO(calibration): if the empirical conflict-loss rate on
real-world repos exceeds ~5%, broaden explicit priority tiers.
apply(graph, match)
abstractmethod
Apply rule to a matched pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern from matches(). |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping if successful, None otherwise. |
Source code in py/cogant/translate/engine.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
explain(node, graph, query)
Explain whether this rule would fire on node.
This is the default implementation used by the cogant explain
CLI subcommand. It re-runs :meth:matches and checks whether any
returned match references the target node's id. Subclasses that
can produce richer evidence (specific edge kinds, keyword hits,
metric values) should override this method.
The base implementation never raises: if :meth:matches blows
up, the returned :class:RuleExplanation has fired=False and
a reason that names the exception type so the CLI can surface it
instead of aborting the whole explain run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The target node whose role we want to justify. |
required |
graph
|
ProgramGraph
|
Program graph the rule is being evaluated against. |
required |
query
|
GraphQuery
|
Graph query engine bound to |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
RuleExplanation
|
class: |
Source code in py/cogant/translate/engine.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
matches(graph, query)
abstractmethod
Check if rule matches graph patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph to analyze. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched fragments, each with node/edge IDs. |
Source code in py/cogant/translate/engine.py
68 69 70 71 72 73 74 75 76 77 78 79 | |
Engine
The core orchestration: TranslationEngine.run() drives the fixpoint loop and the conflict-resolution pass; every rule exposes an .explain() method that returns a RuleExplanation (used by cogant explain).
cogant.translate.engine
Translation engine orchestrating rule application over program graphs.
RuleExplanation
dataclass
Explanation of why a translation rule did or did not fire on a node.
Produced by :meth:TranslationRule.explain during the
cogant explain workflow. Each instance records a single
(rule, node) decision: the rule's name and priority, whether it
fired, a short human-readable reason, and the list of concrete
evidence snippets (edge kinds, keyword matches, qualified
identifiers) that backed the decision.
The dataclass is deliberately JSON-serialization friendly via
:meth:to_dict so the explain CLI can emit either a rich text
report or a machine-readable JSON blob without duplicating the
payload logic.
Attributes:
| Name | Type | Description |
|---|---|---|
rule_name |
str
|
Stable rule identifier ( |
priority |
int
|
Rule priority tier (higher fires first). |
fired |
bool
|
True when the rule actually produced a mapping for this node, False when it was considered but skipped. |
reason |
str
|
One-line explanation of the decision. |
evidence |
list[str]
|
Concrete evidence strings collected during matching
(e.g. |
mapping_kind |
str | None
|
Semantic kind the rule would have produced, or None when the rule did not fire. |
confidence |
float
|
Confidence score (0.0–1.0) if rule fired, 0.0 if not fired. |
contradictions |
list[str]
|
List of contradictory evidence or rule conflicts that might lower confidence in this mapping. |
Source code in py/cogant/translate/engine.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
to_dict()
Serialize to a plain JSON-ready dict.
Source code in py/cogant/translate/engine.py
60 61 62 | |
TranslationEngine
Orchestrates translation of program graphs to semantic concepts.
Applies the registered translation rules with iterative rule
application plus an idempotent confirmation pass. Rules do not consume
prior mappings (TranslationRule.apply only receives the graph and
a single match), so a true semantic fixpoint is NOT performed: the
first pass produces every mapping the rules can produce, and the
second pass exists solely to confirm idempotence (no new mappings)
before conflict resolution. max_iterations bounds the loop as a
safety margin only. Resolves conflicts when multiple mappings target
overlapping node sets.
Source code in py/cogant/translate/engine.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
__init__(max_iterations=10)
Initialize the translation engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_iterations
|
int
|
Maximum rule-application passes (default 10). |
10
|
Rationale for default max_iterations=10:
Because rules do not consume prior mappings, the second pass
never produces new mappings; in practice the loop exits after
the first pass plus one idempotent confirmation pass (<=2
passes) on control-positive fixtures and typical corpora. 10
is a generous safety margin, not an expected iteration count.
See docs/evaluation/CALIBRATION.md.
Source code in py/cogant/translate/engine.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
explain()
Produce human-readable explanations of which rules fired and why.
Returns a list of formatted explanation strings describing the
translation decisions. Each string covers one (rule, node) pair
that was evaluated during the most recent :meth:translate call.
Empty list if no translation has been run yet.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of explanation strings (one per rule evaluation). |
Source code in py/cogant/translate/engine.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | |
get_convergence_info()
Get information about translation-pass convergence.
"Converged" here means the loop reached a pass that produced no new mappings (idempotent confirmation pass) — it does NOT mean a semantic fixpoint was computed, since rules do not consume prior mappings. The dict keys are kept stable for callers/tests.
Returns a dictionary with: - converged: Whether an idempotent (zero-new-mapping) pass was reached - iterations: Number of passes until idempotence (or max_iterations) - final_mapping_count: Number of mappings in final result
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with pass-convergence metadata. |
Source code in py/cogant/translate/engine.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
get_coverage_report(graph)
Report what percentage of graph nodes received at least one mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
The program graph that was translated. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with coverage statistics including total nodes, |
dict[str, Any]
|
covered nodes, uncovered node IDs, and coverage percentage. |
Source code in py/cogant/translate/engine.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
get_mapping(mapping_id)
Get a mapping by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping if found, None otherwise. |
Source code in py/cogant/translate/engine.py
659 660 661 662 663 664 665 666 667 668 | |
get_mappings_by_confidence(tier)
Get all mappings with a specific confidence tier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tier
|
ConfidenceTier
|
Confidence tier to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of mappings at that tier. |
Source code in py/cogant/translate/engine.py
645 646 647 648 649 650 651 652 653 654 655 656 657 | |
get_mappings_by_kind(kind)
Get all mappings of a specific kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
MappingKind
|
Kind of mapping to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of matching mappings. |
Source code in py/cogant/translate/engine.py
634 635 636 637 638 639 640 641 642 643 | |
get_match_log()
Get the match log.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of match events. |
Source code in py/cogant/translate/engine.py
686 687 688 689 690 691 692 | |
get_statistics()
Get statistics about translations.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with statistics. |
Source code in py/cogant/translate/engine.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
register_rule(rule)
Register a translation rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
TranslationRule
|
Rule to register. |
required |
Source code in py/cogant/translate/engine.py
244 245 246 247 248 249 250 | |
translate(graph, rule_filter=None)
Translate a program graph using iterative rule application.
Rules are applied in repeated passes until a pass produces no new
mappings or max_iterations is reached, whichever comes first.
Because rules do not consume prior mappings, this is single-pass
rule application followed by one idempotent confirmation pass
(the second pass re-runs the rules and is expected to add nothing)
— it is NOT a semantic fixpoint. After the loop exits, conflict
resolution picks a single winning mapping per node set using
priority then confidence as the tiebreaker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph to translate. Must have been built by
the graph stage; in particular, |
required |
rule_filter
|
list[str] | None
|
Optional list of rule names to apply. |
None
|
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of |
list[SemanticMapping]
|
resolution, in insertion order. May be empty if no rule |
list[SemanticMapping]
|
matched. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a registered rule raises an unhandled exception. The engine catches and logs per-rule errors but re-raises engine-level invariant violations. |
Example
engine = TranslationEngine() engine.register_rule(ObservationRule()) mappings = engine.translate(graph) all(hasattr(m.kind, "name") for m in mappings) True
Source code in py/cogant/translate/engine.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
translate_with_confidence(graph, rule_filter=None)
Translate and rescore all mappings using the ConfidenceModel.
Runs the standard iterative-pass translation, then applies the ConfidenceModel to update confidence scores, tiers, and conflict penalties on every resulting mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph to translate. |
required |
rule_filter
|
list[str] | None
|
Optional list of rule names to apply (None = all). |
None
|
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of semantic mappings with updated confidence scores. |
Source code in py/cogant/translate/engine.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
validate()
Validate SemanticMappings for internal consistency.
Checks all mappings in :attr:mappings for:
- Non-empty node IDs
- Valid confidence scores (0.0–1.0)
- Consistent mapping kinds
- No orphaned node references (node exists in graph)
Returns:
| Type | Description |
|---|---|
list[str]
|
List of validation issues (empty = valid). Each string |
list[str]
|
describes one inconsistency or violation. |
Source code in py/cogant/translate/engine.py
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | |
TranslationRule
Bases: ABC
Base class for translation rules.
Source code in py/cogant/translate/engine.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
mapping_kind
abstractmethod
property
Kind of semantic mapping produced.
name
abstractmethod
property
Name of this rule.
priority
property
Priority of this rule (higher = applied first). Default 0.
Rationale for default priority=0:
Most shipped rules keep the default 0 and are applied in
registration order within a single translation pass.
:class:~cogant.translate.rules.structural.MutatingSubsystemRule
overrides this property to return 1 so class-level hidden-state
evidence wins ties against overlapping class-scoped mappings from
aggregate rules at equal confidence. Aside from that exception,
conflict resolution between overlapping mappings falls through to
the (priority, confidence_score) lexicographic comparison in
:meth:TranslationEngine._resolve_conflicts. See
docs/evaluation/CALIBRATION.md for the full rule priority audit.
TODO(calibration): if the empirical conflict-loss rate on
real-world repos exceeds ~5%, broaden explicit priority tiers.
apply(graph, match)
abstractmethod
Apply rule to a matched pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern from matches(). |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping if successful, None otherwise. |
Source code in py/cogant/translate/engine.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
explain(node, graph, query)
Explain whether this rule would fire on node.
This is the default implementation used by the cogant explain
CLI subcommand. It re-runs :meth:matches and checks whether any
returned match references the target node's id. Subclasses that
can produce richer evidence (specific edge kinds, keyword hits,
metric values) should override this method.
The base implementation never raises: if :meth:matches blows
up, the returned :class:RuleExplanation has fired=False and
a reason that names the exception type so the CLI can surface it
instead of aborting the whole explain run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The target node whose role we want to justify. |
required |
graph
|
ProgramGraph
|
Program graph the rule is being evaluated against. |
required |
query
|
GraphQuery
|
Graph query engine bound to |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
RuleExplanation
|
class: |
Source code in py/cogant/translate/engine.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
matches(graph, query)
abstractmethod
Check if rule matches graph patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph to analyze. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched fragments, each with node/edge IDs. |
Source code in py/cogant/translate/engine.py
68 69 70 71 72 73 74 75 76 77 78 79 | |
Confidence
Confidence scoring keeps rule decisions epistemic about the pipeline, not about code quality.
cogant.translate.confidence
Confidence scoring model for COGANT semantic mappings.
Overview
This module implements the confidence layer that sits between
COGANT's translation rules (cogant.translate.rules.*) and the
state-space / GNN consumers downstream. Every :class:SemanticMapping
emitted by a rule carries (i) a continuous confidence score in
[0, 1] and (ii) a discrete confidence tier drawn from
:class:ConfidenceTier. Both are produced by :class:ConfidenceModel
and form the canonical signal that downstream code (state-space
compilation, conflict resolution, GNN matrix synthesis) uses to decide
whether a mapping is trustworthy enough to keep, surface for review,
or discard.
The model is deliberately parametric and transparent: every
threshold is a class-level constant or a per-method default, every
constant has an inline rationale, and every empirically-tunable
constant is annotated with a TODO(calibration) marker linking it
to the 20-repo calibration plan. See
docs/reference/calibration_guide.md for the corpus, methodology,
and per-threshold sweep ranges; see docs/evaluation/CALIBRATION.md
for the parameter registry; see docs/evaluation/MUTATION_REPORT.md
for the mutation-testing audit (item M9 covers the boundary semantics
of this module).
Confidence-tier model
COGANT distinguishes four tiers along an evidence-quality axis:
================================ ===== ================================================
Tier (ConfidenceTier value) Floor Meaning
================================ ===== ================================================
STATIC_ONLY 0.50 Static analysis only (AST / tree-sitter); the
baseline tier when no runtime evidence exists.
RUNTIME_ONLY 0.40 Runtime / dynamic-trace evidence with no static
corroboration. The floor is intentionally below
STATIC_ONLY to reflect a -0.10
dynamic-noise discount: traces are noisier
than AST edges, so we accept them at a lower
absolute score.
STATIC_PLUS_RUNTIME 0.65 Both static and runtime evidence present. The
floor is +0.15 above STATIC_ONLY — a
corroboration bonus — so corroborated mappings
must clear a strictly higher bar than either
source on its own.
HUMAN_REVIEWED 0.90 Reviewed and approved by a human; aligned with
the strong-consensus band from classical
meta-analysis reporting conventions.
================================ ===== ================================================
The "three-tier model" referred to in design discussions is the
evidence-source sub-hierarchy (STATIC_ONLY, RUNTIME_ONLY,
STATIC_PLUS_RUNTIME); HUMAN_REVIEWED is an orthogonal override
that always wins regardless of computed score (see
:meth:ConfidenceModel.determine_confidence_tier).
Threshold table
The following table summarises every numeric knob owned by this module. All values are principled defaults (motivated by convention or algebraic rationale, not yet empirically fit) unless otherwise noted.
========================================== ===== ============================== ==========================
Constant Value Sweep range Calibration marker
========================================== ===== ============================== ==========================
STATIC_ONLY_THRESHOLD 0.50 {0.4, 0.5, 0.55, 0.6} line ~40 (class scope)
STATIC_PLUS_RUNTIME_THRESHOLD 0.65 {0.55, 0.6, 0.65, 0.7} line ~40 (class scope)
RUNTIME_ONLY_THRESHOLD 0.40 {0.3, 0.35, 0.4, 0.45} line ~40 (class scope)
HUMAN_REVIEWED_THRESHOLD 0.90 {0.85, 0.9, 0.95} line ~40 (class scope)
diversity_bonus multiplier 0.10 {0.05, 0.10, 0.15, 0.20} :meth:compute_confidence_score
conflict_penalty per-conflict 0.05 {0.02, 0.05, 0.08, 0.10} :meth:compute_confidence_score
divergence-flag spread 0.30 {0.2, 0.3, 0.4} :meth:detect_conflicts
divergence penalty (mild) 0.10 {0.05, 0.10, 0.15} :meth:detect_conflicts
static-vs-dynamic disagreement spread 0.25 {0.15, 0.20, 0.25, 0.30} :meth:detect_conflicts
static-vs-dynamic disagreement penalty 0.15 {0.10, 0.15, 0.20} :meth:detect_conflicts
get_high_confidence_mappings default 0.70 {0.65, 0.70, 0.75, 0.80} :meth:get_high_confidence_mappings
get_low_confidence_mappings default 0.60 {0.50, 0.55, 0.60, 0.65} :meth:get_low_confidence_mappings
unique-source cap (diversity normaliser) 5 not calibrated (taxonomy-fixed) :meth:score_evidence_diversity
========================================== ===== ============================== ==========================
Eight of these knobs carry a TODO(calibration) marker in this
file (see docs/reference/calibration_guide.md, Confidence
combiner section, for the resolution recipe).
Calibration methodology (summary)
Calibration here means threshold tuning against a labelled corpus, not model training in the machine-learning sense. The model itself (linear blend of evidence terms) is held fixed; only the scalar constants in the table above are swept. The procedure is:
- Corpus. Twenty repositories under
cogant/tests/fixtures/repos/(Python + JS/TS, balanced small/medium/large). Each repo has a hand-labelled gold-standard set of correct mappings underevaluation/gold_standards/(TBD; seeCALIBRATION.md§4). - Sweep. For each constant, run COGANT end-to-end across the
corpus with the constant pinned to each candidate value in its
sweep range; collect the resulting :class:
SemanticMappingpopulation. - Score. Compute precision / recall / F1 against the gold
labels, plus the tier-confusion matrix. For continuous parameters
(e.g.
diversity_bonus) report the L2 error of the score distribution against an L1-normalised target. - Pick. Choose the value at the elbow of the F1 curve. Tie-break
in favour of recall for
RUNTIME_ONLY_THRESHOLD(we want noisy traces to surface for review) and in favour of precision forSTATIC_PLUS_RUNTIME_THRESHOLD(we want corroborated mappings to be trustworthy by default). - Document. Replace the
TODO(calibration)annotation withempirically validated — see CALIBRATION.md §Xand update the manuscript supplement with the sweep curve.
Public surface
The module exports a single class, :class:ConfidenceModel. The
relevant types are imported from :mod:cogant.schemas.semantic:
- :class:
SemanticMapping— the canonical mapping dataclass (graph fragment + semantic label +provenance,evidence_count,evidence_diversity,parser_certainty,conflict_penalties,confidence_score,confidence_tier). This is the input to every public method on :class:ConfidenceModeland is mutated in-place by :meth:ConfidenceModel.update_mapping_confidence. - :class:
ConfidenceTier— the four-tierStrEnumdescribed above. - :class:
ProvenanceRecord— one piece of evidence (source,timestamp,metadata, per-sourceconfidence). Every :class:SemanticMappingcarries alist[ProvenanceRecord].
Note on naming: cogant.types.ConfidenceScore is a float type
alias for documentation purposes (range [0.0, 1.0]); it is not
a separate dataclass. The actual confidence data lives on
:class:SemanticMapping (fields confidence_score and
confidence_tier); this module's job is to compute those fields.
End-to-end flow of compute_confidence_score
For a mapping m with len(m.provenance) == n:
- Empty-evidence guard. If
n == 0the score is0.0— un-evidenced mappings are not trusted at all. - Evidence base.
avg_evidence = mean(p.confidence for p in m.provenance). Unweighted mean rather than max so that adding weak corroborating evidence does not artificially inflate a strong primary source. - Diversity bonus.
diversity_bonus = m.evidence_diversity * 0.10.evidence_diversityis precomputed by :meth:score_evidence_diversityasunique_sources / min(n, 5), capped at the five-label evidence taxonomy. The0.10multiplier is sized so that maximum diversity (1.0) contributes exactly one tier-gap of lift (theSTATIC_ONLY→STATIC_PLUS_RUNTIMEgap is 0.15, and a lone diversity bonus must not overshoot it on its own). - Parser-certainty discount.
certainty_factor = m.parser_certainty. This is a multiplicative reliability discount from the underlying parser (≈0.95 for full Python AST, ≈0.80 for the tree-sitter fallback band). Applying it before the conflict penalty is intentional: a noisy parser should reduce both the evidence base and any diversity bonus, but conflicts (which are signal, not noise) survive the discount. - Conflict penalty.
conflict_penalty = sum(m.conflict_penalties) * 0.05. The list is precomputed by :meth:detect_conflictsand contains one entry per detected conflict (0.10for spread divergence,0.15for static-vs-dynamic disagreement). The0.05multiplier means two typical conflicts (~0.10total before multiplication) roughly cancel a full diversity bonus. - Compose and clamp. ``confidence = (avg_evidence + diversity_bonus) * certainty_factor
- conflict_penalty
, then clamped to[0, 1]``.
The resulting score feeds :meth:determine_confidence_tier, which
applies the four-tier decision tree:
has_human→HUMAN_REVIEWED(overrides everything).has_static and has_dynamic→STATIC_PLUS_RUNTIMEifscore >= STATIC_PLUS_RUNTIME_THRESHOLD, otherwise fall through toSTATIC_ONLYif it meetsSTATIC_ONLY_THRESHOLD.has_dynamic and not has_static→RUNTIME_ONLYifscore >= RUNTIME_ONLY_THRESHOLD.has_static→STATIC_ONLYifscore >= STATIC_ONLY_THRESHOLD.- Otherwise →
STATIC_ONLY(lowest-tier fallback; the mapping is retained but flagged for downstream review).
:meth:update_mapping_confidence orchestrates all of the above:
counts evidence, computes diversity, detects conflicts, computes the
score, assigns the tier, and appends a record to the internal scoring
log (which feeds :meth:get_scoring_report). :meth:score_batch is a
trivial loop over :meth:update_mapping_confidence for ergonomic
batch processing.
Cross-references
docs/reference/calibration_guide.md— methodology, sweep recipes, and resolution checklist for everyTODO(calibration)marker in this module.docs/evaluation/CALIBRATION.md— repository-wide parameter registry (§2.3 covers this module specifically).docs/evaluation/MUTATION_REPORT.md— boundary-semantics audit (item M9 covers the>=/>decisions in the tier decision tree).- :mod:
cogant.translate.rules— the rules whose mappings consume this module's output. - :mod:
cogant.statespace.variables— the downstream consumer that collapses the four tiers into the coarserConfidenceLevelcategorical view.
ConfidenceModel
Computes and manages confidence scores for semantic mappings.
Combines evidence count, diversity, parser certainty, and conflict penalties to produce confidence tiers and scores.
Source code in py/cogant/translate/confidence.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
__init__()
Initialize the confidence model.
Source code in py/cogant/translate/confidence.py
263 264 265 | |
clear_log()
Clear the scoring log.
Source code in py/cogant/translate/confidence.py
583 584 585 | |
compute(mapping)
Convenience alias for compute_confidence_score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to score. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Confidence score between 0.0 and 1.0. |
Source code in py/cogant/translate/confidence.py
267 268 269 270 271 272 273 274 275 276 | |
compute_confidence_score(mapping)
Compute overall confidence score from evidence and metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to score. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Confidence score between 0.0 and 1.0. |
Source code in py/cogant/translate/confidence.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
detect_conflicts(mapping)
Detect and score conflicts in evidence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to check. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
List of conflict penalty scores. |
Source code in py/cogant/translate/confidence.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
determine_confidence_tier(mapping, score=None)
Determine confidence tier based on evidence sources and score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to tier. |
required |
score
|
float | None
|
Optional precomputed confidence score. |
None
|
Returns:
| Type | Description |
|---|---|
ConfidenceTier
|
ConfidenceTier for the mapping. |
Source code in py/cogant/translate/confidence.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
get_conflicted_mappings(mappings)
Find mappings with detected conflicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
list[SemanticMapping]
|
List of mappings. |
required |
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of mappings with conflict penalties. |
Source code in py/cogant/translate/confidence.py
545 546 547 548 549 550 551 552 553 554 555 556 557 | |
get_high_confidence_mappings(mappings, threshold=0.7)
Filter mappings by minimum confidence score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
list[SemanticMapping]
|
List of mappings. |
required |
threshold
|
float
|
Minimum confidence threshold. Default 0.7 is a
principled "trust without review" bar — safely above
|
0.7
|
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
Filtered list of high-confidence mappings. |
Source code in py/cogant/translate/confidence.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
get_low_confidence_mappings(mappings, threshold=0.6)
Find mappings below confidence threshold that may need review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
list[SemanticMapping]
|
List of mappings. |
required |
threshold
|
float
|
Maximum confidence threshold. Default 0.6 is a
principled "needs reviewer attention" bar — halfway
between |
0.6
|
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
Filtered list of low-confidence mappings. |
Source code in py/cogant/translate/confidence.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | |
get_scoring_report()
Generate a report of confidence scoring.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with scoring statistics. |
Source code in py/cogant/translate/confidence.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
score_batch(mappings)
Update confidence for a batch of mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
list[SemanticMapping]
|
List of mappings to score. |
required |
Source code in py/cogant/translate/confidence.py
492 493 494 495 496 497 498 499 | |
score_evidence_diversity(mapping)
Compute diversity score of evidence sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping with provenance. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Diversity score between 0.0 and 1.0. |
Source code in py/cogant/translate/confidence.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
update_mapping_confidence(mapping)
Update all confidence fields of a mapping in-place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
SemanticMapping to update. |
required |
Source code in py/cogant/translate/confidence.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
Review
Human-in-the-loop API for curating uncovered or low-confidence mappings.
cogant.translate.review
Review manager for semantic mapping validation and curation.
ReviewManager
Manages human review of semantic mappings.
Accepts, rejects, edits, splits, and merges mappings while tracking all provenance and changes.
Source code in py/cogant/translate/review.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
__init__()
Initialize the review manager.
Source code in py/cogant/translate/review.py
16 17 18 19 | |
accept_mapping(mapping_id, reviewer, feedback=None)
Accept a mapping as valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping to accept. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
feedback
|
str | None
|
Optional review feedback. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False if mapping not found. |
Source code in py/cogant/translate/review.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
add_mapping(mapping)
Add a mapping for potential review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SemanticMapping
|
Mapping to add. |
required |
Source code in py/cogant/translate/review.py
21 22 23 24 25 26 27 | |
edit_mapping(mapping_id, reviewer, updates)
Edit a mapping based on review feedback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping to edit. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
updates
|
dict[str, Any]
|
Dictionary of fields to update. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False if mapping not found. |
Source code in py/cogant/translate/review.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
export_reviewed_mappings()
Export all mappings that have been accepted or edited by reviewers.
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of reviewed and approved mappings. |
Source code in py/cogant/translate/review.py
312 313 314 315 316 317 318 | |
get_mapping_for_review(mapping_id)
Get a mapping for review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
Mapping if found, None otherwise. |
Source code in py/cogant/translate/review.py
237 238 239 240 241 242 243 244 245 246 | |
get_mappings_by_status(status)
Get all mappings with a specific status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
Status to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of mappings with that status. |
Source code in py/cogant/translate/review.py
248 249 250 251 252 253 254 255 256 257 | |
get_review_history()
Get the complete review history.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of review events. |
Source code in py/cogant/translate/review.py
304 305 306 307 308 309 310 | |
get_review_summary()
Get a summary of review status.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with review statistics. |
Source code in py/cogant/translate/review.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
get_unreviewed_mappings()
Get all mappings that haven't been reviewed.
Returns:
| Type | Description |
|---|---|
list[SemanticMapping]
|
List of unreviewed mappings. |
Source code in py/cogant/translate/review.py
259 260 261 262 263 264 265 | |
merge_mappings(mapping_ids, reviewer, merged_definition)
Merge multiple mappings into one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_ids
|
list[str]
|
IDs of mappings to merge. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
merged_definition
|
dict[str, Any]
|
Definition of merged mapping. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
ID of new merged mapping, or None if invalid. |
Source code in py/cogant/translate/review.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
reject_mapping(mapping_id, reviewer, reason)
Reject a mapping as invalid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping to reject. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
reason
|
str
|
Reason for rejection. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False if mapping not found. |
Source code in py/cogant/translate/review.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
split_mapping(mapping_id, reviewer, split_definitions)
Split a mapping into multiple mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_id
|
str
|
ID of mapping to split. |
required |
reviewer
|
str
|
Name of reviewer. |
required |
split_definitions
|
list[dict[str, Any]]
|
List of definitions for new mappings. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of IDs of new mappings. |
Source code in py/cogant/translate/review.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
Rules
Rule classes are split by theme and priority:
Structural rules
cogant.translate.rules.structural
Structural translation rules.
This module is part of the :mod:cogant.translate.rules package and
contains rules that recognise structural patterns in the program graph (reads, writes, containment, inheritance, pipelines). Every class in this file inherits from
:class:cogant.translate.engine.TranslationRule and produces
:class:cogant.schemas.semantic.SemanticMapping records with full
provenance and confidence.
See :mod:cogant.translate.rules for the umbrella re-export and
:doc:../../../specs/mappings/code-to-gnn for the family taxonomy.
ContainmentRule
Bases: TranslationRule
Analyzes methods within classes to extract observation vs action vs policy roles.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.75). Mid band (0.75).
Stronger than pure-structural InheritanceRule (0.70)
because it aggregates lexical evidence across 5+ methods
(majority-vote classification), but weaker than per-function
ObservationRule/ActionRule keyword hits (0.80+)
because the class-level aggregate can mask mixed-role classes.
Method-count threshold = 5 (see matches). TODO(calibration):
sweep {3, 5, 8} method thresholds and the
max(actions, observations) tie-breaking rule.
Source code in py/cogant/translate/rules/structural.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create containment analysis mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping summarizing method roles. |
Source code in py/cogant/translate/rules/structural.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
matches(graph, query)
Find classes with multiple methods for detailed analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched containment patterns. |
Source code in py/cogant/translate/rules/structural.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
DataPipelineRule
Bases: TranslationRule
Maps data transformation chains to data-flow modality.
Detects functions that read from one source, transform, and write to another. Pattern: node with both READS and WRITES edges where read sources differ from write targets.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.75). Mid band (0.75). The
"reads-from-A, writes-to-B (A≠B)" pattern is a strong
structural cue for data flow, but we keep it at 0.75 rather
than 0.80+ because edge-level precision is lower than
name-level precision (tree-sitter occasionally over-reports
READS on attribute-chain accesses). TODO(calibration):
measure false-positive rate on the 20-repo corpus; if <5%,
promote to 0.80.
Source code in py/cogant/translate/rules/structural.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create data-flow mapping for data pipeline node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for data flow. |
Source code in py/cogant/translate/rules/structural.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | |
matches(graph, query)
Find functions with both read and write edges to different targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched data pipeline nodes. |
Source code in py/cogant/translate/rules/structural.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
InheritanceRule
Bases: TranslationRule
Maps class inheritance to inform semantic roles via base class hierarchy.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.7). Bottom band (0.70)
alongside ReadOnlyInputRule and the resilience rules.
Rationale: inheritance is a structural hint, not evidence —
a subclass of AbstractHandler might be a controller or a
test double or a stub. We use the lexical shortcut "name
starts with Abstract/Base => POLICY" because Python
convention strongly correlates those prefixes with abstract
base classes (PEP 3119). Parser certainty 0.75 is slightly
below the 0.80 edge-precision band because tree-sitter has
known gaps on multi-base metaclass hierarchies.
TODO(calibration): measure tier-disagreement rate vs.
behavioral rules on the 20-repo corpus; if inheritance
routinely gets overruled, demote to an "explanation only"
rule that never writes a mapping.
Source code in py/cogant/translate/rules/structural.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create semantic mapping based on inheritance pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for inheritance-informed role. |
Source code in py/cogant/translate/rules/structural.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
matches(graph, query)
Find classes with inheritance relationships.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched inheritance patterns. |
Source code in py/cogant/translate/rules/structural.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
MutatingSubsystemRule
Bases: TranslationRule
Maps objects with frequent internal mutations to hidden-state modality.
Rule priority (audit 2026-04-09):
:meth:priority returns 1 (see override below) so
HIDDEN_STATE wins class-level overlaps against aggregate
POLICY from :class:InheritanceRule at default priority 0
when both fire on the same CLASS node. The confidence score
remains mid band (0.75): a class touched by any
WRITES/MUTATES edge is a mild structural cue for hidden
state, stronger than a pure read-only module (0.70) but weaker
than a lexical action match (0.80) or a configuration hit
(0.85+). The mutation-count threshold is deliberately >=1.
TODO(calibration): sweep the threshold in {1, 2, 3} on the
20-repo corpus; a higher floor would likely raise precision at
the cost of recall on under-instrumented fixtures.
Source code in py/cogant/translate/rules/structural.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
priority
property
Above class-level aggregate rules (e.g. ContainmentRule at 0).
ContainmentRule can emit a class-scoped mapping that overlaps the
same CLASS node as this rule. Equal (priority, confidence)
ties previously dropped the hidden-state mapping lexicographically.
Hidden-state evidence from WRITES/MUTATES edges should win that tie.
apply(graph, match)
Create hidden-state mapping for mutating subsystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for hidden-state. |
Source code in py/cogant/translate/rules/structural.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
explain(node, graph, query)
Explain whether this class is a hidden-state / mutating subsystem.
The rule only applies to CLASS nodes and fires when the class
has at least one edge of kind WRITES or MUTATES touching
it (either as source or as target). This mirrors the match logic
in :meth:matches so the explain report stays honest.
Source code in py/cogant/translate/rules/structural.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
matches(graph, query)
Find objects/classes with high mutation frequency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched class/object nodes. |
Source code in py/cogant/translate/rules/structural.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
ReadOnlyInputRule
Bases: TranslationRule
Maps modules with many read-only external inputs to observation modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.7) via the flat-priority=0 design
documented in :class:TranslationRule.priority, so conflict
resolution falls through to confidence_score = 0.7. This
places the rule in the bottom band (0.70) alongside
InheritanceRule, RetryPatternRule, ErrorBoundaryRule
and the ObservationRule lexical-fallback branch. Rationale:
module-level "all reads, no writes" is a weak structural signal
(modules nearly always expose some read API), so it should
cleanly lose to any function/method-level rule that also fires
on the same fragment. TODO(calibration): measure the
ReadOnlyInputRule→ObservationRule conflict-loss rate on the
20-repo corpus and promote to a dedicated priority tier only
if the loss rate exceeds ~20%.
Source code in py/cogant/translate/rules/structural.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create observation mapping for read-only module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for observation modality. |
Source code in py/cogant/translate/rules/structural.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
matches(graph, query)
Find modules with predominance of read operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched module nodes. |
Source code in py/cogant/translate/rules/structural.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
Semantic rules
cogant.translate.rules.semantic
Semantic translation rules.
This module is part of the :mod:cogant.translate.rules package and
contains rules that produce direct semantic-role mappings (observation, action, policy, preference, context). Every class in this file inherits from
:class:cogant.translate.engine.TranslationRule and produces
:class:cogant.schemas.semantic.SemanticMapping records with full
provenance and confidence.
See :mod:cogant.translate.rules for the umbrella re-export and
:doc:../../../specs/mappings/code-to-gnn for the family taxonomy.
ActionRule
Bases: TranslationRule
Maps setter/mutator functions to action modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80)
alongside PolicyRule, ContextRule, OrchestratorRule
and CircuitBreakerRule. Rationale: action semantics are
slightly less specific than PreferenceRule/TestAssertionRule
(0.85) because CRUD verbs are the most overloaded lexical
category in real codebases. The edge-based fallback
writes_only >= 2 was added (commit e1eb463) to recover
recall on functional codebases where writes are named
apply/reduce rather than set/update.
TODO(calibration): sweep the >=2 writes threshold in
{1, 2, 3} on the 20-repo corpus.
Source code in py/cogant/translate/rules/semantic.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create action mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for action. |
Source code in py/cogant/translate/rules/semantic.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
explain(node, graph, query)
Explain whether this node performs an action.
Mirrors the :meth:matches decision by checking for action
keywords in the node name and counting outgoing WRITES/MUTATES
edges. The rule fires when either (a) the name contains an
action keyword, or (b) at least 1 outgoing WRITES/MUTATES edge
exists (the functional-codebase recall threshold).
Source code in py/cogant/translate/rules/semantic.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
matches(graph, query)
Find functions/methods that mutate state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched action functions/methods. |
Source code in py/cogant/translate/rules/semantic.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
to_gnn_role()
Return the GNN role string for action mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
544 545 546 547 548 549 550 | |
ContextRule
Bases: TranslationRule
Maps configuration and parameter classes to context modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80),
tied with ActionRule/PolicyRule. Rationale: context
keywords config/settings/env/options/params
are specific but less strong than a validate/test_
prefix (which get 0.85); they correlate well with
configuration roles but also occasionally appear in
orchestrators. Note: the dedicated ConfigRule (control.py,
confidence 0.90) supersedes this rule when config is in
the name — this rule provides the broader
settings/params/env fallback.
Source code in py/cogant/translate/rules/semantic.py
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create context mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for context. |
Source code in py/cogant/translate/rules/semantic.py
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 | |
matches(graph, query)
Find context/configuration classes and functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched context nodes. |
Source code in py/cogant/translate/rules/semantic.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 | |
to_gnn_role()
Return the GNN role string for context mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
971 972 973 974 975 976 977 | |
ObservationRule
Bases: TranslationRule
Maps getter/query functions and read-only methods to observation modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.85) on keyword match, or
(0, 0.70) on the edge-based read-only fallback.
- Keyword band: high band (0.85), same as
PreferenceRule and TestAssertionRule, tied second
only to ConfigRule (0.90). Rationale: lexical matches
on get_/read_/fetch_ prefixes carry strong
prior probability of observation semantics based on PEP 8
naming convention.
- Fallback band: bottom band (0.70). The structural "reads,
no writes" signal alone is weaker because pure-read helpers
are also ubiquitous in private utility code.
The bimodal confidence lets conflict resolution automatically
prefer keyword-driven observations over structural ones.
TODO(calibration): empirically validate the 0.85/0.70 split
against a hand-labeled observation fixture.
Source code in py/cogant/translate/rules/semantic.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create observation mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for observation. |
Source code in py/cogant/translate/rules/semantic.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
explain(node, graph, query)
Explain whether this node is an observation.
Walks the same decision path used by :meth:matches, but
collects concrete evidence snippets (keyword matches and
READS/WRITES edge counts) into a :class:RuleExplanation so the
cogant explain CLI can render a justification report.
Source code in py/cogant/translate/rules/semantic.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
matches(graph, query)
Find functions/methods that observe state without mutation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched observation functions/methods. |
Source code in py/cogant/translate/rules/semantic.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
to_gnn_role()
Return the GNN role string for observation mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
332 333 334 335 336 337 338 | |
PolicyRule
Bases: TranslationRule
Maps controllers, handlers, and routers to policy modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80),
tied with ActionRule, ContextRule, OrchestratorRule,
CircuitBreakerRule. Rationale: controller/handler/router
vocabulary is a strong web-framework signal (Flask, Django,
FastAPI) but carries real ambiguity — "handler" also appears
in action and retry contexts. Confidence tie-breaking between
policy and action on handle/dispatch is delegated to
per-match context. TODO(calibration): measure the
policy↔action collision rate on handle/dispatch in
the 20-repo corpus.
Source code in py/cogant/translate/rules/semantic.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create policy mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for policy. |
Source code in py/cogant/translate/rules/semantic.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | |
matches(graph, query)
Find classes and functions that implement policy/control logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched policy nodes. |
Source code in py/cogant/translate/rules/semantic.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | |
to_gnn_role()
Return the GNN role string for policy mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
710 711 712 713 714 715 716 | |
PreferenceRule
Bases: TranslationRule
Maps validators and test functions to preference/constraint modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.85). High band (0.85), tied
with TestAssertionRule and the keyword branch of
ObservationRule. Rationale: validate/check/
Validator/test_ are exceptionally strong lexical
signals — there is essentially no non-constraint use of
test_ prefixes in well-formed Python, and PEP 8 +
pytest/unittest conventions anchor the other patterns.
Parser certainty 0.90 is the highest in the rule family
because name-only matching doesn't depend on edge extraction.
Source code in py/cogant/translate/rules/semantic.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create preference/constraint mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for constraint. |
Source code in py/cogant/translate/rules/semantic.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
matches(graph, query)
Find validation and test functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched preference/constraint nodes. |
Source code in py/cogant/translate/rules/semantic.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | |
to_gnn_role()
Return the GNN role string for preference/constraint mappings.
Returns:
| Type | Description |
|---|---|
str
|
GNN role identifier. |
Source code in py/cogant/translate/rules/semantic.py
841 842 843 844 845 846 847 | |
Behavioral rules
cogant.translate.rules.behavioral
Behavioral translation rules.
This module is part of the :mod:cogant.translate.rules package and
contains rules that recognise behavioural patterns (orchestration, event buses, test assertions). Every class in this file inherits from
:class:cogant.translate.engine.TranslationRule and produces
:class:cogant.schemas.semantic.SemanticMapping records with full
provenance and confidence.
See :mod:cogant.translate.rules for the umbrella re-export and
:doc:../../../specs/mappings/code-to-gnn for the family taxonomy.
EventBusRule
Bases: TranslationRule
Maps event/subscription systems to observation-action coupling.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.75). Mid band (0.75),
tied with MutatingSubsystemRule/ContainmentRule/
DataPipelineRule. Rationale: event-bus detection depends
on the upstream parser recognizing EVENT node kinds,
which is only done for patterns the tree-sitter queries
understand (decorator-driven pub/sub). Confidence tier is
set to STATIC_PLUS_RUNTIME (not STATIC_ONLY) as a hint that
dynamic trace corroboration is especially valuable for
event-driven code. TODO(calibration): measure EVENT-node
coverage across the 20-repo corpus.
Source code in py/cogant/translate/rules/behavioral.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create observation-action coupling mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for event bus. |
Source code in py/cogant/translate/rules/behavioral.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
matches(graph, query)
Find event bus and subscription patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched event bus patterns. |
Source code in py/cogant/translate/rules/behavioral.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
OrchestratorRule
Bases: TranslationRule
Maps schedulers and controllers to policy/action structure.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80),
tied with ActionRule/PolicyRule/ContextRule/
CircuitBreakerRule. Rationale: high call fan-out is a
reliable structural signal for orchestration but not
unambiguous — utility modules can also have many calls.
Call-count threshold = 3 (see matches): below 3, the
pattern is indistinguishable from simple helpers.
TODO(calibration): sweep {2, 3, 5, 8} on the 20-repo corpus.
Source code in py/cogant/translate/rules/behavioral.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create orchestration mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for orchestration. |
Source code in py/cogant/translate/rules/behavioral.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
matches(graph, query)
Find orchestrator patterns (high out-degree controllers).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched orchestrator nodes. |
Source code in py/cogant/translate/rules/behavioral.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
StateMachineRule
Bases: TranslationRule
Maps finite state machine patterns to policy/hidden-state modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80),
tied with ActionRule/PolicyRule/ContextRule/
OrchestratorRule/CircuitBreakerRule. Rationale: state
machines with explicit state enums + transition methods are a
strong structural signal for policy/control logic, but depend
on the upstream parser recognizing STATE node kinds and
transition patterns. Patterns: state enums, on_enter_*/
on_exit_* methods, transitions library usage, explicit
state attributes (self.state, self._state).
TODO(calibration): measure STATE-node coverage on the 20-repo
corpus; if <40%, demote to 0.75 or add heuristics for
transitions-library imports.
Source code in py/cogant/translate/rules/behavioral.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create state machine mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for state machine. |
Source code in py/cogant/translate/rules/behavioral.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
matches(graph, query)
Find finite state machine patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched state machine nodes. |
Source code in py/cogant/translate/rules/behavioral.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
TestAssertionRule
Bases: TranslationRule
Maps test assertions to preference/constraint modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.85). High band (0.85), tied
with PreferenceRule and the keyword branch of
ObservationRule. Rationale: a function with "test" in its
name plus at least one CALLS edge (proxy for assertion)
is one of the most reliable static signals in the entire
rule family — pytest/unittest conventions are nearly
universal. Parser certainty 0.95 is the highest in the
family because both the name match and the call extraction
are handled by the native Python AST with minimal ambiguity.
Source code in py/cogant/translate/rules/behavioral.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create constraint mapping from test assertions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for constraint. |
Source code in py/cogant/translate/rules/behavioral.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
matches(graph, query)
Find test nodes and assertion calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched test nodes. |
Source code in py/cogant/translate/rules/behavioral.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Control-flow rules
cogant.translate.rules.control
Control translation rules.
This module is part of the :mod:cogant.translate.rules package and
contains rules that recognise control-flow modifiers (configuration, feature flags). Every class in this file inherits from
:class:cogant.translate.engine.TranslationRule and produces
:class:cogant.schemas.semantic.SemanticMapping records with full
provenance and confidence.
See :mod:cogant.translate.rules for the umbrella re-export and
:doc:../../../specs/mappings/code-to-gnn for the family taxonomy.
ConfigRule
Bases: TranslationRule
Maps configuration files and structures to context priors.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.90). Top band (0.90) —
the highest confidence score in the entire translation rule
family. Rationale: ConfigRule fires only when the
upstream parser has already classified a node as
NodeKind.CONFIGURATION (yaml/toml/ini/json config files,
module-level CONFIG = {...} dicts, Settings subclasses).
That classification is itself strongly evidenced, so the
confidence stacks: parser_certainty 0.95 (highest) plus
confidence 0.90 makes this rule effectively unbeatable by
heuristic rules, which is correct — explicit config is
ground truth for context. TODO(calibration): confirm that
NodeKind.CONFIGURATION extraction has <5% false-positive
rate on the 20-repo corpus.
Source code in py/cogant/translate/rules/control.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create context mapping for configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for context. |
Source code in py/cogant/translate/rules/control.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
matches(graph, query)
Find configuration nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched configuration nodes. |
Source code in py/cogant/translate/rules/control.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
FeatureFlagRule
Bases: TranslationRule
Maps feature flags to latent context selectors.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.85). High band (0.85),
tied with PreferenceRule/TestAssertionRule and the
keyword branch of ObservationRule. Rationale: feature
flags are specific but slightly less unambiguous than raw
configuration (which gets 0.90); some "feature flag"
patterns are actually dynamic toggles rather than static
context selectors. The rule relies on upstream
NodeKind.FEATURE_FLAG classification.
Source code in py/cogant/translate/rules/control.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create context selector mapping for feature flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for feature flag. |
Source code in py/cogant/translate/rules/control.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
matches(graph, query)
Find feature flag nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched feature flag nodes. |
Source code in py/cogant/translate/rules/control.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
ParameterRule
Bases: TranslationRule
Maps learnable parameters and hyperparameters to context priors.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.85). High band (0.85), tied
with PreferenceRule/TestAssertionRule. Rationale:
learnable parameters are semantic ground truth for context —
they control system behavior but are not part of the observation,
action, or policy logic. Patterns: param_, weight_,
hyperparameter, learning_rate, typed dataclass fields
(float/int), module-level configuration assignments.
TODO(calibration): validate that parameter detection covers
ML frameworks (PyTorch, TensorFlow, scikit-learn) on the
20-repo corpus.
Source code in py/cogant/translate/rules/control.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create context mapping for learnable parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for context. |
Source code in py/cogant/translate/rules/control.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
matches(graph, query)
Find learnable parameters and hyperparameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched parameter nodes. |
Source code in py/cogant/translate/rules/control.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
Resilience rules
cogant.translate.rules.resilience
Resilience translation rules.
This module is part of the :mod:cogant.translate.rules package and
contains rules that recognise resilience and uncertainty patterns (retry, error boundary, singleton, circuit breaker). Every class in this file inherits from
:class:cogant.translate.engine.TranslationRule and produces
:class:cogant.schemas.semantic.SemanticMapping records with full
provenance and confidence.
See :mod:cogant.translate.rules for the umbrella re-export and
:doc:../../../specs/mappings/code-to-gnn for the family taxonomy.
CircuitBreakerRule
Bases: TranslationRule
Maps circuit breaker patterns to circuit-breaker modality.
Detects functions/classes that contain both a GUARDS edge and a retry/fallback pattern (name contains retry/fallback/circuit/breaker keywords or has metadata indicating retry logic).
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.80). Upper-mid band (0.80),
tied with ActionRule/PolicyRule/ContextRule/
OrchestratorRule. Rationale: the combined signal of
GUARDS edge + retry keyword (or metadata hit) is much
stronger than the keyword-only RetryPatternRule (0.70),
so CircuitBreakerRule correctly wins on overlapping
fragments. The composite requirement keeps false positives
low — a function named retry_helper alone won't fire
without a GUARDS edge.
Source code in py/cogant/translate/rules/resilience.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create circuit-breaker mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for circuit breaker. |
Source code in py/cogant/translate/rules/resilience.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
matches(graph, query)
Find nodes with GUARDS edges and retry/fallback indicators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched circuit breaker nodes. |
Source code in py/cogant/translate/rules/resilience.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
ErrorBoundaryRule
Bases: TranslationRule
Maps error handling boundaries to error-handling modality.
Detects functions/methods with CATCHES or THROWS edges, representing error boundaries in the system.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.70). Bottom band (0.70).
Rationale: CATCHES/THROWS edges are directly extracted from
try/except / raise Python constructs (high structural
precision) but the semantic meaning — "this is an error
boundary worth modeling" — is weak because most non-trivial
functions have at least one try/except for cleanup. Parser
certainty 0.75 (below the 0.80 norm) reflects the fact that
tree-sitter does not resolve exception-type hierarchies.
Source code in py/cogant/translate/rules/resilience.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create error-handling mapping for error boundary node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for error handling. |
Source code in py/cogant/translate/rules/resilience.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
matches(graph, query)
Find nodes with CATCHES or THROWS edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched error boundary nodes. |
Source code in py/cogant/translate/rules/resilience.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
RateLimiterRule
Bases: TranslationRule
Maps rate-limiting patterns to throttling modality.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.75). Mid band (0.75), tied
with MutatingSubsystemRule/ContainmentRule/
DataPipelineRule/EventBusRule. Rationale: rate-limiting
detection depends on keyword matching (rate_limit,
throttle_) or structural patterns (sleep/backoff loops with
rate checks). Patterns: decorator-based rate limiters (@rate_limit),
token-bucket implementations, leaky-bucket algorithms, sleep-based
backoff with rate calculations. TODO(calibration): measure
rate-limiter coverage on the 20-repo corpus; if <30%, promote to 0.80
as the pattern is becoming more common in microservices.
Source code in py/cogant/translate/rules/resilience.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create rate-limiter mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for rate limiter. |
Source code in py/cogant/translate/rules/resilience.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |
matches(graph, query)
Find rate-limiting patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched rate limiter nodes. |
Source code in py/cogant/translate/rules/resilience.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
RetryPatternRule
Bases: TranslationRule
Maps retry/backoff/circuit breaker patterns to policy under uncertainty.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.70). Bottom band (0.70),
tied with ReadOnlyInputRule, InheritanceRule,
ErrorBoundaryRule, and the lexical fallback of
ObservationRule. Rationale: keyword matching alone is
a weak signal for retry logic — a function named
retry_count might be a counter, not a retry executor.
This rule intentionally loses to the stronger
CircuitBreakerRule (0.80) when both fire. Parser
certainty 0.70 is the lowest in the family because tree-
sitter pattern detection for retry decorators is
incomplete. TODO(calibration): promote to 0.80 if GUARDS
edge coverage improves in the parser.
Source code in py/cogant/translate/rules/resilience.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create policy mapping for retry pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for policy. |
Source code in py/cogant/translate/rules/resilience.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
matches(graph, query)
Find retry and circuit breaker patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched pattern nodes. |
Source code in py/cogant/translate/rules/resilience.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
SingletonAccessRule
Bases: TranslationRule
Maps singleton/global state access to context modality.
Detects variables or classes that are read by many different modules (high in-degree of READS edges from diverse paths). Threshold: 3+ readers from different modules.
Rule priority (audit 2026-04-09):
Effective priority = (0, 0.65). Lowest band (0.65) —
the lowest confidence score in the entire rule family.
Rationale: "accessed by many modules" is a very weak signal
(logging facilities, common types, and enum constants all
trigger it), so this rule is explicitly the last to win in
any conflict. Thresholds: read_edges >= 3 and
len(reader_modules) >= 3. The module-diversity check
prevents the rule from firing on intra-module utilities.
TODO(calibration): if the false-positive rate on the
20-repo corpus exceeds 30%, raise the module-diversity
threshold to 5 or combine with a "not in typing/stdlib
whitelist" filter.
Source code in py/cogant/translate/rules/resilience.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
mapping_kind
property
GNN mapping kind produced by this rule.
name
property
Stable identifier for this rule.
apply(graph, match)
Create context mapping for singleton/global state node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
match
|
dict[str, Any]
|
Matched pattern. |
required |
Returns:
| Type | Description |
|---|---|
SemanticMapping | None
|
SemanticMapping for context. |
Source code in py/cogant/translate/rules/resilience.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
matches(graph, query)
Find nodes with high in-degree READS from diverse modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
query
|
GraphQuery
|
Graph query engine. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matched singleton/global state nodes. |
Source code in py/cogant/translate/rules/resilience.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
Examples
TranslationEngine, the confidence scorer, the review API, and every rule family above are exercised by:
- Zoo:
examples/zoo/01_simple_state/— exercisesMutatingSubsystemRule(structural; HIDDEN_STATE). - Zoo:
examples/zoo/02_observer/— exercisesObservationRule(semantic). - Zoo:
examples/zoo/03_actor/— exercisesActionRule(semantic). - Zoo:
examples/zoo/09_policy/— exercisesPolicyRule(semantic). - Zoo:
examples/zoo/10_constraint/— exercisesPreferenceRule/ constraint family. - Zoo:
examples/zoo/12_full_pomdp/— fixpoint loop + conflict resolution under all five families simultaneously. - Cookbook: Recipe 3: Explain a single node —
RuleExplanationfrom the.explain()API. - Cookbook: Recipe 19: Adding a custom translation rule — registering a new
TranslationRuleagainst the engine. - Cookbook: Recipe: Custom translation rules — packaging-and-tests workflow for shipping rules.
- Tutorial: Tutorial 4: Writing a custom translation rule — full narrative on rule authorship and registration.