/usr/bin/thesaurusTranslate is in libbiblio-thesaurus-perl 0.43-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | #!/usr/bin/perl -w -s
eval 'exec /usr/bin/perl -w -s -S $0 ${1+"$@"}'
if 0; # not running under some shell
use strict;
use Biblio::Thesaurus;
our ($comment,$dic);
my %AuxDic=();
if ($dic){
open(F,"$dic") or die("cant open auxiliar dictionary\n");
while(<F>){
chomp;
if (/^%\s*enc(oding)?\s+(\S+)/) { binmode(F,"$2:"); next }
if(/(.*?)\s*:\s*([^:\n]*)/){$AuxDic{lc($1)}=$2 }
}
close F;
}
my $thesaurus = shift or die_usage();
my $langorig = shift or die_usage();
my $langdest = shift or die_usage();
my $the = thesaurusLoad($thesaurus);
binmode(STDOUT,"$the->{encoding}:") if defined $the->{encoding};
$langorig = $the->{baselang} if $langorig eq "-";
my $m=$the->meta2str();
$m =~ s/(\%baselang(?:uage)?\s+)([-\w:]+)/$1$langdest/;
print $m;
our $termBody = "";
$the->downtr( {
-order => [qw/PT FR SP ES EN DE BT NT RT MT UF USE SN/],
-default => sub {
if ($the->{languages}{$rel}) { ### Is a language
if ($rel eq "$langdest") {
# $termBody .= "$langorig $term\n"
""
} else {
$termBody .= "$rel ".join(", ",@terms)."\n"
}
} else {
if ($the->{externals}{$rel}) { ### Is external
$termBody .= join("", map { "$rel $_\n" } @terms);
# $termBody .= "$rel $term\n"
} else {
if ($comment) {
$termBody .= join("", map {
my $trans = $the->_translateTerm($_,$langdest,\%AuxDic);
my $t;
if ($t = missing_translation($trans)) {
"# $rel $t\n";
} else {
"$rel $trans\n";
}
} @terms);
} else {
$termBody .= join("", map {"$rel ".$the->_translateTerm($_,$langdest,\%AuxDic)."\n"} @terms);
}
}
}
},
-eachTerm => sub {
my $tterm = $the->_translateTerm($term,$langdest,\%AuxDic);
if ($comment) {
my $t;
if ($t = missing_translation($tterm)) {
print "\n# $t\n$langorig $term\n$termBody";
} else {
print "\n$tterm\n$langorig $term\n$termBody";
}
} else {
print "\n$tterm\n$langorig $term\n$termBody";
}
$termBody = "";
},
});
sub die_usage {
die "Usage: $0 [options] <thesaurus> <lang-source> <lang-target>
Options: -comments # missing translations become comments
-dic=auxiliardic # use an auxiliar dicionary\n";
}
sub missing_translation {
my $t = shift;
if ($t =~ m!^\[[A-Z]+-[A-Z]+:(.*)\]$!) {
return $1
} else {
return undef;
}
}
__END__
=head1 NAME
thesaurusTranslate - Change baselanguage of a thesaurus ISO...
=head1 SYNOPSIS
thesaurusTranslate [ops] thesaurus sourceLang targetLang > f.the
ops:
-comments # missing translations become comments
-dic=auxiliardic # use an auxiliar dicionary
=head1 DESCRIPTION
=head2 EXPORT
=head1 AUTHOR
J.Joao Almeida, jj@di.uminho.pt
=head1 SEE ALSO
perl(1).
Biblio::Thesaurus
=cut
|