Repository navigation
3 1 intent gate and sentence classification
Source: https://deepwiki.com/PonvasanthPon/TransCompilator/3-1-intent-gate-and-sentence-classification
Relevant source files
The following files were used as context for generating this wiki page:
The intent gate is the initial semantic triage layer in tc-semantics. Its primary responsibility is evaluating every parsed English sentence and assigning a strict three-way verdict: executable code (EXEC), deliberate narrative or comments to be omitted (COMMENT_OMITTED), or computational-looking text that lacks a supported lowering path (UNSUPPORTED). This page details the implementation of IntentVerdict, control anchor matching, computational verb verification via tc-lexicon, narrative detection rules, and the suggestion/diagnostics subsystem.
Sources: crates/tc-semantics/src/intent.rs:1-36(), crates/tc-semantics/src/suggest.rs:1-60()
Every sentence entering the semantic pipeline passes through IntentVerdict, which determines whether the compiler lowers it into Core-7 IR, drops it as prose/documentation, or halts with a diagnostic hint.
pub enum IntentVerdict {
Exec,
CommentOmitted { reason: String },
Unsupported { reason: String },
}-
Exec: The sentence contains valid computational semantics (assignments, print/emit statements, loops, conditionals, or declarations) and is forwarded to clause graph decomposition and statement lowering. -
CommentOmitted: The sentence is identified as narrative text, documentation, or conversational filler and is cleanly omitted from the generated program binary without triggering compilation errors. -
Unsupported: The sentence appears to express an action or computation (using recognized verbs or syntactic structures) but has no corresponding implementation in Core-7, triggering a loud diagnostic explanation (tc traceor compilation failure).
+---------------------------------+
| Natural Language Sentence (Text)|
+---------------------------------+
|
v
+---------------------------------+
| is_control_anchor() | [crates/tc-semantics/src/intent.rs:77-105]()
+---------------------------------+
|
v
+---------------------------------+
| first_computational_verb() | [crates/tc-semantics/src/intent.rs:146-164]()
+---------------------------------+
|
+--------+--------+
| |
v v
[Found Verb] [No Verb]
| |
v v
+---------------+ +---------------+
| EXEC | | COMMENT_OMITTED|
+---------------+ +---------------+
Figure 1: Intent Gate decision tree routing natural language sentences to code entities.
Sources: crates/tc-semantics/src/intent.rs:21-65()
Sentences or clauses prefixed with structural control words bypass heuristic verb filtering and are immediately categorized as executable code. The is_control_anchor helper identifies keywords that dictate grammar blocks, variable declarations, loops, and conditional branches.
fn is_control_anchor(word: &str) -> bool {
matches!(
word,
"import"
| "struct"
| "union"
| "global"
| "function"
| "phrase"
| "if"
| "else"
| "otherwise"
| "unless"
| "while"
| "repeat"
| "loop"
| "break"
| "continue"
| "return"
| "syscall"
| "copy"
| "memcopy"
| "trap"
| "define"
| "update"
| "public"
| "private"
)
}Sources: crates/tc-semantics/src/intent.rs:77-105()
When a sentence lacks a top-level control anchor, the intent gate inspects its verbs using lexical evidence from tc-lexicon. Auxiliary verbs (am, is, are, was, were, be, been, being, has, have, had, do, does, did) are filtered out to focus on semantic action verbs.
+--------------------------+
| first_computational_verb| [crates/tc-semantics/src/intent.rs:146-164]()
+--------------------------+
|
v
+--------------------------+
| tokenize(text) | [crates/tc-semantics/src/token.rs]()
+--------------------------+
|
v
+--------------------------+
| is_auxiliary_word() | [crates/tc-semantics/src/intent.rs:112-130]()
+--------------------------+
| (Non-auxiliary word)
v
+--------------------------+
| classify_verb() | [crates/tc-lexicon]()
+--------------------------+
|
[Verb Resolution]
Figure 2: Verb inspection pipeline connecting natural language tokens to lexical classification functions.
The first_computational_verb function scans sentence tokens, pairs words with subsequent prepositions via next_preposition, and queries classify_verb to check whether a verb predicate or semantic concept is present.
Sources: crates/tc-semantics/src/intent.rs:112-164(), crates/tc-lexicon()
Sentences that do not match control anchors and contain no computational verbs are classified under CommentOmitted. TransCompilator guarantees that no hardcoded dictionary of prose nouns exists; omission decisions rely strictly on grammar patterns, punctuation, auxiliary checks, and lexical classification via tc-lexicon.
- Omitted Sentences: Stored in compilation traces and omitted from object code generation.
- Unsupported Sentences: Triggered when a sentence uses a verb or structure that looks computational (e.g., imperative instructions like "Bake the cake") but lacks a lowering rule, yielding actionable suggestions.
Sources: crates/tc-semantics/src/intent.rs:1-5(), crates/tc-semantics/tests/diagnostics_and_std_helpers.rs:217-227()
When an intent gate or type-checker encounters an unknown variable name, record field, union member, or function, the suggestion engine (tc-semantics/src/suggest.rs) computes Levenshtein distances to provide natural corrections.
| Diagnostic Scenario | Trigger / Query | Candidate Sources | Generated Hint / Suggestion |
|---|---|---|---|
| Variable Typo | travle_budget |
Active scope variables | did you mean 'travel budget'? |
| Record Field Typo | distnce |
Record definition fields | has no field 'distnce' — did you mean 'distance'? available fields: distance, toll |
| Function Typo | sqtr |
Imported module functions | function 'sqtr' not found — did you mean 'sqrt'? |
| Unsupported Verb | Bake the cake |
Imperative action verbs | unsupported imperative verb 'bake' — try phrasing it with put/let |
The Levenshtein implementation computes edit distance with a maximum threshold (max_dist = 2) to ensure high-precision suggestions:
pub(crate) fn closest_match<'a>(
query: &str,
candidates: impl IntoIterator<Item = &'a str>,
max_dist: usize,
) -> Option<&'a str> { ... }Sources: crates/tc-semantics/src/suggest.rs:23-103(), crates/tc-semantics/tests/diagnostics_and_std_helpers.rs:59-227()
The TransCompilator Project