uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
Project: Building a Custom Chatbot Intent Parser
Product:
Class:
A step-by-step tutorial on building a simple chatbot intent parser using the uCalc Transformer to extract commands and parameters from natural language.
Remarks
🤖 Project: Building a Custom Chatbot Intent Parser
This project will guide you through building a simple but powerful intent parser for a chatbot or voice assistant. It's a perfect real-world example of how the declarative power of the uCalc.Transformer can solve simple natural language understanding (NLU) problems more effectively than regular expressions and more efficiently than heavyweight machine learning libraries.
The Goal: Understanding User Commands
Our objective is to parse user commands to determine the user's intent (what they want to do) and extract any relevant entities (the parameters for that action).
For example, in the command "set a timer for 5 minutes":
- Intent:
SET_TIMER - Entities:
duration=5,unit=minutes
We want to transform this natural language string into a structured, machine-readable format that our application can easily act upon.
The Strategy: Transformer Rules
We will use the uCalc.Transformer to define a set of rules. Each rule will map a specific command pattern to a structured output string. This approach is ideal for command-and-control applications where the range of user inputs is relatively predictable.
Step 1: Setting Up the Transformer
First, we need a Transformer instance. This will be our parsing engine. Since user commands are typically single lines and case-insensitive, we can configure the default behavior accordingly.
var t = new uCalc.Transformer();// Make all rules case-insensitive by defaultt.DefaultRuleSet.CaseSensitive = false;Step 2: Defining the Intent Rules
Next, we define our parsing logic using FromTo() rules. We'll use pattern variables like {duration} and token category matchers like {@Number} to capture the dynamic parts of the command.
// Rule for setting a timert.FromTo("set timer for {@Number:duration} {unit}", "INTENT:SET_TIMER DURATION:{duration} UNIT:{unit}");// Rule for playing music by a specific artistt.FromTo("play music by {artist}", "INTENT:PLAY_MUSIC ARTIST:{artist}");Note that in the second rule, {artist} will greedily capture all text until the end of the line, which is perfect for multi-word artist names.
Step 3: Processing User Input
With our rules defined, we can now process user input by calling the Transform() method. The output is a clean, structured string that is trivial for our application to parse further.
var command = "play music by The Rolling Stones";var parsed = t.Transform(command);Console.WriteLine(parsed);// Output: INTENT:PLAY_MUSIC ARTIST:The Rolling StonesYour application can then split this string to get the intent and entities and execute the appropriate action.
⚖️ Why uCalc? (Comparative Analysis)
vs. Regular Expressions: While you could use Regex, patterns quickly become complex and brittle. Handling variations like
"set a 5 minute timer"vs."set timer for 5 minutes"requires complicated optional groups. uCalc's token-based patterns are more readable and robust.vs. Machine Learning (ML) / NLP Libraries: For complex, conversational AI, ML-based solutions (like Rasa, Dialogflow) are necessary. However, for simple command-and-control applications, they are heavyweight, slow, and require training data. uCalc provides a lightweight, high-performance, rule-based solution that is perfect for this middle ground, offering deterministic results without the overhead of a neural network.
Examples
A succinct example of parsing a simple 'set timer' command to extract its intent and entities.
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
t.DefaultRuleSet.CaseSensitive = false;
// Define a rule to capture the duration and unit
t.FromTo("set timer for {@Number:duration} {unit}", "INTENT:SET_TIMER DURATION:{duration} UNIT:{unit}");
var command = "set timer for 10 seconds";
Console.WriteLine(t.Transform(command));
INTENT:SET_TIMER DURATION:10 UNIT:seconds using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); t.DefaultRuleSet.CaseSensitive = false; // Define a rule to capture the duration and unit t.FromTo("set timer for {@Number:duration} {unit}", "INTENT:SET_TIMER DURATION:{duration} UNIT:{unit}"); var command = "set timer for 10 seconds"; Console.WriteLine(t.Transform(command));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
t.DefaultRuleSet().CaseSensitive(false);
// Define a rule to capture the duration and unit
t.FromTo("set timer for {@Number:duration} {unit}", "INTENT:SET_TIMER DURATION:{duration} UNIT:{unit}");
auto command = "set timer for 10 seconds";
cout << t.Transform(command) << endl;
}
INTENT:SET_TIMER DURATION:10 UNIT:seconds #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; t.DefaultRuleSet().CaseSensitive(false); // Define a rule to capture the duration and unit t.FromTo("set timer for {@Number:duration} {unit}", "INTENT:SET_TIMER DURATION:{duration} UNIT:{unit}"); auto command = "set timer for 10 seconds"; cout << t.Transform(command) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
t.DefaultRuleSet.CaseSensitive = false
'// Define a rule to capture the duration and unit
t.FromTo("set timer for {@Number:duration} {unit}", "INTENT:SET_TIMER DURATION:{duration} UNIT:{unit}")
Dim command = "set timer for 10 seconds"
Console.WriteLine(t.Transform(command))
End Sub
End Module
INTENT:SET_TIMER DURATION:10 UNIT:seconds Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() t.DefaultRuleSet.CaseSensitive = false '// Define a rule to capture the duration and unit t.FromTo("set timer for {@Number:duration} {unit}", "INTENT:SET_TIMER DURATION:{duration} UNIT:{unit}") Dim command = "set timer for 10 seconds" Console.WriteLine(t.Transform(command)) End Sub End Module
A practical example parsing multiple command variations for different intents, such as playing music and setting alarms.
using uCalcSoftware;
var uc = new uCalc();
var t = new uCalc.Transformer();
t.DefaultRuleSet.CaseSensitive = false;
// Define multiple rules for different intents
t.FromTo("play music by {artist}", "INTENT:PLAY_MUSIC ARTIST:{artist}");
t.FromTo("play the song {song_title}", "INTENT:PLAY_MUSIC SONG:{song_title}");
t.FromTo("set an alarm for {time}", "INTENT:SET_ALARM TIME:{time}");
Console.WriteLine(t.Transform("play music by Queen"));
Console.WriteLine(t.Transform("play the song Bohemian Rhapsody"));
Console.WriteLine(t.Transform("set an alarm for 7 am"));
INTENT:PLAY_MUSIC ARTIST:Queen
INTENT:PLAY_MUSIC SONG:Bohemian Rhapsody
INTENT:SET_ALARM TIME:7 am using uCalcSoftware; var uc = new uCalc(); var t = new uCalc.Transformer(); t.DefaultRuleSet.CaseSensitive = false; // Define multiple rules for different intents t.FromTo("play music by {artist}", "INTENT:PLAY_MUSIC ARTIST:{artist}"); t.FromTo("play the song {song_title}", "INTENT:PLAY_MUSIC SONG:{song_title}"); t.FromTo("set an alarm for {time}", "INTENT:SET_ALARM TIME:{time}"); Console.WriteLine(t.Transform("play music by Queen")); Console.WriteLine(t.Transform("play the song Bohemian Rhapsody")); Console.WriteLine(t.Transform("set an alarm for 7 am"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uCalc::Transformer t;
t.DefaultRuleSet().CaseSensitive(false);
// Define multiple rules for different intents
t.FromTo("play music by {artist}", "INTENT:PLAY_MUSIC ARTIST:{artist}");
t.FromTo("play the song {song_title}", "INTENT:PLAY_MUSIC SONG:{song_title}");
t.FromTo("set an alarm for {time}", "INTENT:SET_ALARM TIME:{time}");
cout << t.Transform("play music by Queen") << endl;
cout << t.Transform("play the song Bohemian Rhapsody") << endl;
cout << t.Transform("set an alarm for 7 am") << endl;
}
INTENT:PLAY_MUSIC ARTIST:Queen
INTENT:PLAY_MUSIC SONG:Bohemian Rhapsody
INTENT:SET_ALARM TIME:7 am #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uCalc::Transformer t; t.DefaultRuleSet().CaseSensitive(false); // Define multiple rules for different intents t.FromTo("play music by {artist}", "INTENT:PLAY_MUSIC ARTIST:{artist}"); t.FromTo("play the song {song_title}", "INTENT:PLAY_MUSIC SONG:{song_title}"); t.FromTo("set an alarm for {time}", "INTENT:SET_ALARM TIME:{time}"); cout << t.Transform("play music by Queen") << endl; cout << t.Transform("play the song Bohemian Rhapsody") << endl; cout << t.Transform("set an alarm for 7 am") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t As New uCalc.Transformer()
t.DefaultRuleSet.CaseSensitive = false
'// Define multiple rules for different intents
t.FromTo("play music by {artist}", "INTENT:PLAY_MUSIC ARTIST:{artist}")
t.FromTo("play the song {song_title}", "INTENT:PLAY_MUSIC SONG:{song_title}")
t.FromTo("set an alarm for {time}", "INTENT:SET_ALARM TIME:{time}")
Console.WriteLine(t.Transform("play music by Queen"))
Console.WriteLine(t.Transform("play the song Bohemian Rhapsody"))
Console.WriteLine(t.Transform("set an alarm for 7 am"))
End Sub
End Module
INTENT:PLAY_MUSIC ARTIST:Queen
INTENT:PLAY_MUSIC SONG:Bohemian Rhapsody
INTENT:SET_ALARM TIME:7 am Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t As New uCalc.Transformer() t.DefaultRuleSet.CaseSensitive = false '// Define multiple rules for different intents t.FromTo("play music by {artist}", "INTENT:PLAY_MUSIC ARTIST:{artist}") t.FromTo("play the song {song_title}", "INTENT:PLAY_MUSIC SONG:{song_title}") t.FromTo("set an alarm for {time}", "INTENT:SET_ALARM TIME:{time}") Console.WriteLine(t.Transform("play music by Queen")) Console.WriteLine(t.Transform("play the song Bohemian Rhapsody")) Console.WriteLine(t.Transform("set an alarm for 7 am")) End Sub End Module