Jump to content

Nested Spintax in AutoIt?


Recommended Posts

I was trying to use the script here:

But this is the console output I'm getting from the example provided:

Hello World!|Greetings Everyone, C++ is an awesome|n astonishing programming language.
Howdy Dude!|Good Day Everyone, Java is an awesome| wonderful programming language.
Hi Dude!|Excuse Me Everyone, C is an amazing| wonderful programming language.
Howdy World!|Excuse Me Ladys and Gents, Java is an awesome|n astonishing language.

It can handle spintax that isn't nested, but not nested.

I'm currently using python for spintax, using this library https://github.com/AceLewis/spintax

But I'd love to not have to make that py CMD call and just use AutoIt instead.

Link to comment
Share on other sites

Which of the code examples did you try? The one by svenadamsson or the one by qsek?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I have already run this code and - as far as I can tell - the result doesn't look bad.

I tested your first result

Hello World!|Greetings Everyone, C++ is an awesome|n astonishing programming language.

and to me it looks correct. 
I understand the "extra" pipe character after "World!" and "|n" after "awesome" to be correct as they are - as far as I understand the Spintax syntax - literals.
So maybe the input string isn't fully correct?
Or it is me ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

5 minutes ago, water said:

So maybe the input string isn't fully correct?

Ah I think this may have been it.
The pipes shouldn't be there, of course, that threw me off, but I tried with this simpler example:
 

$spintext = "{Hello{ooo| There}|Hi}, how's it going?"

And got:

Helloooo, how's it going?
Hi, how's it going?
Hi, how's it going?
Hello There, how's it going?

So yeah, script works, the input string in the example isn't valid spintax :)

 

For future reference, a working script an example for nested spintax in Autoit:
 

;Spintax Test
#include <Array.au3>
; Text in Spintax format
;~ Global $a = 1
$spintext = "{Hello{ooo| There}|Hi}, how's it going?"

ConsoleWrite(Spintax($spintext) & @CRLF)
ConsoleWrite(Spintax($spintext) & @CRLF)
ConsoleWrite(Spintax($spintext) & @CRLF)
ConsoleWrite(Spintax($spintext) & @CRLF)


Func Spintax($sInput)
;~     ConsoleWrite("- Iteration "&$a&" Start -" & @CRLF)
    $SpinArray = StringRegExp($sInput, '{([^{]*?|[^{]*?)}',3); Global matches
;~     _ArrayDisplay($SpinArray,"")
    $sfinrep = StringReplace($sInput,"}|{","|") ; look For final replacing
    If Not IsArray($SpinArray) Then
;~         ConsoleWrite("!No Array!" & @CRLF)
        If $sfinrep = $sInput then ; Nothing replaced, so free of }|{  --> end string
;~             ConsoleWrite("+EndResult: " & @CRLF)
            Return $sInput
        EndIf
        ;else replace workstring with the string without }|{ for further processing
        $sInput = $sfinrep
        $SpinArray = StringRegExp($sInput, '{([^{]*?|[^{]*?)}',3); Global matches
;~         ConsoleWrite("final replaced string:"  & @CRLF)
;~         ConsoleWrite($sInput & @CRLF)
    EndIf

    $TrimmedText = StringRegExpReplace($sInput, '{([^{]*?|[^{]*?)}',chr(0x1A)); or any other special char to mark where to insert

    $RNDText = $TrimmedText
    For $i = 0 To UBound($SpinArray)-1
        $WordArray = StringSplit($SpinArray[$i], "|",3)
        $rnum = Random(0, UBound($WordArray)-1, 1); get random Array index
        $RNDText = StringReplace($RNDText, chr(0x1A), $WordArray[$rnum],1); replace only the next occurrence
    Next

;~     ConsoleWrite($RNDText & @CRLF)
;~     ConsoleWrite("- Iteration "&$a&" End -" & @CRLF)
;~     $a += 1

    Return Spintax($RNDText)
EndFunc

Thanks @qsek and @water :)

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

×
×
  • Create New...