AutoHotkey Community

It is currently May 27th, 2012, 12:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: October 7th, 2011, 12:49 pm 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
[fixed] Doesn't work if you have just a single line quote to memorize. Can anyone spot my current problem. Or have ideas on this might be simplified?

This function is intended to replace words with underscores so you can practice memorizing things. It's called Cloze Deletion. Every time I work on this I break it in a new way.

Code:
AutoTrim Off

v_Quote :=
(
"Let the first act of every morning be to make thefollowing resolve for the day:`nI shall not fear anyone on Earth`nI shall fear only God`nI shall not bear ill will toward anyone`nI shall not submit to injustice from anyone`nI shall conquer untruth by truth. And in resisting`nuntruth, I shall put up with all suffering`n- Mahatma Gandhi"
)

v_Quote2 := "Okay so now if you have a single line it doesn't work?"

msgbox, % f_Cloze(v_Quote, 20)
Msgbox, % v_Quote

msgbox, % f_Cloze(v_Quote2, 20)
Msgbox, % v_Quote2

; later I will reference some files with quotes I want to memorize
; Loop, %A_ScriptDir%\Memorizing\*.txt
; {
;   FileRead, v_File, %A_LoopFileFullPath%
;   msgbox, % f_Cloze(v_File, 20)
;   msgbox, % v_File
; }
return


; replace random words with __, trying to do it x percent of the time. f_Cloze(v_Text, v_Percent)
f_Cloze(v_Text, v_Percent)
{
  ; this bulky mess create a list of ones and zeros
  ; which when sorted randomly let me change exactly
  ; the right number of words (percentage)
  StringSplit, v_TextA, v_Text, %A_Space%
  v_PercentSpecific := ((v_TextA0 * v_Percent) / 100)
  Loop, %v_TextA0%
  {
    if (A_Index = 1) ; it would have to be at least 1% to be useful anyway
      v_ListPercentage := "1"
    if (A_Index > v_PercentSpecific)
      v_ListPercentage := v_ListPercentage . "`r`n0"
    if (A_Index <= v_PercentSpecific)
      v_ListPercentage := v_ListPercentage . "`r`n1"
  }
  Sort, v_ListPercentage, Random
  StringSplit, v_PIndex, v_ListPercentage, `n, `r
  Loop, Parse, v_Text, %A_Space%, `r`n
  {
    if (v_PIndex%A_Index% = 0)
    {
      v_Clozed := v_Clozed . A_Space . A_LoopField
    }
    if (v_PIndex%A_Index% = 1)
    {
      ; using [a-zA-Z-] avoids replacing linefeeds
      v_New := RegexReplace(A_LoopField, "[a-zA-Z-']", "_")
      v_Clozed := v_Clozed . A_Space . v_New
    }
  }
  return v_Clozed
}
return


Last edited by keybored on October 10th, 2011, 12:20 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 7th, 2011, 1:38 pm 
Offline

Joined: April 16th, 2011, 7:18 am
Posts: 176
Location: Jogjakarta, Indonesia
Maybe these lines ?
Code:
  v_PercentSpecific := ((v_TextA0 * v_Percent) / 100)
  Loop, %v_TextA0%
  {
    if (A_Index = 1) ; it would have to be at least 1% to be useful anyway
      v_ListPercentage = 1
    if (A_Index > v_PercentSpecific)
      v_ListPercentage = %v_ListPercentage%`r`n0
    if (A_Index <= v_PercentSpecific)
      v_ListPercentage = %v_ListPercentage%`r`n1
  }

_________________
AHK_Lw 1.1.05, OS: XP SP3, Firefox 3


Last edited by j[]hn on October 7th, 2011, 2:20 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 7th, 2011, 2:09 pm 
Offline

Joined: October 11th, 2010, 6:15 pm
Posts: 1211
Location: Right behind you
I would get used to this:
Code:
Msg := "This is a single line of text."
MsgBox % Msg

_________________
COM Tutorial for Webpages
COM Tutorial for Excel


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 7th, 2011, 3:09 pm 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
j[]hn, Thanks!! That was it.

Mickers, Yes I've tried to learn := some before. I guess I can take my old code swap = for := and post what I break on the forum to get help fully understanding.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2011, 12:18 am 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
I switched to using := and %. Didn't break anything.
Code works well enough for me now too.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, chaosad, Google Feedfetcher, Yahoo [Bot] and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group