Jump to content
Sign in to follow this  
Servant

Function that will return a random spun parameter's value with spin syntax

Recommended Posts

Servant

How to create a function that have a single parameter that contains an article with spin syntax, e.g.:

$param = "{This|This particular|This kind of|This specific|That} {is one of the|is among the|is probably the|is just about the|is amongst the} {sentences|phrases|content|essay sentences|paragraphs} {in the|within the|inside the|inside|from the} {article|post|write-up|content|document} {with|along with|together with|using|having} {spin|rewrite|spin and rewrite|whirl|rotate} {syntax|format}."

And the function that I want to create is such like this:

$return = spinSyntax($param)

Which will return a random spun article that's stored in the variable $param , in every call such like this:

This is one of the paragraphs inside post with spin format.

This topic will be one of the important information here in the AutoIt library if it contain a right solution. Please help..

Share this post


Link to post
Share on other sites
jdelaney

Something like this.  Modify it to suite your needs:

$param = "{This|This particular|This kind of|This specific|That} {is one of the|is among the|is probably the|is just about the|is amongst the} {sentences|phrases|content|essay sentences|paragraphs} {in the|within the|inside the|inside|from the} {article|post|write-up|content|document} {with|along with|together with|using|having} {spin|rewrite|spin and rewrite|whirl|rotate} {syntax|format}."
$a = StringRegExp($param,"\{([^|]+)\|([^|]+)\|?([^|]+)?\|?([^|]+)?\|?([^|]+)?\}",4)
For $i = 0 to UBound($a)-1
    $aTemp = $a[$i]
    ConsoleWrite($aTemp[Random(1,UBound($aTemp)-1,1)] & @CRLF)
Next
Edited by jdelaney
  • Like 1

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Melba23

Servant,

Took me about 2 minutes to write something using a RegEx and StringSplit. What have you tried so far that has not worked? :huh:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Servant

 

Something like this.  Modify it to suite your needs:

$param = "{This|This particular|This kind of|This specific|That} {is one of the|is among the|is probably the|is just about the|is amongst the} {sentences|phrases|content|essay sentences|paragraphs} {in the|within the|inside the|inside|from the} {article|post|write-up|content|document} {with|along with|together with|using|having} {spin|rewrite|spin and rewrite|whirl|rotate} {syntax|format}."
$a = StringRegExp($param,"\{([^|]+)\|([^|]+)\|?([^|]+)?\|?([^|]+)?\|?([^|]+)?\}",4)
For $i = 0 to UBound($a)-1
    $aTemp = $a[$i]
    ConsoleWrite($aTemp[Random(1,UBound($aTemp)-1,1)] & @CRLF)
Next

Wow, you found a good solution in a matter of minutes.. But please see below!

Servant,

Took me about 2 minutes to write something using a RegEx and StringSplit. What have you tried so far that has not worked? :huh:

M23

Sorry, 'cause I'm confused and I'm always forgot the regex because what's in my mind is the question below...

What if the value of the parameter is such like this:

$param = "Note {this is the|this is actually the|here is the|this can be a|this can be the} other {value|worth|benefit|price|importance} of parameter."

The solution of jdelaney will not work properly in that parameter..

Share this post


Link to post
Share on other sites
Melba23

Servant,

So the answer to my question is "nothing" - and you expect us to do all the work for you. :(

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
jdelaney

Well, now you are changing the structure.  If you wrap the other data with the {}, then it will work with a slight modification of the regexp.  Look at the structure, and try to solve it.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Melba23

Servant,

As I have nothing better to do for the moment, try this:

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

$sParam = "{This|This particular|This kind of|This specific|That} {is one of the|is among the|is probably the|is just about the|is amongst the} {sentences|phrases|content|essay sentences|paragraphs} {in the|within the|inside the|inside|from the} {article|post|write-up|content|document} {with|along with|together with|using|having} {spin|rewrite|spin and rewrite|whirl|rotate} {syntax|format}."

While 1
    If MsgBox($MB_YESNO + $MB_SYSTEMMODAL, "Result", _SpinSyntax($sParam) & @CRLF & @CRLF & "Continue?") = 7 Then ExitLoop
WEnd

$sParam = "Note {this is the|this is actually the|here is the|this can be a|this can be the} other {value|worth|benefit|price|importance} of parameter."

While 1
    If MsgBox($MB_YESNO + $MB_SYSTEMMODAL, "Result", _SpinSyntax($sParam) & @CRLF & @CRLF & "Continue?") = 7 Then ExitLoop
WEnd

Func _SpinSyntax($sParam)

    Local $aSplit = StringSplit($sParam, "{}")
    Local $sResult = ""
    For $i = 1 To $aSplit[0]
        $aOption = StringSplit(StringStripWS($aSplit[$i], $STR_STRIPLEADING + $STR_STRIPTRAILING), "|")
        If @error Then
            $sResult &= $aOption[1] & " "
        Else
            $sResult &= $aOption[Random(1, $aOption[0], 1)] & " "
        EndIf
    Next
    Return $sResult

EndFunc
Works for me. ;)

