in reply to Parsing the Law
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:
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.sub major_section { $sec = shift; if ( $sec =~ /^([A-Z])$/ ) { return ( ord $1 - ord 'A' + 1 ); } else { return 0; } }
The only problem is a case like the following:
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.A. 1. 2. a. 1. list data 2. list data 3. 4.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Parsing the Law
by swiftone (Curate) on May 30, 2001 at 01:10 UTC |