Format number in text to be number

Hi.
I need to transform numbers in text, for example onehundredone to 101. It is a input from users so a combine of entity and listeners would work.

1-100 is easy fix by this (swedish); Verbala_nummer.list where it also contains a NLU variable.

The problem is bigger number.

I got this LO: KARDINALTAL.LIST

But problem is it doesnt contain NLU variable. And doesnt contain all numbers that I need.

Can I add this, and what script, or do you know some else LO to use?

Hi @Raquell ,

the situation in Swedish is as you described, and it is not possible to modify a Language Object / Entity which is part of the Lexical Resources. You could create your own custom entity though and include the required NLU variable (and all numbers that you need).
Do you know the range of numbers that you would need to cover here?
/Benjamin

We want it for all numbers but at most, for first case, it could be 6 numbers in a row that could possible come in as a word instead of numbers.

Do you have some tips and best practice of how to do it in the most effective way?

I also have another question, say that I have a input that looks like this; one 5 threehoundred 9

How can I make my entity work for all so I get 153009?

1 Like

Hello @Raquell
Just as Benjamin mentions, you can create a custom entity, re-using the numbers already available with NUMMER.ENTITY, and then expand it with your own custom numbers, either by using existing LOBs or bare words, or creating sub-lobs and/or entities for better organization if you have many.

MINA_NUMMER.ENTITY:

nNumber
%NUMMER.ENTITY lob.nNumber
tvĂĄhundra 200
trehundra 300
fyrahundra 400
femhundra 500
etc…

To solve your specific use case, one idea could be to create a Language Object NUMBER_EXTRACTOR using the custom entity just created, and with the condition:

(%MINA_NUMMER.ENTITY^{digits<<lob.nNumber.toString()} >> %MINA_NUMMER.ENTITY^{digits<<lob.nNumber.toString()} >> (%MINA_NUMMER.ENTITY^{digits<<lob.nNumber.toString()}):o >> (%MINA_NUMMER.ENTITY^{digits<<lob.nNumber.toString()}):o >> (%MINA_NUMMER.ENTITY^{digits<<lob.nNumber.toString()}):o >> (%MINA_NUMMER.ENTITY^{digits<<lob.nNumber.toString()}):o )^{finalNumber=digits.join('')}

(The LOB needs the NLU variables “digits” and finalNumber" declared)

The first and second match of MINA_NUMMER.ENTITY are made mandatory (assuming here that the biggest number the entity covers are in the hundreds, so at least two matches, for example “tvåhundra trehundra”, are needed for a 6 digit number). The rest of the operands are optional for the cases where the user says smaller numbers at a time. Once a number is matched, they are converted to strings and appended to a temporary array. At the end joining them into the final string.

In the Trigger condition, a predicate script is added to ensure the entity only triggers in the case the number is 6 characters long, and if so the value of the variable from the LOB is saved to a flow/session variable:

%NUMBER_EXTRACTOR:{lob.finalNumber.length()==6}^{MyFlowVar=lob.finalNumber}

I hope this helps!
Regards Lina

1 Like