Repository navigation
3 6 paraphrase echo and diagnostics
Source: https://deepwiki.com/PonvasanthPon/TransCompilator/3-6-paraphrase-echo-and-diagnostics
Relevant source files
The following files were used as context for generating this wiki page:
- crates/tc-semantics/Cargo.toml
- crates/tc-semantics/src/cond.rs
- crates/tc-semantics/src/lib.rs
- crates/tc-semantics/src/paraphrase.rs
- crates/tc-semantics/src/quantifier.rs
- crates/tc-semantics/tests/phase3_6_ace_discourse.rs
- crates/tc-semantics/tests/phase4_6_version2_english.rs
- crates/tc-syntax/Cargo.toml
This section covers the semantic front end's diagnostic, tracing, and deterministic paraphrase facilities implemented in tc-semantics. The TransCompilator architecture eschews machine learning in favor of a deterministic zero-ML design. To ensure transparency, inspectability, and rigorous debugging, the compiler maintains two primary audit mechanisms:
-
Deterministic Paraphrase Echo (
tc-semantics/src/paraphrase.rs): Reconstructs canonicalized English statements directly from compiler decisions without re-parsing text. -
Structured Diagnostics and Traces (
tc-semantics/src/lib.rs): Captures sentence-level provenance (SentenceTrace) and categorizes semantic failures viaSemanticErrorKind.
The paraphrase subsystem records semantic actions at the exact moment an anaphor is bound, a condition tree is constructed, or a phrase target is selected. Because entries are captured during lowering, the echo cannot diverge from the generated Core-7 IR.
-
ParaphraseEntry([crates/tc-semantics/src/paraphrase.rs:14-26]()): Holds the sourceSpan, original cleaned text, finalIntentVerdict, canonical resolved string, and explicit discourse resolution annotations (e.g.,[it -> cash]). -
ParaphraseDoc([crates/tc-semantics/src/paraphrase.rs:30-35]()): Groups allParaphraseEntryrecords for a single named compilation module in source order.
The function canonicalize_statement ([crates/tc-semantics/src/paraphrase.rs:115-181]()) maps recognized syntactic patterns (such as assignments, mutations, and let-bindings) into uniform imperative commands (e.g., converting let x be 10 or x is 10 into Set x to 10.).
graph TD
NaturalLanguageSpace["Natural Language Input Text"] -->|tokenize_and_analyze| SemanticLowering["Semantic Lowering Engine"]
SemanticLowering -->|capture_bindings| ParaphraseEntryStruct["ParaphraseEntry Struct"]
ParaphraseEntryStruct -->|group_by_module| ParaphraseDocStruct["ParaphraseDoc Struct"]
ParaphraseDocStruct -->|format_paraphrase| FormattedEcho["Formatted Paraphrase Echo"]
classDef default stroke:#333,fill:#fff;
Sources: crates/tc-semantics/src/paraphrase.rs:14-89, crates/tc-semantics/src/lib.rs:143-151
When the semantic analyzer encounters malformed constructs, unhandled computational directives, or type violations, it emits structured diagnostic records.
The SemanticErrorKind enum ([crates/tc-semantics/src/lib.rs:64-76]) classifies failures into five distinct categories:
-
Segmentation: Source segmentation failed. -
Declaration: A declaration (such as aPhrase:or module import) was malformed. -
Lowering: An executable sentence could not be lowered into the AST/IR. -
Unsupported: A computational directive has no valid Core-7 lowering. -
TypeCheck: The typed AST failed type checking or IR lowering.
graph TD
CompilationFailure["Compilation Failure Encountered"] -->|classify| KindSelection{"SemanticErrorKind"}
KindSelection -->|Segmentation| ErrSeg["Segmentation Error"]
KindSelection -->|Declaration| ErrDecl["Declaration Error"]
KindSelection -->|Lowering| ErrLow["Lowering Error"]
KindSelection -->|Unsupported| ErrUnsup["Unsupported Feature"]
KindSelection -->|TypeCheck| ErrTC["Type Check Error"]
ErrSeg --> SemanticErrorStruct["SemanticError Struct"]
ErrDecl --> SemanticErrorStruct
ErrLow --> SemanticErrorStruct
ErrUnsup --> SemanticErrorStruct
ErrTC --> SemanticErrorStruct
SemanticErrorStruct --> LowerProjectOutcomeStruct["LowerProjectOutcome"]
classDef default stroke:#333,fill:#fff;
Sources: crates/tc-semantics/src/lib.rs:64-91, crates/tc-semantics/src/lib.rs:155-163
Every processed English sentence produces a SentenceTrace record ([crates/tc-semantics/src/lib.rs:106-140]). This structure preserves complete metadata for auditing and language verification:
| Field Name | Type | Description |
|---|---|---|
module |
String |
Source module name |
line / col
|
u32 |
One-based source location coordinates |
text |
String |
Cleaned sentence text |
fillers |
Vec<String> |
Stripped leading discourse fillers |
intent |
IntentVerdict |
Three-way intent classification (Exec, CommentOmitted, Unsupported) |
lg_used |
bool |
True when Link Grammar produced a complete linkage |
voice |
Voice |
Normalized voice (Active, Passive, etc.) |
predicate |
Option<VerbPredicate> |
VerbNet predicate classification |
concept |
Option<SemanticConcept> |
WordNet semantic concept mapping |
graph TD
SourceFileStream["SourceFile Stream"] -->|segment_and_tokenize| SentenceAnalysis["Sentence Analysis Pass"]
SentenceAnalysis -->|extract_metadata| SentenceTraceStruct["SentenceTrace struct in lib.rs"]
SentenceTraceStruct -->|aggregate| LoweredProjectStruct["LoweredProject struct"]
SentenceTraceStruct -->|preserve_on_error| LowerProjectOutcomeStruct["LowerProjectOutcome struct"]
classDef default stroke:#333,fill:#fff;
Sources: crates/tc-semantics/src/lib.rs:106-163
The semantic front end incorporates diagnostic suggestion logic that assists developers in correcting syntactic and semantic slips:
- Typo Hints: When an unknown verb or variable is encountered, lexical lookup scans available identifiers and open/closed class tables to suggest corrections.
-
Control Anchors: Validates block structures (such as
If,Loop, andPhrase) and reports precise column-aligned error messages viaSemanticErrorformatting ([crates/tc-semantics/src/lib.rs:93-100]()). -
Resilient Outcomes: The
LowerProjectOutcomestructure ([crates/tc-semantics/src/lib.rs:155-163]()) retains all collected sentence traces even when subsequent statements trigger compilation errors, enabling tooling like language servers (tc-lsp) to provide real-time diagnostic feedback.
Sources: crates/tc-semantics/src/lib.rs:78-103, crates/tc-semantics/src/lib.rs:155-163
The TransCompilator Project