Example:
I want to type
Rice food China India Spain
and expand it to
Rice is a food that is eaten in China, India, and Spain. <--the structure of the sentence is very rigid so easy to automate based on pre-defined insertion site of the variables.
- China
- India
- Spain
I'm having quite a bit of trouble with this simple, automation task to generate custom but well-defined sentences based on the available texts
I want to be able to press a shortcut that tells ahk to read first or current line of the text (Rice food China India), then using loop parse or which ever function to generate rice=var1, food=var2, china=var3, india=var4 etc...
then generate custom sentense using fields?
%var1% is a %var2% that is eaten in %var3%, %var4%, and %var5%.
- %var3%
- %var4%
- %var5%
- etc....
Thank you!
Automating sentenses using loop parse of a text line?
-
- Posts: 1
- Joined: 24 Dec 2018, 03:42
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: Automating sentenses using loop parse of a text line?
maybe this can help you get started
Code: Select all
wordsare := "Rice food China India Spain"
foodstring := StrSplit(wordsare, A_Space)
msgbox, % foodstring[1] " is a "foodstring[2] " that is eaten in " foodstring[3] " " foodstring[4] " and " foodstring[5]
ExitApp
Re: Automating sentenses using loop parse of a text line?
Here's an attempt. Cheers.
Code: Select all
q:: ;create sentences based on lists
vList := "
(
rice|food|China India Spain
rice|food|China India
rice|food|China
)"
vTextOrig := "[FIELD1] is a [FIELD2] that is eaten in [FIELD3]."
Loop, Parse, vList, `n, `r
{
oTemp := StrSplit(A_LoopField, "|")
oTemp.1 := Format("{:T}", oTemp.1) ;title case
oTemp.3 := StrReplace(oTemp.3, " ", ", ")
oTemp.3 := RegExReplace(oTemp.3, ", (?!.* )", " and ") ;replace last ', ' with ' and '
vText := vTextOrig
Loop, 3
vText := StrReplace(vText, "[FIELD" A_Index "]", oTemp[A_Index])
MsgBox, % vText
}
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Automating sentenses using loop parse of a text line?
Oh WoW I Had TOTALY MIsread your question, my bad... Ooops, Ignore this.
Last edited by CyL0N on 24 Dec 2018, 08:20, edited 1 time in total.
live ? long & prosper : regards
Re: Automating sentenses using loop parse of a text line?
My attempt:
Merry Christmas!
Code: Select all
#NoEnv
WordsStr := "Rice food China India Spain"
WordsArr := StrSplit(WordsStr, A_Space, , 3)
If (WordsArr.Length() <> 3)
ThingStr := WordsStr
Else {
ThingStr := WordsArr[1] . " is a " . WordsArr[2] . " that is eaten in "
ThingVals := StrSplit(WordsArr[3], A_Space)
MaxVal := ThingVals.Length()
For Index, ThingVal In ThingVals
ThingStr .= ThingVal . ((Index = MaxVal) ? "." : (Index = (MaxVal - 1)) ? ", and " : ", ")
For Index, ThingVal In ThingVals
ThingStr .= "`n- " . ThingVal
}
MsgBox, 0, Result, %WordsStr%`n`n->`n`n%ThingStr%
ExitApp
Who is online
Users browsing this forum: No registered users and 218 guests