Jump to content

Number to Text String And Text To Number (English/Spanish/German/French)


SmOke_N
 Share

Recommended Posts

Link to comment
Share on other sites

Hi,

This library is awesome, good job!

Using the latest update, in the case of Spanish, it still does not behave well in some scenarios:

 

892867881741517

eight hundred ninety two trillion eight hundred sixty seven billion eight hundred eighty one million seven hundred forty one thousand five hundred seventeen 

Actual result:

ochocientos noventa y dos billones ochocientos sesenta y siete mil ochocientos ochenta y un millones setecientos cuarenta y mil quinientos diecisiete 

Espected result:

ochocientos noventa y dos billones ochocientos sesenta y siete mil ochocientos ochenta y un millones setecientos cuarenta y un mil quinientos diecisiete.

The error is in "cuarenta y mil" > cuarenta y un mil.

Edited by Mateocedillo
Link to comment
Share on other sites

  • Moderators

I see, sorry, I was going blind trying to do the logic.  That was a regex over look, nice catch. Looks like I'll be looking to do some (?<!) stuff :'(

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators
2 hours ago, Mateocedillo said:

892867881741517

eight hundred ninety two trillion eight hundred sixty seven billion eight hundred eighty one million seven hundred forty one thousand five hundred seventeen 

Actual result:

ochocientos noventa y dos billones ochocientos sesenta y siete mil ochocientos ochenta y un millones setecientos cuarenta y mil quinientos diecisiete 

Espected result:

ochocientos noventa y dos billones ochocientos sesenta y siete mil ochocientos ochenta y un millones setecientos cuarenta y un mil quinientos diecisiete.

The error is in "cuarenta y mil" > cuarenta y un mil.

I believe I got it ... if not, we'll just call it TexMex 😂

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • SmOke_N changed the title to Number to Text String (English/Spanish ATM) And Text To Number (English/Spanish ATM)
  • Moderators

Fixed a few issues I found on last release (for Spanish number to text) as well as added a text to number feature for Spanish.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

This is my absolute last update (already updated twice today) for a while.  Added a generic way to get the language of the numerical text being passed to _AutCode_TextNumberGetLanguage().  See example in zip.

See ya'll... 👋

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators
2 hours ago, Mateocedillo said:

Hi,

Thanks for the bug fixes! You did a good job!👏🏻

I wrote an wrapper for your library that allows you to combine text and numbers at the same time:NumTextNum_wrapper.au3

And, if you want, I can use your library with a G2p (Grapheme to Phoneme) conversor that I'm doing these days.

Thanks... use it as you wish, if you can find a use for it, it's more than I have atm lol.

I assume that's a personal wrapper, the reason I ask is this block of code

If Not StringRegExp($sString, "\d") Then Return $sString
    $aMatches = StringRegExp($sString, "(\d+)", 3) ; <-- only catches digits, what is delimiters are off?
    If @error Then Return SetError(2, 0, "")
    For $i = 0 To UBound($aMatches) - 1
        ; Define if is decimal:
        $bIsDecimal = StringInStr($aMatches[$i], ",") Or StringInStr($aMatches[$i], ".") ; <-- how do you know what dec delimiter is when you're checking both types?
        If $bIsDecimal Then $sString = StringReplace($sString, ",", ".") ; <-- same with this
        ; Convert:
    Next

is kind of redundant and delimiter specific.  It's more loops than necessary honestly...

I know I used to make my own personal wrappers with funcs that had a lot of parameters and I only used 2 or 3 of them lol... I assume that's what you did :) ... but I would just keep the language and decimal string change, that's all you need.

Something like (untested, just throwing it out there:

Func _NumTextNum_wrapper($sString, $sLanguage = "En", $bIsDecimal = True)
    Local $iLanguageId
    Local $sSeparator
    Switch $sLanguage
        Case "en"
            $iLanguageId = $N2T_LANGENGLISH
            $sSeparator = " point "
        Case "es"
            $iLanguageId = $N2T_LANGSPANISH
            $sSeparator = " punto "
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
    
    $sString = _AutCode_NumberToText($sString, $bIsDecimal, "", $sSeparator, $iLanguageId)
    Return SetError(@error, @extended, $sString)
EndFunc   ;==>_NumTextNum_wrapper

I have also re-written the find language func... but I'm not releasing it yet... I'm actually playing with a different structure idea.  No clue what makes me keep looking at this ... smh

Anyway, I'm not aware of the G2p thing, but best of luck to you all the same! :cheer:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

9 hours ago, SmOke_N said:

Thanks... use it as you wish, if you can find a use for it, it's more than I have atm lol.

I assume that's a personal wrapper, the reason I ask is this block of code

If Not StringRegExp($sString, "\d") Then Return $sString
    $aMatches = StringRegExp($sString, "(\d+)", 3) ; <-- only catches digits, what is delimiters are off?
    If @error Then Return SetError(2, 0, "")
    For $i = 0 To UBound($aMatches) - 1
        ; Define if is decimal:
        $bIsDecimal = StringInStr($aMatches[$i], ",") Or StringInStr($aMatches[$i], ".") ; <-- how do you know what dec delimiter is when you're checking both types?
        If $bIsDecimal Then $sString = StringReplace($sString, ",", ".") ; <-- same with this
        ; Convert:
    Next

is kind of redundant and delimiter specific.  It's more loops than necessary honestly...

I know I used to make my own personal wrappers with funcs that had a lot of parameters and I only used 2 or 3 of them lol... I assume that's what you did :) ... but I would just keep the language and decimal string change, that's all you need.

Something like (untested, just throwing it out there:

Func _NumTextNum_wrapper($sString, $sLanguage = "En", $bIsDecimal = True)
    Local $iLanguageId
    Local $sSeparator
    Switch $sLanguage
        Case "en"
            $iLanguageId = $N2T_LANGENGLISH
            $sSeparator = " point "
        Case "es"
            $iLanguageId = $N2T_LANGSPANISH
            $sSeparator = " punto "
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
    
    $sString = _AutCode_NumberToText($sString, $bIsDecimal, "", $sSeparator, $iLanguageId)
    Return SetError(@error, @extended, $sString)
EndFunc   ;==>_NumTextNum_wrapper

I have also re-written the find language func... but I'm not releasing it yet... I'm actually playing with a different structure idea.  No clue what makes me keep looking at this ... smh

Anyway, I'm not aware of the G2p thing, but best of luck to you all the same! :cheer:

Hi,
Regarding to the matches and regex. The loop that is used is to combine numbers and text at the same time, that is why I have included it. For example.
$sText = "July 23, 2024."
_NumTextNum_wrapper($sText)
So, this can return July twenty three, twenti twenti three becaus the original UDF is not cappable to process text and numbers at same time.

The decimal thing is a good idea that I have to develop as well. Thanks for your suggestions!

Link to comment
Share on other sites

  • Moderators

Yeah, it's not for text and numbers at the same time... that's what we as programmers are supposed to do (which is why I thought you wrote your wrapper... eg. a personal preference) lol... I'm not gonna write an entire parser (well I don't think I am 😶).

Just looking at multiple languages and trying to understand how they are formed just for numbers gives me a headache.

I have an update for this version already... but I'm playing around with a different way of doing things .. while I think the new way is safer atm and has the ability to do more with more languages without getting lost in 10s of thousands of lines of code... I'm noticing a bit of a speed difference... about 15ms, and it's annoying me.  So I'll play around with that for a while to see where it can go if anywhere, then I'll post both versions in the first post.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Ok, added a version that uses SQLite.

It's slower more than likely, so why?

1.  I was just going to use Map funcs, but they're still experimental and I'm a bit weary of something like that for my personal works because it could be removed at any time.

2.  My database skills haven't been used in nearly a decade, I've forgotten more than some know lol.  So I used this for practice to get me started again.

3.  Once it's optimized, it may still be slower, but less code will be needed for future languages and will make it easier to grow.

Having said that last part, I feel safer with the DB version, so I will not be updating the hard code one.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • SmOke_N changed the title to Number to Text String And Text To Number (English/Spanish/German/French)
  • Moderators

Added German and French for giggles, not extensively tested, but passed my mini QA.  Remember, only updating the DB version.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...