如何从Watson Assistant提取特定信息并将序列号存入上下文?
Got it, let's walk through exactly how to pull that serial number (GX0211229342 in your example) and store it in Watson Assistant's context. Here's the step-by-step process:
1. Create a Regex Entity for Serial Numbers
Since your serials can be alphanumeric (like H52WBD1) or pure digits (like 7842344), a regex entity is perfect here—it lets you define a flexible pattern to match these values reliably.
Go to your Watson Assistant workspace, navigate to Entities > Create entity.
Name the entity something clear like
serial_number.Under Entity type, select Regular expression.
For the regex pattern, use:
(?<=serial\s)[A-Za-z0-9]+This pattern uses a positive lookbehind (
(?<=serial\s)) to only capture the alphanumeric sequence immediately following the word "serial" and a space. It ignores the rest of the sentence and grabs exactly your target serial number.Note: If users might phrase it as "serial number is XYZ", adjust the regex to
(?<=serial\s(number\sis\s)?)[A-Za-z0-9]+to cover that variation.
2. Train Your Intent with Example Utterances
Make sure your intent (let's say ask_hostname for this scenario) includes sample utterances that use the serial number pattern. This helps Watson recognize when to trigger the intent and extract the entity.
Examples to add:
- "What is the hostname of serial GX0211229342?"
- "Find the hostname for serial 7842344"
- "Can you tell me the hostname of serial H52WBD1?"
- "Hostname for serial ABC123XYZ please"
3. Store the Extracted Serial in Context
Once Watson detects the serial_number entity in the user's input, you need to save it to the conversation context so you can use it later (like passing it to an API, referencing it in responses, etc.).
- Go to the dialog node that handles your
ask_hostnameintent. - In the Response tab, scroll down to Context.
- Click Add variable, name it
$serial_number(or whatever makes sense for your workflow). - Set the value to:
This pulls the extracted value from the<? entities.serial_number.value ?>serial_numberentity and stores it in the$serial_numbercontext variable.
4. Test It Out
Head to the Try it out panel and type your sample input: "What is the hostname of serial GX0211229342?"
Check the Context tab in the test panel—you should see $serial_number set to "GX0211229342". If it's working, you're good to go!
That's all there is to it. This approach will reliably capture your serial numbers and store them in context for whatever you need to do next.
内容的提问来源于stack exchange,提问作者george jiang