M23

  • Like 1

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
jdelaney

I was making mine work, and came across this:

$iRandom = Random(1,1,1)
$iError = @error
ConsoleWrite($iRandom & @CRLF)
ConsoleWrite($iError & @CRLF)

output:

0
1

shouldn't random of 1 to 1 always return 1?  Random of 1 to 2 can return 1 or 2.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Melba23

jdelaney,

It has been discussed many times and the Devs have always maintained that having the same value as maximum and minimum means that the result is actually not random. Hence you need the @error check as I used. At least nowadays the Help file does clearly state what happens. ;)

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
jdelaney

Oops, didnt check that, thanks.

Anyways, for my code to work on the new string:

$param = "{Something}{This|This particular|This kind of|This specific|That} {is one of the|is among the|is probably the|is just about the|is amongst the} {sentences|phrases|content|essay sentences|paragraphs} {in the|within the|inside the|inside|from the} {article|post|write-up|content|document} {with|along with|together with|using|having} {spin|rewrite|spin and rewrite|whirl|rotate} {syntax|format} {Done}."
$a = StringRegExp($param,"\{([^{|}]+)\|?([^{|}]+)?\|?([^{|}]+)?\|?([^{|}]+)?\|?([^{|}]+)?\}",4)
For $i = 0 to UBound($a)-1
    $aTemp = $a[$i]
    If UBound($aTemp) = 2 Then
        ConsoleWrite($aTemp[1] & @CRLF)
    Else
        ConsoleWrite($aTemp[Random(1,UBound($aTemp)-1,1)] & @CRLF)
    EndIf
Next

Notice that I placed {} surrounding all the options.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
czardas

I think Random() ought to be able to handle any range, so it can be used as jdelaney did. I also believe Max and Min ought to be Val1 and Val2 with no preferance of magnitude. This seems most logical to me. This would be adding functionality without breaking anything.

Edited by czardas

Share this post


Link to post
Share on other sites
Melba23

czardas,

Then put in a feature request - the main opposition to the proposal in the past is no longer in posisiton to block it. I for one would support a plea for Min = Max to return the repeated value. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
czardas

Sure, it can always be rejected. After thinking about this, it might break scripts which rely on this error. I'll first have a think. I wasn't aware that Random() would never return 1 - that's most unfortunate.

The result will be in the range of Min to Max INCLUSIVE when using integers (just short of Max when using floats).

Edited by czardas

Share this post


Link to post
Share on other sites
UEZ

Here my version:
 

#include <Array.au3>
$param = "{This|This particular|This kind of|This specific|That} {is one of the|is among the|is probably the|is just about the|is amongst the} {sentences|phrases|content|essay sentences|paragraphs} {in the|within the|inside the|inside|from the} {article|post|write-up|content|document} {with|along with|together with|using|having} {spin|rewrite|spin and rewrite|whirl|rotate} {syntax|format}."

MsgBox(0, "Spin Syntax", Spin($param))

Func Spin($param)
    Local $a = StringRegExp($param, "(?U){(.+)}", 3)
    If @error Then Return SetError(1, 0, 0)
    Local $i, $b, $sSpin
    For $i = 0 To UBound($a) - 1
        $b = StringSplit($a[$i], "|", 2)
        $sSpin &= $b[Random(0, UBound($b) - 1, 1)] & " "
    Next
    $sSpin = StringTrimRight($sSpin, 1) & "."
    Return $sSpin
EndFunc

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
jchd

