#!/usr/bin/perl -ws
use lib ('..');
use lyra;
use Biblio::Thesaurus;
use Biblio::WebPortal;
use strict;
use locale;
my ($userconf,$t,$d);
$userconf = +{
catalog => "ex9-lyracatalog.lst",
thesaurus => (-e "thesaurus.the" ? "thesaurus.the" : "basethesaurus.the"),
name => 'ampp-lyrics',
catsyn => {
asList => sub{ my $file=shift;
return (map {chomp; mastiga($_)} `cat $file`);},
asRelations => sub{ my $f=shift; $f->{asRelations}},
asHTML => sub{ my $f=shift; @{$f->{asHTML}}},
asLaTeX => sub{ my $f=shift; $f->{asLaTeX}},
asText => sub{ my $f=shift; $f->{asText}},
}};
$t = thesaurusLoad("basethesaurus.the");
$d = Biblio::WebPortal::mkdiglib($userconf);
$t->complete();
$t->save("thesaurus.the");
sub mastiga{ my $a = shift;
my $m = lyra::getmusic($a);
for(@{$m->{head}{music}}){next unless /\w/; $t->addTerm(n($_));
$t->addRelation(n($_),'IOF','compositor');}
for(@{$m->{head}{lyrics}}){next unless /\w/; $t->addTerm(n($_));
$t->addRelation(n($_),'IOF','poeta');}
for(@{$m->{head}{singer}}){next unless /\w/; $t->addTerm(n($_));
$t->addRelation(n($_),'IOF','intérprete');}
for(@{$m->{head}{type}}){next unless /\w/; $t->addTerm(n($_));
$t->addRelation(n($_),'BT','tipos de música');}
for(@{$m->{head}{author}}){next unless /\w/; $t->addTerm(n($_));
$t->addRelation(n($_),'IOF','poeta','compositor');}
+{asRelations=>
{(defined $m->{head}{author} ? n1( author => $m->{head}{author}):()),
(defined $m->{head}{lyrics} ? n1( lyrics => $m->{head}{lyrics}):()),
(defined $m->{head}{music} ? n1( music => $m->{head}{music}):()),
(defined $m->{head}{singer} ? n1( singer => $m->{head}{singer}):()),
(defined $m->{head}{type} ? n1( types => $m->{head}{type}):()),
(defined $m->{head}{hasguitar} ? n1( hasguitar => ["acordes"]):()),
(defined $m->{abc} ? n1( hasabc => ["partituras"]):()),
(type => "documento lyra"),
(isa => "música"),
},
asHTML=>[$m->{title},psubt($m->{subti}),"/~jj/musica/html/$m->{file}.html"],
asText => nnl("$m->{title} $m->{subti} $m->{body}"),
asLaTeX => "",
}
}
sub n1{ my ($a,$b)= @_; ($a => [map {n($_)} @$b ]); }
sub n{
my $a=shift;
$a =~ s/\(.*?\)//g;
$a =~ s/[;,:*+?]/ /g;
$a =~ s/ +/ /g;
$a =~ s/^ +| +$//g;
$a || "DESCONHECIDO"
}
sub psubt{
my $a = shift;
$a = join("
",
map {s/([:,()])(\s*)(\w[\w .\-]*\w)/$1$2^$3^/g;$_} split(/;/,$a));
$a ? "$a":$a;
}
sub nnl{
my $a = shift;
$a =~s/\n\s*/ /g;
$a
}