in reply to Parsing the Law

If you're doing it moduleless, why not:

ie

# use this in your rule tests for position my %structure = ( 1 => {qw(a b c d e f g h i etc...)}, 2 => {qw(1 2 3 4 5 6 7 8 9 10 11 12 13 etc...)}, 3 => {qw(A B C D E F G H I etc...)}, 4 => {qw(i ii iii iv v vi vii viii ix x xi etc...)} ); my %legalese; # hash to store text/markers my $key = 2; # key marker to keep order ('1' is tree root) # read into hash while (s/\((\w+)\)(.*?)(\(\w+\))/$3/s) { $legalese{$key}{'list_id'} = $1; $legalese{$key}{'content'} = $2; $key++; } my %node = ( 1 => ''); # node structure tree # initialise with single node # to denote top of page # now work on rules for tree depth my $last_node; # go through markers in order parsed in for (sort {$a <=> $b;} keys %legalese) { # too tired to try to create rule set :) # but set nodes as follows $node{$_}{'parent'} = 'whatever parent node is' # either '1', $last_node, or somewhere in between # using %structure as your guide $last_node = $_; }
The above is in no way final code, but that's the sort of approach I'd take.

Hope that's enough pointers. By knowing what type the previous node was, you can create a valid rule for the next node by asking:

etc, etc...

cLive ;-)

Replies are listed 'Best First'.
Re: Re: Parsing the Law
by swiftone (Curate) on May 30, 2001 at 01:00 UTC
    That is pretty much exactly what I have so far (except that I parsed filter-style, rather than reading it all in at once). It fails to handle lists utterly however, as it sees them as sections...

    By reading them all in as you have done, I could conceivably backtrack and try again if assuming it was a section led to an error, but if this is better done with a "Real" parser I don't want to reinvent the wheel. However, since I have almost no "real" parser experience, I don't know if this is an appropriate situation for one or not.