Extract Quantity
Extracts quantities from plain text according to the magnitude or a unit of measurement defined.
Command availability: IBM RPA SaaS and IBM RPA on premises
Description
Legacy NLP provider: Extracts and converts quantity values from plain text, considering a magnitude or a defined unit of measurement.
Watson NLP provider: Extracts quantities from plain text, considering a magnitude or a defined unit of measurement.
The results that this command returns might vary according to the selected NLP provider. For more information, see Setting an NLP provider.
Script syntax
IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.
extractQuantity --type(QuantityTypes) --units(String) --fractions(String) [--culture(String)] --text(String) (List<Numeric>)=values (Numeric)=first (DataTable)=valuesmapping (Boolean)=success
Input parameters
The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.
Designer mode label | Script mode name | Required | Accepted variable types | Description |
---|---|---|---|---|
Magnitude | type |
Required |
QuantityTypes |
Unit of magnitude that is used to extract quantities from the text defined in the Text parameter.See the type parameter options for details. |
Unit of Measurement | units |
Only when Magnitude is Custom |
Text |
Name of the custom unit of measurement that you want to extract. Important:The Units parameter only works with the Legacy provider.
|
Fractions | fractions |
Only when Magnitude is Custom |
Text |
Fractions of the custom unit of measurement. Set the magnitude of the fraction and its value. Important:The Fractions parameter only works with the Legacy provider.
|
Language | culture |
Optional |
Text , Culture |
Language used to extract the quantity. If you define the language manually, make sure to enter only supported language codes. See the culture parameter options for supported
languages.Important:The number formatting changes according to the defined language.
|
Text | text |
Required |
Text |
Input text to have data extracted from. Values entered in the Text parameter must be properly formatted according to the defined Culture . |
culture
parameter options
The following table displays the options available for the culture
input parameter. The table shows the options available when working in Script mode and the equivalent label in the Designer mode.
Designer mode label | Script mode name | Description | Supported provider |
---|---|---|---|
ar |
ar |
Arabic | Watson NLP |
zh-CN |
zh-CN |
Chinese (Simplified) | Watson NLP |
zh-TW |
zh-TW |
Chinese (Traditional) | Watson NLP |
cs |
cs |
Czech | Watson NLP |
da |
da |
Danish | Watson NLP |
nl |
nl |
Dutch | Watson NLP |
de-DE |
de-DE |
German | Watson NLP |
en-US |
en-US |
English | Legacy and Watson NLP |
fi |
fi |
Finnish | Watson NLP |
fr-FR |
fr-FR |
French (France) | Watson NLP |
fr-CA |
fr-CA |
French (Canada) | Watson NLP |
he |
he |
Hebrew | Watson NLP |
it-IT |
it-IT |
Italian | Watson NLP |
ja-JP |
ja-JP |
Japanese | Watson NLP |
ko-KR |
ko-KR |
Korean | Watson NLP |
nb |
nb |
Norwegian Bokmal | Watson NLP |
nn |
nn |
Norwegian Nynorsk | Watson NLP |
pt-BR |
pt-BR |
Portuguese (Brazil) | Legacy and Watson NLP |
pt-PT |
pt-PT |
Portuguese (Portugal) | Legacy and Watson NLP |
pl |
pl |
Polish | Watson NLP |
ro |
ro |
Romanian | Watson NLP |
ru-RU |
ru-RU |
Russian | Watson NLP |
sk |
sk |
Slovak | Watson NLP |
es-ES |
es-ES |
Spanish | Watson NLP |
sv |
sv |
Swedish | Watson NLP |
tr |
tr |
Turkish | Watson NLP |
type
parameter options
The following table displays the options available for the type
input parameter. The table shows the options available when working in Script mode and the equivalent label in the Designer mode.
Designer mode label | Script mode name | Description |
---|---|---|
Unit | Unit |
Uses unit in general as a unit of measurement. |
Mass | Mass |
Uses mass as a unit of measurement. The Legacy NLP provider converts every mass value to kilograms. |
Distance | Distance |
Uses Distance as a unit of measurement. The Legacy NLP provider converts every distance value to meters. |
Volume | Volume |
Uses Volume as a unit of measurement. The Legacy NLP provider converts every volume value to liters. |
Custom | Custom |
Uses a custom unit of magnitude. |
Output parameters
Designer mode label | Script mode name | Accepted variable types | Description |
---|---|---|---|
Values | values | List<Number> |
List of values found in the text. |
First Value Found | first | Number |
First value found in text. |
Values Mapping | valuesmapping | Data Table |
Data table with extracted values mapped by rows and columns. See the valuesmapping parameter options section for details. |
Success | success | Boolean |
Returns True if the extraction succeeds, or False otherwise. |
valuesmapping
parameter options
This parameter returns a data table that contains the occurrence of each quantity value that is extracted from the input text.
The following list shows the mapped values:
- The index value in the list of extracted values. Index values start at 1.
- Position in number of characters where the value was found in the text.
- Length of the extracted value.
- Text from which the quantity was extracted.
- Quantity extracted.
Example
The following examples demonstrate the use of the Extract Quantity command.
Example 1: The culture is defined as en-US, and it uses distance as a unit of magnitude to extract value.
defVar --name result --type Boolean
defVar --name insertedText --type String
defVar --name foundValuesList --type List --innertype Numeric
defVar --name firstValueFound --type Numeric
setVar --name "${insertedText}" --value "The marathoner must run 42,195 meters to run for the prizes."
extractQuantity --type "Distance" --culture en-US --text "${insertedText}" foundValuesList=values firstValueFound=first result=success
logMessage --message "Values Found: ${foundValuesList}\r\nFirst Value Found: ${firstValueFound}\r\nResult: ${result}\r\n" --type "Info"
// Values Found: [42195.0]
// First Value Found: 42195.0
// Result: True
Example 2: The culture is defined as en-US to extract a custom unit (bits) from the text.
defVar --name result --type Boolean
defVar --name insertedText --type String
defVar --name foundValuesList --type List --innertype Numeric
defVar --name firstValueFound --type Numeric
setVar --name "${insertedText}" --value "This file is 125 megabytes in size."
extractQuantity --type "Custom" --units bits --fractions "bytes=8,kilobytes=8192,megabytes=8388608,gigabytes=8589934592" --culture en-US --text "${insertedText}" foundValuesList=values firstValueFound=first result=success
logMessage --message "Values Found: ${foundValuesList}\r\nFirst Value Found: ${firstValueFound}\r\nResult: ${result}\r\n" --type "Info"
// Values Found: [1048576000.0]
// First Value Found: 1048576000.0
// Result: True