Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

About Parsing

 [1/8] from: arolls:bigpond:au at: 17-Jul-2001 3:11


I think it's a problem to use in 'opt in a some block, because opt == [value | none] when you do some [value | none] if 'value isn't matched then 'none is matched. (Easy to do!) When none is matched, the cursor is not advanced. Therefore it just keeps matching none forever. You could replace all that with: some [ value1 | value2 | value3 ... | skip ] If it doesn't match any of your values, then it advances the cursor with 'skip. Or Brett's way seems even better.

 [2/8] from: rondon::andrade::uol::com::br at: 16-Jul-2001 19:13


Hi Brett and Anton, The problem is that I need to check specific labels. The Brett solve the problem, but I'm converting some labels to other patterns of metadata, so I need to read the correct labels. I mean: Title, Author, Id, Subject, Source, Abstract, etc. The labels are variant. They are not static. They are not in sequence. I'd like just to check if the file has a label type, so print it. that's it. Do you think I can do this using If inside the parse/all command? Thanks in advance. Rondon

 [3/8] from: brett:codeconscious at: 17-Jul-2001 13:23


Hi Rondon, Response below.
> The problem is that I need to check specific labels. The Brett solve the > problem, but I'm converting some labels to other patterns of metadata, so
I
> need to read the correct labels. I mean: Title, Author, Id, Subject,
Source,
> Abstract, etc. The labels are variant. They are not static. They are not
in
> sequence. > I'd like just to check if the file has a label type, so print it. that's
it. I'm confused as to what you want. I'm also confused as to the pattern of the data. Your example showed a file with bibliographic records - all related to one book I guess. But I'll assume you have multiple books in the file. Checking for specific labels: What is it the text that you need to check for - the label name "Author" or the label value "Kann, James"? Here is some example code to consider. file: {Id: 27698 Author: Kann, James Title: Crossroads of Life Abstract: This book talks about the hard ways of life. Source: State Public Library Holdings: AGE 12308082 Id: 12345 Author: Handley, Brett Title: Uncertainty in my mind's I :) Source: Brett's home collection } ; ----- start of example search-for-labels: func [ "Searches the data file for specific labels." data-file label-types [block!] ] [ parse/all data-file [ any [ copy label to ":" skip any " " copy data to "^/" skip (if find label-types label [print [join label ":" data]]) ] end ] ] search-for-labels file ["Title" "Author"] Brett.

 [4/8] from: al:bri:xtra at: 17-Jul-2001 16:12


Brett wrote:
> I just want to show another way of looking at the problem (based on your
example). <snip!> Brett's way is far nicer! Andrew Martin ICQ: 26227169 http://zen.scripterz.org

 [5/8] from: rondon:andrade:uol at: 16-Jul-2001 6:18


Hi Rebolers!, I'm parsing a text file that was converted from M$word with bibliographic records such as: Id: 27698 Author: Kann, James Title: Crossroads of Life Abstract: This book talks about the hard ways of life. Source: State Public Library Holdings: AGE 12308082 I was parsing the file using this code: parse/all file [ some [ (id: "") (author: "") (title: "") (source: "") (abstract: "") (holdings: "") thru "Id: ^/^/^/" copy id to "^/" thru "Author: ^/^/^/" copy author to "^/" thru "Títle:" thru "^/^/^/" copy title to "^/" thru "Source:" thru "^/^/^/" copy source to "^/" thru "Abstract:" thru "^/^/^/" copy abstract to ^/ thru "Holdings:" thru "^/^/^/" copy holdings to ^/ (print "----------------") (count: count + 1) (print count) (print rejoin [ "Id:" id ]) (print rejoin [ "Title:" title ]) (print rejoin [ "Author:" author ]) (print rejoin [ "Source:" source ]) (print rejoin [ "Abstract:" abstract ]) (print rejoin [ "Holdings:" holdings ]) ] ] The problem is that when one of the labels such as "Abstract" is not present, it is not printing the rest of records present in the file. It just print "false". It does just the records that has all the labels, I mean "Id, Title, Author, Abstract, Holdings and Source", if breaks one rule, it will not print the rest of the record. How can fix that ? or Do I have to use one parse for each of the labels, creating a series variable for each label ? Thanks in advance. Rondon

 [6/8] from: al:bri:xtra at: 16-Jul-2001 21:44


Try: opt [thru "Author: ^/^/^/" copy author to "^/"] opt [thru "Títle:" thru "^/^/^/" copy title to "^/"] opt [thru "Source:" thru "^/^/^/" copy source to "^/"] I hope that helps! Andrew Martin ICQ: 26227169 http://zen.scripterz.org

 [7/8] from: brett:codeconscious at: 16-Jul-2001 20:34


Hi Rondon, I've seen Andrew answer your question. I just want to show another way of looking at the problem (based on your example). file: {Id: 27698 Author: Kann, James Title: Crossroads of Life Abstract: This book talks about the hard ways of life. Source: State Public Library Holdings: AGE 12308082 } parse/all file [ any [ copy label to ":" skip any " " copy data to "^/" skip (print mold reduce [label data]) ] end ] HTH Brett.

 [8/8] from: rondon:andrade:uol at: 16-Jul-2001 8:36


Hi Andrew, It's not working. If I suppress the label 'Abstract' it does until the end. Otherwise, it just takes the first eigtht records then stops. I try to put opt in all thru as you sad, but it stops in a loop. Am I doing something wrong ? Thanks in advance. Rondon