Commit | Line | Data |
6f0ec5df |
1 | #!/usr/bin/env perl |
2 | |
3 | use lib 'lib'; |
4 | use strict; |
5 | use warnings; |
6 | use Text::Tradition::Directory; |
7 | |
8 | my( $dsn, $user, $pass ) = @ARGV; |
9 | |
10 | my $connect_args = { dsn => $dsn }; |
11 | $connect_args->{'extra_args'} = { user => $user, password => $pass } |
12 | if $user && $pass; |
13 | my $dir = Text::Tradition::Directory->new( $connect_args ); |
14 | |
15 | foreach my $id ( $dir->tradition_ids ) { |
16 | my $scope = $dir->new_scope; |
17 | my $tradition = $dir->lookup( $id ); |
18 | print STDERR "Processing tradition " . $tradition->name . "\n"; |
19 | foreach my $reading ( $tradition->collation->readings ) { |
20 | $reading->alter_text( strip_punct( $reading->text ) ); |
21 | } |
22 | $tradition->collation->flatten_ranks; |
23 | $dir->save( $tradition ); |
24 | } |
25 | |
26 | print STDERR "Done\n"; |
27 | |
28 | sub strip_punct { |
29 | my( $rtext ) = @_; |
30 | my $orig_r = $rtext; |
31 | return $rtext unless $rtext =~ /\w/; |
32 | $rtext =~ s/^\W+//; |
33 | $rtext =~ s/\W+$//; |
34 | print STDERR "Altering $orig_r to $rtext\n" |
35 | unless $orig_r eq $rtext; |
36 | return $rtext; |
37 | } |
38 | |