Servant Posted March 18, 2014 Posted March 18, 2014 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.. http://developingsites.blogspot.com
jdelaney Posted March 18, 2014 Posted March 18, 2014 (edited) 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 March 18, 2014 by jdelaney Servant 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.
Moderators Melba23 Posted March 18, 2014 Moderators Posted March 18, 2014 Servant,Took me about 2 minutes to write something using a RegEx and StringSplit. What have you tried so far that has not worked? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Servant Posted March 18, 2014 Author Posted March 18, 2014 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? 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.. http://developingsites.blogspot.com
Moderators Melba23 Posted March 18, 2014 Moderators Posted March 18, 2014 Servant,So the answer to my question is "nothing" - and you expect us to do all the work for you. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jdelaney Posted March 18, 2014 Posted March 18, 2014 (edited) 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 March 18, 2014 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.
Moderators Solution Melba23 Posted March 18, 2014 Moderators Solution Posted March 18, 2014 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 EndFuncWorks for me. M23 Servant 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jdelaney Posted March 18, 2014 Posted March 18, 2014 (edited) 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 March 18, 2014 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.
Moderators Melba23 Posted March 18, 2014 Moderators Posted March 18, 2014 (edited) 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 March 18, 2014 by Melba23 Typo Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jdelaney Posted March 18, 2014 Posted March 18, 2014 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.
czardas Posted March 18, 2014 Posted March 18, 2014 (edited) 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 March 18, 2014 by czardas operator64 ArrayWorkshop
Moderators Melba23 Posted March 18, 2014 Moderators Posted March 18, 2014 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 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
czardas Posted March 18, 2014 Posted March 18, 2014 (edited) 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 March 18, 2014 by czardas operator64 ArrayWorkshop
UEZ Posted March 18, 2014 Posted March 18, 2014 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
czardas Posted March 18, 2014 Posted March 18, 2014 Melba23, I did as you suggested. #2686 operator64 ArrayWorkshop
jchd Posted March 18, 2014 Posted March 18, 2014 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 hereRegExp tutorial: enough to get startedPCRE 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now