Commented.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Emmhor1
      By Emmhor1
      Hi All,

      MAIN QUESTION:
      Is it possible to Call specific function within a GUI

      So I have a script with multiple functions although I don't want to use every function every time.
      My Idea is to create a simple GUI which allows me to select what functions I want to use then run the funtions by clicking a button.
      I have already made a GUI which allows me to select specific .exe's I would like to run after selection it runs the .exe one by one.
      This script is on my work laptops and cannot access it right now.
       
      Who can help me with this?
      GUIcreate
      Func1 
      Func2
      Func3
      Then have a boxes which allows me to select the specif Func.(I used GUIChecked and Unchecked in my other script)
      Then a button which executes/calls the selected functions
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I was trying to insert function header to the functions of my script, but, in the SciTE console, this appears:
      Function or struct definition not found, unable to insert header. @Jos Any suggestion?
      Thanks in advance.

      Best Regards.
    • JNutt
      By JNutt
      I see $hWnd used as a local variable in a lot of script examples.  I know the 'h' is used for handles, but what is the 'Wnd' short for?
      Thanks!
    • Amixg
      By Amixg
      Hi! I have another problem with AutoIT.  You see, I'm still the one who's just starting out with this great programming language. I have a problem with AutoIT, it seems not to recognize the "StringReplace" function even when it is by default. The code was made half in KODA and half of my own. It is a software programmed for the Italian language (I am Italian) and translate the SMS language into Italian correct. Would you help me? Thanks in advance.
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $hull = "hello" StringReplace($hull, "hello", "hellx") $Form1 = GUICreate("Linguaggio SMS A Italiano", 507, 498, 192, 124) $Edit1 = GUICtrlCreateEdit("", 24, 40, 465, 177) GUICtrlSetData(-1, "") $Label1 = GUICtrlCreateLabel("Inserisci qui il testo che non riesci a capire:", 24, 8, 205, 17) $Label2 = GUICtrlCreateLabel("Ecco il testo tradotto(non toccare questo campo):", 27, 237, 237, 17) $Edit2 = GUICtrlCreateEdit("", 24, 264, 465, 137) GUICtrlSetData(-1, "") $Button1 = GUICtrlCreateButton("Traduci", 104, 424, 249, 49) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 StringReplace(GUICtrlGetData($Label1), "qlc", "qualcuno") StringReplace(GUICtrlGetData($Label1), "qls", "qualcosa") StringReplace(GUICtrlGetData($Label1), "ke", "che") StringReplace(GUICtrlGetData($Label1), "x", "per") StringReplace(GUICtrlGetData($Label1), "pls", "per favore") StringReplace(GUICtrlGetData($Label1), "tu6", "tu sei") StringReplace(GUICtrlGetData($Label1), "zzz", "mi fai dormire") StringReplace(GUICtrlGetData($Label1), "hagn", "Buonanotte") StringReplace(GUICtrlGetData($Label1), "tvtb", "Ti voglio tanto bene") StringReplace(GUICtrlGetData($Label1), "tat", "Ti amo tanto") StringReplace(GUICtrlGetData($Label1), "lafs", "Amore a prima vista") StringReplace(GUICtrlGetData($Label1), "fli?", "Flirtiamo?") StringReplace(GUICtrlGetData($Label1), "msidt", "Mi sono innamorato di te") StringReplace(GUICtrlGetData($Label1), "ba", "Bacio") StringReplace(GUICtrlGetData($Label1), "midi", "Mi dispiace.") StringReplace(GUICtrlGetData($Label1), "ntm", "Non ti merito") StringReplace(GUICtrlGetData($Label1), "tdp", "Togliti dai piedi.") StringReplace(GUICtrlGetData($Label1), "amò", "Amore") StringReplace(GUICtrlGetData($Label1), "ap", "A presto!") StringReplace(GUICtrlGetData($Label1), "cmq", "comunque") StringReplace(GUICtrlGetData($Label1), "cvd", "Ci vediamo dopo") StringReplace(GUICtrlGetData($Label1), "Tvb", "Ti voglio bene") StringReplace(GUICtrlGetData($Label1), "nn", "non") StringReplace(GUICtrlGetData($Label1), "risp", "rispondimi") StringReplace(GUICtrlGetData($Label1), "cel", "cellulare") StringReplace(GUICtrlGetData($Label1), "dom", "qualcosa") StringReplace(GUICtrlGetData($Label1), "nm", "numero") StringReplace(GUICtrlGetData($Label1), "fv", "favore") StringReplace(GUICtrlGetData($Label1), "-male", "meno male") StringReplace(GUICtrlGetData($Label1), "disc", "discoteca") StringReplace(GUICtrlGetData($Label1), "se#", "settimana") StringReplace(GUICtrlGetData($Label1), "+ o -", "più o meno") StringReplace(GUICtrlGetData($Label1), "ts", "torno subito") StringReplace(GUICtrlGetData($Label1), "tvtbcoa", "Ti voglio tanto bene come amica") EndSwitch WEnd  
    • Karnalsyn
      By Karnalsyn
      As with a lot of programming, the less manual repetition done to achieve the same outcome...the better.
      I package programs for network deployment at the organization I work for. Sometimes these applications require verbose messaging to the user, and sometimes by special request we have to turn that off and deploy silently.
      The way I currently handle these 2 scenarios is this.
      I have a function that builds the splashwin display screen to variable size depending on message length, and displays the desired message to the end user.
      Then at each point throughout my script as I need to make the user aware of what is currently happening, I inject a splashwin function call with the unique message pertaining to that specific event. ie. "Installing Microsoft Office, please wait..."
      In effort to build a more universal script to handle any type of request submitted. I've incorporated a switch command of '/silent'
      If cmdlineraw detects the usage of that switch when the script is triggered it sets a variable flag, ie. $silent = "on"
      Then at every splashwin call I make, I'm prefixing it with an IF statement that checks for the flag, and then does NOT display the message if that flag is "on". Or does display it if its not. Has worked for me just fine. But while I grow my programming skills and look for more streamlined ways of handling areas I find myself creating repetition. I'm curious if I can relocate that flag check. Taking it out of every single splashwin call, and injecting it into the function itself.
      Example of how I currently display or hide the splashwin based on command line...
      If StringInStr($cmdlineraw, "/silent", 0) Then
          $SilentSwitch = "ON"
      EndIf
      If $SilentSwitch = "OFF" Then SplashWin($Uninstalling & $ProductInfo[1][0])
      Some scripts have dozens of those splashwin calls littered throughout, so Is this the best approach I can take already? Or as stated earlier, can I pull the IF statement away from the splashwin call. And left the function as a whole either activate or deactivate as a result of the command line check.
×