Helping with loop please!

Discuss RoboTask here
Post Reply
bama
Posts: 2
Joined: Fri Jun 25, 2010 8:04 am
Location: Canada

Helping with loop please!

Post by bama »

I wonder if somebody can help with this.I have 2 folders, the first one has many text files (hundreds), each text file contain one article, the article starts with a title, an empty line, then the first paragraph.The second folder has one text file, in that file there are sentences (hundreds), each sentence is in a separate line.What I need to do is to insert one of the sentences from the file that contain them into each article(after the first paragraph) in each file(in the folder that contains the article files.I recorded the action, and it work fine for the first text, what should I do to make it go automatically from the first text, to do the next and so on to do all of them, I understand that I need a loop but I don't know how to do it, please help!
igimax
Posts: 12
Joined: Wed Jul 07, 2010 3:39 pm
Location: Iran
Contact:

Helping with loop please!

Post by igimax »

Hi
bama . Well I have 2 question! base on your needs:
What I need to do is to insert one of the sentences from the file that
contain them into each article(after the first paragraph)"
. two thing you forgot to mention here:1) What is it between "first paragraph" and "second paragraph"? 2) Adding those lines from second file into those articles, are first line at second file go to first article was found! and second line from second file go to second file article was found and ....?. If your answer for first question is "empty line" and all article files like each other in this matter, and If your second answer is yes, then you can simply use three nested loops. (File Loop\Text Loop\Text Loop) if your answer like those and need more help about these loops let me know..  But if your answers are different than above answers, Please explain them!! (it will be more helpful, if you can upload at least three of those articles somewhere! and give us a link for download them)Good LuckIgImAx
bama
Posts: 2
Joined: Fri Jun 25, 2010 8:04 am
Location: Canada

Helping with loop please!

Post by bama »

Thank You igimax for trying to help.It's how you understood it.So, I want to insert a sentence from the text file (in the second folder), into one of the text files (the articles in the first folder), and repeat that for all of them. The insertion should be at first line of the text file then I should have an empty line, or (the other option: after the first paragraph (after the first paragraph there is the second paragraph but I don't have an empty line in between)I don't understand how to do (File Loop\Text Loop\Text Loop), can you explain in more details how to do it? Thanks.
igimax
Posts: 12
Joined: Wed Jul 07, 2010 3:39 pm
Location: Iran
Contact:

Helping with loop please!

Post by igimax »

Hi
bama
Thank You igimax for trying to help.
. No problem! I will be happy to help others, If I can!
The insertion should be at
first line of the text file then I should have an empty line, or (the
other option: after the first paragraph (after the first paragraph there
is the second paragraph but I don't have an empty line in between)
. The new option need less coding! But I found I was mistaken about one of the RT commands! So! now you can do both options with RT.. Todo both above options you still need those three loops, But the "Insertion Point" place inside second loop and base on which option you choose, writing the codes for each one will be different! (of course!) . The code will do this in simple steps:1) found "Article Files" at first folder by *.txt condition.2) Read lines of founded "Article File"3) Write each lines at new file at another location with the same filename of "Article File"4) When it's reach to "Insertion Point", the sentence line will write at new file.5) After writing all lines go to step 1 to found another "Article File". Your loops should look like this simple codes:(Read/Bold worlds are RT Commands and variable are GREEN/Bold): //---------------------------------------------------------- ------01> File Loop (return "full path & file name" of all files at "Article Folder" that have "*.txt" condition, one by one and store it at a variable. let's call it "ARTICLE_FILENAME")02>>... COUNT_FOUNDED_ARTICLE_FILES += 1 (Add one to this variable, we will use this counter to know which line of "second text files" should be insert to the current "Article file")03>>... NEW_ARTICLE_FILENAME (store new path + same article filename at this variable)04>> Text Loop (read line by line of "ARTICLE_FILENAME" file and store each line at "READ_ARTICLE_LINE")05>>>...Check If "Insertion Point" reach codes?? (base on your choose insertion point will be place here, and if it reach, variable "INSERTION_STATUS" will be True)06>>>... If {INSERTION_STATUS}==True07>>>>... Text Loop (Read Line by line from "Sentence text file" and store it at "READ_SENTENCE_LINE")08>>>>... COUNT_READ_LINES += 1 (Count Read lines from "Sentence text file")09>>>>... IF {COUNT_READ_LINES} == {COUNT_FOUNDED_ARTICLE_FILES}10>>>>>... Write Text File {READ_SENTENCE_LINE} to file {NEW_ARTICLE_FILENAME} (with "Append option" = true)11>>>>>... Write Text File {READ_ARTICLE_LINE} to file {NEW_ARTICLE_FILENAME} (with
"Append option" = true)
12>>>>>... Break13>>><... END IF14>>><... End Loop

