some debugger-friendly params
[scpubgit/stemmatology.git] / script / orth_case_links.pl
CommitLineData
a0a550ef 1#!/usr/bin/env perl
2
3use lib 'lib';
4use strict;
5use warnings;
6use Text::Tradition::Directory;
7
8binmode STDERR, ':utf8';
9binmode STDOUT, ':utf8';
10eval { no warnings; binmode $DB::OUT, ':utf8' };
11
12my( $dsn, $user, $pass ) = @ARGV;
13
14my $connect_args = { dsn => $dsn };
15$connect_args->{'extra_args'} = { user => $user, password => $pass }
16 if $user && $pass;
17my $dir = Text::Tradition::Directory->new( $connect_args );
18
19foreach my $text ( $dir->traditionlist ) {
20 my $id = $text->{'id'};
21 my $scope = $dir->new_scope;
22 my $tradition = $dir->lookup( $id );
23 print STDERR "Processing tradition " . $tradition->name . "\n";
24 my $c = $tradition->collation;
25 foreach my $rank ( 1 .. $c->end->rank - 1 ) {
26 my @readings = $c->readings_at_rank( $rank );
27 while( @readings ) {
28 my $r = pop @readings;
29 next if $r->is_meta;
30 my @orthmatch = grep { lc( $r->text ) eq lc( $_->text ) } @readings;
31 foreach my $om ( @orthmatch ) {
32 unless( $c->get_relationship( $r, $om ) ) {
33 print STDERR sprintf( "Adding orthographic link for %s / %s\n",
34 $r->text, $om->text );
35 $DB::single = 1;
36 $c->add_relationship( $r, $om,
37 { 'type' => 'orthographic', 'scope' => 'global' } );
38 }
39 }
40 }
41 }
42 $dir->save( $tradition );
43}
44
45print STDERR "Done\n";