in reply to Parsing the Law

This might be oversimplifying the situation, but it's the only reasonable approach I can think of:

Do two operations: split on /\s*\([a-zA-Z1-90]*\)/ in @texts, and then do a /\s*\(([a-zA-Z1-90]*)\)/g into @sections. Shift off the first element of @texts (should be whatever comes before the first section indicator, which you suggest is null), and then for array element $i, $texts[$i] corresponds to $section[$i].

Now, you simply need to work out the tree structure for this. Create an array of subroutines that parse the appropriate section number at the given level. Eg:

sub major_section { $sec = shift; if ( $sec =~ /^([A-Z])$/ ) { return ( ord $1 - ord 'A' + 1 ); } else { return 0; } }
For each @section in turn, start at one level below the current one in this coderef array and see if it matches; if so, it's at that level, otherwise move backwards in the coderef array until you hit a match. If you don't hit a match, then you want to try for your list starter (which must begin with 1) and if it's a list, run the list until the next section changes.

The only problem is a case like the following:

A. 1. 2. a. 1. list data 2. list data 3. 4.
without more formal guidelines from the original format, you will not be able to determin where A.2.a's list stops and section A.3 begins. Also, this assumes that any other text within parenthesis has whitespace and thus does not look like section headers.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: Parsing the Law
by swiftone (Curate) on May 30, 2001 at 01:10 UTC
    without more formal guidelines from the original format, you will not be able to determin where A.2.a's list stops and section A.3 begins.

    Which is pretty much my problem...the original format is written for humans to read (well, politicians), so as far as I can tell there is no syntactical help, which is why I was hoping for an overarching parser to check for all errors on assumptions, but I can see that that isn't going to handle all cases.

    Back to the drawing board I guess.