15>>> ELSE (INSERTION_STATUS==False)16>>>>... Write Text File
{READ_ARTICLE_LINE}
to file {NEW_ARTICLE_FILENAME}
(with
"Append option" = true)17>><... End IF18>< END LOOP (Read from Article File)19< End Loop (Found "Article Files") //---------------------------------------------------------- ------. you can choose any variable name you like! also at above lines, I write simple algorithm to show you how you can use those loops and I did not write a full code for you! (for instance, some variables should set to 0 or false before/after some conditions or maybe you should add some extra conditions...). But about "Insertion point":First Option (Insert sentence at the beginning of article)----------------------------------------------------------.  you can use a Boolean variable to do this. Just create it (for example FIRST_LINE) before "04" line with "True" value.. at "05>>>" line place an "IF" section by this condition:> IF {First_Line}== True>> FIRST_LINE= False>> INSERTION_STATUS= True> End IFSecond Option (Insert sentence before 4th line)
--------------------------------------------------
.  At text files each line will end with "carriage return (CR)"  (Enter Key). "Text Loop" command at RT, read a line that ended with CR. Each paragraph end with CR, so in fact each paragraph with too many lines can be only one line! To found that, at windows OS, you can open text files with Notepad and then turn of "Word Warp" option from "Format" menu of Notepad.. Ok! base on your infoz! each Article files start with a title line then an empty line and then first paragraph. some thing like this://----------------------Article Title<CR><CR>First Paragraph<CR>Second Paragraph<CR>....//----------------------. therefor, base on above sample, If we read 4 lines at "04>> Text
Loop" line, we will reach to Insertion point! to do that, you will need to create a numerical variable (a Counter) before line "04>> Text
Loop" with 0 value. ( INSERTION_POINT_COUNTER). at "05>>>" line place these codes:> INSERTION_POINT_COUNTER += 1> IF {INSERTION_POINT_COUNTER} == 4 >> INSERTION_STATUS= True
> End IF. Ok, that's should be all you need!?Good LuckIgImAx
Last edited by igimax on Fri Jul 09, 2010 9:13 am, edited 1 time in total.
igimax
Posts: 12
Joined: Wed Jul 07, 2010 3:39 pm
Location: Iran
Contact:

Helping with loop please!

Post by igimax »

Hi
bama .
I'm new at RT world! I knew about array variables at RT but I was mistaken about How I can use them! now, I did some test on array variables and I found the better and faster way to execute above code!(Read/Bold worlds
are RT Commands and variable are GREEN/Bold):
//-------------------------------------------------------- -- ------01> Create Variable ALL_SENTENCES = ""02> Text Loop (Read
Line by line from "Sentence text file" and store it at "READ_SENTENCE_LINE")03>> IF ALL_SENTENCES == Is Empty String04>>> Set Variable ALL_SENTENCES = "{READ_SENTENCE_LINE}" (Expand Value = True)05>> ELSE06>>> Set Variable ALL_SENTENCES = {ALL_SENTENCES},"{READ_SENTENCE_LINE}" (Expand Value = True)
07>> End IF08> End Loop09>> Set
Variable
COUNT_FOUNDED_ARTICLE_FILES = 010>
File Loop
(x:\Article Path\*.txt  put file "Path+Filename" into "ARTICLE_FILENAME")11>> Set Variable NEW_ARTICLE_FILENAME (y:\temp\current article filename.txt)12>> Text Loop (read line by line
of "ARTICLE_FILENAME"
file and store each line at "READ_ARTICLE_LINE")13>>> Check
If "Insertion Point" reach codes?? (base on your choose insertion point
will be place here, and if it reach, variable "INSERTION_STATUS" will be
True)14>>> If {INSERTION_STATUS}==True15>>>> Write Text File {ALL_SENTENCES({COUNT_FOUNDED_ARTICLE_FILES})} to file {NEW_ARTICLE_FILENAME} (with "Append option" = true)16>>>>
Write Text File
{READ_ARTICLE_LINE}
to file {NEW_ARTICLE_FILENAME} (with
"Append option" = true)
17>>> ELSE (INSERTION_STATUS==False)18>>>> Write Text File
{READ_ARTICLE_LINE}
to file {NEW_ARTICLE_FILENAME}
(with
"Append option" = true)19>>> End IF20>> END LOOP (Read from "Article File")21>> Set
Variable
COUNT_FOUNDED_ARTICLE_FILES
+= 1 22>
End Loop
(Found another "Article File")
//-------------------------------------------------------- -- ------. This new way will be so much faster and have better algorithm! Insertion Point check codes, will be the same as before!. Do not forget to put those "" at lines 04 and 06 around the variable.Good LuckIgImAx
Post Reply