uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
A step-by-step tutorial on building a simple chatbot intent parser using the uCalc Transformer to extract commands and parameters from natural language.
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.
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":
SET_TIMERduration=5, unit=minutesWe want to transform this natural language string into a structured, machine-readable format that our application can easily act upon.
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.
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.
csharp
var t = new uCalc.Transformer();
// Make all rules case-insensitive by default
t.DefaultRuleSet.CaseSensitive = false;
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.
csharp
// Rule for setting a timer
t.FromTo("set timer for {@Number:duration} {unit}", "INTENT:SET_TIMER DURATION:{duration} UNIT:{unit}");
// Rule for playing music by a specific artist
t.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.
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.
csharp
var command = "play music by The Rolling Stones";
var parsed = t.Transform(command);
Console.WriteLine(parsed);
// Output: INTENT:PLAY_MUSIC ARTIST:The Rolling Stones
Your application can then split this string to get the intent and entities and execute the appropriate action.
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.
ID: 1454
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
ID: 1455
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