Jump to content

Recommended Posts

Posted

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.

Posted

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

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

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:

  Reveal hidden contents

 

Posted
  On 8/27/2023 at 6:15 PM, water said:

So maybe the input string isn't fully correct?

Expand  

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 :)

Posted

:)

My UDFs and Tutorials:

  Reveal hidden contents

 

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
×
×
  • Create New...