Extract Numbers

Extracts numeric values from the text.

Command availability: IBM RPA SaaS and IBM RPA on premises

Description

Extracts numeric values from the text that you provide.

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.

extractNumber [--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
Language culture Optional Text, Culture Language in which the text is written. The numeric value might vary according to the language.

If you define the language manually, make sure to enter only supported language codes. See the culture parameter options for supported languages.

Remember:The decimal notation might change according to the defined language.
Text text Required Text Text containing the numeric values to extract.

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

Output parameters

Designer mode label Script mode name Accepted variable types Description
Values values List<Number> Returns a list containing the numeric values extracted from the text defined in the Text parameter.
First value first Number Returns the first numeric value extracted from the text defined in the Text parameter.
Values mapping valuesmapping Data Table Returns a data table with the extracted numeric values and their mapped information. See valuesmapping parameter options for details.
Success success Boolean Returns True, if the command succeeds in extracting numeric values, otherwise returns False.

valuesmapping parameter options

This parameter returns a data table with details of the extracted values.

The following list shows the mapped values:

  • The index value in the list of extracted numbers. Index values start at 1.
  • Position in number of characters where the value first appears in the text.
  • Length of the numeric value.
  • Extracted part of the text that contains the number.
  • Extracted number converted to a numeric value.

Example

Example 1: Extracts numbers written as text and converts them to a number format.

defVar --name values --type List --innertype Numeric
defVar --name firstValue --type Numeric
defVar --name valueMappings --type DataTable
defVar --name success --type Boolean
setNlpProvider --provider "Legacy"
// Define the text to extract the text from.
extractNumber --culture "en-US" --text "I\'m seventeen years old. My mother is forty-one years old, and my dad is fifty eight. I have three cats." values=values firstValue=first valueMappings=valuesmapping success=success
// Return the values in the console.
logMessage --message "Numbers extracted: ${values}\r\nFirst number: ${firstValue}\r\nMappings: ${valueMappings}" --type "Info"
// Output:
// Numbers extracted: [17.0,50.0,3.0]
// First number: 17.0
// Mappings: 1, 4, 9, seventeen, 17
// 2, 73, 5, fifty, 50
// 3, 93, 5, three, 3

Example 2: Extracts simple monetary values from the text.

defVar --name values --type List --innertype Numeric
defVar --name firstValue --type Numeric
defVar --name valueMappings --type DataTable
defVar --name success --type Boolean
setNlpProvider --provider "Legacy"
extractNumber --culture "en-US" --text "Can I get $500 back from that transaction? Maybe if I give you $4,000 up front, you can give that discount. But I only have $1,326.78 with me right now, let me go to the bank to give you the rest. " values=values firstValue=first valueMappings=valuesmapping success=success
logMessage --message "Numbers extracted: ${values}\r\nFirst number: ${firstValue}\r\nMappings: ${valueMappings}" --type "Info"
// Output:
// Numbers extracted: [500.0,4000.0,1326.78]
// First number: 500.0
// Mappings: 1, 10, 4, $500, 500
// 2, 62, 6,  $4,00, 4000
// 3, 123, 9,  $1,326.7, 1326.78