August 13, 200322 yr Hi, I have the following script which is supposed to create a keyword list from a long text field. Where it is failing is that certain times either a letter or series of letters, not only comes up to be replaced in the text, but also comes at the end of other words in the text. For instance, I have the script replace the word "MB ", but then when "dumb " appears, it becomes "du". Eventually, if the text is long enough, it all starts to deteriorate, since then "du" is a two-letter word to be deleted, and so on, until there's little but garbage left, not keywords. Here's the script: Go to Record/Request/Page [ First ] Loop Set Field [ CommonWords_Holder, CommonWords2 ] (This sets a global to the text field contents) Loop Exit Loop If [ WordCount(CommonWords_Holder) ? 1 ] Set Field [ CommonWords_Holder, Trim(CommonWords_Holder) ] Copy [ Word_Copy ] [ Select entire contents ] (this retrieves the first word of the text from a calc field which holds it) Paste [ Global_Text_Holder ] [ Select entire contents ] (This is a text global for holding the first word) Go to Field [ CommonWords_Holder ] [ Select/perform ] Perform Find/Replace [ Find: Global_Text_Holder_Calc; Replace:
August 13, 200322 yr Try replacing based on " " & Global_Text_Holder & " ". This ensures that ' dumb ' is left alone while ' mb ' is removed.
August 13, 200322 yr Author Hi-- Actually, the reason I didn't do that is it creates another bug. When a word is first in the list, normally, there is no space in front of it. So if the word is "Foo ", It will never be replaced, and so the script keeps printing "Foo " endlessly in the keywords field. So the problem is that I don't know how to account for both instances. All My Best, Jeffrey
August 13, 200322 yr If CommonWords_Holder is the field containing the text, simply prepend/append a " " wherever you require it. E.g. Set Field[ CommonWords_Holder, " " & Trim(CommonWords_Holder) & " "]. Will that work for you?
August 13, 200322 yr So add a space to the list before you start replacing, and remove it at the end.
August 13, 200322 yr Here is an alternative way that is a bit more efficent 1. Create a global number field g_WordCount 2. Change your CommonWords_Holder to a text field. 3. Create a 1 to 1 self relationship (UniqueID::UniqueID) 4. Create a value list "Keywords" that uses values from related field selfjoin::CommonWords_Holder Your Script would be: set field [g_WordCount, wordcount(CommonWords2)] loop if [length(leftwords(rightwords(CommonWords2,g_WordCount),1))>3] set field [CommonWords_Holder,CommonWords_Holder& Leftwords(Rightwords(CommonWords2,g_WordCount),1)& "PP"] end if set field [g_WordCount, g_Wordcount-1] exit loop if [g_wordcount=0] end loop set field [CommonWords_Holder, ValueListItems(status(currentFileName, "KeyWords")) This adds every word larger than 3 letters to WordCount_Holder seperated by carrige returns, then uses the valuelistitems function to filter out duplicates and alphabetize. Just tested it out- works great. I hope that is what you wanted...Anyway, had some time to kill. -Raz
Create an account or sign in to comment